@bigbinary/neeto-assist-frontend 1.1.0 → 1.2.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 +193 -41
- package/app/javascript/src/translations/ar.json +27 -4
- package/app/javascript/src/translations/bg.json +27 -4
- package/app/javascript/src/translations/ca.json +27 -4
- package/app/javascript/src/translations/cs.json +27 -4
- package/app/javascript/src/translations/da.json +27 -4
- package/app/javascript/src/translations/de.json +27 -4
- package/app/javascript/src/translations/en.json +6 -0
- package/app/javascript/src/translations/es-MX.json +27 -4
- package/app/javascript/src/translations/es.json +27 -4
- package/app/javascript/src/translations/et.json +27 -4
- package/app/javascript/src/translations/fi.json +27 -4
- package/app/javascript/src/translations/fil.json +27 -4
- package/app/javascript/src/translations/fr.json +27 -4
- package/app/javascript/src/translations/he.json +27 -4
- package/app/javascript/src/translations/hi.json +27 -4
- package/app/javascript/src/translations/hr.json +27 -4
- package/app/javascript/src/translations/hu.json +27 -4
- package/app/javascript/src/translations/id.json +27 -4
- package/app/javascript/src/translations/it.json +27 -4
- package/app/javascript/src/translations/ja.json +27 -4
- package/app/javascript/src/translations/ko.json +27 -4
- package/app/javascript/src/translations/lv.json +27 -4
- package/app/javascript/src/translations/nl.json +27 -4
- package/app/javascript/src/translations/pl.json +27 -4
- package/app/javascript/src/translations/pt-BR.json +27 -4
- package/app/javascript/src/translations/pt.json +27 -4
- package/app/javascript/src/translations/ro.json +27 -4
- package/app/javascript/src/translations/ru.json +27 -4
- package/app/javascript/src/translations/sk.json +27 -4
- package/app/javascript/src/translations/sl.json +27 -4
- package/app/javascript/src/translations/sv.json +27 -4
- package/app/javascript/src/translations/th.json +27 -4
- package/app/javascript/src/translations/tr.json +27 -4
- package/app/javascript/src/translations/uk.json +27 -4
- package/app/javascript/src/translations/vi.json +27 -4
- package/app/javascript/src/translations/zh-CN.json +27 -4
- package/app/javascript/src/translations/zh-TW.json +27 -4
- package/dist/.ready +1 -1
- package/dist/NeetoAssistButton.js +3 -1
- package/dist/NeetoAssistButton.js.map +1 -1
- package/dist/NeetoAssistPane.js +586 -329
- package/dist/NeetoAssistPane.js.map +1 -1
- package/dist/cjs/NeetoAssistButton.js +3 -1
- package/dist/cjs/NeetoAssistButton.js.map +1 -1
- package/dist/cjs/NeetoAssistPane.js +575 -318
- package/dist/cjs/NeetoAssistPane.js.map +1 -1
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/{useNeetoAssistStore--JwP_Upt.js → useNeetoAssistStore-InICsbe8.js} +89 -6
- package/dist/useNeetoAssistStore-InICsbe8.js.map +1 -0
- package/dist/{useNeetoAssistStore-CGEUMbes.js → useNeetoAssistStore-VaZp3268.js} +91 -4
- package/dist/useNeetoAssistStore-VaZp3268.js.map +1 -0
- package/package.json +1 -1
- package/types.d.ts +31 -6
- package/dist/useNeetoAssistStore--JwP_Upt.js.map +0 -1
- package/dist/useNeetoAssistStore-CGEUMbes.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var useNeetoAssistStore = require('../useNeetoAssistStore-
|
|
3
|
+
var useNeetoAssistStore = require('../useNeetoAssistStore-VaZp3268.js');
|
|
4
4
|
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
5
5
|
var neetoAtoms = require('@bigbinary/neeto-atoms');
|
|
6
6
|
var reactI18next = require('react-i18next');
|
|
@@ -10,12 +10,14 @@ var ramda = require('ramda');
|
|
|
10
10
|
var neeto_assist = require('../neeto_assist-CznTN_YY.js');
|
|
11
11
|
var reactUtils = require('@bigbinary/neeto-commons-frontend/v2/react-utils');
|
|
12
12
|
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
13
|
-
var
|
|
13
|
+
var classnames = require('classnames');
|
|
14
14
|
var lucideReact = require('lucide-react');
|
|
15
15
|
var neetoCist = require('@bigbinary/neeto-cist');
|
|
16
16
|
var utils = require('@bigbinary/neeto-commons-frontend/v2/utils');
|
|
17
17
|
require('@babel/runtime/helpers/objectWithoutProperties');
|
|
18
18
|
require('@tanstack/react-query');
|
|
19
|
+
require('@babel/runtime/helpers/toConsumableArray');
|
|
20
|
+
require('@babel/runtime/helpers/toArray');
|
|
19
21
|
require('zustand');
|
|
20
22
|
require('axios');
|
|
21
23
|
|
|
@@ -157,23 +159,141 @@ var EmptyState = function EmptyState(_ref) {
|
|
|
157
159
|
});
|
|
158
160
|
};
|
|
159
161
|
|
|
162
|
+
var CommandMenu = function CommandMenu(_ref) {
|
|
163
|
+
var _commands$at;
|
|
164
|
+
var commands = _ref.commands,
|
|
165
|
+
id = _ref.id,
|
|
166
|
+
markedIndex = _ref.markedIndex,
|
|
167
|
+
onMark = _ref.onMark,
|
|
168
|
+
onPick = _ref.onPick;
|
|
169
|
+
var _useTranslation = reactI18next.useTranslation(),
|
|
170
|
+
t = _useTranslation.t;
|
|
171
|
+
var markedRef = react.useRef(null);
|
|
172
|
+
var marked = (_commands$at = commands.at(markedIndex)) === null || _commands$at === void 0 ? void 0 : _commands$at.name;
|
|
173
|
+
|
|
174
|
+
// A long menu scrolls, and the marked row has to stay in view.
|
|
175
|
+
react.useEffect(function () {
|
|
176
|
+
var _markedRef$current, _markedRef$current$sc;
|
|
177
|
+
(_markedRef$current = markedRef.current) === null || _markedRef$current === void 0 || (_markedRef$current$sc = _markedRef$current.scrollIntoView) === null || _markedRef$current$sc === void 0 || _markedRef$current$sc.call(_markedRef$current, {
|
|
178
|
+
block: "nearest"
|
|
179
|
+
});
|
|
180
|
+
}, [marked]);
|
|
181
|
+
return /*#__PURE__*/jsxRuntime.jsx("ul", {
|
|
182
|
+
id: id,
|
|
183
|
+
"aria-label": t("neetoAssist.commands.label"),
|
|
184
|
+
className: "border-border bg-popover absolute start-0 end-0 bottom-full z-10 mb-1 max-h-60 overflow-y-auto rounded-lg border p-1 shadow-md",
|
|
185
|
+
"data-testid": "neeto-assist-command-menu",
|
|
186
|
+
role: "listbox",
|
|
187
|
+
onMouseDown: function onMouseDown(event) {
|
|
188
|
+
return event.preventDefault();
|
|
189
|
+
},
|
|
190
|
+
children: commands.map(function (command, index) {
|
|
191
|
+
return /*#__PURE__*/jsxRuntime.jsxs("li", {
|
|
192
|
+
"aria-selected": index === markedIndex,
|
|
193
|
+
"data-command": command.name,
|
|
194
|
+
"data-testid": "neeto-assist-command-option",
|
|
195
|
+
id: useNeetoAssistStore.optionId(id, command),
|
|
196
|
+
ref: index === markedIndex ? markedRef : undefined,
|
|
197
|
+
role: "option",
|
|
198
|
+
className: classnames("cursor-pointer rounded px-2 py-1.5", {
|
|
199
|
+
"bg-muted": index === markedIndex
|
|
200
|
+
}),
|
|
201
|
+
onClick: function onClick() {
|
|
202
|
+
return onPick(command);
|
|
203
|
+
},
|
|
204
|
+
onMouseMove: function onMouseMove() {
|
|
205
|
+
return onMark(index);
|
|
206
|
+
},
|
|
207
|
+
children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
208
|
+
className: "flex items-baseline gap-2",
|
|
209
|
+
children: [/*#__PURE__*/jsxRuntime.jsxs("span", {
|
|
210
|
+
className: "shrink-0 font-mono text-sm font-medium",
|
|
211
|
+
children: ["/", command.name]
|
|
212
|
+
}), /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
213
|
+
className: "min-w-0 text-sm break-words",
|
|
214
|
+
children: command.title
|
|
215
|
+
})]
|
|
216
|
+
}), /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
217
|
+
className: "text-muted-foreground text-xs break-words",
|
|
218
|
+
children: command.description
|
|
219
|
+
})]
|
|
220
|
+
}, command.name);
|
|
221
|
+
})
|
|
222
|
+
});
|
|
223
|
+
};
|
|
224
|
+
|
|
160
225
|
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; }
|
|
161
226
|
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; }
|
|
162
227
|
var MessageInput = function MessageInput(_ref) {
|
|
163
|
-
var
|
|
228
|
+
var _menu$at$name, _menu$at;
|
|
229
|
+
var _ref$commands = _ref.commands,
|
|
230
|
+
commands = _ref$commands === void 0 ? [] : _ref$commands,
|
|
231
|
+
conversationId = _ref.conversationId;
|
|
164
232
|
var _useTranslation = reactI18next.useTranslation(),
|
|
165
233
|
t = _useTranslation.t;
|
|
234
|
+
var menuId = react.useId();
|
|
166
235
|
var _useState = react.useState(""),
|
|
167
236
|
_useState2 = _slicedToArray(_useState, 2),
|
|
168
237
|
question = _useState2[0],
|
|
169
238
|
setQuestion = _useState2[1];
|
|
239
|
+
var _useState3 = react.useState(null),
|
|
240
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
241
|
+
markedName = _useState4[0],
|
|
242
|
+
setMarkedName = _useState4[1];
|
|
243
|
+
var _useState5 = react.useState(false),
|
|
244
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
245
|
+
isMenuClosed = _useState6[0],
|
|
246
|
+
setIsMenuClosed = _useState6[1];
|
|
170
247
|
var requestRef = react.useRef(null);
|
|
248
|
+
var boxRef = react.useRef(null);
|
|
249
|
+
var caretRef = react.useRef(null);
|
|
171
250
|
var _useAskNeetoAssist = useNeetoAssistStore.useAskNeetoAssist(conversationId),
|
|
172
251
|
ask = _useAskNeetoAssist.mutate,
|
|
173
252
|
isPending = _useAskNeetoAssist.isPending,
|
|
174
253
|
error = _useAskNeetoAssist.error;
|
|
175
254
|
var trimmedQuestion = question.trim();
|
|
176
255
|
var canSend = !!trimmedQuestion && !isPending;
|
|
256
|
+
var menu = useNeetoAssistStore.matchingCommands(question, commands);
|
|
257
|
+
var isMenuOpen = !isPending && !isMenuClosed && !ramda.isEmpty(menu);
|
|
258
|
+
var marked = Math.max(0, neetoCist.findIndexBy({
|
|
259
|
+
name: markedName
|
|
260
|
+
}, menu));
|
|
261
|
+
var markedCommand = (_menu$at$name = (_menu$at = menu.at(marked)) === null || _menu$at === void 0 ? void 0 : _menu$at.name) !== null && _menu$at$name !== void 0 ? _menu$at$name : null;
|
|
262
|
+
// The line that says so is only for an empty box: a command starts the text.
|
|
263
|
+
// A screen reader reads it with the box.
|
|
264
|
+
var isHintShown = !ramda.isEmpty(commands) && ramda.isEmpty(question);
|
|
265
|
+
var hintId = "".concat(menuId, "-hint");
|
|
266
|
+
// The box cuts the white space at the ends of its text when it loses the
|
|
267
|
+
// keyboard. Where there are commands it must not: the space after a picked
|
|
268
|
+
// command would go, and the rep's next words would run into it.
|
|
269
|
+
var keepsEnds = !ramda.isEmpty(commands);
|
|
270
|
+
|
|
271
|
+
// A refetch may move a row. Keep the command under the mark, or the first
|
|
272
|
+
// one if it went away, even if the old command comes back in a later poll.
|
|
273
|
+
react.useLayoutEffect(function () {
|
|
274
|
+
if (markedName !== markedCommand) setMarkedName(markedCommand);
|
|
275
|
+
}, [markedCommand, markedName]);
|
|
276
|
+
|
|
277
|
+
// A picked command leaves the cursor right after it, in a box that still has
|
|
278
|
+
// the keyboard, once the box holds the new text.
|
|
279
|
+
react.useLayoutEffect(function () {
|
|
280
|
+
var _boxRef$current, _boxRef$current2;
|
|
281
|
+
if (caretRef.current === null) return;
|
|
282
|
+
(_boxRef$current = boxRef.current) === null || _boxRef$current === void 0 || _boxRef$current.focus();
|
|
283
|
+
(_boxRef$current2 = boxRef.current) === null || _boxRef$current2 === void 0 || _boxRef$current2.setSelectionRange(caretRef.current, caretRef.current);
|
|
284
|
+
caretRef.current = null;
|
|
285
|
+
}, [question]);
|
|
286
|
+
var handleChange = function handleChange(event) {
|
|
287
|
+
setQuestion(event.target.value);
|
|
288
|
+
setMarkedName(null);
|
|
289
|
+
setIsMenuClosed(false);
|
|
290
|
+
};
|
|
291
|
+
var pick = function pick(command) {
|
|
292
|
+
var picked = useNeetoAssistStore.pickedCommand(command);
|
|
293
|
+
caretRef.current = picked.length;
|
|
294
|
+
setQuestion(picked);
|
|
295
|
+
setMarkedName(null);
|
|
296
|
+
};
|
|
177
297
|
var handleSubmit = function handleSubmit(event) {
|
|
178
298
|
var _requestRef$current;
|
|
179
299
|
event.preventDefault();
|
|
@@ -197,31 +317,69 @@ var MessageInput = function MessageInput(_ref) {
|
|
|
197
317
|
});
|
|
198
318
|
};
|
|
199
319
|
|
|
320
|
+
// While the menu is open its keys belong to it: the arrows move the mark,
|
|
321
|
+
// Enter or Tab picks the marked command, and Escape closes the menu. Says
|
|
322
|
+
// whether the key was one of them.
|
|
323
|
+
var handleMenuKey = function handleMenuKey(event) {
|
|
324
|
+
var key = event.key,
|
|
325
|
+
shiftKey = event.shiftKey;
|
|
326
|
+
var isPick = (key === "Enter" || key === "Tab") && !shiftKey;
|
|
327
|
+
if (key === "ArrowDown") {
|
|
328
|
+
setMarkedName(menu.at((marked + 1) % menu.length).name);
|
|
329
|
+
} else if (key === "ArrowUp") {
|
|
330
|
+
setMarkedName(menu.at((marked - 1 + menu.length) % menu.length).name);
|
|
331
|
+
} else if (key === "Escape") setIsMenuClosed(true);else if (isPick) pick(menu.at(marked));else return false;
|
|
332
|
+
event.preventDefault();
|
|
333
|
+
// Escape only closes the menu here, whatever else the page does with it.
|
|
334
|
+
if (key === "Escape") event.stopPropagation();
|
|
335
|
+
return true;
|
|
336
|
+
};
|
|
337
|
+
|
|
200
338
|
// Enter also confirms a word in an input method for languages such as Japanese,
|
|
201
|
-
// and that must
|
|
339
|
+
// and that must neither pick a command nor send the question.
|
|
202
340
|
var handleKeyDown = function handleKeyDown(event) {
|
|
203
341
|
var _event$nativeEvent;
|
|
204
|
-
|
|
205
|
-
if (
|
|
206
|
-
|
|
207
|
-
}
|
|
342
|
+
if ((_event$nativeEvent = event.nativeEvent) !== null && _event$nativeEvent !== void 0 && _event$nativeEvent.isComposing) return;
|
|
343
|
+
if (isMenuOpen && handleMenuKey(event)) return;
|
|
344
|
+
if (event.key === "Enter" && !event.shiftKey) handleSubmit(event);
|
|
208
345
|
};
|
|
209
346
|
return /*#__PURE__*/jsxRuntime.jsxs("form", {
|
|
210
347
|
className: "border-border flex w-full flex-col gap-2 border-t px-4 py-3",
|
|
211
348
|
onSubmit: handleSubmit,
|
|
212
349
|
children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
213
350
|
className: "relative",
|
|
214
|
-
children: [/*#__PURE__*/jsxRuntime.jsx(
|
|
351
|
+
children: [isMenuOpen && /*#__PURE__*/jsxRuntime.jsx(CommandMenu, {
|
|
352
|
+
commands: menu,
|
|
353
|
+
id: menuId,
|
|
354
|
+
markedIndex: marked,
|
|
355
|
+
onMark: function onMark(index) {
|
|
356
|
+
return setMarkedName(menu.at(index).name);
|
|
357
|
+
},
|
|
358
|
+
onPick: pick
|
|
359
|
+
}), /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Textarea, {
|
|
360
|
+
"aria-autocomplete": ramda.isEmpty(commands) ? undefined : "list",
|
|
361
|
+
"aria-controls": isMenuOpen ? menuId : undefined,
|
|
362
|
+
"aria-describedby": isHintShown ? hintId : undefined,
|
|
363
|
+
"aria-expanded": ramda.isEmpty(commands) ? undefined : isMenuOpen,
|
|
364
|
+
"aria-haspopup": ramda.isEmpty(commands) ? undefined : "listbox",
|
|
215
365
|
"aria-label": t("neetoAssist.ask.placeholder"),
|
|
216
366
|
className: "w-full pe-12",
|
|
217
367
|
dataTestId: "neeto-assist-ask",
|
|
368
|
+
disableTrimOnBlur: keepsEnds,
|
|
218
369
|
maxLength: neeto_assist.MAX_QUESTION_LENGTH,
|
|
219
370
|
placeholder: t("neetoAssist.ask.placeholder"),
|
|
220
371
|
readOnly: isPending,
|
|
372
|
+
ref: boxRef,
|
|
373
|
+
role: ramda.isEmpty(commands) ? undefined : "combobox",
|
|
221
374
|
rows: 3,
|
|
222
375
|
value: question,
|
|
223
|
-
|
|
224
|
-
|
|
376
|
+
"aria-activedescendant": isMenuOpen ? useNeetoAssistStore.optionId(menuId, menu.at(marked)) : undefined,
|
|
377
|
+
onBlur: function onBlur() {
|
|
378
|
+
return setIsMenuClosed(true);
|
|
379
|
+
},
|
|
380
|
+
onChange: handleChange,
|
|
381
|
+
onFocus: function onFocus() {
|
|
382
|
+
return setIsMenuClosed(false);
|
|
225
383
|
},
|
|
226
384
|
onKeyDown: handleKeyDown
|
|
227
385
|
}), /*#__PURE__*/jsxRuntime.jsx("button", {
|
|
@@ -229,7 +387,7 @@ var MessageInput = function MessageInput(_ref) {
|
|
|
229
387
|
"data-testid": "neeto-assist-ask-button",
|
|
230
388
|
disabled: !canSend,
|
|
231
389
|
type: "submit",
|
|
232
|
-
className:
|
|
390
|
+
className: classnames("absolute end-2 bottom-2 flex h-7 w-7 items-center justify-center rounded-full transition-opacity", {
|
|
233
391
|
"text-primary hover:opacity-80": canSend,
|
|
234
392
|
"text-muted-foreground cursor-not-allowed opacity-60": !canSend
|
|
235
393
|
}),
|
|
@@ -247,7 +405,12 @@ var MessageInput = function MessageInput(_ref) {
|
|
|
247
405
|
color: "muted",
|
|
248
406
|
variant: "body3",
|
|
249
407
|
children: t("neetoAssist.shadowNote")
|
|
250
|
-
}), /*#__PURE__*/jsxRuntime.
|
|
408
|
+
}), isHintShown ? /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
409
|
+
className: "text-muted-foreground shrink-0 text-xs",
|
|
410
|
+
"data-testid": "neeto-assist-command-hint",
|
|
411
|
+
id: hintId,
|
|
412
|
+
children: t("neetoAssist.commands.hint")
|
|
413
|
+
}) : /*#__PURE__*/jsxRuntime.jsxs("span", {
|
|
251
414
|
className: "text-muted-foreground shrink-0 text-xs",
|
|
252
415
|
children: [question.length, "/", neeto_assist.MAX_QUESTION_LENGTH]
|
|
253
416
|
})]
|
|
@@ -296,6 +459,16 @@ var shownAction = function shownAction(action, answer) {
|
|
|
296
459
|
return answered && isSettled(answered) ? _objectSpread$2(_objectSpread$2({}, action), answered) : action;
|
|
297
460
|
};
|
|
298
461
|
|
|
462
|
+
// The long text an action will save or send, while it is suggested or being
|
|
463
|
+
// applied. A finished card shows only its result, even if an earlier answer
|
|
464
|
+
// still carries the text. A card from an older NeetoAssist may have none.
|
|
465
|
+
var contentOf = function contentOf(_ref4) {
|
|
466
|
+
var content = _ref4.content,
|
|
467
|
+
status = _ref4.status;
|
|
468
|
+
if (!["suggested", "applying"].includes(status)) return null;
|
|
469
|
+
return typeof content === "string" && content.trim() !== "" ? content : null;
|
|
470
|
+
};
|
|
471
|
+
|
|
299
472
|
// The words under the buttons after a click that changed nothing. A 409 has
|
|
300
473
|
// none: the action changed while the card was on screen, and the runs fetched
|
|
301
474
|
// after the click show what became of it. Nor has a 422 on Apply, which the
|
|
@@ -311,264 +484,6 @@ var answerErrorMessageKey = function answerErrorMessageKey(answer) {
|
|
|
311
484
|
return ramda.propOr(useNeetoAssistStore.errorMessageKey(error), status, neeto_assist.ACTION_ERROR_MESSAGE_KEYS);
|
|
312
485
|
};
|
|
313
486
|
|
|
314
|
-
var Outcome = function Outcome(_ref) {
|
|
315
|
-
var _ref$action = _ref.action,
|
|
316
|
-
status = _ref$action.status,
|
|
317
|
-
result = _ref$action.result,
|
|
318
|
-
error = _ref$action.error,
|
|
319
|
-
actedBy = _ref$action.actedBy,
|
|
320
|
-
errorMessageKey = _ref.errorMessageKey,
|
|
321
|
-
isApplying = _ref.isApplying,
|
|
322
|
-
isDismissing = _ref.isDismissing,
|
|
323
|
-
onApply = _ref.onApply,
|
|
324
|
-
onDismiss = _ref.onDismiss;
|
|
325
|
-
var _useTranslation = reactI18next.useTranslation(),
|
|
326
|
-
t = _useTranslation.t;
|
|
327
|
-
if (status === "suggested") {
|
|
328
|
-
return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
329
|
-
children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
330
|
-
className: "flex flex-wrap gap-2",
|
|
331
|
-
children: [/*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Button, {
|
|
332
|
-
"data-testid": "neeto-assist-action-apply-button",
|
|
333
|
-
disabled: isApplying || isDismissing,
|
|
334
|
-
label: t("neetoAssist.actions.apply"),
|
|
335
|
-
loading: isApplying,
|
|
336
|
-
size: "sm",
|
|
337
|
-
onClick: onApply
|
|
338
|
-
}), /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Button, {
|
|
339
|
-
"data-testid": "neeto-assist-action-dismiss-button",
|
|
340
|
-
disabled: isApplying || isDismissing,
|
|
341
|
-
label: t("neetoAssist.actions.dismiss"),
|
|
342
|
-
loading: isDismissing,
|
|
343
|
-
size: "sm",
|
|
344
|
-
variant: "ghost",
|
|
345
|
-
onClick: onDismiss
|
|
346
|
-
})]
|
|
347
|
-
}), errorMessageKey && /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Typography, {
|
|
348
|
-
color: "destructive",
|
|
349
|
-
"data-testid": "neeto-assist-action-error",
|
|
350
|
-
variant: "body3",
|
|
351
|
-
children: t(errorMessageKey)
|
|
352
|
-
})]
|
|
353
|
-
});
|
|
354
|
-
}
|
|
355
|
-
if (status === "applying") {
|
|
356
|
-
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
357
|
-
className: "flex items-center gap-1.5",
|
|
358
|
-
children: [/*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Spinner, {
|
|
359
|
-
size: "sm"
|
|
360
|
-
}), /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Typography, {
|
|
361
|
-
color: "muted",
|
|
362
|
-
variant: "body3",
|
|
363
|
-
children: t("neetoAssist.actions.applying")
|
|
364
|
-
})]
|
|
365
|
-
});
|
|
366
|
-
}
|
|
367
|
-
if (status === "applied") {
|
|
368
|
-
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
369
|
-
className: "flex items-start gap-1.5",
|
|
370
|
-
children: [/*#__PURE__*/jsxRuntime.jsx(lucideReact.Check, {
|
|
371
|
-
className: "text-success-foreground mt-1 shrink-0",
|
|
372
|
-
size: STATUS_ICON_SIZE
|
|
373
|
-
}), /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
374
|
-
className: "min-w-0",
|
|
375
|
-
children: [/*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Typography, {
|
|
376
|
-
variant: "body3",
|
|
377
|
-
children: result || t("neetoAssist.actions.applied")
|
|
378
|
-
}), (actedBy === null || actedBy === void 0 ? void 0 : actedBy.name) && /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Typography, {
|
|
379
|
-
color: "muted",
|
|
380
|
-
variant: "body3",
|
|
381
|
-
children: t("neetoAssist.actions.by", {
|
|
382
|
-
name: actedBy.name
|
|
383
|
-
})
|
|
384
|
-
})]
|
|
385
|
-
})]
|
|
386
|
-
});
|
|
387
|
-
}
|
|
388
|
-
if (status === "failed") {
|
|
389
|
-
return /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Typography, {
|
|
390
|
-
color: "destructive",
|
|
391
|
-
"data-testid": "neeto-assist-action-error",
|
|
392
|
-
variant: "body3",
|
|
393
|
-
children: error || t("neetoAssist.actions.failed")
|
|
394
|
-
});
|
|
395
|
-
}
|
|
396
|
-
return null;
|
|
397
|
-
};
|
|
398
|
-
|
|
399
|
-
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; }
|
|
400
|
-
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; }
|
|
401
|
-
var Card = function Card(_ref) {
|
|
402
|
-
var action = _ref.action,
|
|
403
|
-
conversationId = _ref.conversationId,
|
|
404
|
-
onActionApplied = _ref.onActionApplied;
|
|
405
|
-
var _useTranslation = reactI18next.useTranslation(),
|
|
406
|
-
t = _useTranslation.t;
|
|
407
|
-
var _useState = react.useState(null),
|
|
408
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
409
|
-
answer = _useState2[0],
|
|
410
|
-
setAnswer = _useState2[1];
|
|
411
|
-
var isActingRef = react.useRef(false);
|
|
412
|
-
|
|
413
|
-
// The host is told through the hook, which still hears the answer to a
|
|
414
|
-
// click when this card is gone by then.
|
|
415
|
-
var _useApplyAction = useNeetoAssistStore.useApplyAction(conversationId, function (applied) {
|
|
416
|
-
return onActionApplied === null || onActionApplied === void 0 ? void 0 : onActionApplied(_objectSpread$1(_objectSpread$1({}, action), applied));
|
|
417
|
-
}),
|
|
418
|
-
apply = _useApplyAction.mutate,
|
|
419
|
-
isApplying = _useApplyAction.isPending;
|
|
420
|
-
var _useDismissAction = useNeetoAssistStore.useDismissAction(conversationId),
|
|
421
|
-
dismiss = _useDismissAction.mutate,
|
|
422
|
-
isDismissing = _useDismissAction.isPending;
|
|
423
|
-
var shown = shownAction(action, answer);
|
|
424
|
-
var name = shown.name,
|
|
425
|
-
status = shown.status,
|
|
426
|
-
title = shown.title,
|
|
427
|
-
details = shown.details,
|
|
428
|
-
reason = shown.reason,
|
|
429
|
-
actedBy = shown.actedBy;
|
|
430
|
-
var quietStatusKey = ramda.prop(status, neeto_assist.QUIET_ACTION_STATUS_KEYS);
|
|
431
|
-
// Someone dismissed an action. Nobody expired one.
|
|
432
|
-
var dismissedBy = status === "dismissed" ? actedBy === null || actedBy === void 0 ? void 0 : actedBy.name : null;
|
|
433
|
-
|
|
434
|
-
// Two clicks can land before the buttons are seen as disabled, and the second
|
|
435
|
-
// must not ask the host to make the change again.
|
|
436
|
-
var act = function act(mutate, isApply) {
|
|
437
|
-
if (isActingRef.current) return;
|
|
438
|
-
isActingRef.current = true;
|
|
439
|
-
setAnswer(null);
|
|
440
|
-
mutate({
|
|
441
|
-
conversationId: conversationId,
|
|
442
|
-
actionId: action.id
|
|
443
|
-
}, {
|
|
444
|
-
onSettled: function onSettled(data, error) {
|
|
445
|
-
isActingRef.current = false;
|
|
446
|
-
setAnswer({
|
|
447
|
-
isApply: isApply,
|
|
448
|
-
data: data,
|
|
449
|
-
error: error
|
|
450
|
-
});
|
|
451
|
-
}
|
|
452
|
-
});
|
|
453
|
-
};
|
|
454
|
-
if (quietStatusKey) {
|
|
455
|
-
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
456
|
-
className: "border-border text-muted-foreground rounded-lg border px-3 py-2 text-sm",
|
|
457
|
-
"data-action-name": name,
|
|
458
|
-
"data-status": status,
|
|
459
|
-
"data-testid": "neeto-assist-action-card",
|
|
460
|
-
children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
461
|
-
className: "flex items-center justify-between gap-3",
|
|
462
|
-
children: [/*#__PURE__*/jsxRuntime.jsx("span", {
|
|
463
|
-
title: title,
|
|
464
|
-
className: "truncate",
|
|
465
|
-
children: title
|
|
466
|
-
}), /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
467
|
-
className: "shrink-0",
|
|
468
|
-
children: t(quietStatusKey)
|
|
469
|
-
})]
|
|
470
|
-
}), dismissedBy && /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
471
|
-
className: "text-end",
|
|
472
|
-
children: t("neetoAssist.actions.by", {
|
|
473
|
-
name: dismissedBy
|
|
474
|
-
})
|
|
475
|
-
})]
|
|
476
|
-
});
|
|
477
|
-
}
|
|
478
|
-
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
479
|
-
className: "border-border space-y-2 rounded-lg border p-3 break-words",
|
|
480
|
-
"data-action-name": name,
|
|
481
|
-
"data-status": status,
|
|
482
|
-
"data-testid": "neeto-assist-action-card",
|
|
483
|
-
children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
484
|
-
className: "space-y-1",
|
|
485
|
-
children: [/*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Typography, {
|
|
486
|
-
variant: "body2",
|
|
487
|
-
weight: "medium",
|
|
488
|
-
children: title
|
|
489
|
-
}), (details !== null && details !== void 0 ? details : []).map(function (detail, index) {
|
|
490
|
-
return /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Typography, {
|
|
491
|
-
className: "whitespace-pre-wrap",
|
|
492
|
-
variant: "body3",
|
|
493
|
-
children: detail
|
|
494
|
-
}, index);
|
|
495
|
-
}), reason && /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Typography, {
|
|
496
|
-
color: "muted",
|
|
497
|
-
variant: "body3",
|
|
498
|
-
children: reason
|
|
499
|
-
})]
|
|
500
|
-
}), /*#__PURE__*/jsxRuntime.jsx(Outcome, {
|
|
501
|
-
isApplying: isApplying,
|
|
502
|
-
isDismissing: isDismissing,
|
|
503
|
-
action: shown,
|
|
504
|
-
errorMessageKey: answerErrorMessageKey(answer),
|
|
505
|
-
onApply: function onApply() {
|
|
506
|
-
return act(apply, true);
|
|
507
|
-
},
|
|
508
|
-
onDismiss: function onDismiss() {
|
|
509
|
-
return act(dismiss, false);
|
|
510
|
-
}
|
|
511
|
-
})]
|
|
512
|
-
});
|
|
513
|
-
};
|
|
514
|
-
|
|
515
|
-
var Actions = function Actions(_ref) {
|
|
516
|
-
var actions = _ref.actions,
|
|
517
|
-
conversationId = _ref.conversationId,
|
|
518
|
-
onActionApplied = _ref.onActionApplied;
|
|
519
|
-
if (ramda.isEmpty(actions)) return null;
|
|
520
|
-
return /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
521
|
-
className: "flex flex-col gap-2",
|
|
522
|
-
children: actions.map(function (action) {
|
|
523
|
-
return /*#__PURE__*/react.createElement(Card, {
|
|
524
|
-
action: action,
|
|
525
|
-
conversationId: conversationId,
|
|
526
|
-
onActionApplied: onActionApplied,
|
|
527
|
-
key: action.id
|
|
528
|
-
});
|
|
529
|
-
})
|
|
530
|
-
});
|
|
531
|
-
};
|
|
532
|
-
|
|
533
|
-
var Sources = function Sources(_ref) {
|
|
534
|
-
var _ref$sources = _ref.sources,
|
|
535
|
-
sources = _ref$sources === void 0 ? [] : _ref$sources;
|
|
536
|
-
var _useTranslation = reactI18next.useTranslation(),
|
|
537
|
-
t = _useTranslation.t;
|
|
538
|
-
var links = sources.filter(function (_ref2) {
|
|
539
|
-
var url = _ref2.url;
|
|
540
|
-
return useNeetoAssistStore.isWebUrl(url);
|
|
541
|
-
});
|
|
542
|
-
if (!neetoCist.isNotEmpty(links)) return null;
|
|
543
|
-
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
544
|
-
className: "space-y-1",
|
|
545
|
-
children: [/*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Typography, {
|
|
546
|
-
color: "muted",
|
|
547
|
-
variant: "body3",
|
|
548
|
-
weight: "medium",
|
|
549
|
-
children: t("neetoAssist.run.sources")
|
|
550
|
-
}), /*#__PURE__*/jsxRuntime.jsx("ul", {
|
|
551
|
-
className: "space-y-1",
|
|
552
|
-
children: links.map(function (_ref3) {
|
|
553
|
-
var title = _ref3.title,
|
|
554
|
-
url = _ref3.url;
|
|
555
|
-
return /*#__PURE__*/jsxRuntime.jsx("li", {
|
|
556
|
-
children: /*#__PURE__*/jsxRuntime.jsxs("a", {
|
|
557
|
-
className: "text-primary inline-flex items-center gap-1 break-words text-sm hover:underline",
|
|
558
|
-
href: url,
|
|
559
|
-
rel: "noreferrer",
|
|
560
|
-
target: "_blank",
|
|
561
|
-
children: [/*#__PURE__*/jsxRuntime.jsx(lucideReact.ExternalLink, {
|
|
562
|
-
className: "shrink-0",
|
|
563
|
-
size: 12
|
|
564
|
-
}), title || url]
|
|
565
|
-
})
|
|
566
|
-
}, url);
|
|
567
|
-
})
|
|
568
|
-
})]
|
|
569
|
-
});
|
|
570
|
-
};
|
|
571
|
-
|
|
572
487
|
var BLOCK_TYPES = {
|
|
573
488
|
HEADING: "heading",
|
|
574
489
|
PARAGRAPH: "paragraph",
|
|
@@ -590,8 +505,8 @@ var BOLD_PATTERN = /\*\*(.+?)\*\*/;
|
|
|
590
505
|
var CODE_SPAN_PATTERN = /(`[^`\n]+`)/;
|
|
591
506
|
var UNSAFE_HTML_CHARACTERS = /[&<>"']/g;
|
|
592
507
|
|
|
593
|
-
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; }
|
|
594
|
-
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; }
|
|
508
|
+
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; }
|
|
509
|
+
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; }
|
|
595
510
|
var escapeHtmlCharacter = function escapeHtmlCharacter(character) {
|
|
596
511
|
switch (character) {
|
|
597
512
|
case "&":
|
|
@@ -654,7 +569,9 @@ var matchListItem = function matchListItem(line) {
|
|
|
654
569
|
return {
|
|
655
570
|
type: BLOCK_TYPES.ORDERED_LIST,
|
|
656
571
|
text: orderedItem[2],
|
|
657
|
-
|
|
572
|
+
// The saved article accepts at most nine digits, including leading
|
|
573
|
+
// zeros. Longer numbers leave the list starting at one.
|
|
574
|
+
number: orderedItem[1].length <= 9 ? Number(orderedItem[1]) : 1
|
|
658
575
|
};
|
|
659
576
|
}
|
|
660
577
|
var bulletItem = line.match(BULLET_ITEM_PATTERN);
|
|
@@ -696,7 +613,7 @@ var parseLightMarkdown = function parseLightMarkdown() {
|
|
|
696
613
|
} else if (listItem) {
|
|
697
614
|
var _openBlock;
|
|
698
615
|
if (((_openBlock = openBlock) === null || _openBlock === void 0 ? void 0 : _openBlock.type) !== listItem.type) {
|
|
699
|
-
startBlock(_objectSpread({
|
|
616
|
+
startBlock(_objectSpread$1({
|
|
700
617
|
type: listItem.type,
|
|
701
618
|
items: []
|
|
702
619
|
}, listItem.number === undefined ? {} : {
|
|
@@ -779,63 +696,393 @@ var Lines = function Lines(_ref2) {
|
|
|
779
696
|
code: code,
|
|
780
697
|
text: text
|
|
781
698
|
})
|
|
782
|
-
}, segmentIndex);
|
|
699
|
+
}, segmentIndex);
|
|
700
|
+
})]
|
|
701
|
+
}, lineIndex);
|
|
702
|
+
});
|
|
703
|
+
};
|
|
704
|
+
|
|
705
|
+
var Block = function Block(_ref) {
|
|
706
|
+
var block = _ref.block;
|
|
707
|
+
if (block.type === BLOCK_TYPES.HEADING) {
|
|
708
|
+
return /*#__PURE__*/jsxRuntime.jsx("h2", {
|
|
709
|
+
className: "font-semibold",
|
|
710
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Lines, {
|
|
711
|
+
lines: block.lines
|
|
712
|
+
})
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
if (block.type === BLOCK_TYPES.PARAGRAPH) {
|
|
716
|
+
return /*#__PURE__*/jsxRuntime.jsx("p", {
|
|
717
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Lines, {
|
|
718
|
+
lines: block.lines
|
|
719
|
+
})
|
|
720
|
+
});
|
|
721
|
+
}
|
|
722
|
+
var isOrdered = block.type === BLOCK_TYPES.ORDERED_LIST;
|
|
723
|
+
var List = isOrdered ? "ol" : "ul";
|
|
724
|
+
return /*#__PURE__*/jsxRuntime.jsx(List, {
|
|
725
|
+
start: isOrdered ? block.start : undefined,
|
|
726
|
+
className: classnames({
|
|
727
|
+
"list-decimal space-y-1 pl-5": isOrdered,
|
|
728
|
+
"list-disc space-y-1 pl-5": !isOrdered
|
|
729
|
+
}),
|
|
730
|
+
children: block.items.map(function (lines, index) {
|
|
731
|
+
return /*#__PURE__*/jsxRuntime.jsx("li", {
|
|
732
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Lines, {
|
|
733
|
+
lines: lines
|
|
734
|
+
})
|
|
735
|
+
}, index);
|
|
736
|
+
})
|
|
737
|
+
});
|
|
738
|
+
};
|
|
739
|
+
|
|
740
|
+
var FormattedText = function FormattedText(_ref) {
|
|
741
|
+
var className = _ref.className,
|
|
742
|
+
text = _ref.text;
|
|
743
|
+
return /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
744
|
+
className: classnames(neetoAtoms.typographyVariants({
|
|
745
|
+
variant: "body2"
|
|
746
|
+
}), "space-y-2 break-words", className),
|
|
747
|
+
children: parseLightMarkdown(text).map(function (block, index) {
|
|
748
|
+
return /*#__PURE__*/react.createElement(Block, {
|
|
749
|
+
block: block,
|
|
750
|
+
key: index
|
|
751
|
+
});
|
|
752
|
+
})
|
|
753
|
+
});
|
|
754
|
+
};
|
|
755
|
+
|
|
756
|
+
var Content = function Content(_ref) {
|
|
757
|
+
var text = _ref.text;
|
|
758
|
+
var _useTranslation = reactI18next.useTranslation(),
|
|
759
|
+
t = _useTranslation.t;
|
|
760
|
+
var boxRef = react.useRef(null);
|
|
761
|
+
var _useState = react.useState(false),
|
|
762
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
763
|
+
isOpen = _useState2[0],
|
|
764
|
+
setIsOpen = _useState2[1];
|
|
765
|
+
var _useState3 = react.useState(false),
|
|
766
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
767
|
+
isTallerThanBox = _useState4[0],
|
|
768
|
+
setIsTallerThanBox = _useState4[1];
|
|
769
|
+
react.useLayoutEffect(function () {
|
|
770
|
+
var box = boxRef.current;
|
|
771
|
+
// An open box is as tall as its text, so only a folded one can tell.
|
|
772
|
+
if (!box || isOpen) return undefined;
|
|
773
|
+
var measure = function measure() {
|
|
774
|
+
return setIsTallerThanBox(box.scrollHeight > box.clientHeight);
|
|
775
|
+
};
|
|
776
|
+
measure();
|
|
777
|
+
if (typeof ResizeObserver === "undefined") return undefined;
|
|
778
|
+
|
|
779
|
+
// A rep can widen the pane, and the same text then takes fewer lines.
|
|
780
|
+
var observer = new ResizeObserver(measure);
|
|
781
|
+
observer.observe(box);
|
|
782
|
+
return function () {
|
|
783
|
+
observer.disconnect();
|
|
784
|
+
};
|
|
785
|
+
}, [isOpen, text]);
|
|
786
|
+
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
787
|
+
className: "space-y-1 py-1",
|
|
788
|
+
children: [/*#__PURE__*/jsxRuntime.jsx("div", {
|
|
789
|
+
"data-testid": "neeto-assist-action-content",
|
|
790
|
+
ref: boxRef,
|
|
791
|
+
className: classnames("border-border overflow-y-auto rounded-md border px-3 py-2", {
|
|
792
|
+
"max-h-72": !isOpen
|
|
793
|
+
}),
|
|
794
|
+
children: /*#__PURE__*/jsxRuntime.jsx(FormattedText, {
|
|
795
|
+
text: text
|
|
796
|
+
})
|
|
797
|
+
}), isTallerThanBox && /*#__PURE__*/jsxRuntime.jsxs("button", {
|
|
798
|
+
"aria-expanded": isOpen,
|
|
799
|
+
className: "text-muted-foreground hover:text-foreground flex cursor-pointer items-center gap-1.5 text-sm",
|
|
800
|
+
"data-testid": "neeto-assist-action-content-toggle",
|
|
801
|
+
type: "button",
|
|
802
|
+
onClick: function onClick() {
|
|
803
|
+
return setIsOpen(ramda.not);
|
|
804
|
+
},
|
|
805
|
+
children: [isOpen ? /*#__PURE__*/jsxRuntime.jsx(lucideReact.ChevronUp, {
|
|
806
|
+
size: STATUS_ICON_SIZE
|
|
807
|
+
}) : /*#__PURE__*/jsxRuntime.jsx(lucideReact.ChevronDown, {
|
|
808
|
+
size: STATUS_ICON_SIZE
|
|
809
|
+
}), isOpen ? t("neetoAssist.actions.showLess") : t("neetoAssist.actions.showAll")]
|
|
810
|
+
})]
|
|
811
|
+
});
|
|
812
|
+
};
|
|
813
|
+
|
|
814
|
+
var Outcome = function Outcome(_ref) {
|
|
815
|
+
var _ref$action = _ref.action,
|
|
816
|
+
status = _ref$action.status,
|
|
817
|
+
result = _ref$action.result,
|
|
818
|
+
error = _ref$action.error,
|
|
819
|
+
actedBy = _ref$action.actedBy,
|
|
820
|
+
link = _ref$action.link,
|
|
821
|
+
errorMessageKey = _ref.errorMessageKey,
|
|
822
|
+
isApplying = _ref.isApplying,
|
|
823
|
+
isDismissing = _ref.isDismissing,
|
|
824
|
+
onApply = _ref.onApply,
|
|
825
|
+
onDismiss = _ref.onDismiss;
|
|
826
|
+
var _useTranslation = reactI18next.useTranslation(),
|
|
827
|
+
t = _useTranslation.t;
|
|
828
|
+
if (status === "suggested") {
|
|
829
|
+
return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
830
|
+
children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
831
|
+
className: "flex flex-wrap gap-2",
|
|
832
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Button, {
|
|
833
|
+
"data-testid": "neeto-assist-action-apply-button",
|
|
834
|
+
disabled: isApplying || isDismissing,
|
|
835
|
+
label: t("neetoAssist.actions.apply"),
|
|
836
|
+
loading: isApplying,
|
|
837
|
+
size: "sm",
|
|
838
|
+
onClick: onApply
|
|
839
|
+
}), /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Button, {
|
|
840
|
+
"data-testid": "neeto-assist-action-dismiss-button",
|
|
841
|
+
disabled: isApplying || isDismissing,
|
|
842
|
+
label: t("neetoAssist.actions.dismiss"),
|
|
843
|
+
loading: isDismissing,
|
|
844
|
+
size: "sm",
|
|
845
|
+
variant: "ghost",
|
|
846
|
+
onClick: onDismiss
|
|
847
|
+
})]
|
|
848
|
+
}), errorMessageKey && /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Typography, {
|
|
849
|
+
color: "destructive",
|
|
850
|
+
"data-testid": "neeto-assist-action-error",
|
|
851
|
+
variant: "body3",
|
|
852
|
+
children: t(errorMessageKey)
|
|
853
|
+
})]
|
|
854
|
+
});
|
|
855
|
+
}
|
|
856
|
+
if (status === "applying") {
|
|
857
|
+
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
858
|
+
className: "flex items-center gap-1.5",
|
|
859
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Spinner, {
|
|
860
|
+
size: "sm"
|
|
861
|
+
}), /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Typography, {
|
|
862
|
+
color: "muted",
|
|
863
|
+
variant: "body3",
|
|
864
|
+
children: t("neetoAssist.actions.applying")
|
|
865
|
+
})]
|
|
866
|
+
});
|
|
867
|
+
}
|
|
868
|
+
if (status === "applied") {
|
|
869
|
+
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
870
|
+
className: "flex items-start gap-1.5",
|
|
871
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(lucideReact.Check, {
|
|
872
|
+
className: "text-success-foreground mt-1 shrink-0",
|
|
873
|
+
size: STATUS_ICON_SIZE
|
|
874
|
+
}), /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
875
|
+
className: "min-w-0",
|
|
876
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Typography, {
|
|
877
|
+
variant: "body3",
|
|
878
|
+
children: result || t("neetoAssist.actions.applied")
|
|
879
|
+
}), useNeetoAssistStore.isWebUrl(link === null || link === void 0 ? void 0 : link.url) && /*#__PURE__*/jsxRuntime.jsxs("a", {
|
|
880
|
+
className: "text-primary inline-flex items-center gap-1 text-sm break-words hover:underline",
|
|
881
|
+
"data-testid": "neeto-assist-action-link",
|
|
882
|
+
href: link.url,
|
|
883
|
+
rel: "noreferrer",
|
|
884
|
+
target: "_blank",
|
|
885
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(lucideReact.ExternalLink, {
|
|
886
|
+
className: "shrink-0",
|
|
887
|
+
size: 12
|
|
888
|
+
}), link.label || link.url]
|
|
889
|
+
}), (actedBy === null || actedBy === void 0 ? void 0 : actedBy.name) && /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Typography, {
|
|
890
|
+
color: "muted",
|
|
891
|
+
variant: "body3",
|
|
892
|
+
children: t("neetoAssist.actions.by", {
|
|
893
|
+
name: actedBy.name
|
|
894
|
+
})
|
|
895
|
+
})]
|
|
783
896
|
})]
|
|
784
|
-
}, lineIndex);
|
|
785
|
-
});
|
|
786
|
-
};
|
|
787
|
-
|
|
788
|
-
var Block = function Block(_ref) {
|
|
789
|
-
var block = _ref.block;
|
|
790
|
-
if (block.type === BLOCK_TYPES.HEADING) {
|
|
791
|
-
return /*#__PURE__*/jsxRuntime.jsx("h2", {
|
|
792
|
-
className: "font-semibold",
|
|
793
|
-
children: /*#__PURE__*/jsxRuntime.jsx(Lines, {
|
|
794
|
-
lines: block.lines
|
|
795
|
-
})
|
|
796
897
|
});
|
|
797
898
|
}
|
|
798
|
-
if (
|
|
799
|
-
return /*#__PURE__*/jsxRuntime.jsx(
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
899
|
+
if (status === "failed") {
|
|
900
|
+
return /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Typography, {
|
|
901
|
+
color: "destructive",
|
|
902
|
+
"data-testid": "neeto-assist-action-error",
|
|
903
|
+
variant: "body3",
|
|
904
|
+
children: error || t("neetoAssist.actions.failed")
|
|
803
905
|
});
|
|
804
906
|
}
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
907
|
+
return null;
|
|
908
|
+
};
|
|
909
|
+
|
|
910
|
+
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; }
|
|
911
|
+
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; }
|
|
912
|
+
var Card = function Card(_ref) {
|
|
913
|
+
var action = _ref.action,
|
|
914
|
+
conversationId = _ref.conversationId,
|
|
915
|
+
onActionApplied = _ref.onActionApplied;
|
|
916
|
+
var _useTranslation = reactI18next.useTranslation(),
|
|
917
|
+
t = _useTranslation.t;
|
|
918
|
+
var _useState = react.useState(null),
|
|
919
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
920
|
+
answer = _useState2[0],
|
|
921
|
+
setAnswer = _useState2[1];
|
|
922
|
+
var isActingRef = react.useRef(false);
|
|
923
|
+
|
|
924
|
+
// The host is told through the hook, which still hears the answer to a
|
|
925
|
+
// click when this card is gone by then.
|
|
926
|
+
var _useApplyAction = useNeetoAssistStore.useApplyAction(conversationId, function (applied) {
|
|
927
|
+
return onActionApplied === null || onActionApplied === void 0 ? void 0 : onActionApplied(_objectSpread(_objectSpread({}, action), applied));
|
|
812
928
|
}),
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
929
|
+
apply = _useApplyAction.mutate,
|
|
930
|
+
isApplying = _useApplyAction.isPending;
|
|
931
|
+
var _useDismissAction = useNeetoAssistStore.useDismissAction(conversationId),
|
|
932
|
+
dismiss = _useDismissAction.mutate,
|
|
933
|
+
isDismissing = _useDismissAction.isPending;
|
|
934
|
+
var shown = shownAction(action, answer);
|
|
935
|
+
var name = shown.name,
|
|
936
|
+
status = shown.status,
|
|
937
|
+
title = shown.title,
|
|
938
|
+
details = shown.details,
|
|
939
|
+
reason = shown.reason,
|
|
940
|
+
actedBy = shown.actedBy;
|
|
941
|
+
var content = contentOf(shown);
|
|
942
|
+
var quietStatusKey = ramda.prop(status, neeto_assist.QUIET_ACTION_STATUS_KEYS);
|
|
943
|
+
// Someone dismissed an action. Nobody expired one.
|
|
944
|
+
var dismissedBy = status === "dismissed" ? actedBy === null || actedBy === void 0 ? void 0 : actedBy.name : null;
|
|
945
|
+
|
|
946
|
+
// Two clicks can land before the buttons are seen as disabled, and the second
|
|
947
|
+
// must not ask the host to make the change again.
|
|
948
|
+
var act = function act(mutate, isApply) {
|
|
949
|
+
if (isActingRef.current) return;
|
|
950
|
+
isActingRef.current = true;
|
|
951
|
+
setAnswer(null);
|
|
952
|
+
mutate({
|
|
953
|
+
conversationId: conversationId,
|
|
954
|
+
actionId: action.id
|
|
955
|
+
}, {
|
|
956
|
+
onSettled: function onSettled(data, error) {
|
|
957
|
+
isActingRef.current = false;
|
|
958
|
+
setAnswer({
|
|
959
|
+
isApply: isApply,
|
|
960
|
+
data: data,
|
|
961
|
+
error: error
|
|
962
|
+
});
|
|
963
|
+
}
|
|
964
|
+
});
|
|
965
|
+
};
|
|
966
|
+
if (quietStatusKey) {
|
|
967
|
+
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
968
|
+
className: "border-border text-muted-foreground rounded-lg border px-3 py-2 text-sm",
|
|
969
|
+
"data-action-name": name,
|
|
970
|
+
"data-status": status,
|
|
971
|
+
"data-testid": "neeto-assist-action-card",
|
|
972
|
+
children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
973
|
+
className: "flex items-center justify-between gap-3",
|
|
974
|
+
children: [/*#__PURE__*/jsxRuntime.jsx("span", {
|
|
975
|
+
title: title,
|
|
976
|
+
className: "truncate",
|
|
977
|
+
children: title
|
|
978
|
+
}), /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
979
|
+
className: "shrink-0",
|
|
980
|
+
children: t(quietStatusKey)
|
|
981
|
+
})]
|
|
982
|
+
}), dismissedBy && /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
983
|
+
className: "text-end",
|
|
984
|
+
children: t("neetoAssist.actions.by", {
|
|
985
|
+
name: dismissedBy
|
|
817
986
|
})
|
|
818
|
-
}
|
|
819
|
-
})
|
|
987
|
+
})]
|
|
988
|
+
});
|
|
989
|
+
}
|
|
990
|
+
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
991
|
+
className: "border-border space-y-2 rounded-lg border p-3 break-words",
|
|
992
|
+
"data-action-name": name,
|
|
993
|
+
"data-status": status,
|
|
994
|
+
"data-testid": "neeto-assist-action-card",
|
|
995
|
+
children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
996
|
+
className: "space-y-1",
|
|
997
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Typography, {
|
|
998
|
+
variant: "body2",
|
|
999
|
+
weight: "medium",
|
|
1000
|
+
children: title
|
|
1001
|
+
}), (details !== null && details !== void 0 ? details : []).map(function (detail, index) {
|
|
1002
|
+
return /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Typography, {
|
|
1003
|
+
className: "whitespace-pre-wrap",
|
|
1004
|
+
variant: "body3",
|
|
1005
|
+
children: detail
|
|
1006
|
+
}, index);
|
|
1007
|
+
}), content && /*#__PURE__*/jsxRuntime.jsx(Content, {
|
|
1008
|
+
text: content
|
|
1009
|
+
}), reason && /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Typography, {
|
|
1010
|
+
color: "muted",
|
|
1011
|
+
variant: "body3",
|
|
1012
|
+
children: reason
|
|
1013
|
+
})]
|
|
1014
|
+
}), /*#__PURE__*/jsxRuntime.jsx(Outcome, {
|
|
1015
|
+
isApplying: isApplying,
|
|
1016
|
+
isDismissing: isDismissing,
|
|
1017
|
+
action: shown,
|
|
1018
|
+
errorMessageKey: answerErrorMessageKey(answer),
|
|
1019
|
+
onApply: function onApply() {
|
|
1020
|
+
return act(apply, true);
|
|
1021
|
+
},
|
|
1022
|
+
onDismiss: function onDismiss() {
|
|
1023
|
+
return act(dismiss, false);
|
|
1024
|
+
}
|
|
1025
|
+
})]
|
|
820
1026
|
});
|
|
821
1027
|
};
|
|
822
1028
|
|
|
823
|
-
var
|
|
824
|
-
var
|
|
825
|
-
|
|
1029
|
+
var Actions = function Actions(_ref) {
|
|
1030
|
+
var actions = _ref.actions,
|
|
1031
|
+
conversationId = _ref.conversationId,
|
|
1032
|
+
onActionApplied = _ref.onActionApplied;
|
|
1033
|
+
if (ramda.isEmpty(actions)) return null;
|
|
826
1034
|
return /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
827
|
-
className:
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
key:
|
|
1035
|
+
className: "flex flex-col gap-2",
|
|
1036
|
+
children: actions.map(function (action) {
|
|
1037
|
+
return /*#__PURE__*/react.createElement(Card, {
|
|
1038
|
+
action: action,
|
|
1039
|
+
conversationId: conversationId,
|
|
1040
|
+
onActionApplied: onActionApplied,
|
|
1041
|
+
key: action.id
|
|
834
1042
|
});
|
|
835
1043
|
})
|
|
836
1044
|
});
|
|
837
1045
|
};
|
|
838
1046
|
|
|
1047
|
+
var Sources = function Sources(_ref) {
|
|
1048
|
+
var _ref$sources = _ref.sources,
|
|
1049
|
+
sources = _ref$sources === void 0 ? [] : _ref$sources;
|
|
1050
|
+
var _useTranslation = reactI18next.useTranslation(),
|
|
1051
|
+
t = _useTranslation.t;
|
|
1052
|
+
var links = sources.filter(function (_ref2) {
|
|
1053
|
+
var url = _ref2.url;
|
|
1054
|
+
return useNeetoAssistStore.isWebUrl(url);
|
|
1055
|
+
});
|
|
1056
|
+
if (!neetoCist.isNotEmpty(links)) return null;
|
|
1057
|
+
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
1058
|
+
className: "space-y-1",
|
|
1059
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Typography, {
|
|
1060
|
+
color: "muted",
|
|
1061
|
+
variant: "body3",
|
|
1062
|
+
weight: "medium",
|
|
1063
|
+
children: t("neetoAssist.run.sources")
|
|
1064
|
+
}), /*#__PURE__*/jsxRuntime.jsx("ul", {
|
|
1065
|
+
className: "space-y-1",
|
|
1066
|
+
children: links.map(function (_ref3) {
|
|
1067
|
+
var title = _ref3.title,
|
|
1068
|
+
url = _ref3.url;
|
|
1069
|
+
return /*#__PURE__*/jsxRuntime.jsx("li", {
|
|
1070
|
+
children: /*#__PURE__*/jsxRuntime.jsxs("a", {
|
|
1071
|
+
className: "text-primary inline-flex items-center gap-1 break-words text-sm hover:underline",
|
|
1072
|
+
href: url,
|
|
1073
|
+
rel: "noreferrer",
|
|
1074
|
+
target: "_blank",
|
|
1075
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(lucideReact.ExternalLink, {
|
|
1076
|
+
className: "shrink-0",
|
|
1077
|
+
size: 12
|
|
1078
|
+
}), title || url]
|
|
1079
|
+
})
|
|
1080
|
+
}, url);
|
|
1081
|
+
})
|
|
1082
|
+
})]
|
|
1083
|
+
});
|
|
1084
|
+
};
|
|
1085
|
+
|
|
839
1086
|
var SuggestedReply = function SuggestedReply(_ref) {
|
|
840
1087
|
var onUseReply = _ref.onUseReply,
|
|
841
1088
|
t = _ref.t,
|
|
@@ -1085,6 +1332,7 @@ var Feedback = function Feedback(_ref) {
|
|
|
1085
1332
|
|
|
1086
1333
|
var Question = function Question(_ref) {
|
|
1087
1334
|
var _ref$run = _ref.run,
|
|
1335
|
+
command = _ref$run.command,
|
|
1088
1336
|
kind = _ref$run.kind,
|
|
1089
1337
|
question = _ref$run.question,
|
|
1090
1338
|
requestedBy = _ref$run.requestedBy;
|
|
@@ -1093,6 +1341,7 @@ var Question = function Question(_ref) {
|
|
|
1093
1341
|
if (kind === "ask") {
|
|
1094
1342
|
var _globalProps$user;
|
|
1095
1343
|
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);
|
|
1344
|
+
var typedCommand = useNeetoAssistStore.commandPart(question, command);
|
|
1096
1345
|
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
1097
1346
|
className: "flex flex-col items-end gap-1",
|
|
1098
1347
|
children: [!isOwnQuestion && /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Typography, {
|
|
@@ -1106,7 +1355,12 @@ var Question = function Question(_ref) {
|
|
|
1106
1355
|
children: /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Typography, {
|
|
1107
1356
|
className: "whitespace-pre-wrap",
|
|
1108
1357
|
variant: "body2",
|
|
1109
|
-
children:
|
|
1358
|
+
children: typedCommand ? /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
1359
|
+
children: [/*#__PURE__*/jsxRuntime.jsx("span", {
|
|
1360
|
+
className: "font-medium",
|
|
1361
|
+
children: typedCommand
|
|
1362
|
+
}), question.slice(typedCommand.length)]
|
|
1363
|
+
}) : question
|
|
1110
1364
|
})
|
|
1111
1365
|
})]
|
|
1112
1366
|
});
|
|
@@ -1282,6 +1536,8 @@ var Conversation = function Conversation(_ref3) {
|
|
|
1282
1536
|
runs = _useFetchRuns$data2$r === void 0 ? [] : _useFetchRuns$data2$r,
|
|
1283
1537
|
_useFetchRuns$data2$c = _useFetchRuns$data2.credits,
|
|
1284
1538
|
credits = _useFetchRuns$data2$c === void 0 ? null : _useFetchRuns$data2$c,
|
|
1539
|
+
_useFetchRuns$data2$c2 = _useFetchRuns$data2.commands,
|
|
1540
|
+
commands = _useFetchRuns$data2$c2 === void 0 ? [] : _useFetchRuns$data2$c2,
|
|
1285
1541
|
error = _useFetchRuns.error,
|
|
1286
1542
|
isLoading = _useFetchRuns.isLoading;
|
|
1287
1543
|
var newestRun = runs[0];
|
|
@@ -1327,6 +1583,7 @@ var Conversation = function Conversation(_ref3) {
|
|
|
1327
1583
|
}), credits !== null && credits !== void 0 && credits.exhausted ? /*#__PURE__*/jsxRuntime.jsx(CreditsBanner$1, {
|
|
1328
1584
|
credits: credits
|
|
1329
1585
|
}) : /*#__PURE__*/jsxRuntime.jsx(MessageInput, {
|
|
1586
|
+
commands: commands,
|
|
1330
1587
|
conversationId: conversationId
|
|
1331
1588
|
})]
|
|
1332
1589
|
});
|
|
@@ -1403,7 +1660,7 @@ var Pane = function Pane(_ref) {
|
|
|
1403
1660
|
return /*#__PURE__*/jsxRuntime.jsx("aside", {
|
|
1404
1661
|
"aria-hidden": !isOpen,
|
|
1405
1662
|
"data-testid": "neeto-assist-pane",
|
|
1406
|
-
className:
|
|
1663
|
+
className: classnames("flex h-screen shrink-0 flex-col overflow-hidden", {
|
|
1407
1664
|
"bg-popover border-border border-s": isOpen
|
|
1408
1665
|
}),
|
|
1409
1666
|
style: {
|