@apia/ai 5.2.2 → 6.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 (84) hide show
  1. package/dist/assistant/index.d.d.ts +49 -0
  2. package/dist/assistant/index.d.d.ts.map +1 -0
  3. package/dist/assistant/index.js +154 -0
  4. package/dist/assistant/index.js.map +1 -0
  5. package/dist/assistant/runtime/conversationActivity.js +11 -0
  6. package/dist/assistant/runtime/conversationActivity.js.map +1 -0
  7. package/dist/assistant/runtime/conversationAnnotations.js +28 -0
  8. package/dist/assistant/runtime/conversationAnnotations.js.map +1 -0
  9. package/dist/assistant/runtime/conversationAttachmentPreview.js +33 -0
  10. package/dist/assistant/runtime/conversationAttachmentPreview.js.map +1 -0
  11. package/dist/assistant/runtime/conversationAttachments.js +24 -0
  12. package/dist/assistant/runtime/conversationAttachments.js.map +1 -0
  13. package/dist/assistant/runtime/conversationClient.d.d.ts +26 -0
  14. package/dist/assistant/runtime/conversationClient.d.d.ts.map +1 -0
  15. package/dist/assistant/runtime/conversationClient.js +599 -0
  16. package/dist/assistant/runtime/conversationClient.js.map +1 -0
  17. package/dist/assistant/runtime/conversationPlan.js +12 -0
  18. package/dist/assistant/runtime/conversationPlan.js.map +1 -0
  19. package/dist/assistant/runtime/conversationProjection.d.d.ts +8 -0
  20. package/dist/assistant/runtime/conversationProjection.d.d.ts.map +1 -0
  21. package/dist/assistant/runtime/conversationProjection.js +184 -0
  22. package/dist/assistant/runtime/conversationProjection.js.map +1 -0
  23. package/dist/assistant/runtime/coordinatorProxy.js +302 -0
  24. package/dist/assistant/runtime/coordinatorProxy.js.map +1 -0
  25. package/dist/chat/ChatController/ChatController.d.ts +13 -9
  26. package/dist/chat/ChatController/ChatController.js +103 -94
  27. package/dist/chat/ChatController/ChatController.js.map +1 -1
  28. package/dist/chat/ChatController/annotationStyles.js +1 -78
  29. package/dist/chat/ChatController/annotationStyles.js.map +1 -1
  30. package/dist/chat/ChatController/annotationTargets.d.ts +3 -1
  31. package/dist/chat/ChatController/annotationTargets.js +7 -1
  32. package/dist/chat/ChatController/annotationTargets.js.map +1 -1
  33. package/dist/chat/ChatController/components/AnnotationDraft.js +79 -0
  34. package/dist/chat/ChatController/components/AnnotationDraft.js.map +1 -0
  35. package/dist/chat/ChatController/components/AssistantMessageActions.d.ts +4 -0
  36. package/dist/chat/ChatController/components/AssistantMessageActions.d.ts.map +1 -0
  37. package/dist/chat/ChatController/components/AssistantMessageActions.js +102 -0
  38. package/dist/chat/ChatController/components/AssistantMessageActions.js.map +1 -0
  39. package/dist/chat/ChatController/components/AssistantTurnMessage.d.ts +24 -1
  40. package/dist/chat/ChatController/components/AssistantTurnMessage.js +155 -26
  41. package/dist/chat/ChatController/components/AssistantTurnMessage.js.map +1 -1
  42. package/dist/chat/ChatController/components/ChatMessage.d.ts +8 -5
  43. package/dist/chat/ChatController/components/ChatMessage.js +27 -22
  44. package/dist/chat/ChatController/components/ChatMessage.js.map +1 -1
  45. package/dist/chat/ChatController/components/History.d.ts +5 -1
  46. package/dist/chat/ChatController/components/History.js +19 -8
  47. package/dist/chat/ChatController/components/History.js.map +1 -1
  48. package/dist/chat/ChatController/components/Message.d.ts +7 -2
  49. package/dist/chat/ChatController/components/Message.js +22 -8
  50. package/dist/chat/ChatController/components/Message.js.map +1 -1
  51. package/dist/chat/ChatController/components/MessageBlocks.d.ts +2 -5
  52. package/dist/chat/ChatController/components/MessageBlocks.js +6 -48
  53. package/dist/chat/ChatController/components/MessageBlocks.js.map +1 -1
  54. package/dist/chat/ChatController/components/MessageBody.js +10 -3
  55. package/dist/chat/ChatController/components/MessageBody.js.map +1 -1
  56. package/dist/chat/ChatController/components/PendingMessagesPanel.js +2 -3
  57. package/dist/chat/ChatController/components/PendingMessagesPanel.js.map +1 -1
  58. package/dist/chat/ChatController/components/SentAnnotations.js +6 -3
  59. package/dist/chat/ChatController/components/SentAnnotations.js.map +1 -1
  60. package/dist/chat/ChatController/components/TextArea.d.ts +3 -5
  61. package/dist/chat/ChatController/components/TextArea.js +5 -67
  62. package/dist/chat/ChatController/components/TextArea.js.map +1 -1
  63. package/dist/chat/ChatController/types.d.ts +28 -1
  64. package/dist/index.d.ts +7 -8
  65. package/dist/index.js +5 -6
  66. package/dist/index.js.map +1 -1
  67. package/dist/stream/ResponseStream.d.ts +15 -10
  68. package/dist/stream/ResponseStream.js +58 -61
  69. package/dist/stream/ResponseStream.js.map +1 -1
  70. package/dist/stream/reasoningSummary.js +19 -0
  71. package/dist/stream/reasoningSummary.js.map +1 -0
  72. package/package.json +8 -8
  73. package/dist/assistant/AssistantController.d.ts +0 -53
  74. package/dist/assistant/AssistantController.d.ts.map +0 -1
  75. package/dist/assistant/AssistantController.js +0 -131
  76. package/dist/assistant/AssistantController.js.map +0 -1
  77. package/dist/assistant/HandoffCoordinator.d.ts +0 -18
  78. package/dist/assistant/HandoffCoordinator.d.ts.map +0 -1
  79. package/dist/assistant/HandoffCoordinator.js +0 -35
  80. package/dist/assistant/HandoffCoordinator.js.map +0 -1
  81. package/dist/assistant/PanelAssistantTransport.d.ts +0 -28
  82. package/dist/assistant/PanelAssistantTransport.d.ts.map +0 -1
  83. package/dist/assistant/PanelAssistantTransport.js +0 -48
  84. package/dist/assistant/PanelAssistantTransport.js.map +0 -1
@@ -8,23 +8,27 @@ var __publicField = (obj, key, value) => {
8
8
  };
9
9
  let maxId = 0;
10
10
  class ChatMessage {
11
- constructor(message = "", messageType = "user", attachments = [], reference = null, annotations = []) {
11
+ constructor(message = "", messageType = "user", attachments = [], reference = null) {
12
12
  __publicField(this, "id");
13
+ /** Public delegated context, separate from the user's instruction and the destination's own policy. */
14
+ __publicField(this, "delegationContext");
15
+ __publicField(this, "publicSource");
13
16
  __publicField(this, "state");
14
- __publicField(this, "clone", () => new ChatMessage(
15
- this.message,
16
- this.messageType,
17
- this.attachments.map((x) => {
18
- return { ...x };
19
- }),
20
- this.reference,
21
- this.annotations.map((annotation) => ({
22
- ...annotation,
23
- sourceMessageIds: [...annotation.sourceMessageIds],
24
- data: annotation.data ? { ...annotation.data } : void 0
25
- }))
26
- ));
27
- this.state = { message, messageType, attachments, reference, annotations };
17
+ __publicField(this, "clone", () => {
18
+ const copy = new ChatMessage(
19
+ this.message,
20
+ this.messageType,
21
+ this.attachments.map((x) => {
22
+ return { ...x };
23
+ }),
24
+ this.reference
25
+ );
26
+ copy.delegationContext = this.delegationContext ? JSON.parse(JSON.stringify(this.delegationContext)) : void 0;
27
+ copy.annotations = JSON.parse(JSON.stringify(this.annotations));
28
+ copy.publicSource = this.publicSource ? { ...this.publicSource } : void 0;
29
+ return copy;
30
+ });
31
+ this.state = { message, messageType, attachments, reference, annotations: [] };
28
32
  this.id = maxId++;
29
33
  if (messageType === "response")
30
34
  this.messageType = "system";
@@ -32,7 +36,8 @@ class ChatMessage {
32
36
  this.message = message;
33
37
  makeObservable(this, {
34
38
  state: observable,
35
- message: computed
39
+ message: computed,
40
+ annotations: computed
36
41
  });
37
42
  }
38
43
  get message() {
@@ -44,12 +49,15 @@ class ChatMessage {
44
49
  get attachments() {
45
50
  return this.state.attachments;
46
51
  }
47
- get reference() {
48
- return this.state.reference;
49
- }
50
52
  get annotations() {
51
53
  return this.state.annotations;
52
54
  }
55
+ set annotations(value) {
56
+ this.state.annotations = value;
57
+ }
58
+ get reference() {
59
+ return this.state.reference;
60
+ }
53
61
  set message(value) {
54
62
  this.state.message = value;
55
63
  }
@@ -62,9 +70,6 @@ class ChatMessage {
62
70
  set reference(value) {
63
71
  this.state.reference = value;
64
72
  }
65
- set annotations(value) {
66
- this.state.annotations = value;
67
- }
68
73
  removeAttachment(attachment) {
69
74
  this.attachments = this.attachments.filter(
70
75
  (current) => current !== attachment
@@ -1 +1 @@
1
- {"version":3,"file":"ChatMessage.js","sources":["../../../../src/chat/ChatController/components/ChatMessage.tsx"],"sourcesContent":["import { ReactNode } from 'react';\r\nimport { computed, makeObservable, observable } from 'mobx';\r\nimport { IAttachment, TChatAnnotation, TMessageType } from '../types';\n\r\nlet maxId = 0;\r\n\r\nexport class ChatMessage {\r\n id: number;\r\n state: {\r\n message: ReactNode;\r\n messageType: TMessageType;\r\n attachments: IAttachment[];\n annotations: TChatAnnotation[];\n reference: ReactNode;\r\n };\r\n\r\n get message() {\r\n return this.state.message;\r\n }\r\n get messageType() {\r\n return this.state.messageType;\r\n }\r\n get attachments() {\r\n return this.state.attachments;\r\n }\r\n get reference() {\n return this.state.reference;\r\n }\n get annotations() {\n return this.state.annotations;\n }\n set message(value) {\r\n this.state.message = value;\r\n }\r\n set messageType(value) {\r\n this.state.messageType = value;\r\n }\r\n set attachments(value) {\r\n this.state.attachments = value;\r\n }\r\n set reference(value) {\n this.state.reference = value;\r\n }\n set annotations(value) {\n this.state.annotations = value;\n }\n\r\n constructor(\r\n message: ReactNode = '',\r\n messageType: TMessageType = 'user',\r\n attachments: IAttachment[] = [],\n reference: ReactNode = null,\n annotations: TChatAnnotation[] = [],\n ) {\n this.state = { message, messageType, attachments, reference, annotations };\n\r\n this.id = maxId++;\r\n if (messageType === 'response') this.messageType = 'system';\r\n if (typeof message === 'string') this.message = message;\r\n\r\n makeObservable(this, {\r\n state: observable,\r\n message: computed,\r\n });\r\n }\r\n\r\n clone = () =>\r\n new ChatMessage(\r\n this.message,\r\n this.messageType,\r\n this.attachments.map((x) => {\r\n return { ...x };\r\n }),\r\n this.reference,\n this.annotations.map((annotation) => ({\n ...annotation,\n sourceMessageIds: [...annotation.sourceMessageIds],\n data: annotation.data ? { ...annotation.data } : undefined,\n })),\n );\r\n\r\n removeAttachment(attachment: IAttachment) {\r\n this.attachments = this.attachments.filter(\r\n (current) => current !== attachment,\r\n );\r\n }\r\n addAttachmentDescription(attachment: IAttachment, description: string) {\r\n const a = this.attachments.find((current) => current === attachment);\r\n if (a) {\r\n a.description = description;\r\n }\r\n }\r\n setMessageType(type: TMessageType) {\r\n this.messageType = type;\r\n }\r\n}\r\n"],"names":[],"mappings":";;;;;;;;AAIA,IAAI,KAAA,GAAQ,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IAAA,EAAoB;AACjC,IAAA,IAAA,CAAK,WAAA,GAAc,IAAA;AAAA;AAEvB;;;;"}
1
+ {"version":3,"file":"ChatMessage.js","sources":["../../../../src/chat/ChatController/components/ChatMessage.tsx"],"sourcesContent":["import { ReactNode } from 'react';\r\nimport { computed, makeObservable, observable } from 'mobx';\r\nimport { IAttachment, TMessageType, TChatAnnotation, TChatPublicSource } from '../types';\r\n\r\nlet maxId = 0;\r\n\r\nexport class ChatMessage {\r\n id: number;\r\n /** Public delegated context, separate from the user's instruction and the destination's own policy. */\r\n delegationContext?: Record<string, unknown>;\r\n publicSource?: TChatPublicSource;\r\n state: {\r\n message: ReactNode;\r\n messageType: TMessageType;\r\n attachments: IAttachment[];\r\n reference: ReactNode;\r\n annotations: TChatAnnotation[];\r\n };\r\n\r\n get message() {\r\n return this.state.message;\r\n }\r\n get messageType() {\r\n return this.state.messageType;\r\n }\r\n get attachments() {\r\n return this.state.attachments;\r\n }\r\n get annotations() { return this.state.annotations; }\r\n set annotations(value: TChatAnnotation[]) { this.state.annotations = value; }\r\n get reference() {\r\n return this.state.reference;\r\n }\r\n set message(value) {\r\n this.state.message = value;\r\n }\r\n set messageType(value) {\r\n this.state.messageType = value;\r\n }\r\n set attachments(value) {\r\n this.state.attachments = value;\r\n }\r\n set reference(value) {\r\n this.state.reference = value;\r\n }\r\n\r\n constructor(\r\n message: ReactNode = '',\r\n messageType: TMessageType = 'user',\r\n attachments: IAttachment[] = [],\r\n reference: ReactNode = null,\r\n ) {\r\n this.state = { message, messageType, attachments, reference, annotations: [] };\r\n\r\n this.id = maxId++;\r\n if (messageType === 'response') this.messageType = 'system';\r\n if (typeof message === 'string') this.message = message;\r\n\r\n makeObservable(this, {\r\n state: observable,\r\n message: computed,\r\n annotations: computed,\r\n });\r\n }\r\n\r\n clone = () => {\r\n const copy = new ChatMessage(\r\n this.message,\r\n this.messageType,\r\n this.attachments.map((x) => {\r\n return { ...x };\r\n }),\r\n this.reference,\r\n );\r\n copy.delegationContext = this.delegationContext ? JSON.parse(JSON.stringify(this.delegationContext)) : undefined;\r\n copy.annotations = JSON.parse(JSON.stringify(this.annotations));\r\n copy.publicSource = this.publicSource ? { ...this.publicSource } : undefined;\r\n return copy;\r\n };\r\n\r\n removeAttachment(attachment: IAttachment) {\r\n this.attachments = this.attachments.filter(\r\n (current) => current !== attachment,\r\n );\r\n }\r\n addAttachmentDescription(attachment: IAttachment, description: string) {\r\n const a = this.attachments.find((current) => current === attachment);\r\n if (a) {\r\n a.description = description;\r\n }\r\n }\r\n setMessageType(type: TMessageType) {\r\n this.messageType = type;\r\n }\r\n}\r\n"],"names":[],"mappings":";;;;;;;;AAIA,IAAI,KAAA,GAAQ,CAAA;AAEL,MAAM,WAAA,CAAY;AAAA,EAwCvB,WAAA,CACE,UAAqB,EAAA,EACrB,WAAA,GAA4B,QAC5B,WAAA,GAA6B,EAAC,EAC9B,SAAA,GAAuB,IAAA,EACvB;AA5CF,IAAA,aAAA,CAAA,IAAA,EAAA,IAAA,CAAA;AAEA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAA,mBAAA,CAAA;AACA,IAAA,aAAA,CAAA,IAAA,EAAA,cAAA,CAAA;AACA,IAAA,aAAA,CAAA,IAAA,EAAA,OAAA,CAAA;AAsDA,IAAA,aAAA,CAAA,IAAA,EAAA,OAAA,EAAQ,MAAM;AACZ,MAAA,MAAM,OAAO,IAAI,WAAA;AAAA,QACf,IAAA,CAAK,OAAA;AAAA,QACL,IAAA,CAAK,WAAA;AAAA,QACL,IAAA,CAAK,WAAA,CAAY,GAAA,CAAI,CAAC,CAAA,KAAM;AAC1B,UAAA,OAAO,EAAE,GAAG,CAAA,EAAE;AAAA,SACf,CAAA;AAAA,QACD,IAAA,CAAK;AAAA,OACP;AACA,MAAA,IAAA,CAAK,iBAAA,GAAoB,IAAA,CAAK,iBAAA,GAAoB,IAAA,CAAK,KAAA,CAAM,KAAK,SAAA,CAAU,IAAA,CAAK,iBAAiB,CAAC,CAAA,GAAI,M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AAA,IAAA,CAAK,MAAM,OAAA,GAAU,KAAA;AAAA;AACvB,EACA,IAAI,YAAY,KAAA,EAAO;AACrB,IAAA,IAAA,CAAK,MAAM,WAAA,GAAc,KAAA;AAAA;AAC3B,EACA,IAAI,YAAY,KAAA,EAAO;AACrB,IAAA,IAAA,CAAK,MAAM,WAAA,GAAc,KAAA;AAAA;AAC3B,EACA,IAAI,UAAU,KAAA,EAAO;AACnB,IAAA,IAAA,CAAK,MAAM,SAAA,GAAY,KAAA;AAAA;AACzB,EAoCA,iBAAiB,UAAA,EAAyB;AACxC,IAAA,IAAA,CAAK,WAAA,GAAc,KAAK,WAAA,CAAY,MAAA;AAAA,MAClC,CAAC,YAAY,OAAA,KAAY;AAAA,KAC3B;AAAA;AACF,EACA,wBAAA,CAAyB,YAAyB,WAAA,EAAqB;AACrE,IAAA,MAAM,IAAI,IAAA,CAAK,WAAA,CAAY,KAAK,CAAC,OAAA,KAAY,YAAY,UAAU,CAAA;AACnE,IAAA,IAAI,CAAA,EAAG;AACL,MAAA,CAAA,CAAE,WAAA,GAAc,WAAA;AAAA;AAClB;AACF,EACA,eAAe,IAAA,EAAoB;AACjC,IAAA,IAAA,CAAK,WAAA,GAAc,IAAA;AAAA;AAEvB;;;;"}
@@ -1,12 +1,16 @@
1
1
  import * as react from 'react';
2
2
  import { ChatMessage } from './ChatMessage.js';
3
+ import { ReplyWithAssistantMessage } from './AssistantMessageActions.js';
3
4
  import { TChatAnnotation, TChatAnnotationSelection } from '../types.js';
4
5
 
5
- declare const History: (({ messages, bottomInset, className, canAnnotate, editingAnnotation, onDismissEdit, onUpdateAnnotationComment, resolveAnnotations, onAnnotate, }: {
6
+ declare const History: (({ messages, onReplyWithMessage, bottomInset, className, canAnnotate, draftAnnotations, onEditAnnotation, editingAnnotation, onDismissEdit, onUpdateAnnotationComment, resolveAnnotations, onAnnotate, }: {
6
7
  messages: ChatMessage[];
8
+ onReplyWithMessage?: ReplyWithAssistantMessage;
7
9
  bottomInset?: number;
8
10
  className?: string;
9
11
  canAnnotate?: boolean;
12
+ draftAnnotations?: TChatAnnotation[];
13
+ onEditAnnotation?: (id: string) => void;
10
14
  editingAnnotation?: {
11
15
  annotation: TChatAnnotation;
12
16
  range?: Range;
@@ -1,12 +1,18 @@
1
- import { jsxs, Fragment, jsx } from '@apia/theme/jsx-runtime';
1
+ import { jsxs, jsx, Fragment } from '@apia/theme/jsx-runtime';
2
2
  import { observer } from 'mobx-react-lite';
3
3
  import { Box, getVariant } from '@apia/theme';
4
4
  import { Message } from './Message.js';
5
+ import { AssistantReplyContext } from './AssistantMessageActions.js';
5
6
  import { AutoscrollContainer } from '../../AutoscrollContainer.js';
6
7
  import { useRef, useState, useEffect } from 'react';
7
8
  import { createPortal } from 'react-dom';
8
9
  import { annotationPopoverStyles } from '../annotationStyles.js';
10
+ import { getLabel } from '@apia/util';
9
11
 
12
+ function annotationLabel(code, fallback) {
13
+ const text = getLabel(code).text;
14
+ return !text || text.startsWith("LBL_NOT_FOUND") ? fallback : text;
15
+ }
10
16
  function positionForRange(range, width = 360, height = 210) {
11
17
  const rect = range.getBoundingClientRect();
12
18
  return {
@@ -17,9 +23,12 @@ function positionForRange(range, width = 360, height = 210) {
17
23
  const History = observer(
18
24
  ({
19
25
  messages,
26
+ onReplyWithMessage,
20
27
  bottomInset = 0,
21
28
  className,
22
29
  canAnnotate = false,
30
+ draftAnnotations = [],
31
+ onEditAnnotation,
23
32
  editingAnnotation,
24
33
  onDismissEdit,
25
34
  onUpdateAnnotationComment,
@@ -168,7 +177,7 @@ const History = observer(
168
177
  setComment("");
169
178
  };
170
179
  let currentType = "";
171
- return /* @__PURE__ */ jsxs(Fragment, { children: [
180
+ return /* @__PURE__ */ jsxs(AssistantReplyContext.Provider, { value: onReplyWithMessage, children: [
172
181
  /* @__PURE__ */ jsx(AutoscrollContainer, { className, children: /* @__PURE__ */ jsxs(
173
182
  Box,
174
183
  {
@@ -197,7 +206,9 @@ const History = observer(
197
206
  attachments: current.attachments,
198
207
  annotations: current.annotations,
199
208
  reference: current.reference,
200
- message: current.message
209
+ message: current.message,
210
+ annotationMarkers: draftAnnotations.map((annotation, index) => ({ annotation, number: index + 1 })).filter(({ annotation }) => annotation.sourceMessageIds[annotation.sourceMessageIds.length - 1] === current.id),
211
+ onEditAnnotation
201
212
  },
202
213
  String(current.id)
203
214
  );
@@ -228,7 +239,7 @@ const History = observer(
228
239
  className: "chatAnnotationPopover__offer",
229
240
  onMouseDown: (event) => event.preventDefault(),
230
241
  onClick: () => setSelectionAction((current) => current ? { ...current, editorOpen: true } : current),
231
- children: "A\xF1adir al chat"
242
+ children: annotationLabel("lblAiChatAddToChat", "Anotar")
232
243
  }
233
244
  ) : /* @__PURE__ */ jsxs(Fragment, { children: [
234
245
  /* @__PURE__ */ jsx(Box, { className: "chatAnnotationPopover__preview", title: selectionAction.text, children: selectionAction.text }),
@@ -236,9 +247,9 @@ const History = observer(
236
247
  "textarea",
237
248
  {
238
249
  autoFocus: true,
239
- "aria-label": "Comentario sobre la selecci\xF3n",
250
+ "aria-label": annotationLabel("lblAiChatSelectionComment", "Comentario sobre la cita"),
240
251
  className: "chatAnnotationPopover__comment",
241
- placeholder: "A\xF1ade un comentario opcional...",
252
+ placeholder: annotationLabel("lblAiChatOptionalCommentPlaceholder", "Agreg\xE1 un comentario"),
242
253
  value: comment,
243
254
  onChange: (event) => setComment(event.target.value),
244
255
  onKeyDown: (event) => {
@@ -248,7 +259,7 @@ const History = observer(
248
259
  }
249
260
  ),
250
261
  /* @__PURE__ */ jsxs(Box, { className: "chatAnnotationPopover__actions", children: [
251
- /* @__PURE__ */ jsx("button", { type: "button", onClick: dismissSelection, children: "Cancelar" }),
262
+ /* @__PURE__ */ jsx("button", { type: "button", onClick: dismissSelection, children: getLabel("btnCan").text }),
252
263
  /* @__PURE__ */ jsx(
253
264
  "button",
254
265
  {
@@ -262,7 +273,7 @@ const History = observer(
262
273
  window.getSelection()?.removeAllRanges();
263
274
  dismissSelection();
264
275
  },
265
- children: selectionAction.editingId ? "Guardar" : "A\xF1adir al chat"
276
+ children: annotationLabel(selectionAction.editingId ? "btnGua" : "lblAiChatAddToChat", selectionAction.editingId ? "Guardar" : "Anotar")
266
277
  }
267
278
  )
268
279
  ] })
@@ -1 +1 @@
1
- {"version":3,"file":"History.js","sources":["../../../../src/chat/ChatController/components/History.tsx"],"sourcesContent":["import { observer } from 'mobx-react-lite';\r\nimport { Box, getVariant } from '@apia/theme';\r\nimport { ChatMessage } from './ChatMessage';\r\nimport { Message } from './Message';\r\nimport { AutoscrollContainer } from '../../AutoscrollContainer';\nimport { useEffect, useRef, useState } from 'react';\nimport { createPortal } from 'react-dom';\nimport type { TChatAnnotation, TChatAnnotationSelection } from '../types';\nimport { annotationPopoverStyles } from '../annotationStyles';\n\nfunction positionForRange(range: Range, width = 360, height = 210) {\r\n const rect = range.getBoundingClientRect();\n return {\n x: Math.min(Math.max(rect.left, 8), Math.max(8, window.innerWidth - width - 8)),\r\n y: rect.bottom + height + 8 > window.innerHeight\r\n ? Math.max(8, rect.top - height - 8)\r\n : Math.max(8, rect.bottom + 8),\n };\n}\n\r\nexport const History = observer(\r\n ({\r\n messages,\r\n bottomInset = 0,\r\n className,\n canAnnotate = false,\n editingAnnotation,\n onDismissEdit,\n onUpdateAnnotationComment,\n resolveAnnotations,\n onAnnotate,\n }: {\n messages: ChatMessage[];\r\n bottomInset?: number;\r\n className?: string;\n canAnnotate?: boolean;\n editingAnnotation?: { annotation: TChatAnnotation; range?: Range };\n onDismissEdit?: () => void;\n onUpdateAnnotationComment?: (id: string, comment: string) => void;\n resolveAnnotations?: (selection: TChatAnnotationSelection) => TChatAnnotation[];\n onAnnotate?: (annotations: TChatAnnotation[], comment?: string, range?: Range) => void;\n }) => {\n const historyRef = useRef<HTMLDivElement>(null);\n const popoverRef = useRef<HTMLDivElement>(null);\r\n const [selectionAction, setSelectionAction] = useState<{\n annotations: TChatAnnotation[];\n text: string;\n x: number;\n y: number;\n range?: Range;\n editingId?: string;\n editorOpen: boolean;\r\n } | null>(null);\n const [comment, setComment] = useState('');\n\n const dismissSelection = () => {\n if (selectionAction?.editingId) onDismissEdit?.();\n setSelectionAction(null);\n setComment('');\n };\n\r\n useEffect(() => {\r\n if (!selectionAction) return;\r\n const dismiss = () => {\r\n if (selectionAction.editingId) onDismissEdit?.();\r\n setSelectionAction(null);\r\n setComment('');\r\n };\r\n const onPointerDown = (event: PointerEvent) => {\r\n const target = event.target;\r\n if (!(target instanceof Node) || popoverRef.current?.contains(target) || historyRef.current?.contains(target)) return;\r\n dismiss();\r\n };\r\n const onKeyDown = (event: KeyboardEvent) => {\r\n if (event.key === 'Escape') dismiss();\r\n };\r\n document.addEventListener('pointerdown', onPointerDown);\r\n document.addEventListener('keydown', onKeyDown);\r\n return () => {\r\n document.removeEventListener('pointerdown', onPointerDown);\r\n document.removeEventListener('keydown', onKeyDown);\r\n };\r\n }, [Boolean(selectionAction), selectionAction?.editingId]);\r\n\n useEffect(() => {\n if (!editingAnnotation) {\r\n setSelectionAction((current) => current?.editingId ? null : current);\r\n return;\r\n }\r\n if (!historyRef.current) return;\r\n const { annotation, range } = editingAnnotation;\n if (!range?.startContainer.isConnected || !historyRef.current.contains(range.commonAncestorContainer)) {\n onDismissEdit?.();\n return;\n }\n const selection = window.getSelection();\n selection?.removeAllRanges();\n selection?.addRange(range.cloneRange());\n range.startContainer.parentElement?.scrollIntoView({ block: 'center', behavior: 'auto' });\n const frame = requestAnimationFrame(() => {\n setSelectionAction({\n annotations: [annotation],\n text: annotation.text,\n ...positionForRange(range),\n range,\r\n editingId: annotation.id,\n editorOpen: true,\r\n });\n setComment(annotation.comment || '');\n });\n return () => cancelAnimationFrame(frame);\n }, [editingAnnotation?.annotation.id]);\n\r\n useEffect(() => {\r\n const range = selectionAction?.range;\r\n if (!range) return;\r\n const updatePosition = () => {\r\n if (!range.startContainer.isConnected) {\r\n setSelectionAction(null);\r\n onDismissEdit?.();\r\n return;\r\n }\r\n const position = positionForRange(\r\n range,\r\n popoverRef.current?.offsetWidth,\r\n popoverRef.current?.offsetHeight,\r\n );\r\n setSelectionAction((current) => {\r\n if (!current || current.range !== range || (current.x === position.x && current.y === position.y)) return current;\r\n return { ...current, ...position };\r\n });\r\n };\r\n updatePosition();\r\n window.addEventListener('scroll', updatePosition, true);\r\n window.addEventListener('resize', updatePosition);\r\n const observer = new ResizeObserver(updatePosition);\r\n if (popoverRef.current) observer.observe(popoverRef.current);\r\n return () => {\r\n window.removeEventListener('scroll', updatePosition, true);\r\n window.removeEventListener('resize', updatePosition);\r\n observer.disconnect();\r\n };\r\n }, [selectionAction?.range]);\r\n\n const inspectSelection = () => {\n if (!canAnnotate || !historyRef.current) return;\n const selection = window.getSelection();\n const root = historyRef.current;\n if (\n !selection ||\n selection.isCollapsed ||\n !selection.anchorNode ||\n !selection.focusNode ||\n !root.contains(selection.anchorNode) ||\n !root.contains(selection.focusNode) ||\n selection.rangeCount === 0\n ) {\n dismissSelection();\n return;\n }\n const text = selection.toString().trim();\n if (!text) {\n dismissSelection();\n return;\n }\n const range = selection.getRangeAt(0);\n const sourceMessageIds = Array.from(\n root.querySelectorAll<HTMLElement>('[data-chat-message-id]'),\n )\n .filter((element) => range.intersectsNode(element))\n .map((element) => Number(element.dataset.chatMessageId))\n .filter(Number.isFinite);\n if (sourceMessageIds.length === 0) {\n dismissSelection();\n return;\n }\n const annotations = resolveAnnotations?.({\n selection,\n root,\n text,\n sourceMessageIds,\n });\n if (!annotations?.length) {\n dismissSelection();\n return;\n }\n if (editingAnnotation) onDismissEdit?.();\n setSelectionAction({\n annotations,\n text,\n ...positionForRange(range, 140, 36),\r\n range: range.cloneRange(),\n editorOpen: false,\r\n });\n setComment('');\n };\n let currentType: string = '';\n\r\n return (\n <>\n <AutoscrollContainer className={className}>\n <Box\n ref={historyRef}\n onMouseUp={inspectSelection}\n onKeyUp={inspectSelection}\n {...getVariant('layout.common.chat.history')}\n className=\"chat_history\"\r\n >\r\n {messages.map((current, i) => {\r\n let first = false;\r\n let last = false;\r\n\r\n if (currentType !== current.messageType) {\r\n currentType = current.messageType;\r\n first = true;\r\n }\r\n\r\n if (\r\n i === messages.length - 1 ||\r\n messages[i + 1].messageType !== current.messageType\r\n ) {\r\n last = true;\r\n }\r\n\r\n return (\r\n <Message\r\n key={String(current.id)}\r\n className={first ? 'first' : last ? 'last' : undefined}\r\n type={current.messageType}\r\n id={String(current.id)}\r\n attachments={current.attachments}\n annotations={current.annotations}\n reference={current.reference}\r\n message={current.message}\r\n />\r\n );\r\n })}\r\n {bottomInset > 0 && (\n <Box\r\n aria-hidden\r\n className=\"chatHistory__bottomInset\"\r\n style={{ height: bottomInset }}\r\n />\r\n )}\n </Box>\n </AutoscrollContainer>\n {selectionAction && createPortal(\n <Box\n ref={popoverRef}\r\n className={`chatAnnotationPopover${selectionAction.editorOpen ? '' : ' chatAnnotationPopover--offer'}`}\r\n sx={annotationPopoverStyles}\n style={{ left: selectionAction.x, top: selectionAction.y }}\n >\n {!selectionAction.editorOpen ? (\r\n <button\r\n type=\"button\"\r\n className=\"chatAnnotationPopover__offer\"\r\n onMouseDown={(event) => event.preventDefault()}\r\n onClick={() => setSelectionAction((current) => current ? { ...current, editorOpen: true } : current)}\r\n >\r\n Añadir al chat\r\n </button>\r\n ) : (\r\n <>\r\n <Box className=\"chatAnnotationPopover__preview\" title={selectionAction.text}>\n {selectionAction.text}\n </Box>\n <textarea\n autoFocus\n aria-label=\"Comentario sobre la selección\"\n className=\"chatAnnotationPopover__comment\"\n placeholder=\"Añade un comentario opcional...\"\n value={comment}\n onChange={(event) => setComment(event.target.value)}\n onKeyDown={(event) => {\n if (event.key === 'Escape') dismissSelection();\n }}\n />\n <Box className=\"chatAnnotationPopover__actions\">\n <button type=\"button\" onClick={dismissSelection}>Cancelar</button>\n <button\n type=\"button\"\n onClick={() => {\n if (selectionAction.editingId) {\n onUpdateAnnotationComment?.(selectionAction.editingId, comment);\n } else {\n onAnnotate?.(selectionAction.annotations, comment, selectionAction.range);\n }\n window.getSelection()?.removeAllRanges();\n dismissSelection();\n }}\n >\n {selectionAction.editingId ? 'Guardar' : 'Añadir al chat'}\n </button>\n </Box>\n </>\r\n )}\r\n </Box>,\n document.body,\n )}\n </>\n );\r\n },\r\n);\r\n"],"names":["observer"],"mappings":";;;;;;;;;AAUA,SAAS,gBAAA,CAAiB,KAAA,EAAc,KAAA,GAAQ,GAAA,EAAK,SAAS,GAAA,EAAK;AACjE,EAAA,MAAM,IAAA,GAAO,MAAM,qBAAA,EAAsB;AACzC,EAAA,OAAO;AAAA,IACL,GAAG,IAAA,CAAK,GAAA,CAAI,IAAA,CAAK,GAAA,CAAI,KAAK,IAAA,EAAM,CAAC,CAAA,EAAG,IAAA,CAAK,IAAI,CAAA,EAAG,MAAA,CAAO,UAAA,GAAa,KAAA,GAAQ,CAAC,CAAC,CAAA;AAAA,IAC9E,CAAA,EAAG,KAAK,MAAA,GAAS,MAAA,GAAS,IAAI,MAAA,CAAO,WAAA,GACjC,KAAK,GAAA,CAAI,CAAA,EAAG,KAAK,GAAA,GAAM,MAAA,GAAS,CAAC,CAAA,GACjC,IAAA,CAAK,IAAI,CAAA,EAAG,IAAA,CAAK,SAAS,CAAC;AAAA,GACjC;AACF;AAEO,MAAM,OAAA,GAAU,QAAA;AAAA,EACrB,CAAC;AAAA,IACC,QAAA;AAAA,IACA,WAAA,GAAc,CAAA;AAAA,IACd,SAAA;AAAA,IACA,WAAA,GAAc,KAAA;AAAA,IACd,iBAAA;AAAA,IACA,aAAA;AAAA,IACA,yBAAA;AAAA,IACA,kBAAA;AAAA,IACA;AAAA,GACF,KAUM;AACJ,IAAA,MAAM,UAAA,GAAa,OAAuB,IAAI,CAAA;AAC9C,IAAA,MAAM,UAAA,GAAa,OAAuB,IAAI,CAAA;AAC9C,IAAA,MAAM,CAAC,eAAA,EAAiB,kBAAkB,CAAA,GAAI,SAQpC,IAAI,CAAA;AACd,IAAA,MAAM,CAAC,OAAA,EAAS,UAAU,CAAA,GAAI,SAAS,EAAE,C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AS,eAAA,CAAgB,KAAK,CAAA;AAAA;AAE1E,sBAAA,MAAA,CAAO,YAAA,IAAgB,eAAA,EAAgB;AACvC,sBAAA,gBAAA,EAAiB;AAAA,qBACnB;AAAA,oBAEC,QAAA,EAAA,eAAA,CAAgB,YAAY,SAAA,GAAY;AAAA;AAAA;AAC3C,eAAA,EACF;AAAA,aAAA,EACE;AAAA;AAAA,SAEJ;AAAA,QACA,QAAA,CAAS;AAAA;AACX,KAAA,EACA,CAAA;AAAA;AAGN;;;;"}
1
+ {"version":3,"file":"History.js","sources":["../../../../src/chat/ChatController/components/History.tsx"],"sourcesContent":["import { observer } from 'mobx-react-lite';\r\nimport { Box, getVariant } from '@apia/theme';\r\nimport { ChatMessage } from './ChatMessage';\r\nimport { Message } from './Message';\r\nimport { AssistantReplyContext, type ReplyWithAssistantMessage } from './AssistantMessageActions';\r\nimport { AutoscrollContainer } from '../../AutoscrollContainer';\r\nimport { useEffect, useRef, useState } from 'react';\r\nimport { createPortal } from 'react-dom';\r\nimport type { TChatAnnotation, TChatAnnotationSelection } from '../types';\r\nimport { annotationPopoverStyles } from '../annotationStyles';\r\nimport { getLabel } from '@apia/util';\r\n\r\nfunction annotationLabel(code: string, fallback: string) { const text = getLabel(code).text; return !text || text.startsWith('LBL_NOT_FOUND') ? fallback : text; }\r\n\r\nfunction positionForRange(range: Range, width = 360, height = 210) {\r\n const rect = range.getBoundingClientRect();\r\n return {\r\n x: Math.min(Math.max(rect.left, 8), Math.max(8, window.innerWidth - width - 8)),\r\n y: rect.bottom + height + 8 > window.innerHeight\r\n ? Math.max(8, rect.top - height - 8)\r\n : Math.max(8, rect.bottom + 8),\r\n };\r\n}\r\n\r\nexport const History = observer(\r\n ({\r\n messages,\r\n onReplyWithMessage,\r\n bottomInset = 0,\r\n className,\r\n canAnnotate = false,\r\n draftAnnotations = [],\r\n onEditAnnotation,\r\n editingAnnotation,\r\n onDismissEdit,\r\n onUpdateAnnotationComment,\r\n resolveAnnotations,\r\n onAnnotate,\r\n }: {\r\n messages: ChatMessage[];\r\n onReplyWithMessage?: ReplyWithAssistantMessage;\r\n bottomInset?: number;\r\n className?: string;\r\n canAnnotate?: boolean;\r\n draftAnnotations?: TChatAnnotation[];\r\n onEditAnnotation?: (id: string) => void;\r\n editingAnnotation?: { annotation: TChatAnnotation; range?: Range };\r\n onDismissEdit?: () => void;\r\n onUpdateAnnotationComment?: (id: string, comment: string) => void;\r\n resolveAnnotations?: (selection: TChatAnnotationSelection) => TChatAnnotation[];\r\n onAnnotate?: (annotations: TChatAnnotation[], comment?: string, range?: Range) => void;\r\n }) => {\r\n const historyRef = useRef<HTMLDivElement>(null);\r\n const popoverRef = useRef<HTMLDivElement>(null);\r\n const [selectionAction, setSelectionAction] = useState<{\r\n annotations: TChatAnnotation[];\r\n text: string;\r\n x: number;\r\n y: number;\r\n range?: Range;\r\n editingId?: string;\r\n editorOpen: boolean;\r\n } | null>(null);\r\n const [comment, setComment] = useState('');\r\n\r\n const dismissSelection = () => {\r\n if (selectionAction?.editingId) onDismissEdit?.();\r\n setSelectionAction(null);\r\n setComment('');\r\n };\r\n\r\n useEffect(() => {\r\n if (!selectionAction) return;\r\n const dismiss = () => {\r\n if (selectionAction.editingId) onDismissEdit?.();\r\n setSelectionAction(null);\r\n setComment('');\r\n };\r\n const onPointerDown = (event: PointerEvent) => {\r\n const target = event.target;\r\n if (!(target instanceof Node) || popoverRef.current?.contains(target) || historyRef.current?.contains(target)) return;\r\n dismiss();\r\n };\r\n const onKeyDown = (event: KeyboardEvent) => {\r\n if (event.key === 'Escape') dismiss();\r\n };\r\n document.addEventListener('pointerdown', onPointerDown);\r\n document.addEventListener('keydown', onKeyDown);\r\n return () => {\r\n document.removeEventListener('pointerdown', onPointerDown);\r\n document.removeEventListener('keydown', onKeyDown);\r\n };\r\n }, [Boolean(selectionAction), selectionAction?.editingId]);\r\n\r\n useEffect(() => {\r\n if (!editingAnnotation) {\r\n setSelectionAction((current) => current?.editingId ? null : current);\r\n return;\r\n }\r\n if (!historyRef.current) return;\r\n const { annotation, range } = editingAnnotation;\r\n if (!range?.startContainer.isConnected || !historyRef.current.contains(range.commonAncestorContainer)) {\r\n onDismissEdit?.();\r\n return;\r\n }\r\n const selection = window.getSelection();\r\n selection?.removeAllRanges();\r\n selection?.addRange(range.cloneRange());\r\n range.startContainer.parentElement?.scrollIntoView({ block: 'center', behavior: 'auto' });\r\n const frame = requestAnimationFrame(() => {\r\n setSelectionAction({\r\n annotations: [annotation],\r\n text: annotation.text,\r\n ...positionForRange(range),\r\n range,\r\n editingId: annotation.id,\r\n editorOpen: true,\r\n });\r\n setComment(annotation.comment || '');\r\n });\r\n return () => cancelAnimationFrame(frame);\r\n }, [editingAnnotation?.annotation.id]);\r\n\r\n useEffect(() => {\r\n const range = selectionAction?.range;\r\n if (!range) return;\r\n const updatePosition = () => {\r\n if (!range.startContainer.isConnected) {\r\n setSelectionAction(null);\r\n onDismissEdit?.();\r\n return;\r\n }\r\n const position = positionForRange(\r\n range,\r\n popoverRef.current?.offsetWidth,\r\n popoverRef.current?.offsetHeight,\r\n );\r\n setSelectionAction((current) => {\r\n if (!current || current.range !== range || (current.x === position.x && current.y === position.y)) return current;\r\n return { ...current, ...position };\r\n });\r\n };\r\n updatePosition();\r\n window.addEventListener('scroll', updatePosition, true);\r\n window.addEventListener('resize', updatePosition);\r\n const observer = new ResizeObserver(updatePosition);\r\n if (popoverRef.current) observer.observe(popoverRef.current);\r\n return () => {\r\n window.removeEventListener('scroll', updatePosition, true);\r\n window.removeEventListener('resize', updatePosition);\r\n observer.disconnect();\r\n };\r\n }, [selectionAction?.range]);\r\n\r\n const inspectSelection = () => {\r\n if (!canAnnotate || !historyRef.current) return;\r\n const selection = window.getSelection();\r\n const root = historyRef.current;\r\n if (\r\n !selection ||\r\n selection.isCollapsed ||\r\n !selection.anchorNode ||\r\n !selection.focusNode ||\r\n !root.contains(selection.anchorNode) ||\r\n !root.contains(selection.focusNode) ||\r\n selection.rangeCount === 0\r\n ) {\r\n dismissSelection();\r\n return;\r\n }\r\n const text = selection.toString().trim();\r\n if (!text) {\r\n dismissSelection();\r\n return;\r\n }\r\n const range = selection.getRangeAt(0);\r\n const sourceMessageIds = Array.from(\r\n root.querySelectorAll<HTMLElement>('[data-chat-message-id]'),\r\n )\r\n .filter((element) => range.intersectsNode(element))\r\n .map((element) => Number(element.dataset.chatMessageId))\r\n .filter(Number.isFinite);\r\n if (sourceMessageIds.length === 0) {\r\n dismissSelection();\r\n return;\r\n }\r\n const annotations = resolveAnnotations?.({\r\n selection,\r\n root,\r\n text,\r\n sourceMessageIds,\r\n });\r\n if (!annotations?.length) {\r\n dismissSelection();\r\n return;\r\n }\r\n if (editingAnnotation) onDismissEdit?.();\r\n setSelectionAction({\r\n annotations,\r\n text,\r\n ...positionForRange(range, 140, 36),\r\n range: range.cloneRange(),\r\n editorOpen: false,\r\n });\r\n setComment('');\r\n };\r\n let currentType: string = '';\r\n\r\n return (\r\n <AssistantReplyContext.Provider value={onReplyWithMessage}>\r\n <AutoscrollContainer className={className}>\r\n <Box\r\n ref={historyRef}\r\n onMouseUp={inspectSelection}\r\n onKeyUp={inspectSelection}\r\n {...getVariant('layout.common.chat.history')}\r\n className=\"chat_history\"\r\n >\r\n {messages.map((current, i) => {\r\n let first = false;\r\n let last = false;\r\n\r\n if (currentType !== current.messageType) {\r\n currentType = current.messageType;\r\n first = true;\r\n }\r\n\r\n if (\r\n i === messages.length - 1 ||\r\n messages[i + 1].messageType !== current.messageType\r\n ) {\r\n last = true;\r\n }\r\n\r\n return (\r\n <Message\r\n key={String(current.id)}\r\n className={first ? 'first' : last ? 'last' : undefined}\r\n type={current.messageType}\r\n id={String(current.id)}\r\n attachments={current.attachments}\r\n annotations={current.annotations}\r\n reference={current.reference}\r\n message={current.message}\r\n annotationMarkers={draftAnnotations.map((annotation, index) => ({ annotation, number: index + 1 }))\r\n .filter(({ annotation }) => annotation.sourceMessageIds[annotation.sourceMessageIds.length - 1] === current.id)}\r\n onEditAnnotation={onEditAnnotation}\r\n />\r\n );\r\n })}\r\n {bottomInset > 0 && (\r\n <Box\r\n aria-hidden\r\n className=\"chatHistory__bottomInset\"\r\n style={{ height: bottomInset }}\r\n />\r\n )}\r\n </Box>\r\n </AutoscrollContainer>\r\n {selectionAction && createPortal(\r\n <Box\r\n ref={popoverRef}\r\n className={`chatAnnotationPopover${selectionAction.editorOpen ? '' : ' chatAnnotationPopover--offer'}`}\r\n sx={annotationPopoverStyles}\r\n style={{ left: selectionAction.x, top: selectionAction.y }}\r\n >\r\n {!selectionAction.editorOpen ? (\r\n <button\r\n type=\"button\"\r\n className=\"chatAnnotationPopover__offer\"\r\n onMouseDown={(event) => event.preventDefault()}\r\n onClick={() => setSelectionAction((current) => current ? { ...current, editorOpen: true } : current)}\r\n >\r\n {annotationLabel('lblAiChatAddToChat', 'Anotar')}\r\n </button>\r\n ) : (\r\n <>\r\n <Box className=\"chatAnnotationPopover__preview\" title={selectionAction.text}>\r\n {selectionAction.text}\r\n </Box>\r\n <textarea\r\n autoFocus\r\n aria-label={annotationLabel('lblAiChatSelectionComment', 'Comentario sobre la cita')}\r\n className=\"chatAnnotationPopover__comment\"\r\n placeholder={annotationLabel('lblAiChatOptionalCommentPlaceholder', 'Agregá un comentario')}\r\n value={comment}\r\n onChange={(event) => setComment(event.target.value)}\r\n onKeyDown={(event) => {\r\n if (event.key === 'Escape') dismissSelection();\r\n }}\r\n />\r\n <Box className=\"chatAnnotationPopover__actions\">\r\n <button type=\"button\" onClick={dismissSelection}>{getLabel('btnCan').text}</button>\r\n <button\r\n type=\"button\"\r\n onClick={() => {\r\n if (selectionAction.editingId) {\r\n onUpdateAnnotationComment?.(selectionAction.editingId, comment);\r\n } else {\r\n onAnnotate?.(selectionAction.annotations, comment, selectionAction.range);\r\n }\r\n window.getSelection()?.removeAllRanges();\r\n dismissSelection();\r\n }}\r\n >\r\n {annotationLabel(selectionAction.editingId ? 'btnGua' : 'lblAiChatAddToChat', selectionAction.editingId ? 'Guardar' : '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AAA;AAAA,kBACP,UAAU,CAAC,KAAA,KAAU,UAAA,CAAW,KAAA,CAAM,OAAO,KAAK,CAAA;AAAA,kBAClD,SAAA,EAAW,CAAC,KAAA,KAAU;AACpB,oBAAA,IAAI,MAAM,GAAA,KAAQ,QAAA;AAAU,sBAAA,gBAAA,EAAiB;AAAA;AAC/C;AAAA,eACF;AAAA,8BACA,IAAA,CAAC,GAAA,EAAA,EAAI,SAAA,EAAU,gCAAA,EACb,QAAA,EAAA;AAAA,gCAAA,GAAA,CAAC,QAAA,EAAA,EAAO,MAAK,QAAA,EAAS,OAAA,EAAS,kBAAmB,QAAA,EAAA,QAAA,CAAS,QAAQ,EAAE,IAAA,EAAK,CAAA;AAAA,gCAC1E,GAAA;AAAA,kBAAC,QAAA;AAAA,kBAAA;AAAA,oBACC,IAAA,EAAK,QAAA;AAAA,oBACL,SAAS,MAAM;AACb,sBAAA,IAAI,gBAAgB,SAAA,EAAW;AAC7B,wBAAA,yBAAA,GAA4B,eAAA,CAAgB,WAAW,OAAO,CAAA;AAAA,uBAChE,MAAO;AACL,wBAAA,UAAA,GAAa,eAAA,CAAgB,WAAA,EAAa,OAAA,EAAS,eAAA,CAAgB,KAAK,CAAA;AAAA;AAE1E,sBAAA,MAAA,CAAO,YAAA,IAAgB,eAAA,EAAgB;AACvC,sBAAA,gBAAA,EAAiB;AAAA,qBACnB;AAAA,oBAEC,QAAA,EAAA,eAAA,CAAgB,gBAAgB,SAAA,GAAY,QAAA,GAAW,sBAAsB,eAAA,CAAgB,SAAA,GAAY,YAAY,QAAQ;AAAA;AAAA;AAChI,eAAA,EACF;AAAA,aAAA,EACE;AAAA;AAAA,SAEJ;AAAA,QACA,QAAA,CAAS;AAAA;AACX,KAAA,EACA,CAAA;AAAA;AAGN;;;;"}
@@ -2,14 +2,19 @@ import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
3
  import { TMessageType, IAttachment, TChatAnnotation } from '../types.js';
4
4
 
5
- declare const Message: (({ className, type, id, message, attachments, annotations, reference, }: {
5
+ declare const Message: (({ className, type, id, message, attachments, reference, annotations, annotationMarkers, onEditAnnotation, }: {
6
6
  className?: string;
7
7
  type: TMessageType;
8
8
  id: string;
9
9
  message: ReactNode;
10
10
  attachments: IAttachment[];
11
- annotations: TChatAnnotation[];
12
11
  reference: ReactNode;
12
+ annotations?: TChatAnnotation[];
13
+ annotationMarkers?: {
14
+ annotation: TChatAnnotation;
15
+ number: number;
16
+ }[];
17
+ onEditAnnotation?: (id: string) => void;
13
18
  }) => react.JSX.Element) & {
14
19
  displayName: string;
15
20
  };
@@ -1,9 +1,10 @@
1
1
  import { jsxs, jsx } from '@apia/theme/jsx-runtime';
2
- import { Box } from '@apia/theme';
2
+ import { Box, getVariant } from '@apia/theme';
3
3
  import { observer } from 'mobx-react-lite';
4
4
  import { Attachments } from './Attachments.js';
5
- import { hasResolvedAttachmentPlaceholder, MessageBlocks } from './MessageBlocks.js';
6
5
  import { SentAnnotations } from './SentAnnotations.js';
6
+ import { MessageBlocks } from './MessageBlocks.js';
7
+ import { AssistantMessageActions } from './AssistantMessageActions.js';
7
8
 
8
9
  const Message = observer(
9
10
  ({
@@ -12,10 +13,11 @@ const Message = observer(
12
13
  id,
13
14
  message,
14
15
  attachments,
15
- annotations,
16
- reference
16
+ reference,
17
+ annotations = [],
18
+ annotationMarkers = [],
19
+ onEditAnnotation
17
20
  }) => {
18
- const rendersAttachmentInline = typeof message === "string" && hasResolvedAttachmentPlaceholder(message, attachments);
19
21
  return /* @__PURE__ */ jsxs(Box, { as: "pre", "data-chat-message-id": id, className: `history_message ${className || ""} ${type}`, children: [
20
22
  /* @__PURE__ */ jsx(
21
23
  Box,
@@ -25,16 +27,28 @@ const Message = observer(
25
27
  children: /* @__PURE__ */ jsx(
26
28
  MessageBlocks,
27
29
  {
28
- attachments,
29
30
  streamParts: [{ blockType: "text", str: message }]
30
31
  }
31
32
  )
32
33
  } : { children: message }
33
34
  }
34
35
  ),
35
- attachments.length > 0 && !rendersAttachmentInline && /* @__PURE__ */ jsx(Attachments, { attachments }),
36
+ annotationMarkers.length > 0 && /* @__PURE__ */ jsx(Box, { className: "chatAnnotationMarkers", ...getVariant("layout.common.chat.annotationHistory"), children: annotationMarkers.map(({ annotation, number }) => /* @__PURE__ */ jsx(
37
+ "button",
38
+ {
39
+ type: "button",
40
+ className: "chatAnnotations__number",
41
+ "aria-label": `Editar anotaci\xF3n ${number}`,
42
+ title: annotation.comment || annotation.text,
43
+ onClick: () => onEditAnnotation?.(annotation.id),
44
+ children: number
45
+ },
46
+ annotation.id
47
+ )) }),
36
48
  annotations.length > 0 && /* @__PURE__ */ jsx(SentAnnotations, { annotations }),
37
- reference && /* @__PURE__ */ jsx(Box, { className: "history_message__references", children: reference })
49
+ attachments.length > 0 && /* @__PURE__ */ jsx(Attachments, { attachments }),
50
+ reference && /* @__PURE__ */ jsx(Box, { className: "history_message__references", children: reference }),
51
+ (type === "system" || type === "response") && typeof message === "string" && /* @__PURE__ */ jsx(AssistantMessageActions, { markdown: message })
38
52
  ] });
39
53
  }
40
54
  );
@@ -1 +1 @@
1
- {"version":3,"file":"Message.js","sources":["../../../../src/chat/ChatController/components/Message.tsx"],"sourcesContent":["import { Box } from '@apia/theme';\r\nimport { observer } from 'mobx-react-lite';\r\nimport { ReactNode } from 'react';\r\nimport { Attachments } from './Attachments';\r\nimport { IAttachment, TChatAnnotation, TMessageType } from '../types';\nimport {\n hasResolvedAttachmentPlaceholder,\n MessageBlocks,\n} from './MessageBlocks';\nimport { SentAnnotations } from './SentAnnotations';\r\n\r\nexport const Message = observer(\r\n ({\r\n className,\r\n type,\r\n id,\r\n message,\r\n attachments,\n annotations,\n reference,\r\n }: {\r\n className?: string;\r\n type: TMessageType;\r\n id: string;\r\n message: ReactNode;\r\n attachments: IAttachment[];\n annotations: TChatAnnotation[];\n reference: ReactNode;\r\n }) => {\r\n const rendersAttachmentInline =\r\n typeof message === 'string' &&\r\n hasResolvedAttachmentPlaceholder(message, attachments);\r\n\r\n return (\r\n <Box as=\"pre\" data-chat-message-id={id} className={`history_message ${className || ''} ${type}`}>\n <Box\r\n className=\"history_message__content\"\r\n {...(typeof message === 'string'\r\n ? {\r\n children: (\r\n <MessageBlocks\r\n attachments={attachments}\r\n streamParts={[{ blockType: 'text', str: message }]}\r\n ></MessageBlocks>\r\n ),\r\n }\r\n : { children: message as string })}\r\n />\r\n {attachments.length > 0 && !rendersAttachmentInline && (\n <Attachments attachments={attachments}></Attachments>\n )}\n {annotations.length > 0 && (\n <SentAnnotations annotations={annotations} />\r\n )}\n {reference && (\r\n <Box className=\"history_message__references\">{reference}</Box>\r\n )}\r\n </Box>\r\n );\r\n },\r\n);\r\n"],"names":[],"mappings":";;;;;;;AAWO,MAAM,OAAA,GAAU,QAAA;AAAA,EACrB,CAAC;AAAA,IACC,SAAA;AAAA,IACA,IAAA;AAAA,IACA,EAAA;AAAA,IACA,OAAA;AAAA,IACA,WAAA;AAAA,IACA,WAAA;AAAA,IACA;AAAA,GACF,KAQM;AACJ,IAAA,MAAM,0BACJ,OAAO,OAAA,KAAY,QAAA,IACnB,gCAAA,CAAiC,SAAS,WAAW,CAAA;AAEvD,IAAA,uBACE,IAAA,CAAC,GAAA,EAAA,EAAI,EAAA,EAAG,KAAA,EAAM,sBAAA,EAAsB,EAAA,EAAI,SAAA,EAAW,CAAA,gBAAA,EAAmB,SAAA,IAAa,EAAE,CAAA,CAAA,EAAI,IAAI,CAAA,CAAA,EAC3F,QAAA,EAAA;AAAA,sBAAA,GAAA;AAAA,QAAC,GAAA;AAAA,QAAA;AAAA,UACC,SAAA,EAAU,0BAAA;AAAA,UACT,GAAI,OAAO,OAAA,KAAY,QAAA,GACpB;AAAA,YACE,QAAA,kBACE,GAAA;AAAA,cAAC,aAAA;AAAA,cAAA;AAAA,gBACC,WAAA;AAAA,gBACA,aAAa,CAAC,EAAE,WAAW,MAAA,EAAQ,GAAA,EAAK,SAAS;AAAA;AAAA;AAClD,WAEL,GACA,EAAE,QAAA,EAAU,OAAA;AAAkB;AAAA,OACpC;AAAA,MACC,YAAY,MAAA,GAAS,CAAA,IAAK,CAAC,uBAAA,oBAC1B,GAAA,CAAC,eAAY,WAAA,EAA0B,CAAA;AAAA,MAExC,WAAA,CAAY,MAAA,GAAS,CAAA,oBACpB,GAAA,CAAC,mBAAgB,WAAA,EAA0B,CAAA;AAAA,MAE5C,SAAA,oBACC,GAAA,CAAC,GAAA,EAAA,EAAI,SAAA,EAAU,+BAA+B,QAAA,EAAA,SAAA,EAAU;AAAA,KAAA,EAE5D,CAAA;AAAA;AAGN;;;;"}
1
+ {"version":3,"file":"Message.js","sources":["../../../../src/chat/ChatController/components/Message.tsx"],"sourcesContent":["import { Box, getVariant } from '@apia/theme';\r\nimport { observer } from 'mobx-react-lite';\r\nimport { ReactNode } from 'react';\r\nimport { Attachments } from './Attachments';\r\nimport { IAttachment, TMessageType } from '../types';\r\nimport { SentAnnotations } from './SentAnnotations';\r\nimport type { TChatAnnotation } from '../types';\r\nimport { MessageBlocks } from './MessageBlocks';\r\nimport { AssistantMessageActions } from './AssistantMessageActions';\r\n\r\nexport const Message = observer(\r\n ({\r\n className,\r\n type,\r\n id,\r\n message,\r\n attachments,\r\n reference,\r\n annotations = [],\r\n annotationMarkers = [],\r\n onEditAnnotation,\r\n }: {\r\n className?: string;\r\n type: TMessageType;\r\n id: string;\r\n message: ReactNode;\r\n attachments: IAttachment[];\r\n reference: ReactNode;\r\n annotations?: TChatAnnotation[];\r\n annotationMarkers?: { annotation: TChatAnnotation; number: number }[];\r\n onEditAnnotation?: (id: string) => void;\r\n }) => {\r\n return (\r\n <Box as=\"pre\" data-chat-message-id={id} className={`history_message ${className || ''} ${type}`}>\r\n <Box\r\n className=\"history_message__content\"\r\n {...(typeof message === 'string'\r\n ? {\r\n children: (\r\n <MessageBlocks\r\n streamParts={[{ blockType: 'text', str: message }]}\r\n ></MessageBlocks>\r\n ),\r\n }\r\n : { children: message as string })}\r\n />\r\n {annotationMarkers.length > 0 && <Box className=\"chatAnnotationMarkers\" {...getVariant('layout.common.chat.annotationHistory')}>\r\n {annotationMarkers.map(({ annotation, number }) => <button key={annotation.id} type=\"button\"\r\n className=\"chatAnnotations__number\" aria-label={`Editar anotación ${number}`}\r\n title={annotation.comment || annotation.text}\r\n onClick={() => onEditAnnotation?.(annotation.id)}>{number}</button>)}\r\n </Box>}\r\n {annotations.length > 0 && <SentAnnotations annotations={annotations} />}\r\n {attachments.length > 0 && (\r\n <Attachments attachments={attachments}></Attachments>\r\n )}\r\n {reference && (\r\n <Box className=\"history_message__references\">{reference}</Box>\r\n )}\r\n {(type === 'system' || type === 'response') && typeof message === 'string' && (\r\n <AssistantMessageActions markdown={message} />\r\n )}\r\n </Box>\r\n );\r\n },\r\n);\r\n"],"names":[],"mappings":";;;;;;;;AAUO,MAAM,OAAA,GAAU,QAAA;AAAA,EACrB,CAAC;AAAA,IACC,SAAA;AAAA,IACA,IAAA;AAAA,IACA,EAAA;AAAA,IACA,OAAA;AAAA,IACA,WAAA;AAAA,IACA,SAAA;AAAA,IACA,cAAc,EAAC;AAAA,IACf,oBAAoB,EAAC;AAAA,IACrB;AAAA,GACF,KAUM;AACJ,IAAA,uBACE,IAAA,CAAC,GAAA,EAAA,EAAI,EAAA,EAAG,KAAA,EAAM,sBAAA,EAAsB,EAAA,EAAI,SAAA,EAAW,CAAA,gBAAA,EAAmB,SAAA,IAAa,EAAE,CAAA,CAAA,EAAI,IAAI,CAAA,CAAA,EAC3F,QAAA,EAAA;AAAA,sBAAA,GAAA;AAAA,QAAC,GAAA;AAAA,QAAA;AAAA,UACC,SAAA,EAAU,0BAAA;AAAA,UACT,GAAI,OAAO,OAAA,KAAY,QAAA,GACpB;AAAA,YACE,QAAA,kBACE,GAAA;AAAA,cAAC,aAAA;AAAA,cAAA;AAAA,gBACC,aAAa,CAAC,EAAE,WAAW,MAAA,EAAQ,GAAA,EAAK,SAAS;AAAA;AAAA;AAClD,WAEL,GACA,EAAE,QAAA,EAAU,OAAA;AAAkB;AAAA,OACpC;AAAA,MACC,kBAAkB,MAAA,GAAS,CAAA,oBAAK,GAAA,CAAC,GAAA,EAAA,EAAI,WAAU,uBAAA,EAAyB,GAAG,UAAA,CAAW,sCAAsC,GAC1H,QAAA,EAAA,iBAAA,CAAkB,GAAA,CAAI,CAAC,EAAE,UAAA,EAAY,QAAO,qBAAM,GAAA;AAAA,QAAC,QAAA;AAAA,QAAA;AAAA,UAA2B,IAAA,EAAK,QAAA;AAAA,UAClF,SAAA,EAAU,yBAAA;AAAA,UAA0B,YAAA,EAAY,uBAAoB,MAAM,CAAA,CAAA;AAAA,UAC1E,KAAA,EAAO,UAAA,CAAW,OAAA,IAAW,UAAA,CAAW,IAAA;AAAA,UACxC,OAAA,EAAS,MAAM,gBAAA,GAAmB,UAAA,CAAW,EAAE,CAAA;AAAA,UAAI,QAAA,EAAA;AAAA,SAAA;AAAA,QAHW,UAAA,CAAW;AAAA,OAGN,CAAA,EACvE,CAAA;AAAA,MACC,WAAA,CAAY,MAAA,GAAS,CAAA,oBAAK,GAAA,CAAC,mBAAgB,WAAA,EAA0B,CAAA;AAAA,MACrE,WAAA,CAAY,MAAA,GAAS,CAAA,oBACpB,GAAA,CAAC,eAAY,WAAA,EAA0B,CAAA;AAAA,MAExC,SAAA,oBACC,GAAA,CAAC,GAAA,EAAA,EAAI,SAAA,EAAU,+BAA+B,QAAA,EAAA,SAAA,EAAU,CAAA;AAAA,MAAA,CAExD,IAAA,KAAS,QAAA,IAAY,IAAA,KAAS,UAAA,KAAe,OAAO,YAAY,QAAA,oBAChE,GAAA,CAAC,uBAAA,EAAA,EAAwB,QAAA,EAAU,OAAA,EAAS;AAAA,KAAA,EAEhD,CAAA;AAAA;AAGN;;;;"}
@@ -1,8 +1,6 @@
1
1
  import * as react from 'react';
2
- import { IAttachment } from '../types.js';
3
2
  import { TDescriberBlock, TQuestionBlock } from '../StreamMessage.js';
4
3
 
5
- declare function hasResolvedAttachmentPlaceholder(text: string, attachments: IAttachment[]): boolean;
6
4
  type TBlockType = 'text' | 'describer' | 'question';
7
5
  type TBaseStreamBlock<T extends TBlockType = TBlockType> = {
8
6
  blockType: T;
@@ -17,13 +15,12 @@ type TQuestionStreamBlock = TBaseStreamBlock<'question'> & {
17
15
  question: TQuestionBlock;
18
16
  };
19
17
  type TStreamBlock = TTextStreamBlock | TDescriberStreamBlock | TQuestionStreamBlock;
20
- declare const MessageBlocks: (({ attachments, streamParts, showThinkingSkeleton, }: {
21
- attachments?: IAttachment[];
18
+ declare const MessageBlocks: (({ streamParts, showThinkingSkeleton, }: {
22
19
  streamParts: TStreamBlock[];
23
20
  showThinkingSkeleton?: boolean;
24
21
  }) => react.JSX.Element[]) & {
25
22
  displayName: string;
26
23
  };
27
24
 
28
- export { MessageBlocks, type TBaseStreamBlock, type TBlockType, type TDescriberStreamBlock, type TQuestionStreamBlock, type TStreamBlock, type TTextStreamBlock, hasResolvedAttachmentPlaceholder };
25
+ export { MessageBlocks, type TBaseStreamBlock, type TBlockType, type TDescriberStreamBlock, type TQuestionStreamBlock, type TStreamBlock, type TTextStreamBlock };
29
26
  //# sourceMappingURL=MessageBlocks.d.ts.map
@@ -6,53 +6,9 @@ import { Box } from '@apia/theme';
6
6
  import { observer } from 'mobx-react-lite';
7
7
  import { ThinkingBlocks } from './ThinkingBlocks.js';
8
8
  import { QuestionBlocks } from './QuestionBlocks.js';
9
- import { FileAttachment } from './FileAttachment.js';
10
9
 
11
- const ATTACHMENT_PLACEHOLDER_PATTERN = /\[\[attachment:([^\r\n]+?)\]\]/g;
12
- function resolveAttachment(reference, attachments) {
13
- const normalizedReference = reference.trim();
14
- return attachments.find(
15
- (attachment) => attachment.id === normalizedReference || attachment.name === normalizedReference
16
- );
17
- }
18
- function hasResolvedAttachmentPlaceholder(text, attachments) {
19
- ATTACHMENT_PLACEHOLDER_PATTERN.lastIndex = 0;
20
- let match;
21
- while (match = ATTACHMENT_PLACEHOLDER_PATTERN.exec(text)) {
22
- if (resolveAttachment(match[1], attachments)) {
23
- return true;
24
- }
25
- }
26
- return false;
27
- }
28
- function renderTextWithAttachments(text, attachments, keyPrefix) {
29
- return text.split(/(\[\[attachment:[^\r\n]+?\]\])/g).map((chunk, chunkIndex) => {
30
- const match = chunk.match(/^\[\[attachment:([^\r\n]+?)\]\]$/);
31
- if (!match) {
32
- return /* @__PURE__ */ jsx(MDRenderer, { str: chunk }, `${keyPrefix}_${chunkIndex}`);
33
- }
34
- const attachment = resolveAttachment(match[1], attachments);
35
- if (!attachment) {
36
- return /* @__PURE__ */ jsx(
37
- MDRenderer,
38
- {
39
- str: match[1].trim()
40
- },
41
- `${keyPrefix}_${chunkIndex}`
42
- );
43
- }
44
- return /* @__PURE__ */ jsx(
45
- FileAttachment,
46
- {
47
- attachment
48
- },
49
- `${keyPrefix}_${chunkIndex}`
50
- );
51
- });
52
- }
53
10
  const MessageBlocks = observer(
54
11
  ({
55
- attachments = [],
56
12
  streamParts,
57
13
  showThinkingSkeleton = true
58
14
  }) => {
@@ -113,9 +69,11 @@ const MessageBlocks = observer(
113
69
  `text_content_${groupIndex}_${blockIndex}_${chunkIndex}`
114
70
  );
115
71
  }
116
- return renderTextWithAttachments(
117
- chunk,
118
- attachments,
72
+ return /* @__PURE__ */ jsx(
73
+ MDRenderer,
74
+ {
75
+ str: chunk
76
+ },
119
77
  `text_content_${groupIndex}_${blockIndex}_${chunkIndex}`
120
78
  );
121
79
  });
@@ -125,5 +83,5 @@ const MessageBlocks = observer(
125
83
  }
126
84
  );
127
85
 
128
- export { MessageBlocks, hasResolvedAttachmentPlaceholder };
86
+ export { MessageBlocks };
129
87
  //# sourceMappingURL=MessageBlocks.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"MessageBlocks.js","sources":["../../../../src/chat/ChatController/components/MessageBlocks.tsx"],"sourcesContent":["import { decodeBase64ToUtf8 } from '@apia/util';\r\nimport type { IAttachment, TComponentRender } from '../types';\r\nimport { MessageBlock } from './MessageBlock';\r\nimport { MDRenderer } from '@apia/components';\r\nimport { Box } from '@apia/theme';\r\nimport { TDescriberBlock, TQuestionBlock } from '../StreamMessage';\r\nimport { observer } from 'mobx-react-lite';\r\nimport { ThinkingBlocks } from './ThinkingBlocks';\r\nimport { QuestionBlocks } from './QuestionBlocks';\r\nimport { FileAttachment } from './FileAttachment';\r\n\r\nconst ATTACHMENT_PLACEHOLDER_PATTERN =\r\n /\\[\\[attachment:([^\\r\\n]+?)\\]\\]/g;\r\n\r\nfunction resolveAttachment(\r\n reference: string,\r\n attachments: IAttachment[],\r\n) {\r\n const normalizedReference = reference.trim();\r\n return attachments.find(\r\n (attachment) =>\r\n attachment.id === normalizedReference ||\r\n attachment.name === normalizedReference,\r\n );\r\n}\r\n\r\nexport function hasResolvedAttachmentPlaceholder(\r\n text: string,\r\n attachments: IAttachment[],\r\n) {\r\n ATTACHMENT_PLACEHOLDER_PATTERN.lastIndex = 0;\r\n let match: RegExpExecArray | null;\r\n while ((match = ATTACHMENT_PLACEHOLDER_PATTERN.exec(text))) {\r\n if (resolveAttachment(match[1], attachments)) {\r\n return true;\r\n }\r\n }\r\n return false;\r\n}\r\n\r\nfunction renderTextWithAttachments(\r\n text: string,\r\n attachments: IAttachment[],\r\n keyPrefix: string,\r\n) {\r\n return text\r\n .split(/(\\[\\[attachment:[^\\r\\n]+?\\]\\])/g)\r\n .map((chunk, chunkIndex) => {\r\n const match = chunk.match(/^\\[\\[attachment:([^\\r\\n]+?)\\]\\]$/);\r\n if (!match) {\r\n return <MDRenderer str={chunk} key={`${keyPrefix}_${chunkIndex}`} />;\r\n }\r\n\r\n const attachment = resolveAttachment(match[1], attachments);\r\n if (!attachment) {\r\n return (\r\n <MDRenderer\r\n str={match[1].trim()}\r\n key={`${keyPrefix}_${chunkIndex}`}\r\n />\r\n );\r\n }\r\n\r\n return (\r\n <FileAttachment\r\n attachment={attachment}\r\n key={`${keyPrefix}_${chunkIndex}`}\r\n />\r\n );\r\n });\r\n}\r\n\r\nexport type TBlockType = 'text' | 'describer' | 'question';\r\n\r\nexport type TBaseStreamBlock<T extends TBlockType = TBlockType> = {\r\n blockType: T;\r\n};\r\n\r\nexport type TTextStreamBlock = TBaseStreamBlock<'text'> & { str: string };\r\nexport type TDescriberStreamBlock = TBaseStreamBlock<'describer'> & {\r\n describer: TDescriberBlock;\r\n};\r\nexport type TQuestionStreamBlock = TBaseStreamBlock<'question'> & {\r\n question: TQuestionBlock;\r\n};\r\n\r\nexport type TStreamBlock =\r\n | TTextStreamBlock\r\n | TDescriberStreamBlock\r\n | TQuestionStreamBlock;\r\n\r\ntype TGroupedStreamBlock = {\r\n blockType: TBlockType;\r\n blocks: TStreamBlock[];\r\n};\r\n\r\nexport const MessageBlocks = observer(\r\n ({\r\n attachments = [],\r\n streamParts,\r\n showThinkingSkeleton = true,\r\n }: {\r\n attachments?: IAttachment[];\r\n streamParts: TStreamBlock[];\r\n showThinkingSkeleton?: boolean;\r\n }) => {\r\n const groupedParts = streamParts.reduce<TGroupedStreamBlock[]>(\r\n (groups, part) => {\r\n const currentGroup = groups[groups.length - 1];\r\n\r\n if (!currentGroup || currentGroup.blockType !== part.blockType) {\r\n groups.push({\r\n blockType: part.blockType,\r\n blocks: [part],\r\n });\r\n return groups;\r\n }\r\n\r\n currentGroup.blocks.push(part);\r\n return groups;\r\n },\r\n [],\r\n );\r\n\r\n const parts = groupedParts.map((group, groupIndex) => {\r\n const isLastGroup = !groupedParts[groupIndex + 1];\r\n\r\n if (group.blockType === 'describer') {\r\n return (\r\n <ThinkingBlocks\r\n key={`tool_calls_${groupIndex}`}\r\n blocks={group.blocks as TDescriberStreamBlock[]}\r\n groupIndex={groupIndex}\r\n isThinking={showThinkingSkeleton && isLastGroup}\r\n />\r\n );\r\n }\r\n\r\n if (group.blockType === 'question') {\r\n return (\r\n <QuestionBlocks\r\n key={`question_content_${groupIndex}`}\r\n blocks={group.blocks as TQuestionStreamBlock[]}\r\n />\r\n );\r\n }\r\n\r\n return (\r\n <Box className=\"text__content\" key={`text_content_${groupIndex}`}>\r\n {group.blocks.flatMap((block, blockIndex) => {\r\n const textBlock = block as TTextStreamBlock;\r\n\r\n return textBlock.str\r\n .split(/(!!\\[[^]+])/g)\r\n .map((chunk, chunkIndex) => {\r\n if (chunk.match(/^!!\\[[^]+]$/)) {\r\n const definition = JSON.parse(\r\n decodeBase64ToUtf8(\r\n (chunk.match(/^!!\\[([^]+)]$/) ?? [\r\n undefined,\r\n undefined,\r\n ])[1] ?? '',\r\n ),\r\n ) as TComponentRender;\r\n\r\n return (\r\n <MessageBlock\r\n key={`text_content_${groupIndex}_${blockIndex}_${chunkIndex}`}\r\n componentData={definition}\r\n ></MessageBlock>\r\n );\r\n }\r\n\r\n return renderTextWithAttachments(\r\n chunk,\r\n attachments,\r\n `text_content_${groupIndex}_${blockIndex}_${chunkIndex}`,\r\n );\r\n });\r\n })}\r\n </Box>\r\n );\r\n });\r\n\r\n return parts;\r\n },\r\n);\r\n"],"names":[],"mappings":";;;;;;;;;;AAWA,MAAM,8BAAA,GACJ,iCAAA;AAEF,SAAS,iBAAA,CACP,WACA,WAAA,EACA;AACA,EAAA,MAAM,mBAAA,GAAsB,UAAU,IAAA,EAAK;AAC3C,EAAA,OAAO,WAAA,CAAY,IAAA;AAAA,IACjB,CAAC,UAAA,KACC,UAAA,CAAW,EAAA,KAAO,mBAAA,IAClB,WAAW,IAAA,KAAS;AAAA,GACxB;AACF;AAEO,SAAS,gCAAA,CACd,MACA,WAAA,EACA;AACA,EAAA,8BAAA,CAA+B,SAAA,GAAY,CAAA;AAC3C,EAAA,IAAI,KAAA;AACJ,EAAA,OAAQ,KAAA,GAAQ,8BAAA,CAA+B,IAAA,CAAK,IAAI,CAAA,EAAI;AAC1D,IAAA,IAAI,iBAAA,CAAkB,KAAA,CAAM,CAAC,CAAA,EAAG,WAAW,CAAA,EAAG;AAC5C,MAAA,OAAO,IAAA;AAAA;AACT;AAEF,EAAA,OAAO,KAAA;AACT;AAEA,SAAS,yBAAA,CACP,IAAA,EACA,WAAA,EACA,SAAA,EACA;AACA,E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AAM,eAAe,CAAA,IAAK;AAAA,kBAC/B,MAAA;AAAA,kBACA;AAAA,iBACF,EAAG,CAAC,CAAA,IAAK;AAAA;AACX,aACF;AAEA,YAAA,uBACE,GAAA;AAAA,cAAC,YAAA;AAAA,cAAA;AAAA,gBAEC,aAAA,EAAe;AAAA,eAAA;AAAA,cADV,CAAA,aAAA,EAAgB,UAAU,CAAA,CAAA,EAAI,UAAU,IAAI,UAAU,CAAA;AAAA,aAE5D;AAAA;AAIL,UAAA,OAAO,yBAAA;AAAA,YACL,KAAA;AAAA,YACA,WAAA;AAAA,YACA,CAAA,aAAA,EAAgB,UAAU,CAAA,CAAA,EAAI,UAAU,IAAI,UAAU,CAAA;AAAA,WACxD;AAAA,SACD,CAAA;AAAA,OACJ,CAAA,EAAA,EA/BiC,CAAA,aAAA,EAAgB,UAAU,CAAA,CAgC9D,CAAA;AAAA,KAEH,CAAA;AAED,IAAA,OAAO,KAAA;AAAA;AAEX;;;;"}
1
+ {"version":3,"file":"MessageBlocks.js","sources":["../../../../src/chat/ChatController/components/MessageBlocks.tsx"],"sourcesContent":["import { decodeBase64ToUtf8 } from '@apia/util';\r\nimport { TComponentRender } from '../types';\r\nimport { MessageBlock } from './MessageBlock';\r\nimport { MDRenderer } from '@apia/components';\r\nimport { Box } from '@apia/theme';\r\nimport { TDescriberBlock, TQuestionBlock } from '../StreamMessage';\r\nimport { observer } from 'mobx-react-lite';\r\nimport { ThinkingBlocks } from './ThinkingBlocks';\r\nimport { QuestionBlocks } from './QuestionBlocks';\r\n\r\nexport type TBlockType = 'text' | 'describer' | 'question';\r\n\r\nexport type TBaseStreamBlock<T extends TBlockType = TBlockType> = {\r\n blockType: T;\r\n};\r\n\r\nexport type TTextStreamBlock = TBaseStreamBlock<'text'> & { str: string };\r\nexport type TDescriberStreamBlock = TBaseStreamBlock<'describer'> & {\r\n describer: TDescriberBlock;\r\n};\r\nexport type TQuestionStreamBlock = TBaseStreamBlock<'question'> & {\r\n question: TQuestionBlock;\r\n};\r\n\r\nexport type TStreamBlock =\r\n | TTextStreamBlock\r\n | TDescriberStreamBlock\r\n | TQuestionStreamBlock;\r\n\r\ntype TGroupedStreamBlock = {\r\n blockType: TBlockType;\r\n blocks: TStreamBlock[];\r\n};\r\n\r\nexport const MessageBlocks = observer(\r\n ({\r\n streamParts,\r\n showThinkingSkeleton = true,\r\n }: {\r\n streamParts: TStreamBlock[];\r\n showThinkingSkeleton?: boolean;\r\n }) => {\r\n const groupedParts = streamParts.reduce<TGroupedStreamBlock[]>(\r\n (groups, part) => {\r\n const currentGroup = groups[groups.length - 1];\r\n\r\n if (!currentGroup || currentGroup.blockType !== part.blockType) {\r\n groups.push({\r\n blockType: part.blockType,\r\n blocks: [part],\r\n });\r\n return groups;\r\n }\r\n\r\n currentGroup.blocks.push(part);\r\n return groups;\r\n },\r\n [],\r\n );\r\n\r\n const parts = groupedParts.map((group, groupIndex) => {\r\n const isLastGroup = !groupedParts[groupIndex + 1];\r\n\r\n if (group.blockType === 'describer') {\r\n return (\r\n <ThinkingBlocks\r\n key={`tool_calls_${groupIndex}`}\r\n blocks={group.blocks as TDescriberStreamBlock[]}\r\n groupIndex={groupIndex}\r\n isThinking={showThinkingSkeleton && isLastGroup}\r\n />\r\n );\r\n }\r\n\r\n if (group.blockType === 'question') {\r\n return (\r\n <QuestionBlocks\r\n key={`question_content_${groupIndex}`}\r\n blocks={group.blocks as TQuestionStreamBlock[]}\r\n />\r\n );\r\n }\r\n\r\n return (\r\n <Box className=\"text__content\" key={`text_content_${groupIndex}`}>\r\n {group.blocks.flatMap((block, blockIndex) => {\r\n const textBlock = block as TTextStreamBlock;\r\n\r\n return textBlock.str\r\n .split(/(!!\\[[^]+])/g)\r\n .map((chunk, chunkIndex) => {\r\n if (chunk.match(/^!!\\[[^]+]$/)) {\r\n const definition = JSON.parse(\r\n decodeBase64ToUtf8(\r\n (chunk.match(/^!!\\[([^]+)]$/) ?? [\r\n undefined,\r\n undefined,\r\n ])[1] ?? '',\r\n ),\r\n ) as TComponentRender;\r\n\r\n return (\r\n <MessageBlock\r\n key={`text_content_${groupIndex}_${blockIndex}_${chunkIndex}`}\r\n componentData={definition}\r\n ></MessageBlock>\r\n );\r\n }\r\n\r\n return (\r\n <MDRenderer\r\n str={chunk}\r\n key={`text_content_${groupIndex}_${blockIndex}_${chunkIndex}`}\r\n ></MDRenderer>\r\n );\r\n });\r\n })}\r\n </Box>\r\n );\r\n });\r\n\r\n return parts;\r\n },\r\n);\r\n"],"names":[],"mappings":";;;;;;;;;AAkCO,MAAM,aAAA,GAAgB,QAAA;AAAA,EAC3B,CAAC;AAAA,IACC,WAAA;AAAA,IACA,oBAAA,GAAuB;AAAA,GACzB,KAGM;AACJ,IAAA,MAAM,eAAe,WAAA,CAAY,MAAA;AAAA,MAC/B,CAAC,QAAQ,IAAA,KAAS;AAChB,QAAA,MAAM,YAAA,GAAe,MAAA,CAAO,MAAA,CAAO,MAAA,GAAS,CAAC,CAAA;AAE7C,QAAA,IAAI,CAAC,YAAA,IAAgB,YAAA,CAAa,SAAA,KAAc,KAAK,SAAA,EAAW;AAC9D,UAAA,MAAA,CAAO,IAAA,CAAK;AAAA,YACV,WAAW,IAAA,CAAK,SAAA;AAAA,YAChB,MAAA,EAAQ,CAAC,IAAI;AAAA,WACd,CAAA;AACD,UAAA,OAAO,MAAA;AAAA;AAGT,QAAA,YAAA,CAAa,MAAA,CAAO,KAAK,IAAI,CAAA;AAC7B,QAAA,OAAO,MAAA;AAAA,OACT;AAAA,MACA;AAAC,KACH;AAEA,IAAA,MAAM,KAAA,GAAQ,YAAA,CAAa,GAAA,CAAI,CAAC,OAAO,UAAA,KAAe;AACpD,MAAA,MAAM,WAAA,GAAc,CAAC,YAAA,CAAa,UAAA,GAAa,CAAC,CAAA;AAEhD,MAAA,IAAI,KAAA,CAAM,cAAc,WAAA,EAAa;AACnC,QAAA,uBACE,GAAA;AAAA,UAAC,cAAA;AAAA,UAAA;AAAA,YAEC,QAAQ,KAAA,CAAM,MAAA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,CAAA,EAAA,EAhCiC,CAAA,aAAA,EAAgB,UAAU,CAAA,CAiC9D,CAAA;AAAA,KAEH,CAAA;AAED,IAAA,OAAO,KAAA;AAAA;AAEX;;;;"}
@@ -5,6 +5,7 @@ import { Box } from '@apia/theme';
5
5
  import { Ellipsis } from './Ellipsis.js';
6
6
  import { MessageBlocks } from './MessageBlocks.js';
7
7
  import { IconButton, MDRenderer } from '@apia/components';
8
+ import { AssistantMessageActions } from './AssistantMessageActions.js';
8
9
 
9
10
  const MessageBody = observer(
10
11
  ({
@@ -12,7 +13,8 @@ const MessageBody = observer(
12
13
  store
13
14
  }) => {
14
15
  const [thumb, setThumb] = useState(void 0);
15
- const hasText = (store.blocks.find((x) => x.blockType === "text")?.str ?? "").length > 0;
16
+ const textBlocks = store.blocks.filter((block) => block.blockType === "text");
17
+ const hasText = textBlocks.some((block) => block.str.length > 0);
16
18
  return /* @__PURE__ */ jsxs(Box, { className: "ai__message__system_message", children: [
17
19
  /* @__PURE__ */ jsxs(Fragment, { children: [
18
20
  /* @__PURE__ */ jsx(Box, { className: "message__body markdown", children: /* @__PURE__ */ jsx(
@@ -26,7 +28,7 @@ const MessageBody = observer(
26
28
  str: store.messageHeader
27
29
  }
28
30
  ] : [],
29
- ...store.blocks.filter((x) => x.blockType === "text")
31
+ ...textBlocks
30
32
  ],
31
33
  showThinkingSkeleton: !hasText
32
34
  }
@@ -69,7 +71,12 @@ const MessageBody = observer(
69
71
  ] }) : /* @__PURE__ */ jsx(Fragment, {})
70
72
  ] }),
71
73
  !hasText && /* @__PURE__ */ jsx(Ellipsis, {}),
72
- store.messageFooter && store.finished && /* @__PURE__ */ jsx(Box, { className: "message__body markdown", children: /* @__PURE__ */ jsx(MDRenderer, { str: store.messageFooter }) })
74
+ store.messageFooter && store.finished && /* @__PURE__ */ jsx(Box, { className: "message__body markdown", children: /* @__PURE__ */ jsx(MDRenderer, { str: store.messageFooter }) }),
75
+ store.finished && hasText && /* @__PURE__ */ jsx(AssistantMessageActions, { markdown: [
76
+ store.messageHeader,
77
+ ...textBlocks.map((block) => block.str),
78
+ store.messageFooter
79
+ ].filter(Boolean).join("\n\n") })
73
80
  ] });
74
81
  }
75
82
  );