aov-agent 1.0.0 → 1.0.1
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/README.md +250 -1
- package/dist/agent-ui/components/Assistant/AgentButton/AgentButton.js +28 -0
- package/dist/agent-ui/components/Assistant/AgentButton/AgentButton.scss +40 -0
- package/dist/agent-ui/components/Assistant/Assistant.js +73 -0
- package/dist/agent-ui/components/Assistant/Assistant.scss +3 -0
- package/dist/agent-ui/components/Assistant/AssistantWidget/AssistantWidget.js +187 -0
- package/dist/agent-ui/components/Assistant/AssistantWidget/AssistantWidget.scss +211 -0
- package/dist/agent-ui/components/Assistant/AssistantWidget/components/CampaignRendered.js +30 -0
- package/dist/agent-ui/components/Assistant/AssistantWidget/components/ListChat.js +129 -0
- package/dist/agent-ui/components/Assistant/Markdown/MarkdownText.js +228 -0
- package/dist/agent-ui/components/Assistant/Markdown/MarkdownText.scss +222 -0
- package/dist/agent-ui/components/Assistant/Markdown/MathRenderer.js +46 -0
- package/dist/agent-ui/components/Assistant/Suggestions/Suggestions.js +62 -0
- package/dist/agent-ui/components/Assistant/Suggestions/Suggestions.scss +22 -0
- package/dist/agent-ui/components/Assistant/ThreadProvider.js +482 -0
- package/dist/agent-ui/components/Assistant/ToolResult/CardTool.js +41 -0
- package/dist/agent-ui/components/Assistant/ToolResult/ToolResult.js +20 -0
- package/dist/agent-ui/components/ResizableModal/ResizableModal.js +262 -0
- package/dist/agent-ui/components/ResizableModal/ResizableModal.scss +117 -0
- package/dist/agent-ui/contexts/AgentContext.js +39 -0
- package/dist/agent-ui/contexts/SuggestionsContext.js +64 -0
- package/dist/agent-ui/contexts/ThreadContext.js +60 -0
- package/dist/agent-ui/hooks/useFetchApi.js +238 -0
- package/dist/agent-ui/hooks/useStreamApi.js +127 -0
- package/dist/agent-ui/index.js +1 -0
- package/dist/agent-ui/services/errorService.js +39 -0
- package/dist/agent-ui/utils/api.js +164 -0
- package/package.json +26 -9
- package/dist/index.js +0 -7
- package/types/index.d.ts +0 -5
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
.AOV-Sidekick__Container {
|
|
2
|
+
position: relative;
|
|
3
|
+
background-color: #fff;
|
|
4
|
+
height: 100%;
|
|
5
|
+
padding-bottom: 5px;
|
|
6
|
+
|
|
7
|
+
.Polaris-Spinner--sizeSmall {
|
|
8
|
+
height: 20px;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.AOV-Sidekick__Loading {
|
|
13
|
+
display: flex;
|
|
14
|
+
justify-content: center;
|
|
15
|
+
align-items: center;
|
|
16
|
+
height: 100%;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.assistant-markdown-text {
|
|
20
|
+
// Container for markdown content rendering
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.aui-thread-root {
|
|
24
|
+
height: 100%;
|
|
25
|
+
font-family: Arial, Helvetica, sans-serif;
|
|
26
|
+
display: flex;
|
|
27
|
+
flex-direction: column;
|
|
28
|
+
padding-bottom: 20px;
|
|
29
|
+
button {
|
|
30
|
+
cursor: pointer;
|
|
31
|
+
}
|
|
32
|
+
.aui-thread-message-content {
|
|
33
|
+
font-size: 14px;
|
|
34
|
+
}
|
|
35
|
+
.aui-avatar-root img {
|
|
36
|
+
width: 32px;
|
|
37
|
+
height: 32px;
|
|
38
|
+
max-width: 32px;
|
|
39
|
+
max-height: 32px;
|
|
40
|
+
border-radius: 16px;
|
|
41
|
+
}
|
|
42
|
+
.aui-thread-viewport {
|
|
43
|
+
flex: 1;
|
|
44
|
+
overflow-y: auto;
|
|
45
|
+
scrollbar-width: thin;
|
|
46
|
+
padding: 1rem 0;
|
|
47
|
+
display: flex;
|
|
48
|
+
flex-direction: column;
|
|
49
|
+
gap: 6px;
|
|
50
|
+
.aui-thread-welcome-root {
|
|
51
|
+
text-align: center;
|
|
52
|
+
display: flex;
|
|
53
|
+
flex-direction: column;
|
|
54
|
+
align-items: center;
|
|
55
|
+
gap: 8rem;
|
|
56
|
+
justify-content: center;
|
|
57
|
+
height: 100%;
|
|
58
|
+
padding: 1rem;
|
|
59
|
+
.aui-thread-welcome-center {
|
|
60
|
+
display: flex;
|
|
61
|
+
flex-direction: column;
|
|
62
|
+
align-items: center;
|
|
63
|
+
gap: 8px;
|
|
64
|
+
}
|
|
65
|
+
.aui-thread-welcome-message {
|
|
66
|
+
font-weight: 500;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
.aui-thread-welcome-suggestion-container {
|
|
70
|
+
display: grid;
|
|
71
|
+
grid-template-columns: 1fr 1fr;
|
|
72
|
+
gap: 0.75rem;
|
|
73
|
+
width: 100%;
|
|
74
|
+
max-width: 500px;
|
|
75
|
+
margin: 0 auto;
|
|
76
|
+
.aui-thread-welcome-suggestion {
|
|
77
|
+
font-family: Arial, Helvetica, sans-serif !important;
|
|
78
|
+
background-color: transparent;
|
|
79
|
+
border: 1px solid #e0e0e0;
|
|
80
|
+
border-radius: 10px;
|
|
81
|
+
padding: 6px 12px;
|
|
82
|
+
font-size: 12px;
|
|
83
|
+
cursor: pointer;
|
|
84
|
+
font-weight: 500;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
.aui-user-message-root {
|
|
88
|
+
padding: 1px 12px;
|
|
89
|
+
display: flex;
|
|
90
|
+
justify-content: flex-end;
|
|
91
|
+
margin-left: 2rem;
|
|
92
|
+
.aui-user-message-content {
|
|
93
|
+
width: fit-content;
|
|
94
|
+
padding: 4px 12px;
|
|
95
|
+
background-color: rgb(241, 241, 241);
|
|
96
|
+
border-radius: 10px;
|
|
97
|
+
p {
|
|
98
|
+
word-break: break-word;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
.aui-assistant-message-root {
|
|
103
|
+
display: flex;
|
|
104
|
+
flex-wrap: wrap;
|
|
105
|
+
gap: 6px;
|
|
106
|
+
padding: 1px 12px;
|
|
107
|
+
margin-right: 6px;
|
|
108
|
+
.aui-assistant-message-content {
|
|
109
|
+
width: calc(100% - 40px);
|
|
110
|
+
max-width: 100%;
|
|
111
|
+
}
|
|
112
|
+
.aui-assistant-action-bar-root {
|
|
113
|
+
height: 20px;
|
|
114
|
+
left: 0px;
|
|
115
|
+
&[data-floating='true'] {
|
|
116
|
+
display: none;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
.aui-branch-picker-root {
|
|
120
|
+
display: flex;
|
|
121
|
+
align-items: center;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
img {
|
|
125
|
+
display: block;
|
|
126
|
+
width: 100%;
|
|
127
|
+
height: auto;
|
|
128
|
+
object-fit: contain;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
.aui-thread-viewport-footer {
|
|
132
|
+
height: fit-content;
|
|
133
|
+
min-height: 85px;
|
|
134
|
+
display: flex;
|
|
135
|
+
flex-direction: column;
|
|
136
|
+
justify-content: end;
|
|
137
|
+
width: 100%;
|
|
138
|
+
padding: 12px;
|
|
139
|
+
background-color: #fff;
|
|
140
|
+
gap: 8px;
|
|
141
|
+
.aui-composer-root {
|
|
142
|
+
display: flex;
|
|
143
|
+
align-items: center;
|
|
144
|
+
gap: 8px;
|
|
145
|
+
padding: 4px 8px;
|
|
146
|
+
border: 1px solid #e0e0e0;
|
|
147
|
+
border-radius: 16px;
|
|
148
|
+
background-color: #ffffff;
|
|
149
|
+
.aui-composer-input {
|
|
150
|
+
width: 100%;
|
|
151
|
+
font-family: Arial, Helvetica, sans-serif;
|
|
152
|
+
resize: none;
|
|
153
|
+
border: none;
|
|
154
|
+
outline: none;
|
|
155
|
+
background-color: transparent;
|
|
156
|
+
font-size: 12px;
|
|
157
|
+
padding-left: 6px;
|
|
158
|
+
scrollbar-width: none;
|
|
159
|
+
max-height: 200px;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
.aui-button {
|
|
164
|
+
border: none;
|
|
165
|
+
height: 24px;
|
|
166
|
+
background-color: transparent;
|
|
167
|
+
svg {
|
|
168
|
+
width: 16px;
|
|
169
|
+
height: 16px;
|
|
170
|
+
}
|
|
171
|
+
span {
|
|
172
|
+
display: none;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
.Polaris-Scrollable {
|
|
178
|
+
scrollbar-width: thin;
|
|
179
|
+
li {
|
|
180
|
+
.AOV-Sidekick__ChatItem {
|
|
181
|
+
width: 100%;
|
|
182
|
+
display: flex;
|
|
183
|
+
align-items: center;
|
|
184
|
+
flex-wrap: nowrap;
|
|
185
|
+
position: relative;
|
|
186
|
+
gap: 4px;
|
|
187
|
+
> span {
|
|
188
|
+
width: 100%;
|
|
189
|
+
}
|
|
190
|
+
.AOV-Sidekick__ChatAction {
|
|
191
|
+
display: none;
|
|
192
|
+
position: absolute;
|
|
193
|
+
right: 0;
|
|
194
|
+
}
|
|
195
|
+
> div:first-child {
|
|
196
|
+
width: calc(100% - 50px);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
&:hover {
|
|
200
|
+
.AOV-Sidekick__ChatItem {
|
|
201
|
+
> span {
|
|
202
|
+
width: calc(100% - 60px);
|
|
203
|
+
}
|
|
204
|
+
.AOV-Sidekick__ChatAction {
|
|
205
|
+
display: flex;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { useDispatch } from "react-redux";
|
|
3
|
+
import { useNavigate } from "react-router-dom";
|
|
4
|
+
import { Card, BlockStack, Text, Button } from "@shopify/polaris";
|
|
5
|
+
var CampaignRendered = function CampaignRendered(_ref) {
|
|
6
|
+
var campaignType = _ref.campaignType,
|
|
7
|
+
campaign = _ref.campaign;
|
|
8
|
+
var dispatch = useDispatch();
|
|
9
|
+
var navigate = useNavigate();
|
|
10
|
+
var handleCampaign = function handleCampaign() {
|
|
11
|
+
// TODO: Implement campaign handling logic
|
|
12
|
+
// This is a placeholder - implement based on your business logic
|
|
13
|
+
console.log("Handle campaign", campaignType, campaign);
|
|
14
|
+
};
|
|
15
|
+
return /*#__PURE__*/React.createElement(Card, {
|
|
16
|
+
padding: "400"
|
|
17
|
+
}, /*#__PURE__*/React.createElement(BlockStack, {
|
|
18
|
+
gap: "200"
|
|
19
|
+
}, /*#__PURE__*/React.createElement(Text, {
|
|
20
|
+
as: "span",
|
|
21
|
+
variant: "bodySm",
|
|
22
|
+
fontWeight: "medium",
|
|
23
|
+
alignment: "center"
|
|
24
|
+
}, "Campaign type: ", campaignType), /*#__PURE__*/React.createElement(Button, {
|
|
25
|
+
tone: "success",
|
|
26
|
+
variant: "primary",
|
|
27
|
+
onClick: handleCampaign
|
|
28
|
+
}, "Preview")));
|
|
29
|
+
};
|
|
30
|
+
export default CampaignRendered;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(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; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
8
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
9
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
10
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
11
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
12
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
13
|
+
import React, { useState } from "react";
|
|
14
|
+
import PropTypes from "prop-types";
|
|
15
|
+
import { ActionList, Button, Text, TextField, Tooltip } from "@shopify/polaris";
|
|
16
|
+
import { CheckIcon, DeleteIcon, EditIcon, XIcon } from "@shopify/polaris-icons";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* ListChat - Component for displaying and managing chat thread history
|
|
20
|
+
*
|
|
21
|
+
* @param {Array} threads - Array of thread groups
|
|
22
|
+
* @param {Function} setThread - Function to set active thread
|
|
23
|
+
* @param {Function} deleteThread - Function to delete a thread
|
|
24
|
+
* @param {Function} updateThread - Function to update thread title
|
|
25
|
+
* @returns {React.ReactElement|null} List of chat threads
|
|
26
|
+
*/
|
|
27
|
+
var ListChat = function ListChat(_ref) {
|
|
28
|
+
var threads = _ref.threads,
|
|
29
|
+
setThread = _ref.setThread,
|
|
30
|
+
deleteThread = _ref.deleteThread,
|
|
31
|
+
updateThread = _ref.updateThread;
|
|
32
|
+
if (!threads.length) return null;
|
|
33
|
+
var _useState = useState(null),
|
|
34
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
35
|
+
editThread = _useState2[0],
|
|
36
|
+
setEditThread = _useState2[1];
|
|
37
|
+
return /*#__PURE__*/React.createElement(ActionList, {
|
|
38
|
+
actionRole: "chat-item",
|
|
39
|
+
sections: threads.map(function (thread) {
|
|
40
|
+
return {
|
|
41
|
+
title: thread.title,
|
|
42
|
+
items: thread.items.map(function (item) {
|
|
43
|
+
return {
|
|
44
|
+
content: /*#__PURE__*/React.createElement("div", {
|
|
45
|
+
className: "AOV-Sidekick__ChatItem"
|
|
46
|
+
}, (editThread === null || editThread === void 0 ? void 0 : editThread.id) === item.id ? /*#__PURE__*/React.createElement("div", {
|
|
47
|
+
onClick: function onClick(e) {
|
|
48
|
+
e.stopPropagation();
|
|
49
|
+
},
|
|
50
|
+
onKeyDown: function onKeyDown(e) {
|
|
51
|
+
e.stopPropagation();
|
|
52
|
+
if (e.key === " ") {
|
|
53
|
+
e.preventDefault();
|
|
54
|
+
setEditThread(_objectSpread(_objectSpread({}, editThread), {}, {
|
|
55
|
+
title: editThread.title + " "
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
if (e.key === "Enter") {
|
|
59
|
+
setEditThread(null);
|
|
60
|
+
updateThread(editThread);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}, /*#__PURE__*/React.createElement(TextField, {
|
|
64
|
+
value: editThread.title,
|
|
65
|
+
onChange: function onChange(value) {
|
|
66
|
+
return setEditThread(_objectSpread(_objectSpread({}, editThread), {}, {
|
|
67
|
+
title: value
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
70
|
+
})) : /*#__PURE__*/React.createElement(Tooltip, {
|
|
71
|
+
content: item.title
|
|
72
|
+
}, /*#__PURE__*/React.createElement(Text, {
|
|
73
|
+
truncate: true
|
|
74
|
+
}, item.title)), /*#__PURE__*/React.createElement("div", {
|
|
75
|
+
className: "AOV-Sidekick__ChatAction"
|
|
76
|
+
}, (editThread === null || editThread === void 0 ? void 0 : editThread.id) !== item.id ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Button, {
|
|
77
|
+
icon: EditIcon,
|
|
78
|
+
variant: "plain",
|
|
79
|
+
onClick: function onClick(e) {
|
|
80
|
+
e.stopPropagation();
|
|
81
|
+
setEditThread(item);
|
|
82
|
+
}
|
|
83
|
+
}), /*#__PURE__*/React.createElement(Button, {
|
|
84
|
+
icon: DeleteIcon,
|
|
85
|
+
variant: "plain",
|
|
86
|
+
tone: "critical",
|
|
87
|
+
onClick: function onClick(e) {
|
|
88
|
+
e.stopPropagation();
|
|
89
|
+
deleteThread(item === null || item === void 0 ? void 0 : item.id);
|
|
90
|
+
}
|
|
91
|
+
})) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Button, {
|
|
92
|
+
icon: CheckIcon,
|
|
93
|
+
variant: "plain",
|
|
94
|
+
onClick: function onClick(e) {
|
|
95
|
+
e.stopPropagation();
|
|
96
|
+
setEditThread(null);
|
|
97
|
+
updateThread(editThread);
|
|
98
|
+
}
|
|
99
|
+
}), /*#__PURE__*/React.createElement(Button, {
|
|
100
|
+
icon: XIcon,
|
|
101
|
+
variant: "plain",
|
|
102
|
+
onClick: function onClick(e) {
|
|
103
|
+
e.stopPropagation();
|
|
104
|
+
setEditThread(null);
|
|
105
|
+
}
|
|
106
|
+
})))),
|
|
107
|
+
id: item.id,
|
|
108
|
+
onAction: function onAction() {
|
|
109
|
+
return setThread(item);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
})
|
|
113
|
+
};
|
|
114
|
+
})
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
ListChat.propTypes = {
|
|
118
|
+
threads: PropTypes.arrayOf(PropTypes.shape({
|
|
119
|
+
title: PropTypes.string,
|
|
120
|
+
items: PropTypes.arrayOf(PropTypes.shape({
|
|
121
|
+
id: PropTypes.string,
|
|
122
|
+
title: PropTypes.string
|
|
123
|
+
}))
|
|
124
|
+
})).isRequired,
|
|
125
|
+
setThread: PropTypes.func.isRequired,
|
|
126
|
+
deleteThread: PropTypes.func.isRequired,
|
|
127
|
+
updateThread: PropTypes.func.isRequired
|
|
128
|
+
};
|
|
129
|
+
export default ListChat;
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
var _excluded = ["className"],
|
|
2
|
+
_excluded2 = ["children"],
|
|
3
|
+
_excluded3 = ["className", "children"],
|
|
4
|
+
_excluded4 = ["children"],
|
|
5
|
+
_excluded5 = ["children"],
|
|
6
|
+
_excluded6 = ["children"],
|
|
7
|
+
_excluded7 = ["children"],
|
|
8
|
+
_excluded8 = ["children"],
|
|
9
|
+
_excluded9 = ["children"],
|
|
10
|
+
_excluded0 = ["children"],
|
|
11
|
+
_excluded1 = ["children"],
|
|
12
|
+
_excluded10 = ["children"],
|
|
13
|
+
_excluded11 = ["children"];
|
|
14
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
15
|
+
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
16
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
17
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
18
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
19
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
20
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
21
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
22
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
23
|
+
import React, { memo } from 'react';
|
|
24
|
+
import { MarkdownTextPrimitive, unstable_memoizeMarkdownComponents as memoizeMarkdownComponents } from '@assistant-ui/react-markdown';
|
|
25
|
+
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
|
|
26
|
+
import { vscDarkPlus } from 'react-syntax-highlighter/dist/esm/styles/prism';
|
|
27
|
+
import "./MarkdownText.scss";
|
|
28
|
+
var detectLanguage = function detectLanguage(code) {
|
|
29
|
+
if (!code || typeof code !== 'string') return 'plaintext';
|
|
30
|
+
var patterns = {
|
|
31
|
+
javascript: /(?:import\s+.*from|export\s+(?:default|const)|function\s+\w+|const\s+\w+\s*=|let\s+\w+\s*=|var\s+\w+\s*=|useJoyLoyalty|useState|useEffect|React)/,
|
|
32
|
+
jsx: /(?:<[A-Z]\w*|<div|<span|className=|onClick=|useState|useEffect)/,
|
|
33
|
+
bash: /(?:^npm\s|^yarn\s|^npx\s|^git\s|^cd\s|^mkdir\s|^ls\s|^echo\s|\$\w+|--?\w+)/m,
|
|
34
|
+
json: /^\s*\{[\s\S]*\}\s*$/,
|
|
35
|
+
python: /(?:def\s+\w+|import\s+\w+|from\s+\w+|class\s+\w+|if\s+__name__|print\()/,
|
|
36
|
+
css: /(?:^\.[\w-]+\s*\{|^#[\w-]+\s*\{|@media|:hover|padding:|margin:|color:|background:)/m,
|
|
37
|
+
html: /(?:<!DOCTYPE|<html|<head|<body|<meta|<link|<script)/i,
|
|
38
|
+
typescript: /(?:interface\s+\w+|type\s+\w+|:\s*string|:\s*number|:\s*boolean|export\s+interface)/
|
|
39
|
+
};
|
|
40
|
+
for (var _i = 0, _Object$entries = Object.entries(patterns); _i < _Object$entries.length; _i++) {
|
|
41
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
42
|
+
lang = _Object$entries$_i[0],
|
|
43
|
+
pattern = _Object$entries$_i[1];
|
|
44
|
+
if (pattern.test(code)) {
|
|
45
|
+
if (lang === 'jsx') return 'javascript';
|
|
46
|
+
if (lang === 'typescript') return 'javascript';
|
|
47
|
+
return lang;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return 'javascript';
|
|
51
|
+
};
|
|
52
|
+
var HighlightedCodeBlock = /*#__PURE__*/memo(function (_ref) {
|
|
53
|
+
var language = _ref.language,
|
|
54
|
+
children = _ref.children;
|
|
55
|
+
var codeString = typeof children === 'string' ? children : Array.isArray(children) ? children.join('') : String(children);
|
|
56
|
+
var detectedLanguage = language || detectLanguage(codeString);
|
|
57
|
+
if (!SyntaxHighlighter) {
|
|
58
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
59
|
+
className: "aui-md-code-block-wrapper"
|
|
60
|
+
}, detectedLanguage && /*#__PURE__*/React.createElement("div", {
|
|
61
|
+
className: "aui-md-code-block-header"
|
|
62
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
63
|
+
className: "aui-md-code-block-lang"
|
|
64
|
+
}, detectedLanguage)), /*#__PURE__*/React.createElement("pre", {
|
|
65
|
+
className: "aui-md-pre"
|
|
66
|
+
}, /*#__PURE__*/React.createElement("code", {
|
|
67
|
+
className: "aui-md-code language-".concat(detectedLanguage || 'plaintext')
|
|
68
|
+
}, codeString)));
|
|
69
|
+
}
|
|
70
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
71
|
+
className: "aui-md-code-block-wrapper"
|
|
72
|
+
}, detectedLanguage && /*#__PURE__*/React.createElement("div", {
|
|
73
|
+
className: "aui-md-code-block-header"
|
|
74
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
75
|
+
className: "aui-md-code-block-lang"
|
|
76
|
+
}, detectedLanguage)), /*#__PURE__*/React.createElement(SyntaxHighlighter, {
|
|
77
|
+
language: detectedLanguage,
|
|
78
|
+
style: vscDarkPlus,
|
|
79
|
+
customStyle: {
|
|
80
|
+
margin: 0,
|
|
81
|
+
padding: '12px 16px',
|
|
82
|
+
backgroundColor: '#1e1e1e',
|
|
83
|
+
fontSize: '13px',
|
|
84
|
+
lineHeight: '1.5',
|
|
85
|
+
borderRadius: 0,
|
|
86
|
+
fontFamily: "'Monaco', 'Menlo', 'Ubuntu Mono', 'Courier New', monospace"
|
|
87
|
+
},
|
|
88
|
+
showLineNumbers: false,
|
|
89
|
+
wrapLines: true,
|
|
90
|
+
codeTagProps: {
|
|
91
|
+
style: {
|
|
92
|
+
fontSize: '13px',
|
|
93
|
+
fontFamily: "'Monaco', 'Menlo', 'Ubuntu Mono', 'Courier New', monospace"
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}, codeString));
|
|
97
|
+
});
|
|
98
|
+
HighlightedCodeBlock.displayName = 'HighlightedCodeBlock';
|
|
99
|
+
var defaultComponents = memoizeMarkdownComponents({
|
|
100
|
+
a: function a(_ref2) {
|
|
101
|
+
var className = _ref2.className,
|
|
102
|
+
props = _objectWithoutProperties(_ref2, _excluded);
|
|
103
|
+
return /*#__PURE__*/React.createElement("a", _extends({
|
|
104
|
+
className: "aui-md-a ".concat(className || '')
|
|
105
|
+
}, props, {
|
|
106
|
+
target: "_blank",
|
|
107
|
+
rel: "noopener noreferrer"
|
|
108
|
+
}));
|
|
109
|
+
},
|
|
110
|
+
pre: function pre(_ref3) {
|
|
111
|
+
var children = _ref3.children,
|
|
112
|
+
props = _objectWithoutProperties(_ref3, _excluded2);
|
|
113
|
+
var codeElement = children;
|
|
114
|
+
if (codeElement && codeElement.props) {
|
|
115
|
+
var className = codeElement.props.className || '';
|
|
116
|
+
var match = /language-(\w+)/.exec(className);
|
|
117
|
+
var language = match ? match[1] : '';
|
|
118
|
+
var codeContent = codeElement.props.children;
|
|
119
|
+
if (language || codeContent) {
|
|
120
|
+
return /*#__PURE__*/React.createElement(HighlightedCodeBlock, {
|
|
121
|
+
language: language
|
|
122
|
+
}, codeContent);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
126
|
+
className: "aui-md-code-block-wrapper"
|
|
127
|
+
}, /*#__PURE__*/React.createElement("pre", _extends({
|
|
128
|
+
className: "aui-md-pre"
|
|
129
|
+
}, props), children));
|
|
130
|
+
},
|
|
131
|
+
code: function code(_ref4) {
|
|
132
|
+
var className = _ref4.className,
|
|
133
|
+
children = _ref4.children,
|
|
134
|
+
props = _objectWithoutProperties(_ref4, _excluded3);
|
|
135
|
+
if (className && String(className).includes('language-')) {
|
|
136
|
+
return /*#__PURE__*/React.createElement("code", _extends({
|
|
137
|
+
className: String(className)
|
|
138
|
+
}, props), children);
|
|
139
|
+
}
|
|
140
|
+
return /*#__PURE__*/React.createElement("code", _extends({
|
|
141
|
+
className: "aui-md-code-inline"
|
|
142
|
+
}, props), children);
|
|
143
|
+
},
|
|
144
|
+
h1: function h1(_ref5) {
|
|
145
|
+
var children = _ref5.children,
|
|
146
|
+
props = _objectWithoutProperties(_ref5, _excluded4);
|
|
147
|
+
return /*#__PURE__*/React.createElement("h1", _extends({
|
|
148
|
+
className: "aui-md-h1"
|
|
149
|
+
}, props), children);
|
|
150
|
+
},
|
|
151
|
+
h2: function h2(_ref6) {
|
|
152
|
+
var children = _ref6.children,
|
|
153
|
+
props = _objectWithoutProperties(_ref6, _excluded5);
|
|
154
|
+
return /*#__PURE__*/React.createElement("h2", _extends({
|
|
155
|
+
className: "aui-md-h2"
|
|
156
|
+
}, props), children);
|
|
157
|
+
},
|
|
158
|
+
h3: function h3(_ref7) {
|
|
159
|
+
var children = _ref7.children,
|
|
160
|
+
props = _objectWithoutProperties(_ref7, _excluded6);
|
|
161
|
+
return /*#__PURE__*/React.createElement("h3", _extends({
|
|
162
|
+
className: "aui-md-h3"
|
|
163
|
+
}, props), children);
|
|
164
|
+
},
|
|
165
|
+
h4: function h4(_ref8) {
|
|
166
|
+
var children = _ref8.children,
|
|
167
|
+
props = _objectWithoutProperties(_ref8, _excluded7);
|
|
168
|
+
return /*#__PURE__*/React.createElement("h4", _extends({
|
|
169
|
+
className: "aui-md-h4"
|
|
170
|
+
}, props), children);
|
|
171
|
+
},
|
|
172
|
+
ul: function ul(_ref9) {
|
|
173
|
+
var children = _ref9.children,
|
|
174
|
+
props = _objectWithoutProperties(_ref9, _excluded8);
|
|
175
|
+
return /*#__PURE__*/React.createElement("ul", _extends({
|
|
176
|
+
className: "aui-md-ul"
|
|
177
|
+
}, props), children);
|
|
178
|
+
},
|
|
179
|
+
ol: function ol(_ref0) {
|
|
180
|
+
var children = _ref0.children,
|
|
181
|
+
props = _objectWithoutProperties(_ref0, _excluded9);
|
|
182
|
+
return /*#__PURE__*/React.createElement("ol", _extends({
|
|
183
|
+
className: "aui-md-ol"
|
|
184
|
+
}, props), children);
|
|
185
|
+
},
|
|
186
|
+
li: function li(_ref1) {
|
|
187
|
+
var children = _ref1.children,
|
|
188
|
+
props = _objectWithoutProperties(_ref1, _excluded0);
|
|
189
|
+
return /*#__PURE__*/React.createElement("li", _extends({
|
|
190
|
+
className: "aui-md-li"
|
|
191
|
+
}, props), children);
|
|
192
|
+
},
|
|
193
|
+
blockquote: function blockquote(_ref10) {
|
|
194
|
+
var children = _ref10.children,
|
|
195
|
+
props = _objectWithoutProperties(_ref10, _excluded1);
|
|
196
|
+
return /*#__PURE__*/React.createElement("blockquote", _extends({
|
|
197
|
+
className: "aui-md-blockquote"
|
|
198
|
+
}, props), children);
|
|
199
|
+
},
|
|
200
|
+
strong: function strong(_ref11) {
|
|
201
|
+
var children = _ref11.children,
|
|
202
|
+
props = _objectWithoutProperties(_ref11, _excluded10);
|
|
203
|
+
return /*#__PURE__*/React.createElement("strong", _extends({
|
|
204
|
+
className: "aui-md-strong"
|
|
205
|
+
}, props), children);
|
|
206
|
+
},
|
|
207
|
+
em: function em(_ref12) {
|
|
208
|
+
var children = _ref12.children,
|
|
209
|
+
props = _objectWithoutProperties(_ref12, _excluded11);
|
|
210
|
+
return /*#__PURE__*/React.createElement("em", _extends({
|
|
211
|
+
className: "aui-md-em"
|
|
212
|
+
}, props), children);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
var MarkdownTextImpl = function MarkdownTextImpl(props) {
|
|
216
|
+
try {
|
|
217
|
+
return /*#__PURE__*/React.createElement(MarkdownTextPrimitive, _extends({
|
|
218
|
+
className: "aui-md",
|
|
219
|
+
components: defaultComponents
|
|
220
|
+
}, props));
|
|
221
|
+
} catch (error) {
|
|
222
|
+
console.error('Markdown rendering error:', error);
|
|
223
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
224
|
+
className: "aui-md"
|
|
225
|
+
}, props.children || props.content);
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
export var MarkdownText = /*#__PURE__*/memo(MarkdownTextImpl);
|