@bigbinary/neeto-assist-frontend 0.0.0-stage → 1.0.2

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 (66) hide show
  1. package/README.md +243 -2
  2. package/app/javascript/src/translations/ar.json +78 -0
  3. package/app/javascript/src/translations/bg.json +78 -0
  4. package/app/javascript/src/translations/ca.json +78 -0
  5. package/app/javascript/src/translations/cs.json +78 -0
  6. package/app/javascript/src/translations/da.json +78 -0
  7. package/app/javascript/src/translations/de.json +78 -0
  8. package/app/javascript/src/translations/en.json +75 -0
  9. package/app/javascript/src/translations/es-MX.json +78 -0
  10. package/app/javascript/src/translations/es.json +78 -0
  11. package/app/javascript/src/translations/et.json +78 -0
  12. package/app/javascript/src/translations/fi.json +78 -0
  13. package/app/javascript/src/translations/fil.json +78 -0
  14. package/app/javascript/src/translations/fr.json +78 -0
  15. package/app/javascript/src/translations/he.json +78 -0
  16. package/app/javascript/src/translations/hi.json +78 -0
  17. package/app/javascript/src/translations/hr.json +78 -0
  18. package/app/javascript/src/translations/hu.json +78 -0
  19. package/app/javascript/src/translations/id.json +78 -0
  20. package/app/javascript/src/translations/index.js +3 -0
  21. package/app/javascript/src/translations/it.json +78 -0
  22. package/app/javascript/src/translations/ja.json +78 -0
  23. package/app/javascript/src/translations/ko.json +78 -0
  24. package/app/javascript/src/translations/lv.json +75 -0
  25. package/app/javascript/src/translations/nl.json +78 -0
  26. package/app/javascript/src/translations/pl.json +78 -0
  27. package/app/javascript/src/translations/pt-BR.json +78 -0
  28. package/app/javascript/src/translations/pt.json +78 -0
  29. package/app/javascript/src/translations/ro.json +78 -0
  30. package/app/javascript/src/translations/ru.json +78 -0
  31. package/app/javascript/src/translations/sk.json +78 -0
  32. package/app/javascript/src/translations/sl.json +78 -0
  33. package/app/javascript/src/translations/sv.json +78 -0
  34. package/app/javascript/src/translations/th.json +78 -0
  35. package/app/javascript/src/translations/tr.json +78 -0
  36. package/app/javascript/src/translations/uk.json +78 -0
  37. package/app/javascript/src/translations/vi.json +78 -0
  38. package/app/javascript/src/translations/zh-CN.json +78 -0
  39. package/app/javascript/src/translations/zh-TW.json +78 -0
  40. package/dist/.ready +1 -0
  41. package/dist/NeetoAssistButton.js +98 -0
  42. package/dist/NeetoAssistButton.js.map +1 -0
  43. package/dist/NeetoAssistPane.js +975 -0
  44. package/dist/NeetoAssistPane.js.map +1 -0
  45. package/dist/cjs/NeetoAssistButton.js +100 -0
  46. package/dist/cjs/NeetoAssistButton.js.map +1 -0
  47. package/dist/cjs/NeetoAssistPane.js +977 -0
  48. package/dist/cjs/NeetoAssistPane.js.map +1 -0
  49. package/dist/cjs/index.js +30 -0
  50. package/dist/cjs/index.js.map +1 -0
  51. package/dist/cjs/useNeetoAssistStatus.js +18 -0
  52. package/dist/cjs/useNeetoAssistStatus.js.map +1 -0
  53. package/dist/index.js +22 -0
  54. package/dist/index.js.map +1 -0
  55. package/dist/neeto_assist-BbwXxKis.js +121 -0
  56. package/dist/neeto_assist-BbwXxKis.js.map +1 -0
  57. package/dist/neeto_assist-Ha049T0Q.js +102 -0
  58. package/dist/neeto_assist-Ha049T0Q.js.map +1 -0
  59. package/dist/useNeetoAssistStatus.js +16 -0
  60. package/dist/useNeetoAssistStatus.js.map +1 -0
  61. package/dist/useNeetoAssistStore-B5U7FFgQ.js +218 -0
  62. package/dist/useNeetoAssistStore-B5U7FFgQ.js.map +1 -0
  63. package/dist/useNeetoAssistStore-C4fEnA_y.js +232 -0
  64. package/dist/useNeetoAssistStore-C4fEnA_y.js.map +1 -0
  65. package/package.json +231 -4
  66. package/types.d.ts +53 -0
@@ -0,0 +1,977 @@
1
+ 'use strict';
2
+
3
+ var useNeetoAssistStore = require('../useNeetoAssistStore-C4fEnA_y.js');
4
+ var react = require('react');
5
+ var neetoAtoms = require('@bigbinary/neeto-atoms');
6
+ var ramda = require('ramda');
7
+ var neeto_assist = require('../neeto_assist-BbwXxKis.js');
8
+ var reactUtils = require('@bigbinary/neeto-commons-frontend/v2/react-utils');
9
+ var jsxRuntime = require('react/jsx-runtime');
10
+ var reactI18next = require('react-i18next');
11
+ var _defineProperty = require('@babel/runtime/helpers/defineProperty');
12
+ var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
13
+ var classNames = require('classnames');
14
+ var lucideReact = require('lucide-react');
15
+ var neetoCist = require('@bigbinary/neeto-cist');
16
+ var utils = require('@bigbinary/neeto-commons-frontend/v2/utils');
17
+ require('@babel/runtime/helpers/objectWithoutProperties');
18
+ require('@tanstack/react-query');
19
+ require('zustand');
20
+ require('axios');
21
+
22
+ var HEADER_ICON_SIZE = 18;
23
+ var SEND_ICON_SIZE = 24;
24
+ var SCROLL_MARGIN = 8;
25
+
26
+ var CreditsBanner = function CreditsBanner(_ref) {
27
+ var credits = _ref.credits,
28
+ t = _ref.t;
29
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
30
+ className: "border-border bg-muted space-y-1 border-t px-4 py-3",
31
+ "data-testid": "neeto-assist-credits-banner",
32
+ children: [/*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Typography, {
33
+ variant: "body3",
34
+ children: t("neetoAssist.credits.exhausted")
35
+ }), useNeetoAssistStore.isWebUrl(credits.buyUrl) ? /*#__PURE__*/jsxRuntime.jsx("a", {
36
+ className: "text-primary text-sm font-medium hover:underline",
37
+ "data-testid": "neeto-assist-buy-credits-link",
38
+ href: credits.buyUrl,
39
+ rel: "noreferrer",
40
+ target: "_blank",
41
+ children: t("neetoAssist.credits.buy")
42
+ }) : /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Typography, {
43
+ "data-testid": "neeto-assist-ask-admin",
44
+ variant: "body3",
45
+ children: t("neetoAssist.credits.askAdmin")
46
+ })]
47
+ });
48
+ };
49
+ var CreditsBanner$1 = reactUtils.withT(CreditsBanner);
50
+
51
+ // crypto.randomUUID exists only on secure pages (HTTPS or localhost). A host in
52
+ // development, such as http://spinkart.lvh.me, gets the same shape of id from
53
+ // crypto.getRandomValues, which every page has.
54
+ var newRequestId = function newRequestId() {
55
+ if (globalThis.crypto.randomUUID) return globalThis.crypto.randomUUID();
56
+ var hex = Array.from(globalThis.crypto.getRandomValues(new Uint8Array(16)), function (_byte) {
57
+ return _byte.toString(16).padStart(2, "0");
58
+ }).join("");
59
+ return [8, 12, 16, 20, 32].map(function (end, index, ends) {
60
+ var _ends;
61
+ return hex.slice((_ends = ends[index - 1]) !== null && _ends !== void 0 ? _ends : 0, end);
62
+ }).join("-");
63
+ };
64
+
65
+ var ErrorMessage = function ErrorMessage(_ref) {
66
+ var error = _ref.error,
67
+ t = _ref.t;
68
+ return /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Typography, {
69
+ color: "destructive",
70
+ "data-testid": "neeto-assist-error",
71
+ variant: "body3",
72
+ children: t(useNeetoAssistStore.errorMessageKey(error))
73
+ });
74
+ };
75
+ var ErrorMessage$1 = reactUtils.withT(ErrorMessage);
76
+
77
+ var EmptyState = function EmptyState(_ref) {
78
+ var conversationId = _ref.conversationId;
79
+ var _useTranslation = reactI18next.useTranslation(),
80
+ t = _useTranslation.t;
81
+ var _useAskNeetoAssist = useNeetoAssistStore.useAskNeetoAssist(conversationId),
82
+ ask = _useAskNeetoAssist.mutate,
83
+ isPending = _useAskNeetoAssist.isPending,
84
+ error = _useAskNeetoAssist.error;
85
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
86
+ className: "flex flex-col gap-4 px-2 pt-4",
87
+ "data-testid": "neeto-assist-empty-state",
88
+ children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
89
+ children: [/*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Typography, {
90
+ variant: "h4",
91
+ children: t("neetoAssist.intro.title")
92
+ }), /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Typography, {
93
+ className: "mt-1",
94
+ color: "muted",
95
+ variant: "body3",
96
+ children: t("neetoAssist.intro.description")
97
+ })]
98
+ }), /*#__PURE__*/jsxRuntime.jsx("ul", {
99
+ className: "flex flex-col gap-1",
100
+ children: neeto_assist.SUGGESTION_KEYS.map(function (key) {
101
+ return /*#__PURE__*/jsxRuntime.jsx("li", {
102
+ children: /*#__PURE__*/jsxRuntime.jsxs("button", {
103
+ 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",
104
+ "data-testid": "neeto-assist-suggestion",
105
+ disabled: isPending,
106
+ type: "button",
107
+ onClick: function onClick() {
108
+ return ask({
109
+ conversationId: conversationId,
110
+ question: t(key),
111
+ requestId: newRequestId()
112
+ });
113
+ },
114
+ children: [/*#__PURE__*/jsxRuntime.jsx("span", {
115
+ className: "text-muted-foreground",
116
+ children: "\u203A"
117
+ }), /*#__PURE__*/jsxRuntime.jsx("span", {
118
+ children: t(key)
119
+ })]
120
+ })
121
+ }, key);
122
+ })
123
+ }), error && /*#__PURE__*/jsxRuntime.jsx(ErrorMessage$1, {
124
+ error: error
125
+ })]
126
+ });
127
+ };
128
+
129
+ 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; }
130
+ 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; }
131
+ var MessageInput = function MessageInput(_ref) {
132
+ var conversationId = _ref.conversationId;
133
+ var _useTranslation = reactI18next.useTranslation(),
134
+ t = _useTranslation.t;
135
+ var _useState = react.useState(""),
136
+ _useState2 = _slicedToArray(_useState, 2),
137
+ question = _useState2[0],
138
+ setQuestion = _useState2[1];
139
+ var requestRef = react.useRef(null);
140
+ var _useAskNeetoAssist = useNeetoAssistStore.useAskNeetoAssist(conversationId),
141
+ ask = _useAskNeetoAssist.mutate,
142
+ isPending = _useAskNeetoAssist.isPending,
143
+ error = _useAskNeetoAssist.error;
144
+ var trimmedQuestion = question.trim();
145
+ var canSend = !!trimmedQuestion && !isPending;
146
+ var handleSubmit = function handleSubmit(event) {
147
+ var _requestRef$current;
148
+ event.preventDefault();
149
+ if (!canSend) return;
150
+
151
+ // A failed request may already have reached NeetoAssist. Retrying the same
152
+ // question keeps its identity so it cannot create a second run.
153
+ if (((_requestRef$current = requestRef.current) === null || _requestRef$current === void 0 ? void 0 : _requestRef$current.question) !== trimmedQuestion) {
154
+ requestRef.current = {
155
+ question: trimmedQuestion,
156
+ requestId: newRequestId()
157
+ };
158
+ }
159
+ ask(_objectSpread({
160
+ conversationId: conversationId
161
+ }, requestRef.current), {
162
+ onSuccess: function onSuccess() {
163
+ requestRef.current = null;
164
+ setQuestion("");
165
+ }
166
+ });
167
+ };
168
+
169
+ // Enter also confirms a word in an input method for languages such as Japanese,
170
+ // and that must not send the question.
171
+ var handleKeyDown = function handleKeyDown(event) {
172
+ var _event$nativeEvent;
173
+ var isComposing = (_event$nativeEvent = event.nativeEvent) === null || _event$nativeEvent === void 0 ? void 0 : _event$nativeEvent.isComposing;
174
+ if (event.key === "Enter" && !event.shiftKey && !isComposing) {
175
+ handleSubmit(event);
176
+ }
177
+ };
178
+ return /*#__PURE__*/jsxRuntime.jsxs("form", {
179
+ className: "border-border flex w-full flex-col gap-2 border-t px-4 py-3",
180
+ onSubmit: handleSubmit,
181
+ children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
182
+ className: "relative",
183
+ children: [/*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Textarea, {
184
+ "aria-label": t("neetoAssist.ask.placeholder"),
185
+ className: "w-full pe-12",
186
+ dataTestId: "neeto-assist-ask",
187
+ maxLength: neeto_assist.MAX_QUESTION_LENGTH,
188
+ placeholder: t("neetoAssist.ask.placeholder"),
189
+ readOnly: isPending,
190
+ rows: 3,
191
+ value: question,
192
+ onChange: function onChange(event) {
193
+ return setQuestion(event.target.value);
194
+ },
195
+ onKeyDown: handleKeyDown
196
+ }), /*#__PURE__*/jsxRuntime.jsx("button", {
197
+ "aria-label": t("neetoAssist.ask.submit"),
198
+ "data-testid": "neeto-assist-ask-button",
199
+ disabled: !canSend,
200
+ type: "submit",
201
+ className: classNames("absolute end-2 bottom-2 flex h-7 w-7 items-center justify-center rounded-full transition-opacity", {
202
+ "text-primary hover:opacity-80": canSend,
203
+ "text-muted-foreground cursor-not-allowed opacity-60": !canSend
204
+ }),
205
+ children: isPending ? /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Spinner, {
206
+ size: "sm"
207
+ }) : /*#__PURE__*/jsxRuntime.jsx(lucideReact.CircleArrowUp, {
208
+ size: SEND_ICON_SIZE
209
+ })
210
+ })]
211
+ }), error && /*#__PURE__*/jsxRuntime.jsx(ErrorMessage$1, {
212
+ error: error
213
+ }), /*#__PURE__*/jsxRuntime.jsxs("div", {
214
+ className: "flex items-center justify-between gap-3",
215
+ children: [/*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Typography, {
216
+ color: "muted",
217
+ variant: "body3",
218
+ children: t("neetoAssist.shadowNote")
219
+ }), /*#__PURE__*/jsxRuntime.jsxs("span", {
220
+ className: "text-muted-foreground shrink-0 text-xs",
221
+ children: [question.length, "/", neeto_assist.MAX_QUESTION_LENGTH]
222
+ })]
223
+ })]
224
+ });
225
+ };
226
+
227
+ var Sources = function Sources(_ref) {
228
+ var _ref$sources = _ref.sources,
229
+ sources = _ref$sources === void 0 ? [] : _ref$sources;
230
+ var _useTranslation = reactI18next.useTranslation(),
231
+ t = _useTranslation.t;
232
+ var links = sources.filter(function (_ref2) {
233
+ var url = _ref2.url;
234
+ return useNeetoAssistStore.isWebUrl(url);
235
+ });
236
+ if (!neetoCist.isNotEmpty(links)) return null;
237
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
238
+ className: "space-y-1",
239
+ children: [/*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Typography, {
240
+ color: "muted",
241
+ variant: "body3",
242
+ weight: "medium",
243
+ children: t("neetoAssist.run.sources")
244
+ }), /*#__PURE__*/jsxRuntime.jsx("ul", {
245
+ className: "space-y-1",
246
+ children: links.map(function (_ref3) {
247
+ var title = _ref3.title,
248
+ url = _ref3.url;
249
+ return /*#__PURE__*/jsxRuntime.jsx("li", {
250
+ children: /*#__PURE__*/jsxRuntime.jsxs("a", {
251
+ className: "text-primary inline-flex items-center gap-1 break-words text-sm hover:underline",
252
+ href: url,
253
+ rel: "noreferrer",
254
+ target: "_blank",
255
+ children: [/*#__PURE__*/jsxRuntime.jsx(lucideReact.ExternalLink, {
256
+ className: "shrink-0",
257
+ size: 12
258
+ }), title || url]
259
+ })
260
+ }, url);
261
+ })
262
+ })]
263
+ });
264
+ };
265
+
266
+ var BLOCK_TYPES = {
267
+ HEADING: "heading",
268
+ PARAGRAPH: "paragraph",
269
+ ORDERED_LIST: "orderedList",
270
+ BULLET_LIST: "bulletList"
271
+ };
272
+ var HEADING_PATTERN = /^\s{0,3}#{1,6}\s+(.*)$/;
273
+ var ORDERED_ITEM_PATTERN = /^\s*\d+[.)]\s+(.*)$/;
274
+ var BULLET_ITEM_PATTERN = /^\s*[-*•]\s+(.*)$/;
275
+ var BOLD_PATTERN = /\*\*(.+?)\*\*/;
276
+ var UNSAFE_HTML_CHARACTERS = /[&<>"']/g;
277
+
278
+ // NeetoAssist writes replies and notes in Arion's light markdown: paragraphs
279
+ // split by blank lines, **bold**, numbered and bulleted lists, and ## headings.
280
+ // Model output can carry markup a visitor slipped into the conversation, so
281
+ // text is only ever escaped into HTML or rendered as React text, never trusted
282
+ // as markup.
283
+ var escapeHtmlCharacter = function escapeHtmlCharacter(character) {
284
+ switch (character) {
285
+ case "&":
286
+ return "&amp;";
287
+ case "<":
288
+ return "&lt;";
289
+ case ">":
290
+ return "&gt;";
291
+ case '"':
292
+ return "&quot;";
293
+ default:
294
+ return "&#39;";
295
+ }
296
+ };
297
+ var escapeHtml = function escapeHtml(text) {
298
+ return text.replace(UNSAFE_HTML_CHARACTERS, escapeHtmlCharacter);
299
+ };
300
+
301
+ // "a **b** c" becomes a plain "a ", a bold "b" and a plain " c". An unclosed
302
+ // "**" stays as it is.
303
+ var parseInline = function parseInline(line) {
304
+ return line.split(BOLD_PATTERN).flatMap(function (text, index) {
305
+ return text === "" ? [] : [{
306
+ text: text,
307
+ bold: index % 2 === 1
308
+ }];
309
+ });
310
+ };
311
+ var matchListItem = function matchListItem(line) {
312
+ var orderedItem = line.match(ORDERED_ITEM_PATTERN);
313
+ if (orderedItem) {
314
+ return {
315
+ type: BLOCK_TYPES.ORDERED_LIST,
316
+ text: orderedItem[1]
317
+ };
318
+ }
319
+ var bulletItem = line.match(BULLET_ITEM_PATTERN);
320
+ return bulletItem && {
321
+ type: BLOCK_TYPES.BULLET_LIST,
322
+ text: bulletItem[1]
323
+ };
324
+ };
325
+
326
+ // Blocks hold lines of inline segments: a paragraph's lines, a heading's one
327
+ // line, or each list item's lines. A list carries on across blank lines, since
328
+ // models often leave one between items.
329
+ var parseLightMarkdown = function parseLightMarkdown() {
330
+ var text = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
331
+ var blocks = [];
332
+ var openBlock = null;
333
+ var afterBlankLine = false;
334
+ var startBlock = function startBlock(block) {
335
+ blocks.push(block);
336
+ openBlock = block;
337
+ };
338
+ String(text !== null && text !== void 0 ? text : "").replace(/\r\n?/g, "\n").split("\n").forEach(function (line) {
339
+ var _openBlock2;
340
+ if (line.trim() === "") {
341
+ afterBlankLine = true;
342
+ return;
343
+ }
344
+ var heading = line.match(HEADING_PATTERN);
345
+ var listItem = !heading && matchListItem(line);
346
+ var isList = openBlock && openBlock.type !== BLOCK_TYPES.PARAGRAPH;
347
+ if (heading) {
348
+ blocks.push({
349
+ type: BLOCK_TYPES.HEADING,
350
+ lines: [parseInline(heading[1].trim())]
351
+ });
352
+ openBlock = null;
353
+ } else if (listItem) {
354
+ var _openBlock;
355
+ if (((_openBlock = openBlock) === null || _openBlock === void 0 ? void 0 : _openBlock.type) !== listItem.type) {
356
+ startBlock({
357
+ type: listItem.type,
358
+ items: []
359
+ });
360
+ }
361
+ openBlock.items.push([parseInline(listItem.text.trim())]);
362
+ } else if (isList && !afterBlankLine && /^\s/.test(line)) {
363
+ openBlock.items.at(-1).push(parseInline(line.trim()));
364
+ } else if (((_openBlock2 = openBlock) === null || _openBlock2 === void 0 ? void 0 : _openBlock2.type) === BLOCK_TYPES.PARAGRAPH && !afterBlankLine) {
365
+ openBlock.lines.push(parseInline(line.trim()));
366
+ } else {
367
+ startBlock({
368
+ type: BLOCK_TYPES.PARAGRAPH,
369
+ lines: [parseInline(line.trim())]
370
+ });
371
+ }
372
+ afterBlankLine = false;
373
+ });
374
+ return blocks;
375
+ };
376
+ var segmentsToHtml = function segmentsToHtml(segments) {
377
+ return segments.map(function (_ref) {
378
+ var text = _ref.text,
379
+ bold = _ref.bold;
380
+ return bold ? "<strong>".concat(escapeHtml(text), "</strong>") : escapeHtml(text);
381
+ }).join("");
382
+ };
383
+ var linesToHtml = function linesToHtml(lines) {
384
+ return lines.map(segmentsToHtml).join("<br>");
385
+ };
386
+ var listToHtml = function listToHtml(tag, items) {
387
+ return "<".concat(tag, ">").concat(items.map(function (lines) {
388
+ return "<li>".concat(linesToHtml(lines), "</li>");
389
+ }).join(""), "</").concat(tag, ">");
390
+ };
391
+ var blockToHtml = function blockToHtml(block) {
392
+ switch (block.type) {
393
+ case BLOCK_TYPES.HEADING:
394
+ return "<h2>".concat(linesToHtml(block.lines), "</h2>");
395
+ case BLOCK_TYPES.ORDERED_LIST:
396
+ return listToHtml("ol", block.items);
397
+ case BLOCK_TYPES.BULLET_LIST:
398
+ return listToHtml("ul", block.items);
399
+ default:
400
+ return "<p>".concat(linesToHtml(block.lines), "</p>");
401
+ }
402
+ };
403
+
404
+ // HTML for a rich-text composer, made only of p, br, strong, ol, ul, li and h2
405
+ // around escaped text.
406
+ var lightMarkdownToHtml = function lightMarkdownToHtml(text) {
407
+ return parseLightMarkdown(text).map(blockToHtml).join("");
408
+ };
409
+
410
+ var Lines = function Lines(_ref) {
411
+ var lines = _ref.lines;
412
+ return lines.map(function (segments, lineIndex) {
413
+ return /*#__PURE__*/jsxRuntime.jsxs(react.Fragment, {
414
+ children: [lineIndex > 0 && /*#__PURE__*/jsxRuntime.jsx("br", {}), segments.map(function (_ref2, segmentIndex) {
415
+ var text = _ref2.text,
416
+ bold = _ref2.bold;
417
+ return bold ? /*#__PURE__*/jsxRuntime.jsx("strong", {
418
+ className: "font-semibold",
419
+ children: text
420
+ }, segmentIndex) : /*#__PURE__*/jsxRuntime.jsx(react.Fragment, {
421
+ children: text
422
+ }, segmentIndex);
423
+ })]
424
+ }, lineIndex);
425
+ });
426
+ };
427
+
428
+ var Block = function Block(_ref) {
429
+ var block = _ref.block;
430
+ if (block.type === BLOCK_TYPES.HEADING) {
431
+ return /*#__PURE__*/jsxRuntime.jsx("h2", {
432
+ className: "font-semibold",
433
+ children: /*#__PURE__*/jsxRuntime.jsx(Lines, {
434
+ lines: block.lines
435
+ })
436
+ });
437
+ }
438
+ if (block.type === BLOCK_TYPES.PARAGRAPH) {
439
+ return /*#__PURE__*/jsxRuntime.jsx("p", {
440
+ children: /*#__PURE__*/jsxRuntime.jsx(Lines, {
441
+ lines: block.lines
442
+ })
443
+ });
444
+ }
445
+ var isOrdered = block.type === BLOCK_TYPES.ORDERED_LIST;
446
+ var List = isOrdered ? "ol" : "ul";
447
+ return /*#__PURE__*/jsxRuntime.jsx(List, {
448
+ className: classNames({
449
+ "list-decimal space-y-1 pl-5": isOrdered,
450
+ "list-disc space-y-1 pl-5": !isOrdered
451
+ }),
452
+ children: block.items.map(function (lines, index) {
453
+ return /*#__PURE__*/jsxRuntime.jsx("li", {
454
+ children: /*#__PURE__*/jsxRuntime.jsx(Lines, {
455
+ lines: lines
456
+ })
457
+ }, index);
458
+ })
459
+ });
460
+ };
461
+
462
+ var FormattedText = function FormattedText(_ref) {
463
+ var className = _ref.className,
464
+ text = _ref.text;
465
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
466
+ className: classNames(neetoAtoms.typographyVariants({
467
+ variant: "body2"
468
+ }), "space-y-2 break-words", className),
469
+ children: parseLightMarkdown(text).map(function (block, index) {
470
+ return /*#__PURE__*/react.createElement(Block, {
471
+ block: block,
472
+ key: index
473
+ });
474
+ })
475
+ });
476
+ };
477
+
478
+ var SuggestedReply = function SuggestedReply(_ref) {
479
+ var onUseReply = _ref.onUseReply,
480
+ t = _ref.t,
481
+ text = _ref.text;
482
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
483
+ className: "border-border space-y-2 rounded-lg border p-3",
484
+ children: [/*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Typography, {
485
+ color: "muted",
486
+ variant: "body3",
487
+ weight: "medium",
488
+ children: t("neetoAssist.run.suggestedReply")
489
+ }), /*#__PURE__*/jsxRuntime.jsx(FormattedText, {
490
+ text: text
491
+ }), /*#__PURE__*/jsxRuntime.jsxs("div", {
492
+ className: "flex flex-wrap gap-2",
493
+ children: [onUseReply && /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Button, {
494
+ "data-testid": "neeto-assist-use-reply-button",
495
+ icon: lucideReact.CornerDownLeft,
496
+ label: t("neetoAssist.run.useReply"),
497
+ size: "sm",
498
+ onClick: function onClick() {
499
+ return onUseReply(text, lightMarkdownToHtml(text));
500
+ }
501
+ }), /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Button, {
502
+ "data-testid": "neeto-assist-copy-reply-button",
503
+ icon: lucideReact.Copy,
504
+ label: t("neetoAssist.run.copy"),
505
+ size: "sm",
506
+ variant: "outline",
507
+ onClick: function onClick() {
508
+ return utils.copyToClipboard(text, {
509
+ message: t("neetoAssist.run.copied")
510
+ });
511
+ }
512
+ })]
513
+ })]
514
+ });
515
+ };
516
+ var SuggestedReply$1 = reactUtils.withT(SuggestedReply);
517
+
518
+ var Answer = function Answer(_ref) {
519
+ var onUseReply = _ref.onUseReply,
520
+ _ref$run = _ref.run,
521
+ kind = _ref$run.kind,
522
+ outcome = _ref$run.outcome,
523
+ answer = _ref$run.answer,
524
+ suggestedReply = _ref$run.suggestedReply,
525
+ needsHumanAction = _ref$run.needsHumanAction,
526
+ sources = _ref$run.sources;
527
+ var _useTranslation = reactI18next.useTranslation(),
528
+ t = _useTranslation.t;
529
+ if (outcome === "no_answer") {
530
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
531
+ className: "space-y-1",
532
+ children: [/*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Typography, {
533
+ variant: "body2",
534
+ weight: "medium",
535
+ children: t("neetoAssist.run.noAnswer")
536
+ }), answer && /*#__PURE__*/jsxRuntime.jsx(FormattedText, {
537
+ className: "text-muted-foreground",
538
+ text: answer
539
+ })]
540
+ });
541
+ }
542
+ return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
543
+ children: [kind === "ask" && answer && /*#__PURE__*/jsxRuntime.jsx(FormattedText, {
544
+ text: answer
545
+ }), suggestedReply && /*#__PURE__*/jsxRuntime.jsx(SuggestedReply$1, {
546
+ onUseReply: onUseReply,
547
+ text: suggestedReply
548
+ }), needsHumanAction && /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Typography, {
549
+ "data-testid": "neeto-assist-follow-up-note",
550
+ variant: "body3",
551
+ weight: "medium",
552
+ children: t("neetoAssist.run.needsFollowUp")
553
+ }), /*#__PURE__*/jsxRuntime.jsx(Sources, {
554
+ sources: sources
555
+ })]
556
+ });
557
+ };
558
+
559
+ var Feedback = function Feedback(_ref) {
560
+ var conversationId = _ref.conversationId,
561
+ _ref$run = _ref.run,
562
+ runId = _ref$run.id,
563
+ _ref$run$feedback = _ref$run.feedback,
564
+ feedback = _ref$run$feedback === void 0 ? [] : _ref$run$feedback;
565
+ var _useTranslation = reactI18next.useTranslation(),
566
+ t = _useTranslation.t;
567
+ var _useState = react.useState(null),
568
+ _useState2 = _slicedToArray(_useState, 2),
569
+ pendingRating = _useState2[0],
570
+ setPendingRating = _useState2[1];
571
+ var _useState3 = react.useState(false),
572
+ _useState4 = _slicedToArray(_useState3, 2),
573
+ isEditingNote = _useState4[0],
574
+ setIsEditingNote = _useState4[1];
575
+ var _useState5 = react.useState(""),
576
+ _useState6 = _slicedToArray(_useState5, 2),
577
+ note = _useState6[0],
578
+ setNote = _useState6[1];
579
+ var _useUpdateFeedback = useNeetoAssistStore.useUpdateFeedback(conversationId),
580
+ updateFeedback = _useUpdateFeedback.mutate,
581
+ isPending = _useUpdateFeedback.isPending,
582
+ error = _useUpdateFeedback.error;
583
+ var ownFeedback = feedback.find(function (_ref2) {
584
+ var _globalProps$user;
585
+ var givenBy = _ref2.givenBy;
586
+ return (givenBy === null || givenBy === void 0 ? void 0 : givenBy.id) === ((_globalProps$user = globalProps.user) === null || _globalProps$user === void 0 ? void 0 : _globalProps$user.id);
587
+ });
588
+ var shownRating = pendingRating !== null && pendingRating !== void 0 ? pendingRating : ownFeedback === null || ownFeedback === void 0 ? void 0 : ownFeedback.rating;
589
+
590
+ // The clicked rating shows until NeetoAssist's own copy of it arrives.
591
+ react.useEffect(function () {
592
+ if (pendingRating && (ownFeedback === null || ownFeedback === void 0 ? void 0 : ownFeedback.rating) === pendingRating) {
593
+ setPendingRating(null);
594
+ }
595
+ }, [ownFeedback === null || ownFeedback === void 0 ? void 0 : ownFeedback.rating, pendingRating]);
596
+
597
+ // A click on a thumb records the rating at once, so a rep who rates and
598
+ // moves on still leaves it. The note is an optional follow-up.
599
+ var rate = function rate(value) {
600
+ var _ownFeedback$note;
601
+ var savedNote = (_ownFeedback$note = ownFeedback === null || ownFeedback === void 0 ? void 0 : ownFeedback.note) !== null && _ownFeedback$note !== void 0 ? _ownFeedback$note : "";
602
+ setPendingRating(value);
603
+ setNote(savedNote);
604
+ setIsEditingNote(true);
605
+ updateFeedback({
606
+ conversationId: conversationId,
607
+ runId: runId,
608
+ rating: value,
609
+ note: savedNote
610
+ }, {
611
+ onError: function onError() {
612
+ return setPendingRating(null);
613
+ }
614
+ });
615
+ };
616
+ var handleSubmit = function handleSubmit(event) {
617
+ event.preventDefault();
618
+ updateFeedback({
619
+ conversationId: conversationId,
620
+ runId: runId,
621
+ rating: shownRating,
622
+ note: note.trim()
623
+ }, {
624
+ onSuccess: function onSuccess() {
625
+ return setIsEditingNote(false);
626
+ }
627
+ });
628
+ };
629
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
630
+ className: "space-y-2",
631
+ children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
632
+ className: "flex items-center gap-1",
633
+ children: [/*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Button, {
634
+ "aria-label": t("neetoAssist.feedback.helpful"),
635
+ "data-testid": "neeto-assist-thumbs-up-button",
636
+ disabled: isPending,
637
+ icon: lucideReact.ThumbsUp,
638
+ size: "icon-sm",
639
+ tooltipProps: {
640
+ content: t("neetoAssist.feedback.helpful")
641
+ },
642
+ variant: shownRating === "up" ? "secondary" : "ghost",
643
+ onClick: function onClick() {
644
+ return rate("up");
645
+ }
646
+ }), /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Button, {
647
+ "aria-label": t("neetoAssist.feedback.notHelpful"),
648
+ "data-testid": "neeto-assist-thumbs-down-button",
649
+ disabled: isPending,
650
+ icon: lucideReact.ThumbsDown,
651
+ size: "icon-sm",
652
+ tooltipProps: {
653
+ content: t("neetoAssist.feedback.notHelpful")
654
+ },
655
+ variant: shownRating === "down" ? "secondary" : "ghost",
656
+ onClick: function onClick() {
657
+ return rate("down");
658
+ }
659
+ })]
660
+ }), error && /*#__PURE__*/jsxRuntime.jsx(ErrorMessage$1, {
661
+ error: error
662
+ }), isEditingNote && shownRating && /*#__PURE__*/jsxRuntime.jsxs("form", {
663
+ className: "space-y-2",
664
+ onSubmit: handleSubmit,
665
+ children: [/*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Textarea, {
666
+ "aria-label": t("neetoAssist.feedback.notePlaceholder"),
667
+ dataTestId: "neeto-assist-feedback-note",
668
+ maxLength: neeto_assist.MAX_NOTE_LENGTH,
669
+ placeholder: t("neetoAssist.feedback.notePlaceholder"),
670
+ size: "small",
671
+ value: note,
672
+ onChange: function onChange(event) {
673
+ return setNote(event.target.value);
674
+ }
675
+ }), /*#__PURE__*/jsxRuntime.jsxs("div", {
676
+ className: "flex gap-2",
677
+ children: [/*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Button, {
678
+ "data-testid": "neeto-assist-save-feedback-button",
679
+ label: t("neetoAssist.feedback.save"),
680
+ loading: isPending,
681
+ size: "sm",
682
+ type: "submit"
683
+ }), /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Button, {
684
+ label: t("neetoAssist.feedback.close"),
685
+ size: "sm",
686
+ variant: "ghost",
687
+ onClick: function onClick() {
688
+ return setIsEditingNote(false);
689
+ }
690
+ })]
691
+ })]
692
+ }), feedback.map(function (_ref3) {
693
+ var givenBy = _ref3.givenBy,
694
+ givenNote = _ref3.note,
695
+ givenRating = _ref3.rating;
696
+ return /*#__PURE__*/jsxRuntime.jsxs(neetoAtoms.Typography, {
697
+ className: "break-words",
698
+ color: "muted",
699
+ variant: "body3",
700
+ children: [givenRating === "up" ? t("neetoAssist.feedback.ratedHelpful", {
701
+ name: givenBy === null || givenBy === void 0 ? void 0 : givenBy.name
702
+ }) : t("neetoAssist.feedback.ratedNotHelpful", {
703
+ name: givenBy === null || givenBy === void 0 ? void 0 : givenBy.name
704
+ }), givenNote && ": ".concat(givenNote)]
705
+ }, givenBy === null || givenBy === void 0 ? void 0 : givenBy.id);
706
+ })]
707
+ });
708
+ };
709
+
710
+ var Question = function Question(_ref) {
711
+ var _ref$run = _ref.run,
712
+ kind = _ref$run.kind,
713
+ question = _ref$run.question,
714
+ requestedBy = _ref$run.requestedBy;
715
+ var _useTranslation = reactI18next.useTranslation(),
716
+ t = _useTranslation.t;
717
+ if (kind === "ask") {
718
+ var _globalProps$user;
719
+ 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);
720
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
721
+ className: "flex flex-col items-end gap-1",
722
+ children: [!isOwnQuestion && /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Typography, {
723
+ color: "muted",
724
+ variant: "body3",
725
+ children: t("neetoAssist.run.repAsked", {
726
+ name: requestedBy === null || requestedBy === void 0 ? void 0 : requestedBy.name
727
+ })
728
+ }), /*#__PURE__*/jsxRuntime.jsx("div", {
729
+ className: "bg-muted max-w-[80%] rounded-lg px-3 py-2 break-words",
730
+ children: /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Typography, {
731
+ className: "whitespace-pre-wrap",
732
+ variant: "body2",
733
+ children: question
734
+ })
735
+ })]
736
+ });
737
+ }
738
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
739
+ className: "border-border space-y-1 border-s-2 ps-3",
740
+ children: [/*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Typography, {
741
+ color: "muted",
742
+ variant: "body3",
743
+ weight: "medium",
744
+ children: t("neetoAssist.run.customerWrote")
745
+ }), question && /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Typography, {
746
+ className: "whitespace-pre-wrap break-words",
747
+ variant: "body2",
748
+ children: question
749
+ })]
750
+ });
751
+ };
752
+
753
+ var Run = function Run(_ref) {
754
+ var conversationId = _ref.conversationId,
755
+ onUseReply = _ref.onUseReply,
756
+ run = _ref.run,
757
+ t = _ref.t;
758
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
759
+ className: "flex flex-col gap-3",
760
+ "data-testid": neeto_assist.RUN_TEST_ID,
761
+ children: [/*#__PURE__*/jsxRuntime.jsx(Question, {
762
+ run: run
763
+ }), useNeetoAssistStore.isPending(run) && /*#__PURE__*/jsxRuntime.jsxs("div", {
764
+ className: "flex items-center gap-1.5",
765
+ children: [/*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Spinner, {
766
+ size: "sm"
767
+ }), /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Typography, {
768
+ color: "muted",
769
+ variant: "body3",
770
+ children: t("neetoAssist.run.pending")
771
+ })]
772
+ }), useNeetoAssistStore.hasWrittenReply(run) && /*#__PURE__*/jsxRuntime.jsx(Answer, {
773
+ onUseReply: onUseReply,
774
+ run: run
775
+ }), run.status === "skipped" && !useNeetoAssistStore.hasWrittenReply(run) && /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Typography, {
776
+ color: "muted",
777
+ variant: "body2",
778
+ children: t(useNeetoAssistStore.skippedReasonMessageKey(run.skippedReason))
779
+ }), run.status === "failed" && /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Typography, {
780
+ color: "muted",
781
+ variant: "body2",
782
+ children: t("neetoAssist.run.failed")
783
+ }), useNeetoAssistStore.isRateable(run) && /*#__PURE__*/jsxRuntime.jsx(Feedback, {
784
+ conversationId: conversationId,
785
+ run: run
786
+ })]
787
+ });
788
+ };
789
+ var Run$1 = reactUtils.withT(Run);
790
+
791
+ var Conversation = function Conversation(_ref) {
792
+ var conversationId = _ref.conversationId,
793
+ isVisible = _ref.isVisible,
794
+ onUseReply = _ref.onUseReply;
795
+ var listRef = react.useRef(null);
796
+ var markDraftSeen = useNeetoAssistStore.useNeetoAssistStore(function (state) {
797
+ return state.markDraftSeen;
798
+ });
799
+ var _useFetchRuns = useNeetoAssistStore.useFetchRuns(conversationId),
800
+ _useFetchRuns$data = _useFetchRuns.data,
801
+ _useFetchRuns$data2 = _useFetchRuns$data === void 0 ? {} : _useFetchRuns$data,
802
+ _useFetchRuns$data2$r = _useFetchRuns$data2.runs,
803
+ runs = _useFetchRuns$data2$r === void 0 ? [] : _useFetchRuns$data2$r,
804
+ _useFetchRuns$data2$c = _useFetchRuns$data2.credits,
805
+ credits = _useFetchRuns$data2$c === void 0 ? null : _useFetchRuns$data2$c,
806
+ error = _useFetchRuns.error,
807
+ isLoading = _useFetchRuns.isLoading;
808
+ var newestRun = runs[0];
809
+ var draftId = useNeetoAssistStore.latestDraftId(runs);
810
+
811
+ // The newest run starts at the top of the window, so a long reply is read
812
+ // from its first line.
813
+ react.useEffect(function () {
814
+ var list = listRef.current;
815
+ var renderedRuns = list === null || list === void 0 ? void 0 : list.querySelectorAll("[data-testid=\"".concat(neeto_assist.RUN_TEST_ID, "\"]"));
816
+ var newest = renderedRuns === null || renderedRuns === void 0 ? void 0 : renderedRuns[renderedRuns.length - 1];
817
+ if (!newest) return;
818
+ list.scrollTo({
819
+ top: newest.offsetTop - list.offsetTop - SCROLL_MARGIN
820
+ });
821
+ }, [newestRun === null || newestRun === void 0 ? void 0 : newestRun.id, newestRun === null || newestRun === void 0 ? void 0 : newestRun.status]);
822
+ react.useEffect(function () {
823
+ if (isVisible && draftId) markDraftSeen(conversationId, draftId);
824
+ }, [conversationId, draftId, isVisible, markDraftSeen]);
825
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
826
+ className: "flex min-h-0 w-full flex-1 flex-col",
827
+ children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
828
+ className: "flex w-full flex-1 flex-col gap-6 overflow-y-auto px-4 py-4",
829
+ ref: listRef,
830
+ children: [isLoading && /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Spinner, {}), !isLoading && !error && ramda.isEmpty(runs) && /*#__PURE__*/jsxRuntime.jsx(EmptyState, {
831
+ conversationId: conversationId
832
+ }), useNeetoAssistStore.runsInConversationOrder(runs).map(function (run) {
833
+ return /*#__PURE__*/react.createElement(Run$1, {
834
+ conversationId: conversationId,
835
+ onUseReply: onUseReply,
836
+ run: run,
837
+ key: run.id
838
+ });
839
+ }), error && /*#__PURE__*/jsxRuntime.jsx(ErrorMessage$1, {
840
+ error: error
841
+ })]
842
+ }), credits !== null && credits !== void 0 && credits.exhausted ? /*#__PURE__*/jsxRuntime.jsx(CreditsBanner$1, {
843
+ credits: credits
844
+ }) : /*#__PURE__*/jsxRuntime.jsx(MessageInput, {
845
+ conversationId: conversationId
846
+ })]
847
+ });
848
+ };
849
+
850
+ var Header = function Header(_ref) {
851
+ var isExpanded = _ref.isExpanded,
852
+ onClose = _ref.onClose,
853
+ onToggleExpand = _ref.onToggleExpand,
854
+ t = _ref.t;
855
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
856
+ className: "border-border flex items-center justify-between border-b px-4 py-3",
857
+ children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
858
+ className: "flex items-center gap-2",
859
+ children: [/*#__PURE__*/jsxRuntime.jsx(useNeetoAssistStore.Sparkle, {
860
+ className: "text-purple-600",
861
+ size: HEADER_ICON_SIZE
862
+ }), /*#__PURE__*/jsxRuntime.jsx("span", {
863
+ className: "font-semibold",
864
+ children: t("neetoAssist.title")
865
+ }), /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Tooltip, {
866
+ content: t("neetoAssist.betaNote"),
867
+ position: "bottom",
868
+ children: /*#__PURE__*/jsxRuntime.jsx("span", {
869
+ children: /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Badge, {
870
+ label: t("neetoAssist.beta"),
871
+ size: "sm",
872
+ variant: "secondary"
873
+ })
874
+ })
875
+ })]
876
+ }), /*#__PURE__*/jsxRuntime.jsxs("div", {
877
+ className: "text-muted-foreground flex items-center gap-1",
878
+ children: [/*#__PURE__*/jsxRuntime.jsx("button", {
879
+ className: "hover:bg-muted rounded p-1",
880
+ "data-testid": "neeto-assist-expand-button",
881
+ type: "button",
882
+ "aria-label": isExpanded ? t("neetoAssist.collapse") : t("neetoAssist.expand"),
883
+ onClick: onToggleExpand,
884
+ children: isExpanded ? /*#__PURE__*/jsxRuntime.jsx(lucideReact.Minimize2, {
885
+ size: HEADER_ICON_SIZE
886
+ }) : /*#__PURE__*/jsxRuntime.jsx(lucideReact.Maximize2, {
887
+ size: HEADER_ICON_SIZE
888
+ })
889
+ }), /*#__PURE__*/jsxRuntime.jsx("button", {
890
+ "aria-label": t("neetoAssist.close"),
891
+ className: "hover:bg-muted rounded p-1",
892
+ "data-testid": "neeto-assist-close-button",
893
+ type: "button",
894
+ onClick: onClose,
895
+ children: /*#__PURE__*/jsxRuntime.jsx(lucideReact.X, {
896
+ size: HEADER_ICON_SIZE
897
+ })
898
+ })]
899
+ })]
900
+ });
901
+ };
902
+ var Header$1 = reactUtils.withT(Header);
903
+
904
+ var Pane = function Pane(_ref) {
905
+ var children = _ref.children,
906
+ isExpanded = _ref.isExpanded,
907
+ isOpen = _ref.isOpen;
908
+ var paneWidth = isExpanded ? neeto_assist.EXPANDED_PANE_WIDTH : neeto_assist.COLLAPSED_PANE_WIDTH;
909
+
910
+ // Lets a host make room with its own CSS while the pane is open.
911
+ react.useEffect(function () {
912
+ if (!isOpen) return undefined;
913
+ document.documentElement.setAttribute("data-neeto-assist-open", isExpanded ? "expanded" : "default");
914
+ return function () {
915
+ return document.documentElement.removeAttribute("data-neeto-assist-open");
916
+ };
917
+ }, [isExpanded, isOpen]);
918
+ return /*#__PURE__*/jsxRuntime.jsx("aside", {
919
+ "aria-hidden": !isOpen,
920
+ "data-testid": "neeto-assist-pane",
921
+ className: classNames("flex h-screen shrink-0 flex-col overflow-hidden", {
922
+ "bg-popover border-border border-s": isOpen
923
+ }),
924
+ style: {
925
+ width: isOpen ? paneWidth : "0px",
926
+ visibility: isOpen ? "visible" : "hidden",
927
+ transition: "width 200ms ease, visibility 200ms"
928
+ },
929
+ children: /*#__PURE__*/jsxRuntime.jsx("div", {
930
+ className: "flex h-full flex-col",
931
+ style: {
932
+ width: paneWidth
933
+ },
934
+ children: children
935
+ })
936
+ });
937
+ };
938
+
939
+ var NeetoAssistPane = function NeetoAssistPane() {
940
+ var isOpen = useNeetoAssistStore.useNeetoAssistStore(function (state) {
941
+ return state.isOpen;
942
+ });
943
+ var isExpanded = useNeetoAssistStore.useNeetoAssistStore(function (state) {
944
+ return state.isExpanded;
945
+ });
946
+ var conversation = useNeetoAssistStore.useNeetoAssistStore(function (state) {
947
+ return state.conversation;
948
+ });
949
+ var close = useNeetoAssistStore.useNeetoAssistStore(function (state) {
950
+ return state.close;
951
+ });
952
+ var setExpanded = useNeetoAssistStore.useNeetoAssistStore(function (state) {
953
+ return state.setExpanded;
954
+ });
955
+ var isVisible = isOpen && !!conversation;
956
+ return /*#__PURE__*/jsxRuntime.jsx(Pane, {
957
+ isExpanded: isExpanded,
958
+ isOpen: isVisible,
959
+ children: conversation && /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
960
+ children: [/*#__PURE__*/jsxRuntime.jsx(Header$1, {
961
+ isExpanded: isExpanded,
962
+ onClose: close,
963
+ onToggleExpand: function onToggleExpand() {
964
+ return setExpanded(!isExpanded);
965
+ }
966
+ }), /*#__PURE__*/react.createElement(Conversation, {
967
+ isVisible: isVisible,
968
+ conversationId: conversation.id,
969
+ key: conversation.id,
970
+ onUseReply: conversation.onUseReply
971
+ })]
972
+ })
973
+ });
974
+ };
975
+
976
+ module.exports = NeetoAssistPane;
977
+ //# sourceMappingURL=NeetoAssistPane.js.map