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