@bigbinary/neeto-assist-frontend 1.2.1 → 1.3.0-beta1
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 +430 -21
- package/app/javascript/src/translations/en.json +39 -2
- package/dist/.ready +1 -1
- package/dist/NeetoAssistButton.js +13 -6
- package/dist/NeetoAssistButton.js.map +1 -1
- package/dist/NeetoAssistPane.js +1469 -166
- package/dist/NeetoAssistPane.js.map +1 -1
- package/dist/cjs/NeetoAssistButton.js +16 -9
- package/dist/cjs/NeetoAssistButton.js.map +1 -1
- package/dist/cjs/NeetoAssistPane.js +1491 -188
- package/dist/cjs/NeetoAssistPane.js.map +1 -1
- package/dist/cjs/index.js +11 -5
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/useNeetoAssistAssistant.js +43 -0
- package/dist/cjs/useNeetoAssistAssistant.js.map +1 -0
- package/dist/cjs/useNeetoAssistStatus.js +3 -1
- package/dist/cjs/useNeetoAssistStatus.js.map +1 -1
- package/dist/index.js +10 -5
- package/dist/index.js.map +1 -1
- package/dist/neeto_assist-COp7BR77.js +249 -0
- package/dist/neeto_assist-COp7BR77.js.map +1 -0
- package/dist/neeto_assist-D1wzZ3ou.js +219 -0
- package/dist/neeto_assist-D1wzZ3ou.js.map +1 -0
- package/dist/useNeetoAssistAssistant.js +41 -0
- package/dist/useNeetoAssistAssistant.js.map +1 -0
- package/dist/useNeetoAssistStatus.js +3 -1
- package/dist/useNeetoAssistStatus.js.map +1 -1
- package/dist/useNeetoAssistStore-Bj6niQdc.js +103 -0
- package/dist/useNeetoAssistStore-Bj6niQdc.js.map +1 -0
- package/dist/useNeetoAssistStore-Dgt8aV52.js +101 -0
- package/dist/useNeetoAssistStore-Dgt8aV52.js.map +1 -0
- package/dist/{useNeetoAssistStore-InICsbe8.js → useRunsApi-BgsICthX.js} +228 -113
- package/dist/useRunsApi-BgsICthX.js.map +1 -0
- package/dist/{useNeetoAssistStore-VaZp3268.js → useRunsApi-Rh6xXOwm.js} +232 -112
- package/dist/useRunsApi-Rh6xXOwm.js.map +1 -0
- package/package.json +4 -4
- package/types.d.ts +81 -8
- package/dist/neeto_assist-CpUBA-3Z.js +0 -135
- package/dist/neeto_assist-CpUBA-3Z.js.map +0 -1
- package/dist/neeto_assist-CznTN_YY.js +0 -157
- package/dist/neeto_assist-CznTN_YY.js.map +0 -1
- package/dist/useNeetoAssistStore-InICsbe8.js.map +0 -1
- package/dist/useNeetoAssistStore-VaZp3268.js.map +0 -1
package/dist/NeetoAssistPane.js
CHANGED
|
@@ -1,23 +1,217 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as neetoAssistApi, Q as QUERY_KEYS, M as MAX_ASSISTANT_SUGGESTIONS, h as SUGGESTION_KEYS, i as MAX_QUESTION_LENGTH, j as ACTION_ERROR_MESSAGE_KEYS, k as SETTLED_ACTION_STATUSES, l as QUIET_ACTION_STATUS_KEYS, C as COPIED_FOR, m as MAX_NOTE_LENGTH, o as RUN_TEST_ID, p as EXPANDED_PANE_WIDTH, q as COLLAPSED_PANE_WIDTH, P as PANE_MODES } from './neeto_assist-D1wzZ3ou.js';
|
|
2
|
+
import { u as useNeetoAssistStore } from './useNeetoAssistStore-Dgt8aV52.js';
|
|
2
3
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
4
|
+
import { useRef, useEffect, useId, useState, useLayoutEffect, Fragment, useMemo, createElement } from 'react';
|
|
3
5
|
import { Typography, Textarea, Spinner, typographyVariants, Button, Tooltip, Badge } from '@bigbinary/neeto-atoms';
|
|
6
|
+
import { assoc, uniq, isEmpty, propOr, reject, pluck, not, prop, inc } from 'ramda';
|
|
7
|
+
import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
|
|
8
|
+
import _regeneratorRuntime from '@babel/runtime/regenerator';
|
|
9
|
+
import { useQuery, useQueryClient, useMutation } from '@tanstack/react-query';
|
|
10
|
+
import { e as errorMessageKey, a as useAskNeetoAssist, i as isWebUrl, o as optionId, b as useStopRun, m as matchingCommands, p as pickedCommand, c as useApplyAction, d as useDismissAction, s as shownSources, f as actionsOf, g as useUpdateFeedback, h as commandPart, j as stepsOf, k as isPending, n as hasRunningStep, q as hasWrittenReply, r as skippedReasonMessageKey, t as isStopped, v as isRateable, u as useFetchRuns, l as latestDraftId, w as stoppableAsk, x as runsInConversationOrder, y as useIsAsking, z as hasPendingRun, S as Sparkle } from './useRunsApi-BgsICthX.js';
|
|
11
|
+
import { isNotEmpty, findIndexBy } from '@bigbinary/neeto-cist';
|
|
4
12
|
import { useTranslation } from 'react-i18next';
|
|
5
|
-
import { jsxs, jsx, Fragment as Fragment$1 } from 'react/jsx-runtime';
|
|
6
|
-
import { useRef, useEffect, useId, useState, useLayoutEffect, Fragment, createElement } from 'react';
|
|
7
|
-
import { isEmpty, propOr, not, prop } from 'ramda';
|
|
8
|
-
import { e as SUGGESTION_KEYS, M as MAX_QUESTION_LENGTH, A as ACTION_ERROR_MESSAGE_KEYS, f as SETTLED_ACTION_STATUSES, g as QUIET_ACTION_STATUS_KEYS, h as MAX_NOTE_LENGTH, i as RUN_TEST_ID, j as EXPANDED_PANE_WIDTH, C as COLLAPSED_PANE_WIDTH } from './neeto_assist-CpUBA-3Z.js';
|
|
9
13
|
import { withT } from '@bigbinary/neeto-commons-frontend/v2/react-utils';
|
|
14
|
+
import { jsx, jsxs, Fragment as Fragment$1 } from 'react/jsx-runtime';
|
|
10
15
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
11
16
|
import classnames from 'classnames';
|
|
12
|
-
import { CircleArrowUp, ChevronUp, ChevronDown, Check, ExternalLink, CornerDownLeft, Copy, ThumbsUp, ThumbsDown, X, Minimize2, Maximize2 } from 'lucide-react';
|
|
13
|
-
import
|
|
17
|
+
import { CirclePause, CircleArrowUp, ChevronUp, ChevronDown, Check, ExternalLink, CornerDownLeft, Copy, ThumbsUp, ThumbsDown, X, SquarePen, Minimize2, Maximize2 } from 'lucide-react';
|
|
18
|
+
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
19
|
+
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
14
20
|
import { copyToClipboard } from '@bigbinary/neeto-commons-frontend/v2/utils';
|
|
15
|
-
import '@babel/runtime/helpers/objectWithoutProperties';
|
|
16
|
-
import '@tanstack/react-query';
|
|
17
|
-
import '@babel/runtime/helpers/toConsumableArray';
|
|
18
|
-
import '@babel/runtime/helpers/toArray';
|
|
19
|
-
import 'zustand';
|
|
20
21
|
import 'axios';
|
|
22
|
+
import 'zustand';
|
|
23
|
+
import '@babel/runtime/helpers/typeof';
|
|
24
|
+
import '@babel/runtime/helpers/toArray';
|
|
25
|
+
|
|
26
|
+
// The first questions the engine offers for an empty thread. Only sentences
|
|
27
|
+
// are kept, each once, so a button never shows anything else.
|
|
28
|
+
var suggestionsOf = function suggestionsOf(suggestions) {
|
|
29
|
+
return uniq((Array.isArray(suggestions) ? suggestions : []).filter(function (suggestion) {
|
|
30
|
+
return typeof suggestion === "string" && !!suggestion.trim();
|
|
31
|
+
})).slice(0, MAX_ASSISTANT_SUGGESTIONS);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// The person's thread: asked for once, when the assistant is first opened, and
|
|
35
|
+
// kept for as long as the page is. A new chat replaces it in place, since the
|
|
36
|
+
// engine stores nothing for a new thread until its first question, and asking
|
|
37
|
+
// again would name the old one. A failure is shown in the pane, not as a
|
|
38
|
+
// toast, and the assistant asks again the next time it is opened.
|
|
39
|
+
var useFetchAssistantThread = function useFetchAssistantThread() {
|
|
40
|
+
return useQuery({
|
|
41
|
+
queryKey: [QUERY_KEYS.ASSISTANT_THREAD],
|
|
42
|
+
queryFn: neetoAssistApi.fetchAssistantThread,
|
|
43
|
+
select: function select() {
|
|
44
|
+
var _thread$id;
|
|
45
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
46
|
+
thread = _ref.thread,
|
|
47
|
+
suggestions = _ref.suggestions;
|
|
48
|
+
return {
|
|
49
|
+
threadId: (_thread$id = thread === null || thread === void 0 ? void 0 : thread.id) !== null && _thread$id !== void 0 ? _thread$id : null,
|
|
50
|
+
suggestions: suggestionsOf(suggestions)
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
staleTime: Infinity,
|
|
54
|
+
gcTime: Infinity,
|
|
55
|
+
retry: false
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// New chat. The new thread keeps the suggestions the engine sent, which are
|
|
60
|
+
// the same for every thread of this person. After a first load that failed
|
|
61
|
+
// there are none yet, so they are asked for then, and the new chat is ready
|
|
62
|
+
// once they are in. Without them the thread is still shown, as before.
|
|
63
|
+
var useStartAssistantThread = function useStartAssistantThread() {
|
|
64
|
+
var queryClient = useQueryClient();
|
|
65
|
+
var queryKey = [QUERY_KEYS.ASSISTANT_THREAD];
|
|
66
|
+
return useMutation({
|
|
67
|
+
mutationFn: neetoAssistApi.createAssistantThread,
|
|
68
|
+
onSuccess: function () {
|
|
69
|
+
var _onSuccess = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref2) {
|
|
70
|
+
var thread, hadThread, _yield$neetoAssistApi, suggestions;
|
|
71
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
72
|
+
while (1) switch (_context.prev = _context.next) {
|
|
73
|
+
case 0:
|
|
74
|
+
thread = _ref2.thread;
|
|
75
|
+
hadThread = queryClient.getQueryData(queryKey) !== undefined;
|
|
76
|
+
queryClient.setQueryData(queryKey, assoc("thread", thread));
|
|
77
|
+
if (!hadThread) {
|
|
78
|
+
_context.next = 5;
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
return _context.abrupt("return");
|
|
82
|
+
case 5:
|
|
83
|
+
_context.prev = 5;
|
|
84
|
+
_context.next = 8;
|
|
85
|
+
return neetoAssistApi.fetchAssistantThread();
|
|
86
|
+
case 8:
|
|
87
|
+
_yield$neetoAssistApi = _context.sent;
|
|
88
|
+
suggestions = _yield$neetoAssistApi.suggestions;
|
|
89
|
+
queryClient.setQueryData(queryKey, assoc("suggestions", suggestions));
|
|
90
|
+
_context.next = 15;
|
|
91
|
+
break;
|
|
92
|
+
case 13:
|
|
93
|
+
_context.prev = 13;
|
|
94
|
+
_context.t0 = _context["catch"](5);
|
|
95
|
+
case 15:
|
|
96
|
+
case "end":
|
|
97
|
+
return _context.stop();
|
|
98
|
+
}
|
|
99
|
+
}, _callee, null, [[5, 13]]);
|
|
100
|
+
}));
|
|
101
|
+
function onSuccess(_x) {
|
|
102
|
+
return _onSuccess.apply(this, arguments);
|
|
103
|
+
}
|
|
104
|
+
return onSuccess;
|
|
105
|
+
}()
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// crypto.randomUUID exists only on secure pages (HTTPS or localhost). A host in
|
|
110
|
+
// development, such as http://spinkart.lvh.me, gets the same shape of id from
|
|
111
|
+
// crypto.getRandomValues, which every page has.
|
|
112
|
+
var newRequestId = function newRequestId() {
|
|
113
|
+
if (globalThis.crypto.randomUUID) return globalThis.crypto.randomUUID();
|
|
114
|
+
var hex = Array.from(globalThis.crypto.getRandomValues(new Uint8Array(16)), function (_byte) {
|
|
115
|
+
return _byte.toString(16).padStart(2, "0");
|
|
116
|
+
}).join("");
|
|
117
|
+
return [8, 12, 16, 20, 32].map(function (end, index, ends) {
|
|
118
|
+
var _ends;
|
|
119
|
+
return hex.slice((_ends = ends[index - 1]) !== null && _ends !== void 0 ? _ends : 0, end);
|
|
120
|
+
}).join("-");
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
var ErrorMessage$1 = function ErrorMessage(_ref) {
|
|
124
|
+
var error = _ref.error,
|
|
125
|
+
_ref$isAssistant = _ref.isAssistant,
|
|
126
|
+
isAssistant = _ref$isAssistant === void 0 ? false : _ref$isAssistant,
|
|
127
|
+
t = _ref.t;
|
|
128
|
+
return /*#__PURE__*/jsx(Typography, {
|
|
129
|
+
color: "destructive",
|
|
130
|
+
"data-testid": "neeto-assist-error",
|
|
131
|
+
variant: "body3",
|
|
132
|
+
children: t(errorMessageKey(error, isAssistant))
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
var ErrorMessage = withT(ErrorMessage$1);
|
|
136
|
+
|
|
137
|
+
var EmptyState$1 = function EmptyState(_ref) {
|
|
138
|
+
var _ref$isAskDisabled = _ref.isAskDisabled,
|
|
139
|
+
isAskDisabled = _ref$isAskDisabled === void 0 ? false : _ref$isAskDisabled,
|
|
140
|
+
onAsk = _ref.onAsk,
|
|
141
|
+
_ref$suggestions = _ref.suggestions,
|
|
142
|
+
suggestions = _ref$suggestions === void 0 ? [] : _ref$suggestions,
|
|
143
|
+
threadId = _ref.threadId;
|
|
144
|
+
var _useTranslation = useTranslation(),
|
|
145
|
+
t = _useTranslation.t;
|
|
146
|
+
var requestsRef = useRef(new Map());
|
|
147
|
+
var _useAskNeetoAssist = useAskNeetoAssist({
|
|
148
|
+
threadId: threadId
|
|
149
|
+
}),
|
|
150
|
+
ask = _useAskNeetoAssist.mutate,
|
|
151
|
+
isPending = _useAskNeetoAssist.isPending,
|
|
152
|
+
error = _useAskNeetoAssist.error;
|
|
153
|
+
var isDisabled = isAskDisabled || isPending;
|
|
154
|
+
var askSuggestion = function askSuggestion(question) {
|
|
155
|
+
var _requestsRef$current$;
|
|
156
|
+
if (isDisabled) return;
|
|
157
|
+
|
|
158
|
+
// The first request may have reached NeetoAssist even when its answer
|
|
159
|
+
// was lost. Retrying this suggestion must ask for that same run.
|
|
160
|
+
var requestId = (_requestsRef$current$ = requestsRef.current.get(question)) !== null && _requestsRef$current$ !== void 0 ? _requestsRef$current$ : newRequestId();
|
|
161
|
+
requestsRef.current.set(question, requestId);
|
|
162
|
+
ask({
|
|
163
|
+
threadId: threadId,
|
|
164
|
+
question: question,
|
|
165
|
+
requestId: requestId
|
|
166
|
+
}, {
|
|
167
|
+
onSuccess: function onSuccess() {
|
|
168
|
+
return requestsRef.current["delete"](question);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
onAsk === null || onAsk === void 0 || onAsk();
|
|
172
|
+
};
|
|
173
|
+
return /*#__PURE__*/jsxs("div", {
|
|
174
|
+
className: "flex flex-col gap-4 px-2 pt-4",
|
|
175
|
+
"data-testid": "neeto-assist-empty-state",
|
|
176
|
+
children: [/*#__PURE__*/jsxs("div", {
|
|
177
|
+
children: [/*#__PURE__*/jsx(Typography, {
|
|
178
|
+
variant: "h4",
|
|
179
|
+
children: t("neetoAssist.intro.title")
|
|
180
|
+
}), /*#__PURE__*/jsx(Typography, {
|
|
181
|
+
className: "mt-1",
|
|
182
|
+
color: "muted",
|
|
183
|
+
variant: "body3",
|
|
184
|
+
children: t("neetoAssist.assistant.intro")
|
|
185
|
+
})]
|
|
186
|
+
}), isNotEmpty(suggestions) && /*#__PURE__*/jsx("ul", {
|
|
187
|
+
"aria-label": t("neetoAssist.assistant.suggestions"),
|
|
188
|
+
className: "flex flex-col gap-1",
|
|
189
|
+
children: suggestions.map(function (suggestion) {
|
|
190
|
+
return /*#__PURE__*/jsx("li", {
|
|
191
|
+
children: /*#__PURE__*/jsxs("button", {
|
|
192
|
+
className: "text-foreground hover:bg-muted -mx-2 flex w-full cursor-pointer items-start gap-2 rounded px-2 py-1.5 text-start text-sm leading-snug disabled:cursor-not-allowed disabled:opacity-50 disabled:hover:bg-transparent",
|
|
193
|
+
"data-testid": "neeto-assist-suggestion",
|
|
194
|
+
disabled: isDisabled,
|
|
195
|
+
type: "button",
|
|
196
|
+
onClick: function onClick() {
|
|
197
|
+
return askSuggestion(suggestion);
|
|
198
|
+
},
|
|
199
|
+
children: [/*#__PURE__*/jsx("span", {
|
|
200
|
+
"aria-hidden": "true",
|
|
201
|
+
className: "text-muted-foreground",
|
|
202
|
+
children: "\u203A"
|
|
203
|
+
}), /*#__PURE__*/jsx("span", {
|
|
204
|
+
children: suggestion
|
|
205
|
+
})]
|
|
206
|
+
})
|
|
207
|
+
}, suggestion);
|
|
208
|
+
})
|
|
209
|
+
}), error && /*#__PURE__*/jsx(ErrorMessage, {
|
|
210
|
+
error: error,
|
|
211
|
+
isAssistant: true
|
|
212
|
+
})]
|
|
213
|
+
});
|
|
214
|
+
};
|
|
21
215
|
|
|
22
216
|
var HEADER_ICON_SIZE = 18;
|
|
23
217
|
var SEND_ICON_SIZE = 24;
|
|
@@ -30,30 +224,17 @@ var SCROLL_MARGIN = 8;
|
|
|
30
224
|
// the window's height.
|
|
31
225
|
var REPLY_STARTS_WITHIN = 1 / 3;
|
|
32
226
|
|
|
227
|
+
// How a table's column is aligned, from the colons under its header.
|
|
228
|
+
var TABLE_ALIGNMENT_CLASSES = {
|
|
229
|
+
start: "text-start",
|
|
230
|
+
center: "text-center",
|
|
231
|
+
end: "text-end"
|
|
232
|
+
};
|
|
233
|
+
|
|
33
234
|
// Stands where the host's label goes while the sentence around it is
|
|
34
235
|
// translated.
|
|
35
236
|
var CONTEXT_LABEL_SLOT = "\0";
|
|
36
237
|
|
|
37
|
-
var ContextLabel = function ContextLabel(_ref) {
|
|
38
|
-
var label = _ref.label;
|
|
39
|
-
var _useTranslation = useTranslation(),
|
|
40
|
-
t = _useTranslation.t;
|
|
41
|
-
var _t$split = t("neetoAssist.lookingAt", {
|
|
42
|
-
label: CONTEXT_LABEL_SLOT
|
|
43
|
-
}).split(CONTEXT_LABEL_SLOT),
|
|
44
|
-
_t$split2 = _slicedToArray(_t$split, 2),
|
|
45
|
-
before = _t$split2[0],
|
|
46
|
-
after = _t$split2[1];
|
|
47
|
-
return /*#__PURE__*/jsxs(Typography, {
|
|
48
|
-
className: "border-border truncate border-b px-4 py-2",
|
|
49
|
-
color: "muted",
|
|
50
|
-
"data-testid": "neeto-assist-context-label",
|
|
51
|
-
title: label,
|
|
52
|
-
variant: "body3",
|
|
53
|
-
children: [before, label, after]
|
|
54
|
-
});
|
|
55
|
-
};
|
|
56
|
-
|
|
57
238
|
var CreditsBanner$1 = function CreditsBanner(_ref) {
|
|
58
239
|
var credits = _ref.credits,
|
|
59
240
|
t = _ref.t;
|
|
@@ -79,32 +260,6 @@ var CreditsBanner$1 = function CreditsBanner(_ref) {
|
|
|
79
260
|
};
|
|
80
261
|
var CreditsBanner = withT(CreditsBanner$1);
|
|
81
262
|
|
|
82
|
-
// crypto.randomUUID exists only on secure pages (HTTPS or localhost). A host in
|
|
83
|
-
// development, such as http://spinkart.lvh.me, gets the same shape of id from
|
|
84
|
-
// crypto.getRandomValues, which every page has.
|
|
85
|
-
var newRequestId = function newRequestId() {
|
|
86
|
-
if (globalThis.crypto.randomUUID) return globalThis.crypto.randomUUID();
|
|
87
|
-
var hex = Array.from(globalThis.crypto.getRandomValues(new Uint8Array(16)), function (_byte) {
|
|
88
|
-
return _byte.toString(16).padStart(2, "0");
|
|
89
|
-
}).join("");
|
|
90
|
-
return [8, 12, 16, 20, 32].map(function (end, index, ends) {
|
|
91
|
-
var _ends;
|
|
92
|
-
return hex.slice((_ends = ends[index - 1]) !== null && _ends !== void 0 ? _ends : 0, end);
|
|
93
|
-
}).join("-");
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
var ErrorMessage$1 = function ErrorMessage(_ref) {
|
|
97
|
-
var error = _ref.error,
|
|
98
|
-
t = _ref.t;
|
|
99
|
-
return /*#__PURE__*/jsx(Typography, {
|
|
100
|
-
color: "destructive",
|
|
101
|
-
"data-testid": "neeto-assist-error",
|
|
102
|
-
variant: "body3",
|
|
103
|
-
children: t(errorMessageKey(error))
|
|
104
|
-
});
|
|
105
|
-
};
|
|
106
|
-
var ErrorMessage = withT(ErrorMessage$1);
|
|
107
|
-
|
|
108
263
|
var EmptyState = function EmptyState(_ref) {
|
|
109
264
|
var conversationId = _ref.conversationId;
|
|
110
265
|
var _useTranslation = useTranslation(),
|
|
@@ -220,13 +375,20 @@ var CommandMenu = function CommandMenu(_ref) {
|
|
|
220
375
|
});
|
|
221
376
|
};
|
|
222
377
|
|
|
223
|
-
function ownKeys$
|
|
224
|
-
function _objectSpread$
|
|
378
|
+
function ownKeys$5(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; }
|
|
379
|
+
function _objectSpread$5(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$5(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$5(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
225
380
|
var MessageInput = function MessageInput(_ref) {
|
|
226
381
|
var _menu$at$name, _menu$at;
|
|
227
382
|
var _ref$commands = _ref.commands,
|
|
228
383
|
commands = _ref$commands === void 0 ? [] : _ref$commands,
|
|
229
|
-
conversationId = _ref.conversationId
|
|
384
|
+
conversationId = _ref.conversationId,
|
|
385
|
+
_ref$focusRequest = _ref.focusRequest,
|
|
386
|
+
focusRequest = _ref$focusRequest === void 0 ? 0 : _ref$focusRequest,
|
|
387
|
+
_ref$isAskDisabled = _ref.isAskDisabled,
|
|
388
|
+
isAskDisabled = _ref$isAskDisabled === void 0 ? false : _ref$isAskDisabled,
|
|
389
|
+
_ref$pendingAsk = _ref.pendingAsk,
|
|
390
|
+
pendingAsk = _ref$pendingAsk === void 0 ? null : _ref$pendingAsk,
|
|
391
|
+
threadId = _ref.threadId;
|
|
230
392
|
var _useTranslation = useTranslation(),
|
|
231
393
|
t = _useTranslation.t;
|
|
232
394
|
var menuId = useId();
|
|
@@ -242,15 +404,34 @@ var MessageInput = function MessageInput(_ref) {
|
|
|
242
404
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
243
405
|
isMenuClosed = _useState6[0],
|
|
244
406
|
setIsMenuClosed = _useState6[1];
|
|
407
|
+
var _useState7 = useState(null),
|
|
408
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
409
|
+
stoppingRunId = _useState8[0],
|
|
410
|
+
setStoppingRunId = _useState8[1];
|
|
245
411
|
var requestRef = useRef(null);
|
|
412
|
+
var stopRequestRef = useRef(null);
|
|
246
413
|
var boxRef = useRef(null);
|
|
247
414
|
var caretRef = useRef(null);
|
|
248
|
-
var
|
|
415
|
+
var where = threadId ? {
|
|
416
|
+
threadId: threadId
|
|
417
|
+
} : {
|
|
418
|
+
conversationId: conversationId
|
|
419
|
+
};
|
|
420
|
+
var isAssistant = !!threadId;
|
|
421
|
+
var placeholder = t(isAssistant ? "neetoAssist.assistant.placeholder" : "neetoAssist.ask.placeholder");
|
|
422
|
+
var _useAskNeetoAssist = useAskNeetoAssist(where),
|
|
249
423
|
ask = _useAskNeetoAssist.mutate,
|
|
250
424
|
isPending = _useAskNeetoAssist.isPending,
|
|
251
425
|
error = _useAskNeetoAssist.error;
|
|
426
|
+
var _useStopRun = useStopRun(where),
|
|
427
|
+
stop = _useStopRun.mutate,
|
|
428
|
+
stopError = _useStopRun.error,
|
|
429
|
+
stopVariables = _useStopRun.variables;
|
|
252
430
|
var trimmedQuestion = question.trim();
|
|
253
|
-
var canSend = !!trimmedQuestion && !isPending;
|
|
431
|
+
var canSend = !!trimmedQuestion && !isPending && !pendingAsk && !isAskDisabled;
|
|
432
|
+
var isStopping = !!pendingAsk && stoppingRunId === pendingAsk.id;
|
|
433
|
+
// A stop that failed is told under the box for as long as its ask goes on.
|
|
434
|
+
var isStopErrorShown = !!stopError && !!pendingAsk && (stopVariables === null || stopVariables === void 0 ? void 0 : stopVariables.runId) === pendingAsk.id;
|
|
254
435
|
var menu = matchingCommands(question, commands);
|
|
255
436
|
var isMenuOpen = !isPending && !isMenuClosed && !isEmpty(menu);
|
|
256
437
|
var marked = Math.max(0, findIndexBy({
|
|
@@ -265,6 +446,10 @@ var MessageInput = function MessageInput(_ref) {
|
|
|
265
446
|
// keyboard. Where there are commands it must not: the space after a picked
|
|
266
447
|
// command would go, and the rep's next words would run into it.
|
|
267
448
|
var keepsEnds = !isEmpty(commands);
|
|
449
|
+
useEffect(function () {
|
|
450
|
+
var _boxRef$current;
|
|
451
|
+
if (focusRequest > 0) (_boxRef$current = boxRef.current) === null || _boxRef$current === void 0 || _boxRef$current.focus();
|
|
452
|
+
}, [focusRequest]);
|
|
268
453
|
|
|
269
454
|
// A refetch may move a row. Keep the command under the mark, or the first
|
|
270
455
|
// one if it went away, even if the old command comes back in a later poll.
|
|
@@ -275,10 +460,10 @@ var MessageInput = function MessageInput(_ref) {
|
|
|
275
460
|
// A picked command leaves the cursor right after it, in a box that still has
|
|
276
461
|
// the keyboard, once the box holds the new text.
|
|
277
462
|
useLayoutEffect(function () {
|
|
278
|
-
var _boxRef$
|
|
463
|
+
var _boxRef$current2, _boxRef$current3;
|
|
279
464
|
if (caretRef.current === null) return;
|
|
280
|
-
(_boxRef$
|
|
281
|
-
(_boxRef$
|
|
465
|
+
(_boxRef$current2 = boxRef.current) === null || _boxRef$current2 === void 0 || _boxRef$current2.focus();
|
|
466
|
+
(_boxRef$current3 = boxRef.current) === null || _boxRef$current3 === void 0 || _boxRef$current3.setSelectionRange(caretRef.current, caretRef.current);
|
|
282
467
|
caretRef.current = null;
|
|
283
468
|
}, [question]);
|
|
284
469
|
var handleChange = function handleChange(event) {
|
|
@@ -305,9 +490,7 @@ var MessageInput = function MessageInput(_ref) {
|
|
|
305
490
|
requestId: newRequestId()
|
|
306
491
|
};
|
|
307
492
|
}
|
|
308
|
-
ask(_objectSpread$
|
|
309
|
-
conversationId: conversationId
|
|
310
|
-
}, requestRef.current), {
|
|
493
|
+
ask(_objectSpread$5(_objectSpread$5({}, where), requestRef.current), {
|
|
311
494
|
onSuccess: function onSuccess() {
|
|
312
495
|
requestRef.current = null;
|
|
313
496
|
setQuestion("");
|
|
@@ -315,6 +498,27 @@ var MessageInput = function MessageInput(_ref) {
|
|
|
315
498
|
});
|
|
316
499
|
};
|
|
317
500
|
|
|
501
|
+
// One click stops: a second one before the first is answered sends nothing,
|
|
502
|
+
// and the button shows it is working until the list says the ask has ended.
|
|
503
|
+
// A stop that failed leaves the button as it was, to try again. The keyboard
|
|
504
|
+
// goes back to the box, for the next question.
|
|
505
|
+
var handleStop = function handleStop() {
|
|
506
|
+
var _boxRef$current4;
|
|
507
|
+
var runId = pendingAsk.id;
|
|
508
|
+
(_boxRef$current4 = boxRef.current) === null || _boxRef$current4 === void 0 || _boxRef$current4.focus();
|
|
509
|
+
if (stopRequestRef.current === runId) return;
|
|
510
|
+
stopRequestRef.current = runId;
|
|
511
|
+
setStoppingRunId(runId);
|
|
512
|
+
stop(_objectSpread$5(_objectSpread$5({}, where), {}, {
|
|
513
|
+
runId: runId
|
|
514
|
+
}), {
|
|
515
|
+
onError: function onError() {
|
|
516
|
+
stopRequestRef.current = null;
|
|
517
|
+
setStoppingRunId(null);
|
|
518
|
+
}
|
|
519
|
+
});
|
|
520
|
+
};
|
|
521
|
+
|
|
318
522
|
// While the menu is open its keys belong to it: the arrows move the mark,
|
|
319
523
|
// Enter or Tab picks the marked command, and Escape closes the menu. Says
|
|
320
524
|
// whether the key was one of them.
|
|
@@ -355,17 +559,17 @@ var MessageInput = function MessageInput(_ref) {
|
|
|
355
559
|
},
|
|
356
560
|
onPick: pick
|
|
357
561
|
}), /*#__PURE__*/jsx(Textarea, {
|
|
562
|
+
placeholder: placeholder,
|
|
358
563
|
"aria-autocomplete": isEmpty(commands) ? undefined : "list",
|
|
359
564
|
"aria-controls": isMenuOpen ? menuId : undefined,
|
|
360
565
|
"aria-describedby": isHintShown ? hintId : undefined,
|
|
361
566
|
"aria-expanded": isEmpty(commands) ? undefined : isMenuOpen,
|
|
362
567
|
"aria-haspopup": isEmpty(commands) ? undefined : "listbox",
|
|
363
|
-
"aria-label":
|
|
568
|
+
"aria-label": placeholder,
|
|
364
569
|
className: "w-full pe-12",
|
|
365
570
|
dataTestId: "neeto-assist-ask",
|
|
366
571
|
disableTrimOnBlur: keepsEnds,
|
|
367
572
|
maxLength: MAX_QUESTION_LENGTH,
|
|
368
|
-
placeholder: t("neetoAssist.ask.placeholder"),
|
|
369
573
|
readOnly: isPending,
|
|
370
574
|
ref: boxRef,
|
|
371
575
|
role: isEmpty(commands) ? undefined : "combobox",
|
|
@@ -380,7 +584,22 @@ var MessageInput = function MessageInput(_ref) {
|
|
|
380
584
|
return setIsMenuClosed(false);
|
|
381
585
|
},
|
|
382
586
|
onKeyDown: handleKeyDown
|
|
383
|
-
}), /*#__PURE__*/jsx("button", {
|
|
587
|
+
}), pendingAsk ? /*#__PURE__*/jsx("button", {
|
|
588
|
+
"data-testid": "neeto-assist-stop-button",
|
|
589
|
+
disabled: isStopping,
|
|
590
|
+
type: "button",
|
|
591
|
+
"aria-label": t(isStopping ? "neetoAssist.ask.stopping" : "neetoAssist.ask.stop"),
|
|
592
|
+
className: classnames("absolute end-2 bottom-2 flex h-7 w-7 items-center justify-center rounded-full transition-opacity", {
|
|
593
|
+
"text-destructive hover:opacity-80": !isStopping,
|
|
594
|
+
"text-muted-foreground cursor-not-allowed opacity-60": isStopping
|
|
595
|
+
}),
|
|
596
|
+
onClick: handleStop,
|
|
597
|
+
children: isStopping ? /*#__PURE__*/jsx(Spinner, {
|
|
598
|
+
size: "sm"
|
|
599
|
+
}) : /*#__PURE__*/jsx(CirclePause, {
|
|
600
|
+
size: SEND_ICON_SIZE
|
|
601
|
+
})
|
|
602
|
+
}) : /*#__PURE__*/jsx("button", {
|
|
384
603
|
"aria-label": t("neetoAssist.ask.submit"),
|
|
385
604
|
"data-testid": "neeto-assist-ask-button",
|
|
386
605
|
disabled: !canSend,
|
|
@@ -396,13 +615,17 @@ var MessageInput = function MessageInput(_ref) {
|
|
|
396
615
|
})
|
|
397
616
|
})]
|
|
398
617
|
}), error && /*#__PURE__*/jsx(ErrorMessage, {
|
|
399
|
-
error: error
|
|
618
|
+
error: error,
|
|
619
|
+
isAssistant: isAssistant
|
|
620
|
+
}), isStopErrorShown && /*#__PURE__*/jsx(ErrorMessage, {
|
|
621
|
+
isAssistant: isAssistant,
|
|
622
|
+
error: stopError
|
|
400
623
|
}), /*#__PURE__*/jsxs("div", {
|
|
401
624
|
className: "flex items-center justify-between gap-3",
|
|
402
625
|
children: [/*#__PURE__*/jsx(Typography, {
|
|
403
626
|
color: "muted",
|
|
404
627
|
variant: "body3",
|
|
405
|
-
children: t("neetoAssist.shadowNote")
|
|
628
|
+
children: t(isAssistant ? "neetoAssist.assistant.note" : "neetoAssist.shadowNote")
|
|
406
629
|
}), isHintShown ? /*#__PURE__*/jsx("span", {
|
|
407
630
|
className: "text-muted-foreground shrink-0 text-xs",
|
|
408
631
|
"data-testid": "neeto-assist-command-hint",
|
|
@@ -416,8 +639,197 @@ var MessageInput = function MessageInput(_ref) {
|
|
|
416
639
|
});
|
|
417
640
|
};
|
|
418
641
|
|
|
419
|
-
|
|
420
|
-
|
|
642
|
+
// The tag of English, the language of the reading NeetoAssist adds for a team
|
|
643
|
+
// that reads it.
|
|
644
|
+
var ENGLISH = "en";
|
|
645
|
+
|
|
646
|
+
// The languages that are written from right to left, by the first part of
|
|
647
|
+
// their tags: Arabic, Hebrew, Persian, Urdu, Pashto, Sindhi, Uyghur, Yiddish,
|
|
648
|
+
// Dhivehi and Sorani.
|
|
649
|
+
var RIGHT_TO_LEFT_LANGUAGES = ["ar", "he", "fa", "ur", "ps", "sd", "ug", "yi", "dv", "ckb"];
|
|
650
|
+
|
|
651
|
+
// A letter of a script that is written from right to left: an Arabic, a Hebrew
|
|
652
|
+
// or a Thaana one, which are the scripts of the languages above. The digits,
|
|
653
|
+
// the punctuation and the vowel marks of those scripts are no letters, so text
|
|
654
|
+
// in Latin letters that borrows an Arabic comma or number holds none. These
|
|
655
|
+
// are Unicode's own letters of the three scripts, spelled out as ranges: the
|
|
656
|
+
// build would turn a pattern that names them by property into one that lists
|
|
657
|
+
// every letter of every script.
|
|
658
|
+
var RIGHT_TO_LEFT_LETTER_PATTERN = /[\u05D0-\u05EA\u05EF-\u05F2\u0620-\u063F\u0641-\u064A\u066E-\u066F\u0671-\u06D3\u06D5\u06E5-\u06E6\u06EE-\u06EF\u06FA-\u06FC\u06FF\u0750-\u07A5\u07B1\u0870-\u0887\u0889-\u088E\u08A0-\u08C9\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40-\uFB41\uFB43-\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC]/;
|
|
659
|
+
|
|
660
|
+
// For a team that reads English, NeetoAssist can send a suggested reply, and
|
|
661
|
+
// what the customer wrote, in English beside another language. A reading is
|
|
662
|
+
// one of the two: its text, the tag of the language it is in, and the
|
|
663
|
+
// direction that language is written in. A run from an older NeetoAssist, or
|
|
664
|
+
// from a workspace that has not switched this on, carries neither, and the
|
|
665
|
+
// pane shows it as it always did.
|
|
666
|
+
var hasText = function hasText(value) {
|
|
667
|
+
return typeof value === "string" && value.trim() !== "";
|
|
668
|
+
};
|
|
669
|
+
|
|
670
|
+
// The first part of a tag says which language it is: "pt" for "pt-BR".
|
|
671
|
+
var languageOf = function languageOf(code) {
|
|
672
|
+
return code.split("-")[0].toLowerCase();
|
|
673
|
+
};
|
|
674
|
+
|
|
675
|
+
// Two tags name one language when their first parts match, as "pt-BR" and
|
|
676
|
+
// "pt-PT" do.
|
|
677
|
+
var isSameLanguage = function isSameLanguage(code, other) {
|
|
678
|
+
return hasText(code) && hasText(other) && languageOf(code) === languageOf(other);
|
|
679
|
+
};
|
|
680
|
+
|
|
681
|
+
// The direction a reading in another language is set in: from the right when
|
|
682
|
+
// its language is one that is written that way and the reading itself holds a
|
|
683
|
+
// letter of such a script. The language decides, and not the reading's first
|
|
684
|
+
// letter: a reply in Arabic often opens with the name of a product or a
|
|
685
|
+
// screen, which stays in English, and would then be set from the left. The
|
|
686
|
+
// letter is asked for because Urdu, Arabic and Persian are written in Latin
|
|
687
|
+
// letters too, and such a reading runs from the left whatever its tag says.
|
|
688
|
+
// Everything else is left to the text.
|
|
689
|
+
var directionOf = function directionOf(code, text) {
|
|
690
|
+
return hasText(code) && RIGHT_TO_LEFT_LANGUAGES.includes(languageOf(code)) && RIGHT_TO_LEFT_LETTER_PATTERN.test(text) ? "rtl" : "auto";
|
|
691
|
+
};
|
|
692
|
+
|
|
693
|
+
// The English reading always runs from the left, also when it opens with a
|
|
694
|
+
// name in Arabic letters.
|
|
695
|
+
var inEnglish = function inEnglish(text) {
|
|
696
|
+
return {
|
|
697
|
+
dir: "ltr",
|
|
698
|
+
lang: ENGLISH,
|
|
699
|
+
text: text
|
|
700
|
+
};
|
|
701
|
+
};
|
|
702
|
+
var customerWritesIn = function customerWritesIn(t, name) {
|
|
703
|
+
return name ? t("neetoAssist.languages.customerWritesIn", {
|
|
704
|
+
language: name
|
|
705
|
+
}) : t("neetoAssist.languages.customerWritesInAnotherLanguage");
|
|
706
|
+
};
|
|
707
|
+
var replyIsIn = function replyIsIn(t, name) {
|
|
708
|
+
return name ? t("neetoAssist.languages.replyIsIn", {
|
|
709
|
+
language: name
|
|
710
|
+
}) : t("neetoAssist.languages.replyIsInAnotherLanguage");
|
|
711
|
+
};
|
|
712
|
+
|
|
713
|
+
// "Show in English", with English named by the browser like any other
|
|
714
|
+
// language, or as the translation file has it when the browser names nothing.
|
|
715
|
+
var showInEnglish = function showInEnglish(t, english) {
|
|
716
|
+
return english ? t("neetoAssist.languages.showIn", {
|
|
717
|
+
language: english
|
|
718
|
+
}) : t("neetoAssist.languages.showInEnglish");
|
|
719
|
+
};
|
|
720
|
+
|
|
721
|
+
// The two readings of a suggested reply: the English one, and the one the
|
|
722
|
+
// customer is sent, in the language the run names for it. A reply is in two
|
|
723
|
+
// languages only when the run has that language and the reply both ways, each
|
|
724
|
+
// a text with something in it. One reading alone is none.
|
|
725
|
+
// The language the customer writes in comes along when the run knows it. It
|
|
726
|
+
// can be missing, when they wrote too little to tell by, and it can be another
|
|
727
|
+
// than the reply's, when a rep asked for the reply in a language of their
|
|
728
|
+
// choosing.
|
|
729
|
+
var replyReadings = function replyReadings(_ref) {
|
|
730
|
+
var customerLanguage = _ref.customerLanguage,
|
|
731
|
+
suggestedReplyInCustomerLanguage = _ref.suggestedReplyInCustomerLanguage,
|
|
732
|
+
suggestedReplyInEnglish = _ref.suggestedReplyInEnglish,
|
|
733
|
+
suggestedReplyLanguage = _ref.suggestedReplyLanguage;
|
|
734
|
+
var isInTwoLanguages = [suggestedReplyLanguage, suggestedReplyInCustomerLanguage, suggestedReplyInEnglish].every(hasText);
|
|
735
|
+
if (!isInTwoLanguages) return null;
|
|
736
|
+
return {
|
|
737
|
+
english: inEnglish(suggestedReplyInEnglish),
|
|
738
|
+
customer: {
|
|
739
|
+
dir: directionOf(suggestedReplyLanguage, suggestedReplyInCustomerLanguage),
|
|
740
|
+
lang: suggestedReplyLanguage,
|
|
741
|
+
text: suggestedReplyInCustomerLanguage
|
|
742
|
+
},
|
|
743
|
+
customerLanguage: hasText(customerLanguage) ? customerLanguage : null
|
|
744
|
+
};
|
|
745
|
+
};
|
|
746
|
+
|
|
747
|
+
// What the customer wrote, in English and in their own words, for a run that
|
|
748
|
+
// has both. The customer's language is named with it. Should it be missing,
|
|
749
|
+
// their words are still shown, in no language the pane can name.
|
|
750
|
+
var questionReadings = function questionReadings(_ref2) {
|
|
751
|
+
var customerLanguage = _ref2.customerLanguage,
|
|
752
|
+
question = _ref2.question,
|
|
753
|
+
questionInEnglish = _ref2.questionInEnglish;
|
|
754
|
+
if (!hasText(question) || !hasText(questionInEnglish)) return null;
|
|
755
|
+
return {
|
|
756
|
+
english: inEnglish(questionInEnglish),
|
|
757
|
+
original: {
|
|
758
|
+
dir: directionOf(customerLanguage, question),
|
|
759
|
+
lang: hasText(customerLanguage) ? customerLanguage : null,
|
|
760
|
+
text: question
|
|
761
|
+
}
|
|
762
|
+
};
|
|
763
|
+
};
|
|
764
|
+
|
|
765
|
+
// The name of a language in the language the pane is in, such as "Spanish" for
|
|
766
|
+
// "es", from the browser's own list of names. The browser throws at a tag that
|
|
767
|
+
// is none. For a language it has no name for it would give the tag back, whole
|
|
768
|
+
// ("xx") or in part ("xx (Spain)"), so it is asked to give nothing instead.
|
|
769
|
+
// Either way there is no name, and the pane never shows a tag to a person.
|
|
770
|
+
var languageName = function languageName(code, locale) {
|
|
771
|
+
try {
|
|
772
|
+
var name = new Intl.DisplayNames([locale], {
|
|
773
|
+
type: "language",
|
|
774
|
+
fallback: "none"
|
|
775
|
+
}).of(code);
|
|
776
|
+
return name && name.toLowerCase() !== code.toLowerCase() ? name : null;
|
|
777
|
+
} catch (_unused) {
|
|
778
|
+
return null;
|
|
779
|
+
}
|
|
780
|
+
};
|
|
781
|
+
|
|
782
|
+
// What the card of a reply in two languages says: the line under the reply,
|
|
783
|
+
// the link that turns the card either way, and the two buttons that hand a
|
|
784
|
+
// reading to the host. The link and the buttons name the language of the
|
|
785
|
+
// reading the customer is sent. The line says the customer writes in it when
|
|
786
|
+
// they do, and otherwise only that the reply is in it: the customer may write
|
|
787
|
+
// in another language, or in one nobody could tell. What the customer writes
|
|
788
|
+
// in is named by their own tag, which may say more than the reply's ("pt-PT"
|
|
789
|
+
// beside "pt-BR"), and by the reply's when the browser has no name for it.
|
|
790
|
+
// Every sentence has a form without a name, for a language the browser has no
|
|
791
|
+
// name for. The names come from the browser and not from a customer, so they
|
|
792
|
+
// are safe to hand to the translator.
|
|
793
|
+
var replyWords = function replyWords(t, locale, _ref3) {
|
|
794
|
+
var _languageName;
|
|
795
|
+
var customer = _ref3.customer,
|
|
796
|
+
customerLanguage = _ref3.customerLanguage;
|
|
797
|
+
var theirs = languageName(customer.lang, locale);
|
|
798
|
+
var english = languageName(ENGLISH, locale);
|
|
799
|
+
return {
|
|
800
|
+
line: isSameLanguage(customerLanguage, customer.lang) ? customerWritesIn(t, (_languageName = languageName(customerLanguage, locale)) !== null && _languageName !== void 0 ? _languageName : theirs) : replyIsIn(t, theirs),
|
|
801
|
+
showCustomer: theirs ? t("neetoAssist.languages.showIn", {
|
|
802
|
+
language: theirs
|
|
803
|
+
}) : t("neetoAssist.languages.showInTheirLanguage"),
|
|
804
|
+
showEnglish: showInEnglish(t, english),
|
|
805
|
+
useCustomer: theirs ? t("neetoAssist.languages.useIn", {
|
|
806
|
+
language: theirs
|
|
807
|
+
}) : t("neetoAssist.languages.useInTheirLanguage"),
|
|
808
|
+
useEnglish: english ? t("neetoAssist.languages.useIn", {
|
|
809
|
+
language: english
|
|
810
|
+
}) : t("neetoAssist.languages.useInEnglish")
|
|
811
|
+
};
|
|
812
|
+
};
|
|
813
|
+
|
|
814
|
+
// What "Customer wrote" says under the customer's words: that they were
|
|
815
|
+
// translated while the English shows, that they are the original while the
|
|
816
|
+
// customer's own show, and the link that turns them either way.
|
|
817
|
+
var questionWords = function questionWords(t, locale, customerLanguage) {
|
|
818
|
+
var theirs = languageName(customerLanguage, locale);
|
|
819
|
+
return {
|
|
820
|
+
translated: theirs ? t("neetoAssist.languages.translatedFrom", {
|
|
821
|
+
language: theirs
|
|
822
|
+
}) : t("neetoAssist.languages.translated"),
|
|
823
|
+
original: theirs ? t("neetoAssist.languages.originalIn", {
|
|
824
|
+
language: theirs
|
|
825
|
+
}) : t("neetoAssist.languages.original"),
|
|
826
|
+
showOriginal: t("neetoAssist.languages.showOriginal"),
|
|
827
|
+
showEnglish: showInEnglish(t, languageName(ENGLISH, locale))
|
|
828
|
+
};
|
|
829
|
+
};
|
|
830
|
+
|
|
831
|
+
function ownKeys$4(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; }
|
|
832
|
+
function _objectSpread$4(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$4(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$4(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
421
833
|
var isSettled = function isSettled(_ref) {
|
|
422
834
|
var status = _ref.status;
|
|
423
835
|
return SETTLED_ACTION_STATUSES.includes(status);
|
|
@@ -439,7 +851,7 @@ var answeredAction = function answeredAction(_ref2) {
|
|
|
439
851
|
if (status === 409) return body === null || body === void 0 ? void 0 : body.action;
|
|
440
852
|
if (status === 422 && isApply) {
|
|
441
853
|
var _body$message, _body$action;
|
|
442
|
-
return _objectSpread$
|
|
854
|
+
return _objectSpread$4(_objectSpread$4({}, body === null || body === void 0 ? void 0 : body.action), {}, {
|
|
443
855
|
status: "failed",
|
|
444
856
|
error: (_body$message = body === null || body === void 0 ? void 0 : body.message) !== null && _body$message !== void 0 ? _body$message : body === null || body === void 0 || (_body$action = body.action) === null || _body$action === void 0 ? void 0 : _body$action.error
|
|
445
857
|
});
|
|
@@ -454,7 +866,7 @@ var answeredAction = function answeredAction(_ref2) {
|
|
|
454
866
|
var shownAction = function shownAction(action, answer) {
|
|
455
867
|
if (!answer || isSettled(action)) return action;
|
|
456
868
|
var answered = answeredAction(answer);
|
|
457
|
-
return answered && isSettled(answered) ? _objectSpread$
|
|
869
|
+
return answered && isSettled(answered) ? _objectSpread$4(_objectSpread$4({}, action), answered) : action;
|
|
458
870
|
};
|
|
459
871
|
|
|
460
872
|
// The long text an action will save or send, while it is suggested or being
|
|
@@ -486,7 +898,9 @@ var BLOCK_TYPES = {
|
|
|
486
898
|
HEADING: "heading",
|
|
487
899
|
PARAGRAPH: "paragraph",
|
|
488
900
|
ORDERED_LIST: "orderedList",
|
|
489
|
-
BULLET_LIST: "bulletList"
|
|
901
|
+
BULLET_LIST: "bulletList",
|
|
902
|
+
TABLE: "table",
|
|
903
|
+
CODE: "code"
|
|
490
904
|
};
|
|
491
905
|
var HEADING_PATTERN = /^\s{0,3}#{1,6}\s+(.*)$/;
|
|
492
906
|
|
|
@@ -501,10 +915,36 @@ var BOLD_PATTERN = /\*\*(.+?)\*\*/;
|
|
|
501
915
|
// `Settings`: a name a model set off as code. Splits a line into the text
|
|
502
916
|
// around the spans and the spans themselves, backticks included.
|
|
503
917
|
var CODE_SPAN_PATTERN = /(`[^`\n]+`)/;
|
|
918
|
+
|
|
919
|
+
// The line that opens a fenced block of code: three backticks, with or without
|
|
920
|
+
// a language word after them. The first group is the line's indent.
|
|
921
|
+
var CODE_FENCE_OPEN_PATTERN = /^(\s*)```[ \t]*[\w#+.-]*\s*$/;
|
|
922
|
+
|
|
923
|
+
// The line that closes one: three backticks and nothing else.
|
|
924
|
+
var CODE_FENCE_CLOSE_PATTERN = /^\s*```\s*$/;
|
|
925
|
+
|
|
926
|
+
// Every way a line of text may end.
|
|
927
|
+
var LINE_BREAK_PATTERN = /\r\n?|\n/;
|
|
928
|
+
|
|
929
|
+
// One cell of the line under a table's header: dashes, with a colon at the
|
|
930
|
+
// start, the end or both for how the column is aligned.
|
|
931
|
+
var TABLE_DELIMITER_CELL_PATTERN = /^:?-+:?$/;
|
|
932
|
+
|
|
933
|
+
// The most a table may have and still be shown as one. A larger one stays the
|
|
934
|
+
// text it was, so no answer can make the pane draw more cells than this.
|
|
935
|
+
var MAX_TABLE_COLUMNS = 12;
|
|
936
|
+
var MAX_TABLE_ROWS = 200;
|
|
937
|
+
|
|
938
|
+
// Every table of an answer together, header rows included: one table of the
|
|
939
|
+
// largest size, or several smaller ones. A table past what is left stays text.
|
|
940
|
+
var MAX_TABLE_CELLS = MAX_TABLE_COLUMNS * (MAX_TABLE_ROWS + 1);
|
|
941
|
+
|
|
942
|
+
// A pipe a model escaped so that it stays in the cell's text.
|
|
943
|
+
var ESCAPED_PIPE_PATTERN = /\\\|/g;
|
|
504
944
|
var UNSAFE_HTML_CHARACTERS = /[&<>"']/g;
|
|
505
945
|
|
|
506
|
-
function ownKeys$
|
|
507
|
-
function _objectSpread$
|
|
946
|
+
function ownKeys$3(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; }
|
|
947
|
+
function _objectSpread$3(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$3(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$3(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
508
948
|
var escapeHtmlCharacter = function escapeHtmlCharacter(character) {
|
|
509
949
|
switch (character) {
|
|
510
950
|
case "&":
|
|
@@ -579,26 +1019,216 @@ var matchListItem = function matchListItem(line) {
|
|
|
579
1019
|
};
|
|
580
1020
|
};
|
|
581
1021
|
|
|
1022
|
+
// Where a table row splits into cells: at every "|" outside a code span that no
|
|
1023
|
+
// backslash escapes, so a pipe a model quotes in `a|b` stays in its cell. A
|
|
1024
|
+
// backslash escapes only an odd run of them, as "\\|" is an escaped backslash
|
|
1025
|
+
// and then a pipe.
|
|
1026
|
+
var pipePositions = function pipePositions(line) {
|
|
1027
|
+
var backslashes = 0;
|
|
1028
|
+
return blankCodeSpans(line).split("").flatMap(function (character, at) {
|
|
1029
|
+
var isPipe = character === "|" && backslashes % 2 === 0;
|
|
1030
|
+
backslashes = character === "\\" ? backslashes + 1 : 0;
|
|
1031
|
+
return isPipe ? [at] : [];
|
|
1032
|
+
});
|
|
1033
|
+
};
|
|
1034
|
+
|
|
1035
|
+
// The cells of a table row as text, at most `width` of them, or null for a
|
|
1036
|
+
// line that has no pipe to split at. The pipes at the ends are optional, as
|
|
1037
|
+
// models leave the closing one out as often as not.
|
|
1038
|
+
var rowCells = function rowCells(line) {
|
|
1039
|
+
var width = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Infinity;
|
|
1040
|
+
var row = line.trim();
|
|
1041
|
+
var pipes = pipePositions(row);
|
|
1042
|
+
if (isEmpty(pipes)) return null;
|
|
1043
|
+
var cuts = [-1].concat(_toConsumableArray(pipes), [row.length]);
|
|
1044
|
+
var cells = cuts.slice(0, -1).map(function (cut, index) {
|
|
1045
|
+
return row.slice(cut + 1, cuts[index + 1]);
|
|
1046
|
+
});
|
|
1047
|
+
var first = pipes[0] === 0 ? 1 : 0;
|
|
1048
|
+
var last = pipes.at(-1) === row.length - 1 ? cells.length - 1 : cells.length;
|
|
1049
|
+
var kept = cells.slice(first, Math.max(first, last));
|
|
1050
|
+
return isEmpty(kept) ? null : kept.slice(0, width).map(function (cell) {
|
|
1051
|
+
return cell.trim().replace(ESCAPED_PIPE_PATTERN, "|");
|
|
1052
|
+
});
|
|
1053
|
+
};
|
|
1054
|
+
var alignmentOf = function alignmentOf(cell) {
|
|
1055
|
+
var isStart = cell.startsWith(":");
|
|
1056
|
+
var isEnd = cell.endsWith(":");
|
|
1057
|
+
if (isStart && isEnd) return "center";
|
|
1058
|
+
if (isEnd) return "end";
|
|
1059
|
+
return isStart ? "start" : null;
|
|
1060
|
+
};
|
|
1061
|
+
|
|
1062
|
+
// How each column is aligned when the line is the one under a table's header,
|
|
1063
|
+
// or null when it is not that line.
|
|
1064
|
+
var delimiterAlignments = function delimiterAlignments(line) {
|
|
1065
|
+
var cells = rowCells(line);
|
|
1066
|
+
if (!(cells !== null && cells !== void 0 && cells.every(function (cell) {
|
|
1067
|
+
return TABLE_DELIMITER_CELL_PATTERN.test(cell);
|
|
1068
|
+
}))) {
|
|
1069
|
+
return null;
|
|
1070
|
+
}
|
|
1071
|
+
return cells.map(alignmentOf);
|
|
1072
|
+
};
|
|
1073
|
+
|
|
1074
|
+
// A row as wide as the header: as GFM does, a short row gets empty cells and
|
|
1075
|
+
// the cells past the header's last are dropped. So no row can make a table
|
|
1076
|
+
// wider than its header.
|
|
1077
|
+
var fitRow = function fitRow(cells, width) {
|
|
1078
|
+
return [].concat(_toConsumableArray(cells), _toConsumableArray(Array(width - cells.length).fill("")));
|
|
1079
|
+
};
|
|
1080
|
+
|
|
1081
|
+
// The table that starts at this line, and the line after its last row. A table
|
|
1082
|
+
// is a row of at most MAX_TABLE_COLUMNS cells that is no heading, the line of
|
|
1083
|
+
// dashes under it with as many cells, and the rows after it up to a blank line
|
|
1084
|
+
// or a line without a pipe. Past MAX_TABLE_ROWS rows the rest are only counted,
|
|
1085
|
+
// since such a table is not shown as one.
|
|
1086
|
+
var tableAt = function tableAt(lines, index) {
|
|
1087
|
+
var _lines;
|
|
1088
|
+
var line = lines.at(index);
|
|
1089
|
+
if (HEADING_PATTERN.test(line)) return null;
|
|
1090
|
+
var header = rowCells(line);
|
|
1091
|
+
if (!header || header.length > MAX_TABLE_COLUMNS) return null;
|
|
1092
|
+
var alignments = delimiterAlignments((_lines = lines[index + 1]) !== null && _lines !== void 0 ? _lines : "");
|
|
1093
|
+
if ((alignments === null || alignments === void 0 ? void 0 : alignments.length) !== header.length) return null;
|
|
1094
|
+
var rows = [];
|
|
1095
|
+
var end = index + 2;
|
|
1096
|
+
while (end < lines.length && lines.at(end).trim() !== "") {
|
|
1097
|
+
var cells = rowCells(lines.at(end), header.length);
|
|
1098
|
+
if (!cells) break;
|
|
1099
|
+
if (rows.length <= MAX_TABLE_ROWS) rows.push(fitRow(cells, header.length));
|
|
1100
|
+
end += 1;
|
|
1101
|
+
}
|
|
1102
|
+
return {
|
|
1103
|
+
alignments: alignments,
|
|
1104
|
+
end: end,
|
|
1105
|
+
header: header,
|
|
1106
|
+
rows: rows
|
|
1107
|
+
};
|
|
1108
|
+
};
|
|
1109
|
+
|
|
1110
|
+
// Where each fenced block of code starts, with its block, its closing fence and
|
|
1111
|
+
// the line after it. Its lines are kept as they were written, less the opening
|
|
1112
|
+
// fence's indent, and nothing in them is read as markdown. A fence that nothing
|
|
1113
|
+
// closes stays the text it was. Once no line below one closes it, no fence
|
|
1114
|
+
// further down can be closed either, so every line is read at most twice.
|
|
1115
|
+
var findCodeBlocks = function findCodeBlocks(lines) {
|
|
1116
|
+
var blocks = new Map();
|
|
1117
|
+
var index = 0;
|
|
1118
|
+
var _loop = function _loop() {
|
|
1119
|
+
var opening = lines.at(index).match(CODE_FENCE_OPEN_PATTERN);
|
|
1120
|
+
var closing = opening ? index + 1 : lines.length;
|
|
1121
|
+
while (closing < lines.length && !CODE_FENCE_CLOSE_PATTERN.test(lines.at(closing))) {
|
|
1122
|
+
closing += 1;
|
|
1123
|
+
}
|
|
1124
|
+
if (!opening) {
|
|
1125
|
+
index += 1;
|
|
1126
|
+
} else if (closing === lines.length) {
|
|
1127
|
+
index = lines.length;
|
|
1128
|
+
} else {
|
|
1129
|
+
var _opening = _slicedToArray(opening, 2),
|
|
1130
|
+
indent = _opening[1];
|
|
1131
|
+
blocks.set(index, {
|
|
1132
|
+
closing: closing,
|
|
1133
|
+
end: closing + 1,
|
|
1134
|
+
block: {
|
|
1135
|
+
type: BLOCK_TYPES.CODE,
|
|
1136
|
+
lines: lines.slice(index + 1, closing).map(function (line) {
|
|
1137
|
+
return line.startsWith(indent) ? line.slice(indent.length) : line;
|
|
1138
|
+
})
|
|
1139
|
+
}
|
|
1140
|
+
});
|
|
1141
|
+
index = closing + 1;
|
|
1142
|
+
}
|
|
1143
|
+
};
|
|
1144
|
+
while (index < lines.length) {
|
|
1145
|
+
_loop();
|
|
1146
|
+
}
|
|
1147
|
+
return blocks;
|
|
1148
|
+
};
|
|
1149
|
+
|
|
1150
|
+
// Where each table starts, with its block and the line after it. A table of
|
|
1151
|
+
// more than MAX_TABLE_ROWS rows, or one with more cells than the answer has
|
|
1152
|
+
// left of MAX_TABLE_CELLS, stays the text it was, and no table starts among
|
|
1153
|
+
// its lines. Every line is read a fixed number of times, so no answer, however
|
|
1154
|
+
// it is made, takes long to read or gives the pane more cells to draw than one
|
|
1155
|
+
// table of the largest size. A block of code is code: no table starts in one.
|
|
1156
|
+
var findTables = function findTables(lines, codeBlocks) {
|
|
1157
|
+
var tables = new Map();
|
|
1158
|
+
var cellsLeft = MAX_TABLE_CELLS;
|
|
1159
|
+
var index = 0;
|
|
1160
|
+
while (index < lines.length) {
|
|
1161
|
+
var code = codeBlocks.get(index);
|
|
1162
|
+
var table = !code && tableAt(lines, index);
|
|
1163
|
+
if (code) {
|
|
1164
|
+
index = code.end;
|
|
1165
|
+
} else if (!table) {
|
|
1166
|
+
index += 1;
|
|
1167
|
+
} else {
|
|
1168
|
+
var alignments = table.alignments,
|
|
1169
|
+
end = table.end,
|
|
1170
|
+
header = table.header,
|
|
1171
|
+
rows = table.rows;
|
|
1172
|
+
var cells = header.length * (rows.length + 1);
|
|
1173
|
+
if (rows.length <= MAX_TABLE_ROWS && cells <= cellsLeft) {
|
|
1174
|
+
cellsLeft -= cells;
|
|
1175
|
+
tables.set(index, {
|
|
1176
|
+
end: end,
|
|
1177
|
+
block: {
|
|
1178
|
+
type: BLOCK_TYPES.TABLE,
|
|
1179
|
+
alignments: alignments,
|
|
1180
|
+
header: header.map(parseInline),
|
|
1181
|
+
rows: rows.map(function (row) {
|
|
1182
|
+
return row.map(parseInline);
|
|
1183
|
+
})
|
|
1184
|
+
}
|
|
1185
|
+
});
|
|
1186
|
+
}
|
|
1187
|
+
index = end;
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
return tables;
|
|
1191
|
+
};
|
|
1192
|
+
|
|
582
1193
|
// Blocks hold lines of inline segments: a paragraph's lines, a heading's one
|
|
583
1194
|
// line, or each list item's lines. A list carries on across blank lines, since
|
|
584
1195
|
// models often leave one between items. A numbered list remembers the number
|
|
585
1196
|
// it starts at, so one that carries on after bullets a model nested under an
|
|
586
1197
|
// item counts on instead of starting again at 1.
|
|
1198
|
+
// Blocks of code are found first, then tables, and the rest is read line by
|
|
1199
|
+
// line as it was before there were either, so text without them gives the
|
|
1200
|
+
// blocks it always did. With tables off, a table's lines are read that way.
|
|
587
1201
|
var parseLightMarkdown = function parseLightMarkdown() {
|
|
588
1202
|
var text = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
|
|
1203
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
1204
|
+
_ref$tables = _ref.tables,
|
|
1205
|
+
tables = _ref$tables === void 0 ? true : _ref$tables;
|
|
589
1206
|
var blocks = [];
|
|
590
1207
|
var openBlock = null;
|
|
591
1208
|
var afterBlankLine = false;
|
|
1209
|
+
var nextLine = 0;
|
|
592
1210
|
var startBlock = function startBlock(block) {
|
|
593
1211
|
blocks.push(block);
|
|
594
1212
|
openBlock = block;
|
|
595
1213
|
};
|
|
596
|
-
String(text !== null && text !== void 0 ? text : "").replace(/\r\n?/g, "\n").split("\n")
|
|
597
|
-
|
|
1214
|
+
var lines = String(text !== null && text !== void 0 ? text : "").replace(/\r\n?/g, "\n").split("\n");
|
|
1215
|
+
var codeAt = findCodeBlocks(lines);
|
|
1216
|
+
var tablesAt = tables ? findTables(lines, codeAt) : new Map();
|
|
1217
|
+
lines.forEach(function (line, index) {
|
|
1218
|
+
var _codeAt$get, _openBlock2;
|
|
1219
|
+
if (index < nextLine) return;
|
|
598
1220
|
if (line.trim() === "") {
|
|
599
1221
|
afterBlankLine = true;
|
|
600
1222
|
return;
|
|
601
1223
|
}
|
|
1224
|
+
var whole = (_codeAt$get = codeAt.get(index)) !== null && _codeAt$get !== void 0 ? _codeAt$get : tablesAt.get(index);
|
|
1225
|
+
if (whole) {
|
|
1226
|
+
blocks.push(whole.block);
|
|
1227
|
+
openBlock = null;
|
|
1228
|
+
afterBlankLine = false;
|
|
1229
|
+
nextLine = whole.end;
|
|
1230
|
+
return;
|
|
1231
|
+
}
|
|
602
1232
|
var heading = line.match(HEADING_PATTERN);
|
|
603
1233
|
var listItem = !heading && matchListItem(line);
|
|
604
1234
|
var isList = openBlock && openBlock.type !== BLOCK_TYPES.PARAGRAPH;
|
|
@@ -611,7 +1241,7 @@ var parseLightMarkdown = function parseLightMarkdown() {
|
|
|
611
1241
|
} else if (listItem) {
|
|
612
1242
|
var _openBlock;
|
|
613
1243
|
if (((_openBlock = openBlock) === null || _openBlock === void 0 ? void 0 : _openBlock.type) !== listItem.type) {
|
|
614
|
-
startBlock(_objectSpread$
|
|
1244
|
+
startBlock(_objectSpread$3({
|
|
615
1245
|
type: listItem.type,
|
|
616
1246
|
items: []
|
|
617
1247
|
}, listItem.number === undefined ? {} : {
|
|
@@ -634,9 +1264,9 @@ var parseLightMarkdown = function parseLightMarkdown() {
|
|
|
634
1264
|
return blocks;
|
|
635
1265
|
};
|
|
636
1266
|
var segmentsToHtml = function segmentsToHtml(segments) {
|
|
637
|
-
return segments.map(function (
|
|
638
|
-
var text =
|
|
639
|
-
bold =
|
|
1267
|
+
return segments.map(function (_ref2) {
|
|
1268
|
+
var text = _ref2.text,
|
|
1269
|
+
bold = _ref2.bold;
|
|
640
1270
|
return bold ? "<strong>".concat(escapeHtml(text), "</strong>") : escapeHtml(text);
|
|
641
1271
|
}).join("");
|
|
642
1272
|
};
|
|
@@ -650,6 +1280,8 @@ var listToHtml = function listToHtml(tag, items) {
|
|
|
650
1280
|
};
|
|
651
1281
|
var blockToHtml = function blockToHtml(block) {
|
|
652
1282
|
switch (block.type) {
|
|
1283
|
+
case BLOCK_TYPES.CODE:
|
|
1284
|
+
return isEmpty(block.lines) ? "" : "<p>".concat(block.lines.map(escapeHtml).join("<br>"), "</p>");
|
|
653
1285
|
case BLOCK_TYPES.HEADING:
|
|
654
1286
|
return "<h2>".concat(linesToHtml(block.lines), "</h2>");
|
|
655
1287
|
case BLOCK_TYPES.ORDERED_LIST:
|
|
@@ -662,9 +1294,112 @@ var blockToHtml = function blockToHtml(block) {
|
|
|
662
1294
|
};
|
|
663
1295
|
|
|
664
1296
|
// HTML for a rich-text composer, made only of p, br, strong, ol, ul, li and h2
|
|
665
|
-
// around escaped text.
|
|
1297
|
+
// around escaped text. A composer may have no tables, so this reads the text
|
|
1298
|
+
// with tables off: a table's lines stay lines of the paragraph around them,
|
|
1299
|
+
// and Use reply hands a host what it did before the pane showed tables. Nor
|
|
1300
|
+
// may it have code, so a block of code is a paragraph of its lines.
|
|
666
1301
|
var lightMarkdownToHtml = function lightMarkdownToHtml(text) {
|
|
667
|
-
return parseLightMarkdown(text
|
|
1302
|
+
return parseLightMarkdown(text, {
|
|
1303
|
+
tables: false
|
|
1304
|
+
}).map(blockToHtml).join("");
|
|
1305
|
+
};
|
|
1306
|
+
var segmentsToText = function segmentsToText(segments) {
|
|
1307
|
+
return pluck("text", segments).join("");
|
|
1308
|
+
};
|
|
1309
|
+
var linesToText = function linesToText(lines) {
|
|
1310
|
+
return lines.map(segmentsToText).join("\n");
|
|
1311
|
+
};
|
|
1312
|
+
var blockToText = function blockToText(block) {
|
|
1313
|
+
switch (block.type) {
|
|
1314
|
+
case BLOCK_TYPES.CODE:
|
|
1315
|
+
return block.lines.join("\n");
|
|
1316
|
+
case BLOCK_TYPES.ORDERED_LIST:
|
|
1317
|
+
return block.items.map(function (lines, index) {
|
|
1318
|
+
return "".concat(block.start + index, ". ").concat(linesToText(lines));
|
|
1319
|
+
}).join("\n");
|
|
1320
|
+
case BLOCK_TYPES.BULLET_LIST:
|
|
1321
|
+
return block.items.map(function (lines) {
|
|
1322
|
+
return "- ".concat(linesToText(lines));
|
|
1323
|
+
}).join("\n");
|
|
1324
|
+
default:
|
|
1325
|
+
return linesToText(block.lines);
|
|
1326
|
+
}
|
|
1327
|
+
};
|
|
1328
|
+
|
|
1329
|
+
// An answer as plain text, for a person to paste anywhere: the words without
|
|
1330
|
+
// the marks around them, a list with its numbers or dashes, a table as the
|
|
1331
|
+
// lines it was written in, and a block of code as its lines.
|
|
1332
|
+
var lightMarkdownToText = function lightMarkdownToText(text) {
|
|
1333
|
+
return reject(isEmpty, parseLightMarkdown(text, {
|
|
1334
|
+
tables: false
|
|
1335
|
+
}).map(blockToText)).join("\n\n");
|
|
1336
|
+
};
|
|
1337
|
+
|
|
1338
|
+
// The text Use reply hands a host: the reply as NeetoAssist wrote it, with
|
|
1339
|
+
// only the fences of each block of code left out, so a block is its lines.
|
|
1340
|
+
// A reply without a block is handed over exactly as it came.
|
|
1341
|
+
var replyText = function replyText(text) {
|
|
1342
|
+
var written = String(text !== null && text !== void 0 ? text : "");
|
|
1343
|
+
var lines = written.split(LINE_BREAK_PATTERN);
|
|
1344
|
+
var fences = new Set(_toConsumableArray(findCodeBlocks(lines).entries()).flatMap(function (_ref3) {
|
|
1345
|
+
var _ref4 = _slicedToArray(_ref3, 2),
|
|
1346
|
+
opening = _ref4[0],
|
|
1347
|
+
closing = _ref4[1].closing;
|
|
1348
|
+
return [opening, closing];
|
|
1349
|
+
}));
|
|
1350
|
+
return fences.size === 0 ? written : lines.filter(function (_, index) {
|
|
1351
|
+
return !fences.has(index);
|
|
1352
|
+
}).join("\n");
|
|
1353
|
+
};
|
|
1354
|
+
|
|
1355
|
+
var scrollsSideways$1 = function scrollsSideways(box) {
|
|
1356
|
+
return box.scrollWidth > box.clientWidth;
|
|
1357
|
+
};
|
|
1358
|
+
|
|
1359
|
+
// An example of code a model wrote, in a fenced block. Its lines are one text,
|
|
1360
|
+
// shown as they were written: nothing in them is read as markup or coloured. A
|
|
1361
|
+
// long line scrolls sideways inside the block, so the pane never does, and as
|
|
1362
|
+
// with a table only a block that does scroll takes the keyboard.
|
|
1363
|
+
var CodeBlock = function CodeBlock(_ref) {
|
|
1364
|
+
var lines = _ref.block.lines;
|
|
1365
|
+
var boxRef = useRef(null);
|
|
1366
|
+
var _useState = useState(false),
|
|
1367
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
1368
|
+
isScrollable = _useState2[0],
|
|
1369
|
+
setIsScrollable = _useState2[1];
|
|
1370
|
+
|
|
1371
|
+
// Other lines can take these lines' place in the same block, as when a
|
|
1372
|
+
// reply is shown in its other language, and be longer or shorter. So the
|
|
1373
|
+
// block is measured again when its lines change.
|
|
1374
|
+
useLayoutEffect(function () {
|
|
1375
|
+
var box = boxRef.current;
|
|
1376
|
+
if (box) setIsScrollable(scrollsSideways$1(box));
|
|
1377
|
+
}, [lines]);
|
|
1378
|
+
|
|
1379
|
+
// The pane can be widened, so the block is measured again when its width
|
|
1380
|
+
// changes.
|
|
1381
|
+
useLayoutEffect(function () {
|
|
1382
|
+
var box = boxRef.current;
|
|
1383
|
+
if (!box || typeof globalThis.ResizeObserver !== "function") {
|
|
1384
|
+
return undefined;
|
|
1385
|
+
}
|
|
1386
|
+
var observer = new globalThis.ResizeObserver(function () {
|
|
1387
|
+
return setIsScrollable(scrollsSideways$1(box));
|
|
1388
|
+
});
|
|
1389
|
+
observer.observe(box);
|
|
1390
|
+
return function () {
|
|
1391
|
+
observer.disconnect();
|
|
1392
|
+
};
|
|
1393
|
+
}, []);
|
|
1394
|
+
return /*#__PURE__*/jsx("pre", {
|
|
1395
|
+
className: "bg-muted text-foreground max-w-full overflow-x-auto rounded-md p-3 font-mono text-xs leading-relaxed break-normal whitespace-pre",
|
|
1396
|
+
"data-testid": "neeto-assist-code-block",
|
|
1397
|
+
ref: boxRef,
|
|
1398
|
+
tabIndex: isScrollable ? 0 : undefined,
|
|
1399
|
+
children: /*#__PURE__*/jsx("code", {
|
|
1400
|
+
children: lines.join("\n")
|
|
1401
|
+
})
|
|
1402
|
+
});
|
|
668
1403
|
};
|
|
669
1404
|
|
|
670
1405
|
var Words = function Words(_ref) {
|
|
@@ -700,6 +1435,92 @@ var Lines = function Lines(_ref2) {
|
|
|
700
1435
|
});
|
|
701
1436
|
};
|
|
702
1437
|
|
|
1438
|
+
var scrollsSideways = function scrollsSideways(box) {
|
|
1439
|
+
return box.scrollWidth > box.clientWidth;
|
|
1440
|
+
};
|
|
1441
|
+
var cellClassName = function cellClassName(alignment) {
|
|
1442
|
+
for (var _len = arguments.length, classNames = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
1443
|
+
classNames[_key - 1] = arguments[_key];
|
|
1444
|
+
}
|
|
1445
|
+
return classnames.apply(void 0, ["border-border border-b px-3 py-2", propOr("text-start", alignment, TABLE_ALIGNMENT_CLASSES)].concat(classNames));
|
|
1446
|
+
};
|
|
1447
|
+
|
|
1448
|
+
// A table a model wrote, as Neeti's pane shows one. A wide table scrolls
|
|
1449
|
+
// sideways inside its own box, so the pane never does. Only a box that does
|
|
1450
|
+
// scroll takes the keyboard, so the arrow keys can move it; one that fits is
|
|
1451
|
+
// no tab stop. The table itself is what a screen reader announces.
|
|
1452
|
+
var Table = function Table(_ref) {
|
|
1453
|
+
var _ref$block = _ref.block,
|
|
1454
|
+
alignments = _ref$block.alignments,
|
|
1455
|
+
header = _ref$block.header,
|
|
1456
|
+
rows = _ref$block.rows;
|
|
1457
|
+
var boxRef = useRef(null);
|
|
1458
|
+
var _useState = useState(false),
|
|
1459
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
1460
|
+
isScrollable = _useState2[0],
|
|
1461
|
+
setIsScrollable = _useState2[1];
|
|
1462
|
+
|
|
1463
|
+
// Another table can take this one's place in the same box, as when a reply
|
|
1464
|
+
// is shown in its other language, and be wider or narrower. So the box is
|
|
1465
|
+
// measured again when the table changes.
|
|
1466
|
+
useLayoutEffect(function () {
|
|
1467
|
+
var box = boxRef.current;
|
|
1468
|
+
if (box) setIsScrollable(scrollsSideways(box));
|
|
1469
|
+
}, [header, rows]);
|
|
1470
|
+
|
|
1471
|
+
// The pane can be widened, so the box is measured again when its width
|
|
1472
|
+
// changes.
|
|
1473
|
+
useLayoutEffect(function () {
|
|
1474
|
+
var box = boxRef.current;
|
|
1475
|
+
if (!box || typeof globalThis.ResizeObserver !== "function") {
|
|
1476
|
+
return undefined;
|
|
1477
|
+
}
|
|
1478
|
+
var observer = new globalThis.ResizeObserver(function () {
|
|
1479
|
+
return setIsScrollable(scrollsSideways(box));
|
|
1480
|
+
});
|
|
1481
|
+
observer.observe(box);
|
|
1482
|
+
return function () {
|
|
1483
|
+
observer.disconnect();
|
|
1484
|
+
};
|
|
1485
|
+
}, []);
|
|
1486
|
+
return /*#__PURE__*/jsx("div", {
|
|
1487
|
+
className: "max-w-full overflow-x-auto",
|
|
1488
|
+
"data-testid": "neeto-assist-table",
|
|
1489
|
+
ref: boxRef,
|
|
1490
|
+
tabIndex: isScrollable ? 0 : undefined,
|
|
1491
|
+
children: /*#__PURE__*/jsxs("table", {
|
|
1492
|
+
className: "border-border w-full border-collapse text-sm",
|
|
1493
|
+
children: [/*#__PURE__*/jsx("thead", {
|
|
1494
|
+
className: "bg-muted",
|
|
1495
|
+
children: /*#__PURE__*/jsx("tr", {
|
|
1496
|
+
children: header.map(function (cell, index) {
|
|
1497
|
+
return /*#__PURE__*/jsx("th", {
|
|
1498
|
+
className: cellClassName(alignments.at(index), "font-semibold"),
|
|
1499
|
+
scope: "col",
|
|
1500
|
+
children: /*#__PURE__*/jsx(Lines, {
|
|
1501
|
+
lines: [cell]
|
|
1502
|
+
})
|
|
1503
|
+
}, index);
|
|
1504
|
+
})
|
|
1505
|
+
})
|
|
1506
|
+
}), /*#__PURE__*/jsx("tbody", {
|
|
1507
|
+
children: rows.map(function (row, rowIndex) {
|
|
1508
|
+
return /*#__PURE__*/jsx("tr", {
|
|
1509
|
+
children: row.map(function (cell, index) {
|
|
1510
|
+
return /*#__PURE__*/jsx("td", {
|
|
1511
|
+
className: cellClassName(alignments.at(index), "align-top"),
|
|
1512
|
+
children: /*#__PURE__*/jsx(Lines, {
|
|
1513
|
+
lines: [cell]
|
|
1514
|
+
})
|
|
1515
|
+
}, index);
|
|
1516
|
+
})
|
|
1517
|
+
}, rowIndex);
|
|
1518
|
+
})
|
|
1519
|
+
})]
|
|
1520
|
+
})
|
|
1521
|
+
});
|
|
1522
|
+
};
|
|
1523
|
+
|
|
703
1524
|
var Block = function Block(_ref) {
|
|
704
1525
|
var block = _ref.block;
|
|
705
1526
|
if (block.type === BLOCK_TYPES.HEADING) {
|
|
@@ -710,6 +1531,12 @@ var Block = function Block(_ref) {
|
|
|
710
1531
|
})
|
|
711
1532
|
});
|
|
712
1533
|
}
|
|
1534
|
+
if (block.type === BLOCK_TYPES.TABLE) return /*#__PURE__*/jsx(Table, {
|
|
1535
|
+
block: block
|
|
1536
|
+
});
|
|
1537
|
+
if (block.type === BLOCK_TYPES.CODE) return /*#__PURE__*/jsx(CodeBlock, {
|
|
1538
|
+
block: block
|
|
1539
|
+
});
|
|
713
1540
|
if (block.type === BLOCK_TYPES.PARAGRAPH) {
|
|
714
1541
|
return /*#__PURE__*/jsx("p", {
|
|
715
1542
|
children: /*#__PURE__*/jsx(Lines, {
|
|
@@ -719,11 +1546,14 @@ var Block = function Block(_ref) {
|
|
|
719
1546
|
}
|
|
720
1547
|
var isOrdered = block.type === BLOCK_TYPES.ORDERED_LIST;
|
|
721
1548
|
var List = isOrdered ? "ol" : "ul";
|
|
1549
|
+
|
|
1550
|
+
// The room for the numbers and bullets is on the side the list starts at, so
|
|
1551
|
+
// they stay inside a reply that reads right to left, as Arabic does.
|
|
722
1552
|
return /*#__PURE__*/jsx(List, {
|
|
723
1553
|
start: isOrdered ? block.start : undefined,
|
|
724
1554
|
className: classnames({
|
|
725
|
-
"list-decimal space-y-1
|
|
726
|
-
"list-disc space-y-1
|
|
1555
|
+
"list-decimal space-y-1 ps-5": isOrdered,
|
|
1556
|
+
"list-disc space-y-1 ps-5": !isOrdered
|
|
727
1557
|
}),
|
|
728
1558
|
children: block.items.map(function (lines, index) {
|
|
729
1559
|
return /*#__PURE__*/jsx("li", {
|
|
@@ -738,11 +1568,14 @@ var Block = function Block(_ref) {
|
|
|
738
1568
|
var FormattedText = function FormattedText(_ref) {
|
|
739
1569
|
var className = _ref.className,
|
|
740
1570
|
text = _ref.text;
|
|
1571
|
+
var blocks = useMemo(function () {
|
|
1572
|
+
return parseLightMarkdown(text);
|
|
1573
|
+
}, [text]);
|
|
741
1574
|
return /*#__PURE__*/jsx("div", {
|
|
742
1575
|
className: classnames(typographyVariants({
|
|
743
1576
|
variant: "body2"
|
|
744
1577
|
}), "space-y-2 break-words", className),
|
|
745
|
-
children:
|
|
1578
|
+
children: blocks.map(function (block, index) {
|
|
746
1579
|
return /*#__PURE__*/createElement(Block, {
|
|
747
1580
|
block: block,
|
|
748
1581
|
key: index
|
|
@@ -905,9 +1738,9 @@ var Outcome = function Outcome(_ref) {
|
|
|
905
1738
|
return null;
|
|
906
1739
|
};
|
|
907
1740
|
|
|
908
|
-
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; }
|
|
909
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).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; }
|
|
910
|
-
var Card = function Card(_ref) {
|
|
1741
|
+
function ownKeys$2(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; }
|
|
1742
|
+
function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$2(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$2(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
1743
|
+
var Card$1 = function Card(_ref) {
|
|
911
1744
|
var action = _ref.action,
|
|
912
1745
|
conversationId = _ref.conversationId,
|
|
913
1746
|
onActionApplied = _ref.onActionApplied;
|
|
@@ -922,7 +1755,7 @@ var Card = function Card(_ref) {
|
|
|
922
1755
|
// The host is told through the hook, which still hears the answer to a
|
|
923
1756
|
// click when this card is gone by then.
|
|
924
1757
|
var _useApplyAction = useApplyAction(conversationId, function (applied) {
|
|
925
|
-
return onActionApplied === null || onActionApplied === void 0 ? void 0 : onActionApplied(_objectSpread(_objectSpread({}, action), applied));
|
|
1758
|
+
return onActionApplied === null || onActionApplied === void 0 ? void 0 : onActionApplied(_objectSpread$2(_objectSpread$2({}, action), applied));
|
|
926
1759
|
}),
|
|
927
1760
|
apply = _useApplyAction.mutate,
|
|
928
1761
|
isApplying = _useApplyAction.isPending;
|
|
@@ -1032,7 +1865,7 @@ var Actions = function Actions(_ref) {
|
|
|
1032
1865
|
return /*#__PURE__*/jsx("div", {
|
|
1033
1866
|
className: "flex flex-col gap-2",
|
|
1034
1867
|
children: actions.map(function (action) {
|
|
1035
|
-
return /*#__PURE__*/createElement(Card, {
|
|
1868
|
+
return /*#__PURE__*/createElement(Card$1, {
|
|
1036
1869
|
action: action,
|
|
1037
1870
|
conversationId: conversationId,
|
|
1038
1871
|
onActionApplied: onActionApplied,
|
|
@@ -1043,17 +1876,14 @@ var Actions = function Actions(_ref) {
|
|
|
1043
1876
|
};
|
|
1044
1877
|
|
|
1045
1878
|
var Sources = function Sources(_ref) {
|
|
1046
|
-
var
|
|
1047
|
-
sources = _ref$sources === void 0 ? [] : _ref$sources;
|
|
1879
|
+
var sources = _ref.sources;
|
|
1048
1880
|
var _useTranslation = useTranslation(),
|
|
1049
1881
|
t = _useTranslation.t;
|
|
1050
|
-
var
|
|
1051
|
-
|
|
1052
|
-
return isWebUrl(url);
|
|
1053
|
-
});
|
|
1054
|
-
if (!isNotEmpty(links)) return null;
|
|
1882
|
+
var shown = shownSources(sources);
|
|
1883
|
+
if (!isNotEmpty(shown)) return null;
|
|
1055
1884
|
return /*#__PURE__*/jsxs("div", {
|
|
1056
1885
|
className: "space-y-1",
|
|
1886
|
+
"data-testid": "neeto-assist-sources",
|
|
1057
1887
|
children: [/*#__PURE__*/jsx(Typography, {
|
|
1058
1888
|
color: "muted",
|
|
1059
1889
|
variant: "body3",
|
|
@@ -1061,30 +1891,48 @@ var Sources = function Sources(_ref) {
|
|
|
1061
1891
|
children: t("neetoAssist.run.sources")
|
|
1062
1892
|
}), /*#__PURE__*/jsx("ul", {
|
|
1063
1893
|
className: "space-y-1",
|
|
1064
|
-
children:
|
|
1065
|
-
var
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1894
|
+
children: shown.map(function (_ref2, index) {
|
|
1895
|
+
var kindKey = _ref2.kindKey,
|
|
1896
|
+
product = _ref2.product,
|
|
1897
|
+
title = _ref2.title,
|
|
1898
|
+
url = _ref2.url;
|
|
1899
|
+
return /*#__PURE__*/jsxs("li", {
|
|
1900
|
+
className: "text-muted-foreground text-sm break-words",
|
|
1901
|
+
"data-testid": "neeto-assist-source",
|
|
1902
|
+
children: [(kindKey || product) && /*#__PURE__*/jsx("span", {
|
|
1903
|
+
className: "me-1.5 text-xs font-medium",
|
|
1904
|
+
children: kindKey ? t(kindKey) : product
|
|
1905
|
+
}), url ? /*#__PURE__*/jsxs("a", {
|
|
1906
|
+
className: "hover:text-foreground hover:underline",
|
|
1070
1907
|
href: url,
|
|
1071
1908
|
rel: "noreferrer",
|
|
1072
1909
|
target: "_blank",
|
|
1073
|
-
children: [/*#__PURE__*/jsx(
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1910
|
+
children: [title || url, /*#__PURE__*/jsx("span", {
|
|
1911
|
+
"aria-hidden": "true",
|
|
1912
|
+
className: "text-xs",
|
|
1913
|
+
children: "\xA0\u2197"
|
|
1914
|
+
})]
|
|
1915
|
+
}) : /*#__PURE__*/jsx("span", {
|
|
1916
|
+
children: title
|
|
1917
|
+
})]
|
|
1918
|
+
}, index);
|
|
1079
1919
|
})
|
|
1080
1920
|
})]
|
|
1081
1921
|
});
|
|
1082
1922
|
};
|
|
1083
1923
|
|
|
1084
|
-
var
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1924
|
+
var _excluded = ["onUseReply", "reading"];
|
|
1925
|
+
function ownKeys$1(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; }
|
|
1926
|
+
function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
1927
|
+
var handOver = function handOver(onUseReply, text) {
|
|
1928
|
+
return onUseReply(replyText(text), lightMarkdownToHtml(text));
|
|
1929
|
+
};
|
|
1930
|
+
|
|
1931
|
+
// The frame and the heading that a reply as written and a reply in two
|
|
1932
|
+
// languages share.
|
|
1933
|
+
var Card = function Card(_ref) {
|
|
1934
|
+
var children = _ref.children,
|
|
1935
|
+
t = _ref.t;
|
|
1088
1936
|
return /*#__PURE__*/jsxs("div", {
|
|
1089
1937
|
className: "border-border space-y-2 rounded-lg border p-3",
|
|
1090
1938
|
children: [/*#__PURE__*/jsx(Typography, {
|
|
@@ -1092,7 +1940,135 @@ var SuggestedReply$1 = function SuggestedReply(_ref) {
|
|
|
1092
1940
|
variant: "body3",
|
|
1093
1941
|
weight: "medium",
|
|
1094
1942
|
children: t("neetoAssist.run.suggestedReply")
|
|
1095
|
-
}),
|
|
1943
|
+
}), children]
|
|
1944
|
+
});
|
|
1945
|
+
};
|
|
1946
|
+
|
|
1947
|
+
// Copies the reply that is showing, as NeetoAssist wrote it, and says so in a
|
|
1948
|
+
// toast.
|
|
1949
|
+
var CopyButton = function CopyButton(_ref2) {
|
|
1950
|
+
var t = _ref2.t,
|
|
1951
|
+
text = _ref2.text;
|
|
1952
|
+
return /*#__PURE__*/jsx(Button, {
|
|
1953
|
+
"data-testid": "neeto-assist-copy-reply-button",
|
|
1954
|
+
icon: Copy,
|
|
1955
|
+
label: t("neetoAssist.run.copy"),
|
|
1956
|
+
size: "sm",
|
|
1957
|
+
variant: "outline",
|
|
1958
|
+
onClick: function onClick() {
|
|
1959
|
+
return copyToClipboard(text, {
|
|
1960
|
+
message: t("neetoAssist.run.copied")
|
|
1961
|
+
});
|
|
1962
|
+
}
|
|
1963
|
+
});
|
|
1964
|
+
};
|
|
1965
|
+
|
|
1966
|
+
// Hands the host one of a reply's two readings. Its name carries the name of a
|
|
1967
|
+
// language, which can be long in a narrow pane ("Use in Brazilian Portuguese"),
|
|
1968
|
+
// so the name wraps inside the button and the button never grows wider than
|
|
1969
|
+
// the card.
|
|
1970
|
+
var UseReading = function UseReading(_ref3) {
|
|
1971
|
+
var onUseReply = _ref3.onUseReply,
|
|
1972
|
+
reading = _ref3.reading,
|
|
1973
|
+
buttonProps = _objectWithoutProperties(_ref3, _excluded);
|
|
1974
|
+
return /*#__PURE__*/jsx(Button, _objectSpread$1(_objectSpread$1({}, buttonProps), {}, {
|
|
1975
|
+
className: "h-auto min-h-7 max-w-full py-1 whitespace-normal",
|
|
1976
|
+
icon: CornerDownLeft,
|
|
1977
|
+
size: "sm",
|
|
1978
|
+
onClick: function onClick() {
|
|
1979
|
+
return handOver(onUseReply, reading.text);
|
|
1980
|
+
}
|
|
1981
|
+
}));
|
|
1982
|
+
};
|
|
1983
|
+
|
|
1984
|
+
// A reply that came in English and in the language the customer is sent it
|
|
1985
|
+
// in, for a rep who reads English. The card shows the English reading. The
|
|
1986
|
+
// link under it turns the card to what the customer will read, and back, and
|
|
1987
|
+
// the rep picks which of the two goes to the composer. Copy copies the one
|
|
1988
|
+
// that is showing. The card remembers its turn only while it is on screen.
|
|
1989
|
+
// The block that holds a reading names its language, so a screen reader picks
|
|
1990
|
+
// the right voice, and it is read out again, whole, when the card turns. Its
|
|
1991
|
+
// direction comes from that language too, so an Arabic reading that opens
|
|
1992
|
+
// with the name of a product still reads right to left.
|
|
1993
|
+
// The link stays the same button through a turn, so the keyboard stays on it.
|
|
1994
|
+
var Readings = function Readings(_ref4) {
|
|
1995
|
+
var onUseReply = _ref4.onUseReply,
|
|
1996
|
+
readings = _ref4.readings;
|
|
1997
|
+
var _useTranslation = useTranslation(),
|
|
1998
|
+
t = _useTranslation.t,
|
|
1999
|
+
i18n = _useTranslation.i18n;
|
|
2000
|
+
var _useState = useState(false),
|
|
2001
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
2002
|
+
isInCustomerLanguage = _useState2[0],
|
|
2003
|
+
setIsInCustomerLanguage = _useState2[1];
|
|
2004
|
+
var customer = readings.customer,
|
|
2005
|
+
english = readings.english;
|
|
2006
|
+
var words = replyWords(t, i18n.resolvedLanguage, readings);
|
|
2007
|
+
var shown = isInCustomerLanguage ? customer : english;
|
|
2008
|
+
return /*#__PURE__*/jsxs(Card, {
|
|
2009
|
+
t: t,
|
|
2010
|
+
children: [/*#__PURE__*/jsx("div", {
|
|
2011
|
+
"aria-atomic": "true",
|
|
2012
|
+
"aria-live": "polite",
|
|
2013
|
+
"data-testid": "neeto-assist-reply-reading",
|
|
2014
|
+
dir: shown.dir,
|
|
2015
|
+
lang: shown.lang,
|
|
2016
|
+
children: /*#__PURE__*/jsx(FormattedText, {
|
|
2017
|
+
text: shown.text
|
|
2018
|
+
})
|
|
2019
|
+
}), /*#__PURE__*/jsxs("div", {
|
|
2020
|
+
className: "flex flex-wrap items-baseline gap-x-1.5",
|
|
2021
|
+
children: [/*#__PURE__*/jsx(Typography, {
|
|
2022
|
+
color: "muted",
|
|
2023
|
+
"data-testid": "neeto-assist-reply-language",
|
|
2024
|
+
variant: "body3",
|
|
2025
|
+
children: words.line
|
|
2026
|
+
}), /*#__PURE__*/jsx(Button, {
|
|
2027
|
+
className: "max-w-full text-start whitespace-normal",
|
|
2028
|
+
"data-testid": "neeto-assist-reply-language-toggle",
|
|
2029
|
+
label: isInCustomerLanguage ? words.showEnglish : words.showCustomer,
|
|
2030
|
+
variant: "link",
|
|
2031
|
+
onClick: function onClick() {
|
|
2032
|
+
return setIsInCustomerLanguage(not);
|
|
2033
|
+
}
|
|
2034
|
+
})]
|
|
2035
|
+
}), /*#__PURE__*/jsxs("div", {
|
|
2036
|
+
className: "flex flex-wrap gap-2",
|
|
2037
|
+
children: [onUseReply && /*#__PURE__*/jsxs(Fragment$1, {
|
|
2038
|
+
children: [/*#__PURE__*/jsx(UseReading, {
|
|
2039
|
+
onUseReply: onUseReply,
|
|
2040
|
+
"data-testid": "neeto-assist-use-reply-button",
|
|
2041
|
+
label: words.useCustomer,
|
|
2042
|
+
reading: customer
|
|
2043
|
+
}), /*#__PURE__*/jsx(UseReading, {
|
|
2044
|
+
onUseReply: onUseReply,
|
|
2045
|
+
"data-testid": "neeto-assist-use-english-reply-button",
|
|
2046
|
+
label: words.useEnglish,
|
|
2047
|
+
reading: english,
|
|
2048
|
+
variant: "outline"
|
|
2049
|
+
})]
|
|
2050
|
+
}), /*#__PURE__*/jsx(CopyButton, {
|
|
2051
|
+
t: t,
|
|
2052
|
+
text: shown.text
|
|
2053
|
+
})]
|
|
2054
|
+
})]
|
|
2055
|
+
});
|
|
2056
|
+
};
|
|
2057
|
+
|
|
2058
|
+
// A reply as NeetoAssist wrote it, with "Use reply" for a host that has a
|
|
2059
|
+
// composer, and "Copy". A run that carries the reply in English and in the
|
|
2060
|
+
// language the customer is sent it in shows its two readings instead.
|
|
2061
|
+
var SuggestedReply$1 = function SuggestedReply(_ref5) {
|
|
2062
|
+
var onUseReply = _ref5.onUseReply,
|
|
2063
|
+
readings = _ref5.readings,
|
|
2064
|
+
t = _ref5.t,
|
|
2065
|
+
text = _ref5.text;
|
|
2066
|
+
return readings ? /*#__PURE__*/jsx(Readings, {
|
|
2067
|
+
onUseReply: onUseReply,
|
|
2068
|
+
readings: readings
|
|
2069
|
+
}) : /*#__PURE__*/jsxs(Card, {
|
|
2070
|
+
t: t,
|
|
2071
|
+
children: [/*#__PURE__*/jsx(FormattedText, {
|
|
1096
2072
|
text: text
|
|
1097
2073
|
}), /*#__PURE__*/jsxs("div", {
|
|
1098
2074
|
className: "flex flex-wrap gap-2",
|
|
@@ -1102,19 +2078,11 @@ var SuggestedReply$1 = function SuggestedReply(_ref) {
|
|
|
1102
2078
|
label: t("neetoAssist.run.useReply"),
|
|
1103
2079
|
size: "sm",
|
|
1104
2080
|
onClick: function onClick() {
|
|
1105
|
-
return onUseReply
|
|
1106
|
-
}
|
|
1107
|
-
}), /*#__PURE__*/jsx(Button, {
|
|
1108
|
-
"data-testid": "neeto-assist-copy-reply-button",
|
|
1109
|
-
icon: Copy,
|
|
1110
|
-
label: t("neetoAssist.run.copy"),
|
|
1111
|
-
size: "sm",
|
|
1112
|
-
variant: "outline",
|
|
1113
|
-
onClick: function onClick() {
|
|
1114
|
-
return copyToClipboard(text, {
|
|
1115
|
-
message: t("neetoAssist.run.copied")
|
|
1116
|
-
});
|
|
2081
|
+
return handOver(onUseReply, text);
|
|
1117
2082
|
}
|
|
2083
|
+
}), /*#__PURE__*/jsx(CopyButton, {
|
|
2084
|
+
t: t,
|
|
2085
|
+
text: text
|
|
1118
2086
|
})]
|
|
1119
2087
|
})]
|
|
1120
2088
|
});
|
|
@@ -1125,7 +2093,8 @@ var Answer = function Answer(_ref) {
|
|
|
1125
2093
|
var conversationId = _ref.conversationId,
|
|
1126
2094
|
onActionApplied = _ref.onActionApplied,
|
|
1127
2095
|
onUseReply = _ref.onUseReply,
|
|
1128
|
-
run = _ref.run
|
|
2096
|
+
run = _ref.run,
|
|
2097
|
+
threadId = _ref.threadId;
|
|
1129
2098
|
var _useTranslation = useTranslation(),
|
|
1130
2099
|
t = _useTranslation.t;
|
|
1131
2100
|
var kind = run.kind,
|
|
@@ -1134,7 +2103,9 @@ var Answer = function Answer(_ref) {
|
|
|
1134
2103
|
suggestedReply = run.suggestedReply,
|
|
1135
2104
|
needsHumanAction = run.needsHumanAction,
|
|
1136
2105
|
sources = run.sources;
|
|
1137
|
-
|
|
2106
|
+
|
|
2107
|
+
// Nothing can be applied from an assistant thread, so it shows no cards.
|
|
2108
|
+
var actions = threadId ? null : /*#__PURE__*/jsx(Actions, {
|
|
1138
2109
|
conversationId: conversationId,
|
|
1139
2110
|
onActionApplied: onActionApplied,
|
|
1140
2111
|
actions: actionsOf(run)
|
|
@@ -1165,6 +2136,7 @@ var Answer = function Answer(_ref) {
|
|
|
1165
2136
|
text: answer
|
|
1166
2137
|
}), suggestedReply && /*#__PURE__*/jsx(SuggestedReply, {
|
|
1167
2138
|
onUseReply: onUseReply,
|
|
2139
|
+
readings: replyReadings(run),
|
|
1168
2140
|
text: suggestedReply
|
|
1169
2141
|
}), needsHumanAction && /*#__PURE__*/jsx(Typography, {
|
|
1170
2142
|
"data-testid": "neeto-assist-follow-up-note",
|
|
@@ -1177,12 +2149,77 @@ var Answer = function Answer(_ref) {
|
|
|
1177
2149
|
});
|
|
1178
2150
|
};
|
|
1179
2151
|
|
|
2152
|
+
var CopyAnswer = function CopyAnswer(_ref) {
|
|
2153
|
+
var answer = _ref.answer;
|
|
2154
|
+
var _useTranslation = useTranslation(),
|
|
2155
|
+
t = _useTranslation.t;
|
|
2156
|
+
var _useState = useState(false),
|
|
2157
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
2158
|
+
isCopied = _useState2[0],
|
|
2159
|
+
setIsCopied = _useState2[1];
|
|
2160
|
+
useEffect(function () {
|
|
2161
|
+
if (!isCopied) return undefined;
|
|
2162
|
+
var timer = setTimeout(function () {
|
|
2163
|
+
return setIsCopied(false);
|
|
2164
|
+
}, COPIED_FOR);
|
|
2165
|
+
return function () {
|
|
2166
|
+
return clearTimeout(timer);
|
|
2167
|
+
};
|
|
2168
|
+
}, [isCopied]);
|
|
2169
|
+
var copy = /*#__PURE__*/function () {
|
|
2170
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
2171
|
+
var text;
|
|
2172
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
2173
|
+
while (1) switch (_context.prev = _context.next) {
|
|
2174
|
+
case 0:
|
|
2175
|
+
text = lightMarkdownToText(answer);
|
|
2176
|
+
_context.prev = 1;
|
|
2177
|
+
_context.next = 4;
|
|
2178
|
+
return globalThis.navigator.clipboard.writeText(text);
|
|
2179
|
+
case 4:
|
|
2180
|
+
setIsCopied(true);
|
|
2181
|
+
_context.next = 11;
|
|
2182
|
+
break;
|
|
2183
|
+
case 7:
|
|
2184
|
+
_context.prev = 7;
|
|
2185
|
+
_context.t0 = _context["catch"](1);
|
|
2186
|
+
_context.next = 11;
|
|
2187
|
+
return copyToClipboard(text);
|
|
2188
|
+
case 11:
|
|
2189
|
+
case "end":
|
|
2190
|
+
return _context.stop();
|
|
2191
|
+
}
|
|
2192
|
+
}, _callee, null, [[1, 7]]);
|
|
2193
|
+
}));
|
|
2194
|
+
return function copy() {
|
|
2195
|
+
return _ref2.apply(this, arguments);
|
|
2196
|
+
};
|
|
2197
|
+
}();
|
|
2198
|
+
var label = t(isCopied ? "neetoAssist.run.answerCopied" : "neetoAssist.run.copyAnswer");
|
|
2199
|
+
return /*#__PURE__*/jsx(Button, {
|
|
2200
|
+
"aria-label": label,
|
|
2201
|
+
"data-testid": "neeto-assist-copy-answer-button",
|
|
2202
|
+
icon: isCopied ? Check : Copy,
|
|
2203
|
+
size: "icon-sm",
|
|
2204
|
+
tooltipProps: {
|
|
2205
|
+
content: label
|
|
2206
|
+
},
|
|
2207
|
+
variant: "ghost",
|
|
2208
|
+
onClick: copy
|
|
2209
|
+
});
|
|
2210
|
+
};
|
|
2211
|
+
|
|
2212
|
+
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; }
|
|
2213
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).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; }
|
|
1180
2214
|
var Feedback = function Feedback(_ref) {
|
|
1181
2215
|
var conversationId = _ref.conversationId,
|
|
1182
2216
|
_ref$run = _ref.run,
|
|
1183
2217
|
runId = _ref$run.id,
|
|
2218
|
+
answer = _ref$run.answer,
|
|
1184
2219
|
_ref$run$feedback = _ref$run.feedback,
|
|
1185
|
-
feedback = _ref$run$feedback === void 0 ? [] : _ref$run$feedback
|
|
2220
|
+
feedback = _ref$run$feedback === void 0 ? [] : _ref$run$feedback,
|
|
2221
|
+
kind = _ref$run.kind,
|
|
2222
|
+
threadId = _ref.threadId;
|
|
1186
2223
|
var _useTranslation = useTranslation(),
|
|
1187
2224
|
t = _useTranslation.t;
|
|
1188
2225
|
var _useState = useState(null),
|
|
@@ -1197,7 +2234,13 @@ var Feedback = function Feedback(_ref) {
|
|
|
1197
2234
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
1198
2235
|
note = _useState6[0],
|
|
1199
2236
|
setNote = _useState6[1];
|
|
1200
|
-
var
|
|
2237
|
+
var where = threadId ? {
|
|
2238
|
+
threadId: threadId
|
|
2239
|
+
} : {
|
|
2240
|
+
conversationId: conversationId
|
|
2241
|
+
};
|
|
2242
|
+
var isAssistant = !!threadId;
|
|
2243
|
+
var _useUpdateFeedback = useUpdateFeedback(where),
|
|
1201
2244
|
updateFeedback = _useUpdateFeedback.mutate,
|
|
1202
2245
|
isPending = _useUpdateFeedback.isPending,
|
|
1203
2246
|
error = _useUpdateFeedback.error;
|
|
@@ -1223,12 +2266,11 @@ var Feedback = function Feedback(_ref) {
|
|
|
1223
2266
|
setPendingRating(value);
|
|
1224
2267
|
setNote(savedNote);
|
|
1225
2268
|
setIsEditingNote(true);
|
|
1226
|
-
updateFeedback({
|
|
1227
|
-
conversationId: conversationId,
|
|
2269
|
+
updateFeedback(_objectSpread(_objectSpread({}, where), {}, {
|
|
1228
2270
|
runId: runId,
|
|
1229
2271
|
rating: value,
|
|
1230
2272
|
note: savedNote
|
|
1231
|
-
}, {
|
|
2273
|
+
}), {
|
|
1232
2274
|
onError: function onError() {
|
|
1233
2275
|
return setPendingRating(null);
|
|
1234
2276
|
}
|
|
@@ -1236,12 +2278,11 @@ var Feedback = function Feedback(_ref) {
|
|
|
1236
2278
|
};
|
|
1237
2279
|
var handleSubmit = function handleSubmit(event) {
|
|
1238
2280
|
event.preventDefault();
|
|
1239
|
-
updateFeedback({
|
|
1240
|
-
conversationId: conversationId,
|
|
2281
|
+
updateFeedback(_objectSpread(_objectSpread({}, where), {}, {
|
|
1241
2282
|
runId: runId,
|
|
1242
2283
|
rating: shownRating,
|
|
1243
2284
|
note: note.trim()
|
|
1244
|
-
}, {
|
|
2285
|
+
}), {
|
|
1245
2286
|
onSuccess: function onSuccess() {
|
|
1246
2287
|
return setIsEditingNote(false);
|
|
1247
2288
|
}
|
|
@@ -1251,7 +2292,9 @@ var Feedback = function Feedback(_ref) {
|
|
|
1251
2292
|
className: "space-y-2",
|
|
1252
2293
|
children: [/*#__PURE__*/jsxs("div", {
|
|
1253
2294
|
className: "flex items-center gap-1",
|
|
1254
|
-
children: [/*#__PURE__*/jsx(
|
|
2295
|
+
children: [kind === "ask" && answer && /*#__PURE__*/jsx(CopyAnswer, {
|
|
2296
|
+
answer: answer
|
|
2297
|
+
}), /*#__PURE__*/jsx(Button, {
|
|
1255
2298
|
"aria-label": t("neetoAssist.feedback.helpful"),
|
|
1256
2299
|
"data-testid": "neeto-assist-thumbs-up-button",
|
|
1257
2300
|
disabled: isPending,
|
|
@@ -1279,7 +2322,8 @@ var Feedback = function Feedback(_ref) {
|
|
|
1279
2322
|
}
|
|
1280
2323
|
})]
|
|
1281
2324
|
}), error && /*#__PURE__*/jsx(ErrorMessage, {
|
|
1282
|
-
error: error
|
|
2325
|
+
error: error,
|
|
2326
|
+
isAssistant: isAssistant
|
|
1283
2327
|
}), isEditingNote && shownRating && /*#__PURE__*/jsxs("form", {
|
|
1284
2328
|
className: "space-y-2",
|
|
1285
2329
|
onSubmit: handleSubmit,
|
|
@@ -1329,13 +2373,19 @@ var Feedback = function Feedback(_ref) {
|
|
|
1329
2373
|
};
|
|
1330
2374
|
|
|
1331
2375
|
var Question = function Question(_ref) {
|
|
1332
|
-
var
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
2376
|
+
var _questionReadings;
|
|
2377
|
+
var run = _ref.run;
|
|
2378
|
+
var command = run.command,
|
|
2379
|
+
kind = run.kind,
|
|
2380
|
+
question = run.question,
|
|
2381
|
+
requestedBy = run.requestedBy;
|
|
1337
2382
|
var _useTranslation = useTranslation(),
|
|
1338
|
-
t = _useTranslation.t
|
|
2383
|
+
t = _useTranslation.t,
|
|
2384
|
+
i18n = _useTranslation.i18n;
|
|
2385
|
+
var _useState = useState(false),
|
|
2386
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
2387
|
+
isOriginal = _useState2[0],
|
|
2388
|
+
setIsOriginal = _useState2[1];
|
|
1339
2389
|
if (kind === "ask") {
|
|
1340
2390
|
var _globalProps$user;
|
|
1341
2391
|
var isOwnQuestion = (requestedBy === null || requestedBy === void 0 ? void 0 : requestedBy.id) === ((_globalProps$user = globalProps.user) === null || _globalProps$user === void 0 ? void 0 : _globalProps$user.id);
|
|
@@ -1363,6 +2413,11 @@ var Question = function Question(_ref) {
|
|
|
1363
2413
|
})]
|
|
1364
2414
|
});
|
|
1365
2415
|
}
|
|
2416
|
+
var _ref2 = (_questionReadings = questionReadings(run)) !== null && _questionReadings !== void 0 ? _questionReadings : {},
|
|
2417
|
+
english = _ref2.english,
|
|
2418
|
+
original = _ref2.original;
|
|
2419
|
+
var shown = isOriginal ? original : english;
|
|
2420
|
+
var words = shown && questionWords(t, i18n.resolvedLanguage, original.lang);
|
|
1366
2421
|
return /*#__PURE__*/jsxs("div", {
|
|
1367
2422
|
className: "border-border space-y-1 border-s-2 ps-3",
|
|
1368
2423
|
children: [/*#__PURE__*/jsx(Typography, {
|
|
@@ -1370,7 +2425,33 @@ var Question = function Question(_ref) {
|
|
|
1370
2425
|
variant: "body3",
|
|
1371
2426
|
weight: "medium",
|
|
1372
2427
|
children: t("neetoAssist.run.customerWrote")
|
|
1373
|
-
}),
|
|
2428
|
+
}), shown ? /*#__PURE__*/jsxs(Fragment$1, {
|
|
2429
|
+
children: [/*#__PURE__*/jsx(Typography, {
|
|
2430
|
+
"aria-live": "polite",
|
|
2431
|
+
className: "whitespace-pre-wrap break-words",
|
|
2432
|
+
"data-testid": "neeto-assist-question-reading",
|
|
2433
|
+
dir: shown.dir,
|
|
2434
|
+
lang: shown.lang,
|
|
2435
|
+
variant: "body2",
|
|
2436
|
+
children: shown.text
|
|
2437
|
+
}), /*#__PURE__*/jsxs("div", {
|
|
2438
|
+
className: "flex flex-wrap items-baseline gap-x-1.5",
|
|
2439
|
+
children: [/*#__PURE__*/jsx(Typography, {
|
|
2440
|
+
color: "muted",
|
|
2441
|
+
"data-testid": "neeto-assist-question-language",
|
|
2442
|
+
variant: "body3",
|
|
2443
|
+
children: isOriginal ? words.original : words.translated
|
|
2444
|
+
}), /*#__PURE__*/jsx(Button, {
|
|
2445
|
+
className: "max-w-full text-start whitespace-normal",
|
|
2446
|
+
"data-testid": "neeto-assist-question-language-toggle",
|
|
2447
|
+
label: isOriginal ? words.showEnglish : words.showOriginal,
|
|
2448
|
+
variant: "link",
|
|
2449
|
+
onClick: function onClick() {
|
|
2450
|
+
return setIsOriginal(not);
|
|
2451
|
+
}
|
|
2452
|
+
})]
|
|
2453
|
+
})]
|
|
2454
|
+
}) : question && /*#__PURE__*/jsx(Typography, {
|
|
1374
2455
|
className: "whitespace-pre-wrap break-words",
|
|
1375
2456
|
variant: "body2",
|
|
1376
2457
|
children: question
|
|
@@ -1466,7 +2547,8 @@ var Run$1 = function Run(_ref) {
|
|
|
1466
2547
|
onActionApplied = _ref.onActionApplied,
|
|
1467
2548
|
onUseReply = _ref.onUseReply,
|
|
1468
2549
|
run = _ref.run,
|
|
1469
|
-
t = _ref.t
|
|
2550
|
+
t = _ref.t,
|
|
2551
|
+
threadId = _ref.threadId;
|
|
1470
2552
|
return /*#__PURE__*/jsxs("div", {
|
|
1471
2553
|
className: "flex flex-col gap-3",
|
|
1472
2554
|
"data-testid": RUN_TEST_ID,
|
|
@@ -1487,18 +2569,26 @@ var Run$1 = function Run(_ref) {
|
|
|
1487
2569
|
conversationId: conversationId,
|
|
1488
2570
|
onActionApplied: onActionApplied,
|
|
1489
2571
|
onUseReply: onUseReply,
|
|
1490
|
-
run: run
|
|
2572
|
+
run: run,
|
|
2573
|
+
threadId: threadId
|
|
1491
2574
|
}), run.status === "skipped" && !hasWrittenReply(run) && /*#__PURE__*/jsx(Typography, {
|
|
1492
2575
|
color: "muted",
|
|
1493
2576
|
variant: "body2",
|
|
1494
2577
|
children: t(skippedReasonMessageKey(run.skippedReason))
|
|
2578
|
+
}), isStopped(run) && /*#__PURE__*/jsx(Typography, {
|
|
2579
|
+
color: "muted",
|
|
2580
|
+
"data-testid": "neeto-assist-stopped",
|
|
2581
|
+
role: "status",
|
|
2582
|
+
variant: "body2",
|
|
2583
|
+
children: t("neetoAssist.run.stopped")
|
|
1495
2584
|
}), run.status === "failed" && /*#__PURE__*/jsx(Typography, {
|
|
1496
2585
|
color: "muted",
|
|
1497
2586
|
variant: "body2",
|
|
1498
2587
|
children: t("neetoAssist.run.failed")
|
|
1499
2588
|
}), isRateable(run) && /*#__PURE__*/jsx(Feedback, {
|
|
1500
2589
|
conversationId: conversationId,
|
|
1501
|
-
run: run
|
|
2590
|
+
run: run,
|
|
2591
|
+
threadId: threadId
|
|
1502
2592
|
})]
|
|
1503
2593
|
});
|
|
1504
2594
|
};
|
|
@@ -1518,16 +2608,29 @@ var topOfFinishedRun = function topOfFinishedRun(list, run) {
|
|
|
1518
2608
|
// Everything NeetoAssist did on one ticket, kept for as long as the ticket is,
|
|
1519
2609
|
// and the box to ask it more. Keyed by conversation, so moving to another
|
|
1520
2610
|
// ticket starts fresh and not even a half-typed question carries over.
|
|
2611
|
+
// The assistant shows one of its threads the same way, given the thread's key
|
|
2612
|
+
// instead of a conversation, its own empty state, and a focusRequest that
|
|
2613
|
+
// moves the keyboard to the box.
|
|
1521
2614
|
var Conversation = function Conversation(_ref3) {
|
|
1522
2615
|
var conversationId = _ref3.conversationId,
|
|
2616
|
+
emptyState = _ref3.emptyState,
|
|
2617
|
+
focusRequest = _ref3.focusRequest,
|
|
2618
|
+
_ref3$isAskDisabled = _ref3.isAskDisabled,
|
|
2619
|
+
isAskDisabled = _ref3$isAskDisabled === void 0 ? false : _ref3$isAskDisabled,
|
|
1523
2620
|
isVisible = _ref3.isVisible,
|
|
1524
2621
|
onActionApplied = _ref3.onActionApplied,
|
|
1525
|
-
onUseReply = _ref3.onUseReply
|
|
2622
|
+
onUseReply = _ref3.onUseReply,
|
|
2623
|
+
threadId = _ref3.threadId;
|
|
1526
2624
|
var listRef = useRef(null);
|
|
1527
2625
|
var markDraftSeen = useNeetoAssistStore(function (state) {
|
|
1528
2626
|
return state.markDraftSeen;
|
|
1529
2627
|
});
|
|
1530
|
-
var
|
|
2628
|
+
var isAssistant = !!threadId;
|
|
2629
|
+
var _useFetchRuns = useFetchRuns(isAssistant ? {
|
|
2630
|
+
threadId: threadId
|
|
2631
|
+
} : conversationId, {
|
|
2632
|
+
enabled: !isAssistant || isVisible
|
|
2633
|
+
}),
|
|
1531
2634
|
_useFetchRuns$data = _useFetchRuns.data,
|
|
1532
2635
|
_useFetchRuns$data2 = _useFetchRuns$data === void 0 ? {} : _useFetchRuns$data,
|
|
1533
2636
|
_useFetchRuns$data2$r = _useFetchRuns$data2.runs,
|
|
@@ -1536,12 +2639,18 @@ var Conversation = function Conversation(_ref3) {
|
|
|
1536
2639
|
credits = _useFetchRuns$data2$c === void 0 ? null : _useFetchRuns$data2$c,
|
|
1537
2640
|
_useFetchRuns$data2$c2 = _useFetchRuns$data2.commands,
|
|
1538
2641
|
commands = _useFetchRuns$data2$c2 === void 0 ? [] : _useFetchRuns$data2$c2,
|
|
2642
|
+
_useFetchRuns$data2$c3 = _useFetchRuns$data2.canStop,
|
|
2643
|
+
canStop = _useFetchRuns$data2$c3 === void 0 ? false : _useFetchRuns$data2$c3,
|
|
1539
2644
|
error = _useFetchRuns.error,
|
|
1540
2645
|
isLoading = _useFetchRuns.isLoading;
|
|
1541
2646
|
var newestRun = runs[0];
|
|
1542
2647
|
var newestRunLookups = newestRun ? stepsOf(newestRun).length : 0;
|
|
1543
2648
|
var isNewestRunPending = !!newestRun && isPending(newestRun);
|
|
1544
2649
|
var draftId = latestDraftId(runs);
|
|
2650
|
+
// Only an engine that says it can stop an ask gets a stop button, and only
|
|
2651
|
+
// then does the box wait for the ask to end. With an older one the box is
|
|
2652
|
+
// what it always was.
|
|
2653
|
+
var pendingAsk = canStop ? stoppableAsk(runs) : null;
|
|
1545
2654
|
|
|
1546
2655
|
// While NeetoAssist works, each lookup adds a line at the end, and the window
|
|
1547
2656
|
// stays on the end: from the top of a long question or a long list of
|
|
@@ -1565,31 +2674,86 @@ var Conversation = function Conversation(_ref3) {
|
|
|
1565
2674
|
children: [/*#__PURE__*/jsxs("div", {
|
|
1566
2675
|
className: "flex w-full flex-1 flex-col gap-6 overflow-y-auto px-4 py-4",
|
|
1567
2676
|
ref: listRef,
|
|
1568
|
-
children: [isLoading && /*#__PURE__*/jsx(Spinner, {}), !isLoading && !error && isEmpty(runs) && /*#__PURE__*/jsx(EmptyState, {
|
|
2677
|
+
children: [isLoading && /*#__PURE__*/jsx(Spinner, {}), !isLoading && !error && isEmpty(runs) && (emptyState !== null && emptyState !== void 0 ? emptyState : /*#__PURE__*/jsx(EmptyState, {
|
|
1569
2678
|
conversationId: conversationId
|
|
1570
|
-
}), runsInConversationOrder(runs).map(function (run) {
|
|
2679
|
+
})), runsInConversationOrder(runs).map(function (run) {
|
|
1571
2680
|
return /*#__PURE__*/createElement(Run, {
|
|
1572
2681
|
conversationId: conversationId,
|
|
1573
2682
|
onActionApplied: onActionApplied,
|
|
1574
2683
|
onUseReply: onUseReply,
|
|
1575
2684
|
run: run,
|
|
2685
|
+
threadId: threadId,
|
|
1576
2686
|
key: run.id
|
|
1577
2687
|
});
|
|
1578
2688
|
}), error && /*#__PURE__*/jsx(ErrorMessage, {
|
|
1579
|
-
error: error
|
|
2689
|
+
error: error,
|
|
2690
|
+
isAssistant: isAssistant
|
|
1580
2691
|
})]
|
|
1581
|
-
}), credits !== null && credits !== void 0 && credits.exhausted ? /*#__PURE__*/jsx(CreditsBanner, {
|
|
2692
|
+
}), credits !== null && credits !== void 0 && credits.exhausted && !pendingAsk ? /*#__PURE__*/jsx(CreditsBanner, {
|
|
1582
2693
|
credits: credits
|
|
1583
2694
|
}) : /*#__PURE__*/jsx(MessageInput, {
|
|
1584
2695
|
commands: commands,
|
|
1585
|
-
conversationId: conversationId
|
|
2696
|
+
conversationId: conversationId,
|
|
2697
|
+
focusRequest: focusRequest,
|
|
2698
|
+
isAskDisabled: isAskDisabled,
|
|
2699
|
+
pendingAsk: pendingAsk,
|
|
2700
|
+
threadId: threadId
|
|
2701
|
+
})]
|
|
2702
|
+
});
|
|
2703
|
+
};
|
|
2704
|
+
|
|
2705
|
+
var Thread = function Thread(_ref) {
|
|
2706
|
+
var focusRequest = _ref.focusRequest,
|
|
2707
|
+
_ref$isStarting = _ref.isStarting,
|
|
2708
|
+
isStarting = _ref$isStarting === void 0 ? false : _ref$isStarting,
|
|
2709
|
+
isVisible = _ref.isVisible,
|
|
2710
|
+
onAsk = _ref.onAsk,
|
|
2711
|
+
renderHeader = _ref.renderHeader,
|
|
2712
|
+
suggestions = _ref.suggestions,
|
|
2713
|
+
threadId = _ref.threadId;
|
|
2714
|
+
var _useFetchRuns = useFetchRuns({
|
|
2715
|
+
threadId: threadId
|
|
2716
|
+
}, {
|
|
2717
|
+
enabled: isVisible
|
|
2718
|
+
}),
|
|
2719
|
+
_useFetchRuns$data = _useFetchRuns.data,
|
|
2720
|
+
_useFetchRuns$data2 = _useFetchRuns$data === void 0 ? {} : _useFetchRuns$data,
|
|
2721
|
+
_useFetchRuns$data2$r = _useFetchRuns$data2.runs,
|
|
2722
|
+
runs = _useFetchRuns$data2$r === void 0 ? [] : _useFetchRuns$data2$r,
|
|
2723
|
+
isLoading = _useFetchRuns.isLoading;
|
|
2724
|
+
var isAsking = useIsAsking({
|
|
2725
|
+
threadId: threadId
|
|
2726
|
+
});
|
|
2727
|
+
var isRunPending = isLoading || isAsking || hasPendingRun(runs);
|
|
2728
|
+
// The box and suggestions wait for the same question, and neither can ask
|
|
2729
|
+
// on the old thread while New chat is making its replacement.
|
|
2730
|
+
var isAskDisabled = isStarting || isRunPending;
|
|
2731
|
+
return /*#__PURE__*/jsxs(Fragment$1, {
|
|
2732
|
+
children: [renderHeader({
|
|
2733
|
+
isRunPending: isRunPending
|
|
2734
|
+
}), /*#__PURE__*/jsx(Conversation, {
|
|
2735
|
+
focusRequest: focusRequest,
|
|
2736
|
+
isAskDisabled: isAskDisabled,
|
|
2737
|
+
isVisible: isVisible,
|
|
2738
|
+
threadId: threadId,
|
|
2739
|
+
emptyState: /*#__PURE__*/jsx(EmptyState$1, {
|
|
2740
|
+
isAskDisabled: isAskDisabled,
|
|
2741
|
+
onAsk: onAsk,
|
|
2742
|
+
suggestions: suggestions,
|
|
2743
|
+
threadId: threadId
|
|
2744
|
+
})
|
|
1586
2745
|
})]
|
|
1587
2746
|
});
|
|
1588
2747
|
};
|
|
1589
2748
|
|
|
1590
2749
|
var Header$1 = function Header(_ref) {
|
|
1591
|
-
var
|
|
2750
|
+
var _ref$betaNoteKey = _ref.betaNoteKey,
|
|
2751
|
+
betaNoteKey = _ref$betaNoteKey === void 0 ? "neetoAssist.betaNote" : _ref$betaNoteKey,
|
|
2752
|
+
isExpanded = _ref.isExpanded,
|
|
2753
|
+
_ref$isNewChatDisable = _ref.isNewChatDisabled,
|
|
2754
|
+
isNewChatDisabled = _ref$isNewChatDisable === void 0 ? false : _ref$isNewChatDisable,
|
|
1592
2755
|
onClose = _ref.onClose,
|
|
2756
|
+
onNewChat = _ref.onNewChat,
|
|
1593
2757
|
onToggleExpand = _ref.onToggleExpand,
|
|
1594
2758
|
t = _ref.t;
|
|
1595
2759
|
return /*#__PURE__*/jsxs("div", {
|
|
@@ -1603,7 +2767,7 @@ var Header$1 = function Header(_ref) {
|
|
|
1603
2767
|
className: "font-semibold",
|
|
1604
2768
|
children: t("neetoAssist.title")
|
|
1605
2769
|
}), /*#__PURE__*/jsx(Tooltip, {
|
|
1606
|
-
content: t(
|
|
2770
|
+
content: t(betaNoteKey),
|
|
1607
2771
|
position: "bottom",
|
|
1608
2772
|
children: /*#__PURE__*/jsx("span", {
|
|
1609
2773
|
children: /*#__PURE__*/jsx(Badge, {
|
|
@@ -1615,7 +2779,21 @@ var Header$1 = function Header(_ref) {
|
|
|
1615
2779
|
})]
|
|
1616
2780
|
}), /*#__PURE__*/jsxs("div", {
|
|
1617
2781
|
className: "text-muted-foreground flex items-center gap-1",
|
|
1618
|
-
children: [/*#__PURE__*/jsx(
|
|
2782
|
+
children: [onNewChat && /*#__PURE__*/jsx(Tooltip, {
|
|
2783
|
+
content: t("neetoAssist.assistant.newChat"),
|
|
2784
|
+
position: "bottom",
|
|
2785
|
+
children: /*#__PURE__*/jsx("button", {
|
|
2786
|
+
"aria-label": t("neetoAssist.assistant.newChat"),
|
|
2787
|
+
className: "hover:bg-muted rounded p-1 disabled:cursor-not-allowed disabled:opacity-50 disabled:hover:bg-transparent",
|
|
2788
|
+
"data-testid": "neeto-assist-new-chat-button",
|
|
2789
|
+
disabled: isNewChatDisabled,
|
|
2790
|
+
type: "button",
|
|
2791
|
+
onClick: onNewChat,
|
|
2792
|
+
children: /*#__PURE__*/jsx(SquarePen, {
|
|
2793
|
+
size: HEADER_ICON_SIZE
|
|
2794
|
+
})
|
|
2795
|
+
})
|
|
2796
|
+
}), /*#__PURE__*/jsx("button", {
|
|
1619
2797
|
className: "hover:bg-muted rounded p-1",
|
|
1620
2798
|
"data-testid": "neeto-assist-expand-button",
|
|
1621
2799
|
type: "button",
|
|
@@ -1641,6 +2819,113 @@ var Header$1 = function Header(_ref) {
|
|
|
1641
2819
|
};
|
|
1642
2820
|
var Header = withT(Header$1);
|
|
1643
2821
|
|
|
2822
|
+
var Assistant = function Assistant(_ref) {
|
|
2823
|
+
var isExpanded = _ref.isExpanded,
|
|
2824
|
+
isVisible = _ref.isVisible,
|
|
2825
|
+
onClose = _ref.onClose,
|
|
2826
|
+
onToggleExpand = _ref.onToggleExpand;
|
|
2827
|
+
var _useState = useState(0),
|
|
2828
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
2829
|
+
focusRequest = _useState2[0],
|
|
2830
|
+
setFocusRequest = _useState2[1];
|
|
2831
|
+
var requestFocus = function requestFocus() {
|
|
2832
|
+
return setFocusRequest(inc);
|
|
2833
|
+
};
|
|
2834
|
+
var _useFetchAssistantThr = useFetchAssistantThread(),
|
|
2835
|
+
_useFetchAssistantThr2 = _useFetchAssistantThr.data,
|
|
2836
|
+
_useFetchAssistantThr3 = _useFetchAssistantThr2 === void 0 ? {} : _useFetchAssistantThr2,
|
|
2837
|
+
_useFetchAssistantThr4 = _useFetchAssistantThr3.threadId,
|
|
2838
|
+
threadId = _useFetchAssistantThr4 === void 0 ? null : _useFetchAssistantThr4,
|
|
2839
|
+
_useFetchAssistantThr5 = _useFetchAssistantThr3.suggestions,
|
|
2840
|
+
suggestions = _useFetchAssistantThr5 === void 0 ? [] : _useFetchAssistantThr5,
|
|
2841
|
+
error = _useFetchAssistantThr.error,
|
|
2842
|
+
isFetching = _useFetchAssistantThr.isFetching,
|
|
2843
|
+
refetch = _useFetchAssistantThr.refetch;
|
|
2844
|
+
|
|
2845
|
+
// Only on opening: a load that fails again while the assistant is open waits
|
|
2846
|
+
// for the next time it is opened, or for New chat.
|
|
2847
|
+
useEffect(function () {
|
|
2848
|
+
if (isVisible && error) refetch({
|
|
2849
|
+
cancelRefetch: false
|
|
2850
|
+
});
|
|
2851
|
+
}, [isVisible]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
2852
|
+
|
|
2853
|
+
var _useStartAssistantThr = useStartAssistantThread(),
|
|
2854
|
+
startThread = _useStartAssistantThr.mutate,
|
|
2855
|
+
isStarting = _useStartAssistantThr.isPending,
|
|
2856
|
+
startError = _useStartAssistantThr.error;
|
|
2857
|
+
var header = function header(isRunPending) {
|
|
2858
|
+
return /*#__PURE__*/jsx(Header, {
|
|
2859
|
+
isExpanded: isExpanded,
|
|
2860
|
+
onClose: onClose,
|
|
2861
|
+
onToggleExpand: onToggleExpand,
|
|
2862
|
+
betaNoteKey: "neetoAssist.assistant.betaNote",
|
|
2863
|
+
isNewChatDisabled: isFetching || isStarting || isRunPending,
|
|
2864
|
+
onNewChat: function onNewChat() {
|
|
2865
|
+
return startThread(undefined, {
|
|
2866
|
+
onSuccess: requestFocus
|
|
2867
|
+
});
|
|
2868
|
+
}
|
|
2869
|
+
});
|
|
2870
|
+
};
|
|
2871
|
+
if (!threadId) {
|
|
2872
|
+
return /*#__PURE__*/jsxs(Fragment$1, {
|
|
2873
|
+
children: [header(false), /*#__PURE__*/jsx("div", {
|
|
2874
|
+
className: "flex flex-col gap-4 px-4 py-4",
|
|
2875
|
+
children: isFetching ? /*#__PURE__*/jsx(Spinner, {}) : /*#__PURE__*/jsx(ErrorMessage, {
|
|
2876
|
+
isAssistant: true,
|
|
2877
|
+
error: startError !== null && startError !== void 0 ? startError : error
|
|
2878
|
+
})
|
|
2879
|
+
})]
|
|
2880
|
+
});
|
|
2881
|
+
}
|
|
2882
|
+
|
|
2883
|
+
// A new chat that failed leaves the person on the thread they had, with a
|
|
2884
|
+
// line under the header that says so.
|
|
2885
|
+
var renderHeader = function renderHeader(_ref2) {
|
|
2886
|
+
var isRunPending = _ref2.isRunPending;
|
|
2887
|
+
return /*#__PURE__*/jsxs(Fragment$1, {
|
|
2888
|
+
children: [header(isRunPending), startError && /*#__PURE__*/jsx("div", {
|
|
2889
|
+
className: "px-4 pt-3",
|
|
2890
|
+
children: /*#__PURE__*/jsx(ErrorMessage, {
|
|
2891
|
+
isAssistant: true,
|
|
2892
|
+
error: startError
|
|
2893
|
+
})
|
|
2894
|
+
})]
|
|
2895
|
+
});
|
|
2896
|
+
};
|
|
2897
|
+
return /*#__PURE__*/createElement(Thread, {
|
|
2898
|
+
focusRequest: focusRequest,
|
|
2899
|
+
isStarting: isStarting,
|
|
2900
|
+
isVisible: isVisible,
|
|
2901
|
+
renderHeader: renderHeader,
|
|
2902
|
+
suggestions: suggestions,
|
|
2903
|
+
threadId: threadId,
|
|
2904
|
+
key: threadId,
|
|
2905
|
+
onAsk: requestFocus
|
|
2906
|
+
});
|
|
2907
|
+
};
|
|
2908
|
+
|
|
2909
|
+
var ContextLabel = function ContextLabel(_ref) {
|
|
2910
|
+
var label = _ref.label;
|
|
2911
|
+
var _useTranslation = useTranslation(),
|
|
2912
|
+
t = _useTranslation.t;
|
|
2913
|
+
var _t$split = t("neetoAssist.lookingAt", {
|
|
2914
|
+
label: CONTEXT_LABEL_SLOT
|
|
2915
|
+
}).split(CONTEXT_LABEL_SLOT),
|
|
2916
|
+
_t$split2 = _slicedToArray(_t$split, 2),
|
|
2917
|
+
before = _t$split2[0],
|
|
2918
|
+
after = _t$split2[1];
|
|
2919
|
+
return /*#__PURE__*/jsxs(Typography, {
|
|
2920
|
+
className: "border-border truncate border-b px-4 py-2",
|
|
2921
|
+
color: "muted",
|
|
2922
|
+
"data-testid": "neeto-assist-context-label",
|
|
2923
|
+
title: label,
|
|
2924
|
+
variant: "body3",
|
|
2925
|
+
children: [before, label, after]
|
|
2926
|
+
});
|
|
2927
|
+
};
|
|
2928
|
+
|
|
1644
2929
|
var Pane = function Pane(_ref) {
|
|
1645
2930
|
var children = _ref.children,
|
|
1646
2931
|
isExpanded = _ref.isExpanded,
|
|
@@ -1692,7 +2977,25 @@ var NeetoAssistPane = function NeetoAssistPane() {
|
|
|
1692
2977
|
var setExpanded = useNeetoAssistStore(function (state) {
|
|
1693
2978
|
return state.setExpanded;
|
|
1694
2979
|
});
|
|
1695
|
-
var
|
|
2980
|
+
var mode = useNeetoAssistStore(function (state) {
|
|
2981
|
+
return state.mode;
|
|
2982
|
+
});
|
|
2983
|
+
var isAssistant = mode === PANE_MODES.ASSISTANT;
|
|
2984
|
+
var isVisible = isOpen && (isAssistant || !!conversation);
|
|
2985
|
+
if (isAssistant) {
|
|
2986
|
+
return /*#__PURE__*/jsx(Pane, {
|
|
2987
|
+
isExpanded: isExpanded,
|
|
2988
|
+
isOpen: isVisible,
|
|
2989
|
+
children: /*#__PURE__*/jsx(Assistant, {
|
|
2990
|
+
isExpanded: isExpanded,
|
|
2991
|
+
isVisible: isVisible,
|
|
2992
|
+
onClose: close,
|
|
2993
|
+
onToggleExpand: function onToggleExpand() {
|
|
2994
|
+
return setExpanded(!isExpanded);
|
|
2995
|
+
}
|
|
2996
|
+
})
|
|
2997
|
+
});
|
|
2998
|
+
}
|
|
1696
2999
|
return /*#__PURE__*/jsx(Pane, {
|
|
1697
3000
|
isExpanded: isExpanded,
|
|
1698
3001
|
isOpen: isVisible,
|