@bigbinary/neeto-assist-frontend 1.2.0 → 1.3.0-beta1

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