cozy-search 0.1.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/LICENSE +21 -0
- package/README.md +89 -0
- package/dist/components/AssistantDesktop.d.ts +16 -0
- package/dist/components/AssistantDesktop.js +44 -0
- package/dist/components/AssistantIcon/AssistantIcon.d.ts +6 -0
- package/dist/components/AssistantIcon/AssistantIcon.js +43 -0
- package/dist/components/AssistantMobile.d.ts +2 -0
- package/dist/components/AssistantMobile.js +50 -0
- package/dist/components/AssistantProvider.d.ts +7 -0
- package/dist/components/AssistantProvider.js +174 -0
- package/dist/components/Conversations/ChatAssistantItem.d.ts +8 -0
- package/dist/components/Conversations/ChatAssistantItem.js +53 -0
- package/dist/components/Conversations/ChatConversation.d.ts +5 -0
- package/dist/components/Conversations/ChatConversation.js +110 -0
- package/dist/components/Conversations/ChatItem.d.ts +7 -0
- package/dist/components/Conversations/ChatItem.js +39 -0
- package/dist/components/Conversations/ChatItemLabel.d.ts +5 -0
- package/dist/components/Conversations/ChatItemLabel.js +29 -0
- package/dist/components/Conversations/ChatRealtimeAnswer.d.ts +5 -0
- package/dist/components/Conversations/ChatRealtimeAnswer.js +30 -0
- package/dist/components/Conversations/ChatUserItem.d.ts +7 -0
- package/dist/components/Conversations/ChatUserItem.js +41 -0
- package/dist/components/Conversations/Conversation.d.ts +4 -0
- package/dist/components/Conversations/Conversation.js +41 -0
- package/dist/components/Conversations/ConversationBar.d.ts +4 -0
- package/dist/components/Conversations/ConversationBar.js +164 -0
- package/dist/components/Conversations/Sources/Sources.d.ts +5 -0
- package/dist/components/Conversations/Sources/Sources.js +134 -0
- package/dist/components/Conversations/Sources/SourcesItem.d.ts +4 -0
- package/dist/components/Conversations/Sources/SourcesItem.js +55 -0
- package/dist/components/Conversations/Sources/styles.styl +5 -0
- package/dist/components/Conversations/styles.styl +15 -0
- package/dist/components/ResultMenu/NoResultItem.d.ts +2 -0
- package/dist/components/ResultMenu/NoResultItem.js +30 -0
- package/dist/components/ResultMenu/NotEnoughItem.d.ts +2 -0
- package/dist/components/ResultMenu/NotEnoughItem.js +30 -0
- package/dist/components/ResultMenu/ResultMenu.d.ts +6 -0
- package/dist/components/ResultMenu/ResultMenu.js +47 -0
- package/dist/components/ResultMenu/ResultMenuContent.d.ts +3 -0
- package/dist/components/ResultMenu/ResultMenuContent.js +117 -0
- package/dist/components/ResultMenu/ResultMenuItem.d.ts +12 -0
- package/dist/components/ResultMenu/ResultMenuItem.js +65 -0
- package/dist/components/ResultMenu/SuggestionItemTextHighlighted.d.ts +5 -0
- package/dist/components/ResultMenu/SuggestionItemTextHighlighted.js +100 -0
- package/dist/components/ResultMenu/SuggestionItemTextSecondary.d.ts +7 -0
- package/dist/components/ResultMenu/SuggestionItemTextSecondary.js +70 -0
- package/dist/components/ResultMenu/styles.styl +8 -0
- package/dist/components/Search/EncryptedFolderIcon.d.ts +2 -0
- package/dist/components/Search/EncryptedFolderIcon.js +34 -0
- package/dist/components/Search/SearchBar.d.ts +4 -0
- package/dist/components/Search/SearchBar.js +71 -0
- package/dist/components/Search/SearchBarDesktop.d.ts +15 -0
- package/dist/components/Search/SearchBarDesktop.js +167 -0
- package/dist/components/Search/SearchBarMobile.d.ts +6 -0
- package/dist/components/Search/SearchBarMobile.js +71 -0
- package/dist/components/Search/SearchProvider.d.ts +7 -0
- package/dist/components/Search/SearchProvider.js +81 -0
- package/dist/components/Search/SearchSubmitFab.d.ts +5 -0
- package/dist/components/Search/SearchSubmitFab.js +59 -0
- package/dist/components/Search/SuggestionsPlaceholder.d.ts +2 -0
- package/dist/components/Search/SuggestionsPlaceholder.js +55 -0
- package/dist/components/Search/getFileMimetype.d.ts +1 -0
- package/dist/components/Search/getFileMimetype.js +54 -0
- package/dist/components/Search/getIconForSearchResult.d.ts +12 -0
- package/dist/components/Search/getIconForSearchResult.js +127 -0
- package/dist/components/Search/styles.styl +7 -0
- package/dist/components/Search/useFetchResult.d.ts +4 -0
- package/dist/components/Search/useFetchResult.js +191 -0
- package/dist/components/Views/AssistantDialog.d.ts +2 -0
- package/dist/components/Views/AssistantDialog.js +79 -0
- package/dist/components/Views/SearchDialog.d.ts +2 -0
- package/dist/components/Views/SearchDialog.js +96 -0
- package/dist/components/helpers.d.ts +5 -0
- package/dist/components/helpers.js +58 -0
- package/dist/components/queries.d.ts +25 -0
- package/dist/components/queries.js +58 -0
- package/dist/components/styles.styl +18 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +39 -0
- package/dist/locales/en.json +21 -0
- package/dist/locales/fr.json +21 -0
- package/dist/locales/index.d.ts +6 -0
- package/dist/locales/index.js +53 -0
- package/dist/stylesheet.css +48 -0
- package/package.json +91 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016 Cozy.io
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# Cozy-search
|
|
2
|
+
|
|
3
|
+
### Prerequisite for both components
|
|
4
|
+
|
|
5
|
+
1. Install `cozy-dataproxy-lib` and update `cozy-scripts` version of your app to 8.4.0.
|
|
6
|
+
|
|
7
|
+
2. Add the provider in your tree because the SearchEngine is provided by the DataProxyProvider :
|
|
8
|
+
|
|
9
|
+
```jsx
|
|
10
|
+
import { DataProxyProvider } from 'cozy-dataproxy-lib'
|
|
11
|
+
|
|
12
|
+
<DataProxyProvider>
|
|
13
|
+
{ children }
|
|
14
|
+
</DataProxyProvider>
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
3. Import the CSS :
|
|
18
|
+
|
|
19
|
+
```jsx
|
|
20
|
+
import 'cozy-search/dist/stylesheet.css'
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Prerequisite for AI components
|
|
24
|
+
|
|
25
|
+
1. Add following permissions in manifest.webapp :
|
|
26
|
+
|
|
27
|
+
```json
|
|
28
|
+
"chatConversations": {
|
|
29
|
+
"description": "Required by the cozy Assistant",
|
|
30
|
+
"type": "io.cozy.ai.chat.conversations",
|
|
31
|
+
"verbs": ["GET", "POST"]
|
|
32
|
+
},
|
|
33
|
+
"chatEvents": {
|
|
34
|
+
"description": "Required by the cozy Assistant",
|
|
35
|
+
"type": "io.cozy.ai.chat.events",
|
|
36
|
+
"verbs": ["GET"]
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
2. Add realtime queries for chat conversations in your tree :
|
|
41
|
+
|
|
42
|
+
```jsx
|
|
43
|
+
<RealTimeQueries doctype="io.cozy.ai.chat.conversations" />
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### On desktop
|
|
47
|
+
|
|
48
|
+
You can add the search bar like this :
|
|
49
|
+
|
|
50
|
+
```jsx
|
|
51
|
+
import React from 'react'
|
|
52
|
+
|
|
53
|
+
import { BarSearch } from 'cozy-bar'
|
|
54
|
+
import { AssistantDesktop } from 'cozy-search'
|
|
55
|
+
import useBreakpoints from 'cozy-ui/transpiled/react/providers/Breakpoints'
|
|
56
|
+
|
|
57
|
+
const AppBarSearch = () => {
|
|
58
|
+
const { isMobile } = useBreakpoints()
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<BarSearch>
|
|
62
|
+
{!isMobile && (
|
|
63
|
+
<AssistantDesktop
|
|
64
|
+
componentsProps={{ SearchBarDesktop: { size: 'small' } }}
|
|
65
|
+
/>
|
|
66
|
+
)}
|
|
67
|
+
</BarSearch>
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export default AppBarSearch
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### On mobile
|
|
75
|
+
|
|
76
|
+
The search and assistant are dialogs. So you just need to create a route for each dialog, and open them when you want. The SearchDialog can open the AssistantDialog and expect a route like this `assistant/:conversationId`.
|
|
77
|
+
|
|
78
|
+
```jsx
|
|
79
|
+
<Route path="search" element={<SearchDialog />} />
|
|
80
|
+
<Route
|
|
81
|
+
path="assistant/:conversationId"
|
|
82
|
+
element={
|
|
83
|
+
<>
|
|
84
|
+
<RealTimeQueries doctype="io.cozy.ai.chat.conversations" />
|
|
85
|
+
<AssistantDialog />
|
|
86
|
+
</>
|
|
87
|
+
}
|
|
88
|
+
/>
|
|
89
|
+
```
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export default AssistantDesktop;
|
|
2
|
+
declare function AssistantDesktop({ componentsProps }: {
|
|
3
|
+
componentsProps: any;
|
|
4
|
+
}): JSX.Element;
|
|
5
|
+
declare namespace AssistantDesktop {
|
|
6
|
+
namespace propTypes {
|
|
7
|
+
let componentsProps: PropTypes.Requireable<PropTypes.InferProps<{
|
|
8
|
+
SearchBarDesktop: PropTypes.Requireable<PropTypes.InferProps<{
|
|
9
|
+
elevation: PropTypes.Requireable<boolean>;
|
|
10
|
+
size: PropTypes.Requireable<string>;
|
|
11
|
+
hasHalfBorderRadius: PropTypes.Requireable<boolean>;
|
|
12
|
+
}>>;
|
|
13
|
+
}>>;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
import PropTypes from 'prop-types';
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
+
|
|
12
|
+
var _react = _interopRequireDefault(require("react"));
|
|
13
|
+
|
|
14
|
+
var _useExtendI18n = _interopRequireDefault(require("cozy-ui/transpiled/react/providers/I18n/useExtendI18n"));
|
|
15
|
+
|
|
16
|
+
var _AssistantProvider = _interopRequireDefault(require("./AssistantProvider"));
|
|
17
|
+
|
|
18
|
+
var _SearchBar = _interopRequireDefault(require("./Search/SearchBar"));
|
|
19
|
+
|
|
20
|
+
var _SearchProvider = _interopRequireDefault(require("./Search/SearchProvider"));
|
|
21
|
+
|
|
22
|
+
var _locales = require("../locales");
|
|
23
|
+
|
|
24
|
+
var AssistantDesktop = function AssistantDesktop(_ref) {
|
|
25
|
+
var componentsProps = _ref.componentsProps;
|
|
26
|
+
(0, _useExtendI18n.default)(_locales.locales);
|
|
27
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
28
|
+
className: "u-mh-auto u-w-100 u-maw-100"
|
|
29
|
+
}, /*#__PURE__*/_react.default.createElement(_AssistantProvider.default, null, /*#__PURE__*/_react.default.createElement(_SearchProvider.default, null, /*#__PURE__*/_react.default.createElement(_SearchBar.default, {
|
|
30
|
+
componentsProps: componentsProps
|
|
31
|
+
}))));
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
AssistantDesktop.propTypes = {
|
|
35
|
+
componentsProps: _propTypes.default.shape({
|
|
36
|
+
SearchBarDesktop: _propTypes.default.shape({
|
|
37
|
+
elevation: _propTypes.default.bool,
|
|
38
|
+
size: _propTypes.default.string,
|
|
39
|
+
hasHalfBorderRadius: _propTypes.default.bool
|
|
40
|
+
})
|
|
41
|
+
})
|
|
42
|
+
};
|
|
43
|
+
var _default = AssistantDesktop;
|
|
44
|
+
exports.default = _default;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.AssistantIcon = void 0;
|
|
9
|
+
|
|
10
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
11
|
+
|
|
12
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
13
|
+
|
|
14
|
+
var _react = _interopRequireDefault(require("react"));
|
|
15
|
+
|
|
16
|
+
var _excluded = ["height", "width", "style"];
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The assistant's icon cannot be a SVG because it uses some conical gradients.
|
|
20
|
+
*
|
|
21
|
+
* Also we don't want to embed it as a PNG resource for now because we encounter some issues
|
|
22
|
+
* in the Flagship app's WebViews when loaded in offline mode (the cache control seems not
|
|
23
|
+
* to work after an app's restart).
|
|
24
|
+
*
|
|
25
|
+
* To fix those issues, we chose to embed the icon PNG as a base64 string until we find a
|
|
26
|
+
* better solution.
|
|
27
|
+
*
|
|
28
|
+
* Base64 string generated using https://base64.guru/converter/encode/image/png
|
|
29
|
+
*/
|
|
30
|
+
var AssistantIcon = function AssistantIcon(_ref) {
|
|
31
|
+
var height = _ref.height,
|
|
32
|
+
width = _ref.width,
|
|
33
|
+
style = _ref.style,
|
|
34
|
+
restProps = (0, _objectWithoutProperties2.default)(_ref, _excluded);
|
|
35
|
+
return /*#__PURE__*/_react.default.createElement("img", (0, _extends2.default)({
|
|
36
|
+
src: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAMAAADVRocKAAAC9FBMVEUAAAD1U50zpPBCif0YvucF1OBEhfv/UpT/RJ5Dgf//Qp9DhP7+RaH6SaJFhP3/hFtDgv8fsO02lPlrdOz/tCoes+3/si0mqfD2SKT/VY4lqvD/tyiDbuP/h1j/uikYuek2lPn/bnNAiPwmqPD1TKb/pDwD1N//T5Eqo/L/jVNEhP3/b3FNf/r/cG+9WMPWULWbZNL/RJ3/X4H/h1ZTgPW1Vcplde2+WsL/eGf/gV8F0uHQUrf/WocIzuGhYc//uSWFbN7QUbckq+8H0OD/tygH0eH/tSmvXcn/j1GPaNj/RJ7/siv+VJKjYdD/tSsIzd8E1t//emfRUbYVv+f/TpO3W8Qjq+8unvR5b+P/bXJcefOlYM0YvOkD1d7/rTNnde3/U48D1t0Iz+Fuc+z/Qp9Egv9Dgf9Eg///qzQMyeP/qDY1lfglqfAKzeIIzuE3kvkLy+P/rTIPxuQ/iP0ro/MNyOP/pDs7jvsiru4ymfYsoPQppfL/gGD/pjgnp/H/fWNBhv48i/w5kPoes+wVvugunvQQxeUG0eD/d2kjrO8fse0auOr/anb/ry//T5L/bXP/dGz/emb/l0f/oD8UwOf/Vov/Wob/ZXv/Z3n/kk0zl/dfePKDbN//jlL/lUr/YID/cm7/h1j/kE//mkX/nEMwm/Yctez/VI3/Y37/i1T/oj1kdu8Yu+kRw+YSwubRUbf/TJX/UY//b3D/nkH/sS1DhP8btuuSZ9jdTbH/XIT/g13/iVZGgf4+iv0vnPVpde2kYc7sSan8Q6H/R5r/hFsXvOl6b+R+beKyXMfhTK/4RaP/Q57/RZxQffkTwOZ2cOaIa922W8XBV8DHVbzVULXwR6f0Rqb/XoJaefRyceiWZdWfYtH/SZj/WIlMfvtXe/auXcnLU7roSqz/SpYZueqOaNmnYM2qX8q5WcO9WMHZT7PlS63/syxJf/1TfPcgr+5vcumLaduZZNOcY9L/tSltc+rEVr3/uCYE1N/OU7j9SKINyOUKkDUGAAAAZHRSTlMAIBAgIINgEIDv79/dxZWDgIB/f3/v77mTf19cICAg/e/Xz5RfEO/v39q/urWIf39gYGBgUBDv7+/v7u7n39/f19fPz8+/v7ewr6+on4+PYF9YV1BQ/fzv7+/u7t/f38/Pr59fgyzHzgAACBpJREFUaN7tlkOUXVEURG9s27Zt27Zt27Zt27Zt27atSerg596Yg2StVH53T7L2flXnBeZ//ud//qakSFwgV8Zym889y5inQOLwf5yeMNfuy5dv3dy8+dy5p0/PrlqVGY4/iU91+8ju3SJ49vTs2VU3bjw5nOePKRKmunNHBTc9gidPDo8fH+yP4L1keXn0KARHILjFAiyEAhDsyvwHShRNd+zlSwi0ghWMh2Bn6eS/y0905cqxY1LBCjwFdu08dCjYb/IXvWEDBCWOuALhQ3DmtwxFjy8ig1ZQAS2EAsp//Ljab9w33XGPwRVoAeW/SPnrl85y964YjqmBBLIQCih/06ZKv3yA1autQSqoAAUsf9O8YL840J49q0khBlT4IEABDAT+ixfAz5uX0usvCULfcw1c4fItCLAQBmL+JuaPGxfslwpcvQcDKTATDFyBBSggfMEjZX+lQvSrV6GAQw0Y6TYJsJDlM/706dO/UiHAli1QcAs20EhHLm9+dhYnZr4+/mnkUvxfWOjEFgQOLUEGFlAB8PXxiY489PrzC51ArIINL2/vvvls1eFdO8+88OAJjhzw+fPv0MmTJ09QxIESx98cO3rk5rMb45lv6QcoAX/+BHtPStQBxd1Fx27fenoYfMJb+EXk54/gf69GJaS4u+jo5bPjz2wCHnRmSx488PfTgq0SayHH6kVHbpyZB7qgH2jWP1jv56cF1atvrV4dBnxpyLNl0ZlLBy4S05Ma+KpZo2aNHyf7ShI6r3+/1b+WGjXdEFq+11rhL25An96+S/cd4Py2bfv37fsa/60fwin8wzfwa61Y0blzs2ZRyfF1fJhYi6+RYP9XBf79MVBjXWjQmQTNNmwI+FVFmFgDF0Nw/luCAPFrYA8BWw2ywiPo0qVL0C//3VB5IALDtwRvQwdkojogU34tNhAfaeXvCyWSxlqyZAkE12ijrwui+yS8jYePiXQh8Fu1ipz8s3lmzZoFAQzfFnjxqljLl6iA+EjXrkE/4Y8YMQIG3eirgrcBjIlLFWwNYuODt8izEPO7NvrIUPzCBRaggwr2fWUhYwJ/8vwaFXzgN2rk07lv+pFqQIdvCrwY49WP85LWqmUFvBDzRRDZXjr9SAjUgArnz+//Cj+/QQLrOvgBrnxUYAsg9aJ+OMCaNSOhEINW+GoBrQC88vFFwULyCnnwSFAd6NQa1/ANgW/DCWznVzpdGQLiq6AeJbL8Q5r/1ClVwCAVvvwa+TeaqCpQvF0IfMFLxgblApMmfWxgwRf4fjGQxJsfLeCUgODDQEJHuELSSQgcYpCRvnjl4uZD8MdZ4fRLBVKgkeW3adOGKkSZjagCBq2w72sH0DOALXz6oQIUIL7Sid8mFBYaNYoNqhADBF/lq8FeQAUogIEED75khleTdBTFtmDD4vMisPsnMZ8kuR8tYQV4fuUrHQlrEowazQp1wDByxKyB1z4W+Nf7uvHmj/AfWmChVuADr3Bk44yN0Uy80RxxqGLEksX73cd353FnWu+8SJ03gM94hXN6hDJRROCxsGLkiIHbHLwv85V4C7h+PR2aG7Sixxc6o/FBYpv+njiSSWtGnFd8AMF/VeEz6vpa66lCMzw+0YntpBQLNNY1avaI6n795w2dROnfdgSM6299rUZtLLotPm31mxn0eZYunTy4fe1XmXIWDBfx+wKvhX1UqRCzcet2zZG2n8WUsVwE7MmDB/ce0n7CstrLn7969So7O75O95Hj9evXvRo2Xriydf2O7do1Jw2bPC4ThajKRhjfqf2UqdNb1h5w/zk58kX8Oj4m4cFvOvx6t9Z96neEAxYnsU08InvYoPceAv72OWOmDetQe8ByUQT/Mp/wvYBv0LjFguHXZ/aFAQpyWEsokwBkS1f+ugljpi1rWbd2E1LAkekLJbxnEzzxmy7oHmllNxhY4TqimSICt/hO7ddOmTNhzNBlczuwYfl9OEKG+5RfOG0vwgu/58Hu8/vNVIMqxBLW+HLojG+/dvu6OVMnDp0+rCUbUIIUwT+Zh/FI48Z1WvRcQAJUeNQaM6lCBN6NiWfxyp+ybgIJls1lg5S4bw0uv0ED8Juy4DpVeIQOohBHVvzeBETXx1c+Fpo4dNqyYS1b1mWDKJyVijn8Ok2bLlg4vPsOEnAHNqgjLP2fPbXiPXxcYCoJpg+jCmqAImTED/dNq3jwpQAEkfqtRAU2WIV3gwQivIfPBVSwzDUg2Y0mg/Jpf+IvVAFXcA3RDCVGasUr/2MBzgCDKILrAYBXPp7fI8CVuULf1mwoSQIU4Aounwo4AqpQlw1QhIzBA4Gu+2gBnKD7/Pn9qIKMpCWCGE2UD3xPARZMHyYGdKjNBqlQFXTCK18KoMH1fv1mfmSIbTyJkAZ8OrAUUAFXoJGsARVQQAV1ZCArQIOZNJLeIQQNpElGeOF/ENBGXME1oEIhxitfL6ACGKiCdihmnAQCXwtgIZxAGlAFPYOcOqcx2Xh+5nsK0I1FQFfoJhXkANbgFvA0mK4CMTQhQwzvDv+dFeDIImADFMq3KZIGfC4gDVQgV9CRkHCFiM8H1gILdCE1iCBEWPNZIsQBXxcSATbSK9gOBX0I3sPnl1QNEPSTClmd+7ozge8KtII1QJEvR2MdSAvIQriB3SiEzvOFErnB/6QBV9AzIBUzWLxcgF6i4SJgQ4ggXoH6qiJZHI+Aj6ACawhJfHcgLEQNyBAJglAW/3VHoNxxPkykG9mRVNCUGqgABcAPUT5UtLBezf/8z//8z//8k3kPnkAfIbjCSakAAAAASUVORK5CYII=",
|
|
37
|
+
width: width,
|
|
38
|
+
height: height,
|
|
39
|
+
style: style
|
|
40
|
+
}, restProps));
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
exports.AssistantIcon = AssistantIcon;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = exports.AssistantMobile = void 0;
|
|
9
|
+
|
|
10
|
+
var _react = _interopRequireDefault(require("react"));
|
|
11
|
+
|
|
12
|
+
var _reactRouterDom = require("react-router-dom");
|
|
13
|
+
|
|
14
|
+
var _Icon = _interopRequireDefault(require("cozy-ui/transpiled/react/Icon"));
|
|
15
|
+
|
|
16
|
+
var _SearchBar = _interopRequireDefault(require("cozy-ui/transpiled/react/SearchBar"));
|
|
17
|
+
|
|
18
|
+
var _I18n = require("cozy-ui/transpiled/react/providers/I18n");
|
|
19
|
+
|
|
20
|
+
var _useExtendI18n = _interopRequireDefault(require("cozy-ui/transpiled/react/providers/I18n/useExtendI18n"));
|
|
21
|
+
|
|
22
|
+
var _AssistantIcon = require("./AssistantIcon/AssistantIcon");
|
|
23
|
+
|
|
24
|
+
var _locales = require("../locales");
|
|
25
|
+
|
|
26
|
+
var AssistantMobile = function AssistantMobile() {
|
|
27
|
+
var _useI18n = (0, _I18n.useI18n)(),
|
|
28
|
+
t = _useI18n.t;
|
|
29
|
+
|
|
30
|
+
var navigate = (0, _reactRouterDom.useNavigate)();
|
|
31
|
+
(0, _useExtendI18n.default)(_locales.locales);
|
|
32
|
+
return /*#__PURE__*/_react.default.createElement(_SearchBar.default, {
|
|
33
|
+
size: "medium",
|
|
34
|
+
icon: /*#__PURE__*/_react.default.createElement(_Icon.default, {
|
|
35
|
+
className: "u-ml-1 u-mr-half",
|
|
36
|
+
icon: _AssistantIcon.AssistantIcon,
|
|
37
|
+
size: 24
|
|
38
|
+
}),
|
|
39
|
+
type: "button",
|
|
40
|
+
label: t('assistant.search.placeholder'),
|
|
41
|
+
onClick: function onClick() {
|
|
42
|
+
return navigate('connected/search');
|
|
43
|
+
} // FIXME this route is related to home app
|
|
44
|
+
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
exports.AssistantMobile = AssistantMobile;
|
|
49
|
+
var _default = AssistantMobile;
|
|
50
|
+
exports.default = _default;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.useAssistant = exports.default = exports.AssistantContext = void 0;
|
|
9
|
+
|
|
10
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
|
+
|
|
12
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
13
|
+
|
|
14
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
+
|
|
16
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
17
|
+
|
|
18
|
+
var _set = _interopRequireDefault(require("lodash/set"));
|
|
19
|
+
|
|
20
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
21
|
+
|
|
22
|
+
var _reactRouterDom = require("react-router-dom");
|
|
23
|
+
|
|
24
|
+
var _cozyClient = require("cozy-client");
|
|
25
|
+
|
|
26
|
+
var _useRealtime3 = _interopRequireDefault(require("cozy-realtime/dist/useRealtime"));
|
|
27
|
+
|
|
28
|
+
var _helpers = require("./helpers");
|
|
29
|
+
|
|
30
|
+
var _queries = require("./queries");
|
|
31
|
+
|
|
32
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
33
|
+
|
|
34
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
35
|
+
|
|
36
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
37
|
+
|
|
38
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
39
|
+
|
|
40
|
+
var AssistantContext = /*#__PURE__*/_react.default.createContext();
|
|
41
|
+
|
|
42
|
+
exports.AssistantContext = AssistantContext;
|
|
43
|
+
|
|
44
|
+
var useAssistant = function useAssistant() {
|
|
45
|
+
var context = (0, _react.useContext)(AssistantContext);
|
|
46
|
+
|
|
47
|
+
if (!context) {
|
|
48
|
+
throw new Error('useAssistant must be used within a AssistantProvider');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return context;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
exports.useAssistant = useAssistant;
|
|
55
|
+
|
|
56
|
+
var AssistantProvider = function AssistantProvider(_ref) {
|
|
57
|
+
var children = _ref.children;
|
|
58
|
+
|
|
59
|
+
var _useParams = (0, _reactRouterDom.useParams)(),
|
|
60
|
+
conversationId = _useParams.conversationId;
|
|
61
|
+
|
|
62
|
+
var client = (0, _cozyClient.useClient)();
|
|
63
|
+
|
|
64
|
+
var _useState = (0, _react.useState)({
|
|
65
|
+
message: {},
|
|
66
|
+
status: 'pending',
|
|
67
|
+
messagesId: []
|
|
68
|
+
}),
|
|
69
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
70
|
+
assistantState = _useState2[0],
|
|
71
|
+
setAssistantState = _useState2[1];
|
|
72
|
+
|
|
73
|
+
(0, _useRealtime3.default)(client, (0, _defineProperty2.default)({}, _queries.CHAT_CONVERSATIONS_DOCTYPE, {
|
|
74
|
+
created: function created(res) {
|
|
75
|
+
(0, _helpers.pushMessagesIdInState)(conversationId, res, setAssistantState);
|
|
76
|
+
},
|
|
77
|
+
updated: function updated(res) {
|
|
78
|
+
(0, _helpers.pushMessagesIdInState)(conversationId, res, setAssistantState);
|
|
79
|
+
}
|
|
80
|
+
}), []);
|
|
81
|
+
(0, _useRealtime3.default)(client, (0, _defineProperty2.default)({}, _queries.CHAT_EVENTS_DOCTYPE, {
|
|
82
|
+
created: function created(res) {
|
|
83
|
+
setAssistantState(function (prevState) {
|
|
84
|
+
// to exclude realtime messages if not relevant to the actual conversation
|
|
85
|
+
if (!(0, _helpers.isMessageForThisConversation)(res, prevState.messagesId)) {
|
|
86
|
+
return prevState;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (res.object === 'done') {
|
|
90
|
+
if (prevState.status !== 'idle') {
|
|
91
|
+
return _objectSpread(_objectSpread({}, prevState), {}, {
|
|
92
|
+
status: 'idle'
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (res.object === 'delta') {
|
|
98
|
+
var message = (0, _set.default)(prevState.message, res.position, res.content);
|
|
99
|
+
return _objectSpread(_objectSpread({}, prevState), {}, {
|
|
100
|
+
message: message,
|
|
101
|
+
status: 'writing'
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return prevState;
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}), []);
|
|
109
|
+
var clearAssistant = (0, _react.useCallback)(function () {
|
|
110
|
+
return setAssistantState({
|
|
111
|
+
message: {},
|
|
112
|
+
status: 'pending',
|
|
113
|
+
messagesId: []
|
|
114
|
+
});
|
|
115
|
+
}, []);
|
|
116
|
+
var onAssistantExecute = (0, _react.useCallback)( /*#__PURE__*/function () {
|
|
117
|
+
var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(_ref2, callback) {
|
|
118
|
+
var value, conversationId;
|
|
119
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
120
|
+
while (1) {
|
|
121
|
+
switch (_context.prev = _context.next) {
|
|
122
|
+
case 0:
|
|
123
|
+
value = _ref2.value, conversationId = _ref2.conversationId;
|
|
124
|
+
|
|
125
|
+
if (value) {
|
|
126
|
+
_context.next = 3;
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return _context.abrupt("return");
|
|
131
|
+
|
|
132
|
+
case 3:
|
|
133
|
+
callback === null || callback === void 0 ? void 0 : callback();
|
|
134
|
+
clearAssistant();
|
|
135
|
+
_context.next = 7;
|
|
136
|
+
return client.stackClient.fetchJSON('POST', "/ai/chat/conversations/".concat(conversationId), {
|
|
137
|
+
q: value
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
case 7:
|
|
141
|
+
setAssistantState(function (v) {
|
|
142
|
+
return _objectSpread(_objectSpread({}, v), {}, {
|
|
143
|
+
status: 'pending'
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
case 8:
|
|
148
|
+
case "end":
|
|
149
|
+
return _context.stop();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}, _callee);
|
|
153
|
+
}));
|
|
154
|
+
|
|
155
|
+
return function (_x, _x2) {
|
|
156
|
+
return _ref3.apply(this, arguments);
|
|
157
|
+
};
|
|
158
|
+
}(), [client, clearAssistant]);
|
|
159
|
+
var value = (0, _react.useMemo)(function () {
|
|
160
|
+
return {
|
|
161
|
+
assistantState: assistantState,
|
|
162
|
+
setAssistantState: setAssistantState,
|
|
163
|
+
clearAssistant: clearAssistant,
|
|
164
|
+
onAssistantExecute: onAssistantExecute
|
|
165
|
+
};
|
|
166
|
+
}, [assistantState, clearAssistant, onAssistantExecute]);
|
|
167
|
+
return /*#__PURE__*/_react.default.createElement(AssistantContext.Provider, {
|
|
168
|
+
value: value
|
|
169
|
+
}, children);
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
var _default = /*#__PURE__*/_react.default.memo(AssistantProvider);
|
|
173
|
+
|
|
174
|
+
exports.default = _default;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
11
|
+
|
|
12
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
13
|
+
|
|
14
|
+
var _react = _interopRequireDefault(require("react"));
|
|
15
|
+
|
|
16
|
+
var _Icon = _interopRequireDefault(require("cozy-ui/transpiled/react/Icon"));
|
|
17
|
+
|
|
18
|
+
var _I18n = require("cozy-ui/transpiled/react/providers/I18n");
|
|
19
|
+
|
|
20
|
+
var _ChatItem = _interopRequireDefault(require("./ChatItem"));
|
|
21
|
+
|
|
22
|
+
var _Sources = _interopRequireDefault(require("./Sources/Sources"));
|
|
23
|
+
|
|
24
|
+
var _AssistantIcon = require("../AssistantIcon/AssistantIcon");
|
|
25
|
+
|
|
26
|
+
var _excluded = ["label", "className", "id", "sources"];
|
|
27
|
+
|
|
28
|
+
var ChatAssistantItem = function ChatAssistantItem(_ref) {
|
|
29
|
+
var label = _ref.label,
|
|
30
|
+
className = _ref.className,
|
|
31
|
+
id = _ref.id,
|
|
32
|
+
sources = _ref.sources,
|
|
33
|
+
props = (0, _objectWithoutProperties2.default)(_ref, _excluded);
|
|
34
|
+
|
|
35
|
+
var _useI18n = (0, _I18n.useI18n)(),
|
|
36
|
+
t = _useI18n.t;
|
|
37
|
+
|
|
38
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_ChatItem.default, (0, _extends2.default)({}, props, {
|
|
39
|
+
label: label,
|
|
40
|
+
className: className,
|
|
41
|
+
icon: /*#__PURE__*/_react.default.createElement(_Icon.default, {
|
|
42
|
+
icon: _AssistantIcon.AssistantIcon,
|
|
43
|
+
size: 32
|
|
44
|
+
}),
|
|
45
|
+
name: t('assistant.name')
|
|
46
|
+
})), (sources === null || sources === void 0 ? void 0 : sources.length) > 0 && /*#__PURE__*/_react.default.createElement(_Sources.default, {
|
|
47
|
+
messageId: id,
|
|
48
|
+
sources: sources
|
|
49
|
+
}));
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
var _default = ChatAssistantItem;
|
|
53
|
+
exports.default = _default;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
11
|
+
|
|
12
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
13
|
+
|
|
14
|
+
var _cozyClient = require("cozy-client");
|
|
15
|
+
|
|
16
|
+
var _ChatAssistantItem = _interopRequireDefault(require("./ChatAssistantItem"));
|
|
17
|
+
|
|
18
|
+
var _ChatRealtimeAnswer = _interopRequireDefault(require("./ChatRealtimeAnswer"));
|
|
19
|
+
|
|
20
|
+
var _ChatUserItem = _interopRequireDefault(require("./ChatUserItem"));
|
|
21
|
+
|
|
22
|
+
var _AssistantProvider = require("../AssistantProvider");
|
|
23
|
+
|
|
24
|
+
var _helpers = require("../helpers");
|
|
25
|
+
|
|
26
|
+
var _queries = require("../queries");
|
|
27
|
+
|
|
28
|
+
var _excluded = ["data"];
|
|
29
|
+
|
|
30
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
31
|
+
|
|
32
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
33
|
+
|
|
34
|
+
var ChatConversation = function ChatConversation(_ref) {
|
|
35
|
+
var _conversation$message, _conversation$message2, _conversation$message3, _conversation$message4, _conversation$message5;
|
|
36
|
+
|
|
37
|
+
var conversation = _ref.conversation,
|
|
38
|
+
myself = _ref.myself;
|
|
39
|
+
|
|
40
|
+
var _useAssistant = (0, _AssistantProvider.useAssistant)(),
|
|
41
|
+
assistantState = _useAssistant.assistantState;
|
|
42
|
+
|
|
43
|
+
var listRef = (0, _react.useRef)();
|
|
44
|
+
var instantMessageKeysCount = Object.keys(assistantState.message).length; // test on role === user to be sure the last response is inside io.cozy.ai.chat.conversations
|
|
45
|
+
|
|
46
|
+
var showRealtimeMessage = assistantState.status !== 'idle' || (conversation === null || conversation === void 0 ? void 0 : (_conversation$message = conversation.messages) === null || _conversation$message === void 0 ? void 0 : (_conversation$message2 = _conversation$message[(conversation === null || conversation === void 0 ? void 0 : (_conversation$message3 = conversation.messages) === null || _conversation$message3 === void 0 ? void 0 : _conversation$message3.length) - 1]) === null || _conversation$message2 === void 0 ? void 0 : _conversation$message2.role) === 'user';
|
|
47
|
+
(0, _react.useEffect)(function () {
|
|
48
|
+
var _listRef$current, _listRef$current$last;
|
|
49
|
+
|
|
50
|
+
// force scroll down if new message of change in AI instant response
|
|
51
|
+
(_listRef$current = listRef.current) === null || _listRef$current === void 0 ? void 0 : (_listRef$current$last = _listRef$current.lastElementChild) === null || _listRef$current$last === void 0 ? void 0 : _listRef$current$last.scrollIntoView(false);
|
|
52
|
+
}, [conversation === null || conversation === void 0 ? void 0 : (_conversation$message4 = conversation.messages) === null || _conversation$message4 === void 0 ? void 0 : _conversation$message4.length, assistantState.status, instantMessageKeysCount]);
|
|
53
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
54
|
+
ref: listRef
|
|
55
|
+
}, conversation === null || conversation === void 0 ? void 0 : (_conversation$message5 = conversation.messages) === null || _conversation$message5 === void 0 ? void 0 : _conversation$message5.map(function (message, idx) {
|
|
56
|
+
if (message.role === 'user') {
|
|
57
|
+
return /*#__PURE__*/_react.default.createElement(_ChatUserItem.default, {
|
|
58
|
+
key: conversation._id + '--' + idx,
|
|
59
|
+
className: "u-mt-1-half",
|
|
60
|
+
myself: myself,
|
|
61
|
+
label: message.content
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (idx !== (conversation === null || conversation === void 0 ? void 0 : conversation.messages.length) - 1) {
|
|
66
|
+
return /*#__PURE__*/_react.default.createElement(_ChatAssistantItem.default, {
|
|
67
|
+
key: conversation._id + '--' + idx,
|
|
68
|
+
className: "u-mt-1-half",
|
|
69
|
+
id: message.id,
|
|
70
|
+
label: message.content,
|
|
71
|
+
sources: message.sources
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (showRealtimeMessage) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return /*#__PURE__*/_react.default.createElement(_ChatAssistantItem.default, {
|
|
80
|
+
key: conversation._id + '--' + idx,
|
|
81
|
+
className: "u-mt-1-half",
|
|
82
|
+
id: message.id,
|
|
83
|
+
label: message.content,
|
|
84
|
+
sources: message.sources
|
|
85
|
+
});
|
|
86
|
+
}), showRealtimeMessage && /*#__PURE__*/_react.default.createElement(_ChatRealtimeAnswer.default, {
|
|
87
|
+
isLoading: assistantState.status === 'pending',
|
|
88
|
+
label: (0, _helpers.getInstantMessage)(assistantState)
|
|
89
|
+
}));
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
var ChatConversationWithQuery = function ChatConversationWithQuery(_ref2) {
|
|
93
|
+
var id = _ref2.id,
|
|
94
|
+
myself = _ref2.myself;
|
|
95
|
+
var chatConversationQuery = (0, _queries.buildChatConversationQueryById)(id);
|
|
96
|
+
|
|
97
|
+
var _useQuery = (0, _cozyClient.useQuery)(chatConversationQuery.definition, chatConversationQuery.options),
|
|
98
|
+
chatConversation = _useQuery.data,
|
|
99
|
+
queryResult = (0, _objectWithoutProperties2.default)(_useQuery, _excluded);
|
|
100
|
+
|
|
101
|
+
var isLoading = (0, _cozyClient.isQueryLoading)(queryResult);
|
|
102
|
+
if (isLoading) return null;
|
|
103
|
+
return /*#__PURE__*/_react.default.createElement(ChatConversation, {
|
|
104
|
+
conversation: chatConversation,
|
|
105
|
+
myself: myself
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
var _default = ChatConversationWithQuery;
|
|
110
|
+
exports.default = _default;
|