@aleph-alpha/chat-kit 3.2.0 → 3.3.0

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 (87) hide show
  1. package/dist/{CkInput.vue_vue_type_script_setup_true_lang-B-4xnH2c.js → CkInput.vue_vue_type_script_setup_true_lang-BAcBFs6I.js} +302 -71
  2. package/dist/chat-kit.css +6 -0
  3. package/dist/components/base/CkAgentMessage/CkAgentMessage.stories.d.ts +7 -0
  4. package/dist/components/base/CkAgentMessage/CkAgentMessage.stories.d.ts.map +1 -1
  5. package/dist/components/base/CkCitation/CkCitation.stories.d.ts +47 -0
  6. package/dist/components/base/CkCitation/CkCitation.stories.d.ts.map +1 -0
  7. package/dist/components/base/CkCitation/CkCitation.vue.d.ts +15 -0
  8. package/dist/components/base/CkCitation/CkCitation.vue.d.ts.map +1 -0
  9. package/dist/components/base/CkCitation/index.d.ts +3 -0
  10. package/dist/components/base/CkCitation/index.d.ts.map +1 -0
  11. package/dist/components/base/CkCitation/types.d.ts +79 -0
  12. package/dist/components/base/CkCitation/types.d.ts.map +1 -0
  13. package/dist/components/base/CkCitationCard/CkCitationCard.stories.d.ts +51 -0
  14. package/dist/components/base/CkCitationCard/CkCitationCard.stories.d.ts.map +1 -0
  15. package/dist/components/base/CkCitationCard/CkCitationCard.vue.d.ts +13 -0
  16. package/dist/components/base/CkCitationCard/CkCitationCard.vue.d.ts.map +1 -0
  17. package/dist/components/base/CkCitationCard/index.d.ts +3 -0
  18. package/dist/components/base/CkCitationCard/index.d.ts.map +1 -0
  19. package/dist/components/base/CkCitationCard/types.d.ts +51 -0
  20. package/dist/components/base/CkCitationCard/types.d.ts.map +1 -0
  21. package/dist/components/base/CkDropZoneOverlay/CkDropZoneOverlay.vue.d.ts +1 -1
  22. package/dist/components/base/CkFeedbackDialog/CkFeedbackDialog.vue.d.ts +2 -2
  23. package/dist/components/base/CkFileItemsList/CkFileItemsList.vue.d.ts +1 -1
  24. package/dist/components/base/CkMarkdownRenderer/CkMarkdownRenderer.stories.d.ts +15 -0
  25. package/dist/components/base/CkMarkdownRenderer/CkMarkdownRenderer.stories.d.ts.map +1 -1
  26. package/dist/components/base/CkMarkdownRenderer/CkMarkdownRenderer.vue.d.ts +16 -2
  27. package/dist/components/base/CkMarkdownRenderer/CkMarkdownRenderer.vue.d.ts.map +1 -1
  28. package/dist/components/base/CkMarkdownRenderer/index.d.ts +1 -1
  29. package/dist/components/base/CkMarkdownRenderer/index.d.ts.map +1 -1
  30. package/dist/components/base/CkMarkdownRenderer/types.d.ts +25 -0
  31. package/dist/components/base/CkMarkdownRenderer/types.d.ts.map +1 -1
  32. package/dist/components/base/CkMarkdownRenderer/useCitationRendering.d.ts +17 -0
  33. package/dist/components/base/CkMarkdownRenderer/useCitationRendering.d.ts.map +1 -0
  34. package/dist/components/base/CkPromptSendButton/CkPromptSendButton.vue.d.ts +1 -1
  35. package/dist/components/base/index.d.ts +5 -1
  36. package/dist/components/base/index.d.ts.map +1 -1
  37. package/dist/components/composed/CkInput/CkInput.vue.d.ts +1 -1
  38. package/dist/components/index.d.ts +2 -2
  39. package/dist/components/index.d.ts.map +1 -1
  40. package/dist/components/index.js +25 -23
  41. package/dist/composables/fileUpload/useFileUpload.d.ts.map +1 -1
  42. package/dist/composables/fileUpload/useFileUploadWrapper.d.ts.map +1 -1
  43. package/dist/composables/index.js +1 -1
  44. package/dist/handlers/index.d.ts +2 -0
  45. package/dist/handlers/index.d.ts.map +1 -1
  46. package/dist/handlers/index.js +3 -2
  47. package/dist/handlers/useChatKitLabels.d.ts +11 -0
  48. package/dist/handlers/useChatKitLabels.d.ts.map +1 -1
  49. package/dist/handlers/useMarkdownParser.d.ts.map +1 -1
  50. package/dist/helpers/unified/remarkCitations.d.ts +17 -0
  51. package/dist/helpers/unified/remarkCitations.d.ts.map +1 -0
  52. package/dist/{index-DAmWGYNH.js → index-C6njJ8EB.js} +85 -70
  53. package/dist/index.d.ts +2 -2
  54. package/dist/index.d.ts.map +1 -1
  55. package/dist/index.js +28 -26
  56. package/dist/{useChatKitLabels-D5gNv8se.js → useChatKitLabels-BM2I7-9o.js} +30 -3
  57. package/package.json +4 -2
  58. package/src/components/base/CkAgentMessage/CkAgentMessage.stories.ts +112 -0
  59. package/src/components/base/CkCitation/CkCitation.spec.ts +79 -0
  60. package/src/components/base/CkCitation/CkCitation.stories.ts +136 -0
  61. package/src/components/base/CkCitation/CkCitation.vue +145 -0
  62. package/src/components/base/CkCitation/index.ts +2 -0
  63. package/src/components/base/CkCitation/types.ts +80 -0
  64. package/src/components/base/CkCitationCard/CkCitationCard.spec.ts +77 -0
  65. package/src/components/base/CkCitationCard/CkCitationCard.stories.ts +144 -0
  66. package/src/components/base/CkCitationCard/CkCitationCard.vue +76 -0
  67. package/src/components/base/CkCitationCard/index.ts +2 -0
  68. package/src/components/base/CkCitationCard/types.ts +51 -0
  69. package/src/components/base/CkMarkdownRenderer/CkMarkdownRenderer.spec.ts +124 -0
  70. package/src/components/base/CkMarkdownRenderer/CkMarkdownRenderer.stories.ts +118 -0
  71. package/src/components/base/CkMarkdownRenderer/CkMarkdownRenderer.vue +70 -28
  72. package/src/components/base/CkMarkdownRenderer/index.ts +1 -0
  73. package/src/components/base/CkMarkdownRenderer/types.ts +26 -0
  74. package/src/components/base/CkMarkdownRenderer/useCitationRendering.spec.ts +94 -0
  75. package/src/components/base/CkMarkdownRenderer/useCitationRendering.ts +52 -0
  76. package/src/components/base/index.ts +12 -0
  77. package/src/components/index.ts +8 -0
  78. package/src/composables/fileUpload/useFileUpload.spec.ts +2 -61
  79. package/src/composables/fileUpload/useFileUpload.ts +2 -9
  80. package/src/composables/fileUpload/useFileUploadWrapper.spec.ts +195 -14
  81. package/src/composables/fileUpload/useFileUploadWrapper.ts +114 -81
  82. package/src/handlers/index.ts +2 -0
  83. package/src/handlers/useChatKitLabels.ts +13 -0
  84. package/src/handlers/useMarkdownParser.ts +5 -2
  85. package/src/helpers/unified/remarkCitations.spec.ts +112 -0
  86. package/src/helpers/unified/remarkCitations.ts +55 -0
  87. package/src/index.ts +8 -0
@@ -1,6 +1,6 @@
1
- import { defineComponent, openBlock, createBlock, unref, createElementBlock, createElementVNode, renderSlot, createCommentVNode, ref, onMounted, nextTick, onUnmounted, watch, Fragment, renderList, normalizeStyle, mergeProps, withCtx, createVNode, Transition, toDisplayString, createStaticVNode, computed, onBeforeUnmount, Teleport, withModifiers, normalizeClass, toRefs, h, useId, createTextVNode, useAttrs, useSlots, resolveDynamicComponent, useTemplateRef, onUpdated, createSlots, normalizeProps, guardReactiveProps } from "vue";
2
- import { UiIcon, UiButton, UiTooltip, formatFileSize, UiDialog, UiDialogContent, UiDialogDescription, UiFieldLabel, UiToggleGroup, UiToggleGroupItem, UiField, UiTextarea, UiFileItem, UiPopover, UiPopoverTrigger, UiFileType, UiProgress, UiPopoverContent, Primitive, UiAvatar, UiAvatarImage, UiSpinner, UiAvatarFallback, UiSidebarPopoverMenu, UiSidebarPopoverMenuItem } from "@aleph-alpha/ui-library";
3
- import { u as useChatKitLabels, d as defaultChatKitLabels, a as useMarkdownParser } from "./useChatKitLabels-D5gNv8se.js";
1
+ import { defineComponent, openBlock, createBlock, unref, createElementBlock, createElementVNode, renderSlot, createCommentVNode, computed, createVNode, toDisplayString, withCtx, ref, onBeforeUnmount, normalizeClass, onMounted, nextTick, onUnmounted, watch, Fragment, renderList, normalizeStyle, mergeProps, Transition, createStaticVNode, Teleport, withModifiers, toValue, h, toRefs, useId, createTextVNode, useAttrs, useSlots, resolveDynamicComponent, useTemplateRef, onUpdated, createSlots, normalizeProps, guardReactiveProps } from "vue";
2
+ import { UiIcon, UiFileType, UiButton, UiPopover, UiPopoverTrigger, UiPopoverContent, UiTooltip, formatFileSize, UiDialog, UiDialogContent, UiDialogDescription, UiFieldLabel, UiToggleGroup, UiToggleGroupItem, UiField, UiTextarea, UiFileItem, UiProgress, Primitive, UiAvatar, UiAvatarImage, UiSpinner, UiAvatarFallback, UiSidebarPopoverMenu, UiSidebarPopoverMenuItem } from "@aleph-alpha/ui-library";
3
+ import { u as useChatKitLabels, d as defaultChatKitLabels, r as remarkCitations, a as useMarkdownParser } from "./useChatKitLabels-BM2I7-9o.js";
4
4
  const MINUTE = 60;
5
5
  const HOUR = 60 * MINUTE;
6
6
  const DAY = 24 * HOUR;
@@ -36,7 +36,7 @@ function formatRelativeTime(unixSeconds, nowSeconds = Math.floor(Date.now() / 1e
36
36
  const years = Math.floor(delta / YEAR);
37
37
  return years === 1 ? "1 year ago" : `${years} years ago`;
38
38
  }
39
- const _sfc_main$o = /* @__PURE__ */ defineComponent({
39
+ const _sfc_main$q = /* @__PURE__ */ defineComponent({
40
40
  ...{ name: "CkSendIcon" },
41
41
  __name: "CkSendIcon",
42
42
  setup(__props) {
@@ -45,19 +45,19 @@ const _sfc_main$o = /* @__PURE__ */ defineComponent({
45
45
  };
46
46
  }
47
47
  });
48
- const _hoisted_1$d = {
48
+ const _hoisted_1$f = {
49
49
  xmlns: "http://www.w3.org/2000/svg",
50
50
  width: "16",
51
51
  height: "16",
52
52
  viewBox: "0 0 16 16",
53
53
  fill: "none"
54
54
  };
55
- const _sfc_main$n = /* @__PURE__ */ defineComponent({
55
+ const _sfc_main$p = /* @__PURE__ */ defineComponent({
56
56
  ...{ name: "CkStopIcon" },
57
57
  __name: "CkStopIcon",
58
58
  setup(__props) {
59
59
  return (_ctx, _cache) => {
60
- return openBlock(), createElementBlock("svg", _hoisted_1$d, [..._cache[0] || (_cache[0] = [
60
+ return openBlock(), createElementBlock("svg", _hoisted_1$f, [..._cache[0] || (_cache[0] = [
61
61
  createElementVNode("path", {
62
62
  d: "M13.3335 3.33301C13.3335 2.96482 13.035 2.66634 12.6668 2.66634H3.3335C2.96531 2.66634 2.66683 2.96482 2.66683 3.33301V12.6663C2.66683 13.0345 2.96531 13.333 3.3335 13.333H12.6668C13.035 13.333 13.3335 13.0345 13.3335 12.6663V3.33301ZM14.6668 12.6663C14.6668 13.7709 13.7714 14.6663 12.6668 14.6663H3.3335C2.22893 14.6663 1.3335 13.7709 1.3335 12.6663V3.33301C1.3335 2.22844 2.22893 1.33301 3.3335 1.33301H12.6668C13.7714 1.33301 14.6668 2.22844 14.6668 3.33301V12.6663Z",
63
63
  fill: "currentColor"
@@ -66,41 +66,41 @@ const _sfc_main$n = /* @__PURE__ */ defineComponent({
66
66
  };
67
67
  }
68
68
  });
69
- const _hoisted_1$c = { class: "flex w-full min-w-0 flex-col gap-6 pb-6" };
70
- const _hoisted_2$8 = {
69
+ const _hoisted_1$e = { class: "flex w-full min-w-0 flex-col gap-6 pb-6" };
70
+ const _hoisted_2$9 = {
71
71
  key: 0,
72
72
  class: "flex items-start gap-3"
73
73
  };
74
- const _hoisted_3$7 = {
74
+ const _hoisted_3$8 = {
75
75
  key: 0,
76
76
  "data-testid": "ck-agent-message-icon",
77
77
  class: "flex flex-shrink-0 justify-center"
78
78
  };
79
- const _hoisted_4$6 = {
79
+ const _hoisted_4$7 = {
80
80
  key: 1,
81
81
  "data-testid": "ck-agent-message-header",
82
82
  class: "body-14-regular text-content-on-surface-muted min-w-0 flex-1 [word-break:break-word]"
83
83
  };
84
- const _hoisted_5$4 = { class: "text-content-on-surface-primary min-w-0 text-base leading-7" };
84
+ const _hoisted_5$5 = { class: "text-content-on-surface-primary min-w-0 text-base leading-7" };
85
85
  const _hoisted_6$3 = {
86
86
  key: 1,
87
87
  class: "flex items-center gap-4"
88
88
  };
89
- const _sfc_main$m = /* @__PURE__ */ defineComponent({
89
+ const _sfc_main$o = /* @__PURE__ */ defineComponent({
90
90
  ...{ name: "CkAgentMessage" },
91
91
  __name: "CkAgentMessage",
92
92
  setup(__props) {
93
93
  return (_ctx, _cache) => {
94
- return openBlock(), createElementBlock("div", _hoisted_1$c, [
95
- _ctx.$slots.icon || _ctx.$slots.header ? (openBlock(), createElementBlock("div", _hoisted_2$8, [
96
- _ctx.$slots.icon ? (openBlock(), createElementBlock("div", _hoisted_3$7, [
94
+ return openBlock(), createElementBlock("div", _hoisted_1$e, [
95
+ _ctx.$slots.icon || _ctx.$slots.header ? (openBlock(), createElementBlock("div", _hoisted_2$9, [
96
+ _ctx.$slots.icon ? (openBlock(), createElementBlock("div", _hoisted_3$8, [
97
97
  renderSlot(_ctx.$slots, "icon")
98
98
  ])) : createCommentVNode("", true),
99
- _ctx.$slots.header ? (openBlock(), createElementBlock("span", _hoisted_4$6, [
99
+ _ctx.$slots.header ? (openBlock(), createElementBlock("span", _hoisted_4$7, [
100
100
  renderSlot(_ctx.$slots, "header")
101
101
  ])) : createCommentVNode("", true)
102
102
  ])) : createCommentVNode("", true),
103
- createElementVNode("div", _hoisted_5$4, [
103
+ createElementVNode("div", _hoisted_5$5, [
104
104
  renderSlot(_ctx.$slots, "default")
105
105
  ]),
106
106
  _ctx.$slots.footer ? (openBlock(), createElementBlock("div", _hoisted_6$3, [
@@ -110,6 +110,194 @@ const _sfc_main$m = /* @__PURE__ */ defineComponent({
110
110
  };
111
111
  }
112
112
  });
113
+ const _hoisted_1$d = { class: "ck-citation-card flex w-[22.5rem] max-w-[90vw] flex-col gap-2 rounded-md bg-background-surface-floating px-6 pb-6 pt-4 shadow-md" };
114
+ const _hoisted_2$8 = { class: "flex items-center gap-3" };
115
+ const _hoisted_3$7 = ["title"];
116
+ const _hoisted_4$6 = { class: "break-words text-sm leading-5 text-content-on-surface-secondary" };
117
+ const _hoisted_5$4 = {
118
+ key: 0,
119
+ class: "text-sm leading-5 text-content-on-surface-muted"
120
+ };
121
+ const _sfc_main$n = /* @__PURE__ */ defineComponent({
122
+ ...{
123
+ name: "CkCitationCard"
124
+ },
125
+ __name: "CkCitationCard",
126
+ props: {
127
+ fileName: {},
128
+ snippet: {},
129
+ locationLabel: { default: void 0 },
130
+ url: { default: void 0 },
131
+ openSourceLabel: { default: void 0 }
132
+ },
133
+ emits: ["open-source"],
134
+ setup(__props, { emit: __emit }) {
135
+ const props = __props;
136
+ const emit = __emit;
137
+ const labels = useChatKitLabels();
138
+ const openSourceAriaLabel = computed(
139
+ () => props.openSourceLabel ?? labels.value.citationOpenSource ?? defaultChatKitLabels.citationOpenSource
140
+ );
141
+ function handleOpen() {
142
+ if (props.url) {
143
+ emit("open-source", props.url);
144
+ }
145
+ }
146
+ return (_ctx, _cache) => {
147
+ return openBlock(), createElementBlock("div", _hoisted_1$d, [
148
+ createElementVNode("div", _hoisted_2$8, [
149
+ createVNode(unref(UiFileType), {
150
+ filename: __props.fileName,
151
+ class: "shrink-0"
152
+ }, null, 8, ["filename"]),
153
+ createElementVNode("p", {
154
+ class: "min-w-0 flex-1 truncate text-sm font-medium text-content-on-surface-primary",
155
+ title: __props.fileName
156
+ }, toDisplayString(__props.fileName), 9, _hoisted_3$7),
157
+ __props.url ? (openBlock(), createBlock(unref(UiButton), {
158
+ key: 0,
159
+ variant: "ghost",
160
+ size: "icon-sm",
161
+ "aria-label": openSourceAriaLabel.value,
162
+ class: "shrink-0",
163
+ onClick: handleOpen
164
+ }, {
165
+ default: withCtx(() => [
166
+ createVNode(unref(UiIcon), {
167
+ name: "external-link",
168
+ size: 16,
169
+ "aria-hidden": "true"
170
+ })
171
+ ]),
172
+ _: 1
173
+ }, 8, ["aria-label"])) : createCommentVNode("", true)
174
+ ]),
175
+ createElementVNode("p", _hoisted_4$6, toDisplayString(__props.snippet), 1),
176
+ __props.locationLabel ? (openBlock(), createElementBlock("p", _hoisted_5$4, toDisplayString(__props.locationLabel), 1)) : createCommentVNode("", true)
177
+ ]);
178
+ };
179
+ }
180
+ });
181
+ const _hoisted_1$c = ["aria-label"];
182
+ const CLOSE_DELAY_MS = 80;
183
+ const _sfc_main$m = /* @__PURE__ */ defineComponent({
184
+ ...{
185
+ name: "CkCitation"
186
+ },
187
+ __name: "CkCitation",
188
+ props: {
189
+ selected: { type: Boolean, default: false },
190
+ ariaLabel: { default: void 0 },
191
+ openSourceLabel: { default: void 0 },
192
+ index: {},
193
+ fileName: {},
194
+ snippet: {},
195
+ locationLabel: { default: void 0 },
196
+ url: { default: void 0 }
197
+ },
198
+ emits: ["open-source"],
199
+ setup(__props, { emit: __emit }) {
200
+ const props = __props;
201
+ const emit = __emit;
202
+ const labels = useChatKitLabels();
203
+ const triggerLabel = computed(
204
+ () => props.ariaLabel ?? `${labels.value.citationSourceLabel ?? defaultChatKitLabels.citationSourceLabel} ${props.index}`
205
+ );
206
+ const open = ref(false);
207
+ const isPointerInteraction = ref(false);
208
+ let closeTimer;
209
+ function show() {
210
+ if (closeTimer) {
211
+ clearTimeout(closeTimer);
212
+ closeTimer = void 0;
213
+ }
214
+ open.value = true;
215
+ }
216
+ function scheduleHide() {
217
+ if (closeTimer) clearTimeout(closeTimer);
218
+ closeTimer = setTimeout(() => {
219
+ open.value = false;
220
+ closeTimer = void 0;
221
+ }, CLOSE_DELAY_MS);
222
+ }
223
+ function onPointerEnter() {
224
+ isPointerInteraction.value = true;
225
+ show();
226
+ }
227
+ function onPointerLeave() {
228
+ isPointerInteraction.value = false;
229
+ scheduleHide();
230
+ }
231
+ function onOpenAutoFocus(event) {
232
+ if (isPointerInteraction.value) event.preventDefault();
233
+ }
234
+ function onContentFocusOut(event) {
235
+ const nextTarget = event.relatedTarget;
236
+ const content = event.currentTarget;
237
+ if (!nextTarget || !content.contains(nextTarget)) {
238
+ scheduleHide();
239
+ }
240
+ }
241
+ onBeforeUnmount(() => {
242
+ if (closeTimer) clearTimeout(closeTimer);
243
+ });
244
+ return (_ctx, _cache) => {
245
+ return openBlock(), createBlock(unref(UiPopover), {
246
+ open: open.value,
247
+ "onUpdate:open": _cache[1] || (_cache[1] = ($event) => open.value = $event)
248
+ }, {
249
+ default: withCtx(() => [
250
+ createVNode(unref(UiPopoverTrigger), { "as-child": "" }, {
251
+ default: withCtx(() => [
252
+ createElementVNode("button", {
253
+ type: "button",
254
+ "aria-label": triggerLabel.value,
255
+ class: normalizeClass([
256
+ "ck-citation mx-px inline-flex h-5 min-w-5 select-none items-center justify-center rounded-sm px-1 align-middle text-sm leading-4 tabular-nums transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
257
+ __props.selected ? "bg-background-accent-soft text-black" : "bg-background-accent-yellow text-background-status-warning"
258
+ ]),
259
+ onMouseenter: onPointerEnter,
260
+ onMouseleave: onPointerLeave
261
+ }, toDisplayString(__props.index), 43, _hoisted_1$c)
262
+ ]),
263
+ _: 1
264
+ }),
265
+ createVNode(unref(UiPopoverContent), {
266
+ align: "start",
267
+ "side-offset": 8,
268
+ class: "w-auto border-0 bg-transparent p-0 shadow-none",
269
+ onOpenAutoFocus,
270
+ onMouseenter: onPointerEnter,
271
+ onMouseleave: onPointerLeave,
272
+ onFocusin: show,
273
+ onFocusout: onContentFocusOut
274
+ }, {
275
+ default: withCtx(() => [
276
+ createVNode(unref(_sfc_main$n), {
277
+ "file-name": __props.fileName,
278
+ snippet: __props.snippet,
279
+ "location-label": __props.locationLabel,
280
+ url: __props.url,
281
+ "open-source-label": __props.openSourceLabel,
282
+ onOpenSource: _cache[0] || (_cache[0] = (u) => emit("open-source", u))
283
+ }, null, 8, ["file-name", "snippet", "location-label", "url", "open-source-label"])
284
+ ]),
285
+ _: 1
286
+ })
287
+ ]),
288
+ _: 1
289
+ }, 8, ["open"]);
290
+ };
291
+ }
292
+ });
293
+ const _export_sfc = (sfc, props) => {
294
+ const target = sfc.__vccOpts || sfc;
295
+ for (const [key, val] of props) {
296
+ target[key] = val;
297
+ }
298
+ return target;
299
+ };
300
+ const CkCitation = /* @__PURE__ */ _export_sfc(_sfc_main$m, [["__scopeId", "data-v-0d83c5f8"]]);
113
301
  const _hoisted_1$b = ["data-message-row"];
114
302
  const _hoisted_2$7 = {
115
303
  key: 0,
@@ -395,13 +583,6 @@ const _sfc_main$j = /* @__PURE__ */ defineComponent({
395
583
  };
396
584
  }
397
585
  });
398
- const _export_sfc = (sfc, props) => {
399
- const target = sfc.__vccOpts || sfc;
400
- for (const [key, val] of props) {
401
- target[key] = val;
402
- }
403
- return target;
404
- };
405
586
  const CkCopyMessageActionButton = /* @__PURE__ */ _export_sfc(_sfc_main$j, [["__scopeId", "data-v-f77a1193"]]);
406
587
  const _hoisted_1$9 = {
407
588
  width: "208",
@@ -740,6 +921,28 @@ const _sfc_main$g = /* @__PURE__ */ defineComponent({
740
921
  }
741
922
  });
742
923
  const CkFeedbackButton = /* @__PURE__ */ _export_sfc(_sfc_main$g, [["__scopeId", "data-v-245705b8"]]);
924
+ function useCitationRendering(citations, onOpenSource) {
925
+ const sourcesByIndex = computed(
926
+ () => new Map(
927
+ (toValue(citations) ?? []).map((source) => [source.index, source])
928
+ )
929
+ );
930
+ const citationPlugins = computed(() => {
931
+ const list = toValue(citations);
932
+ if (!list?.length) return [];
933
+ const indices = new Set(list.map((source) => source.index));
934
+ return [[remarkCitations, { indices }]];
935
+ });
936
+ function renderCitationNode(el, slot) {
937
+ if (!el.hasAttribute("data-citation-index")) return null;
938
+ const index = Number(el.getAttribute("data-citation-index"));
939
+ const source = sourcesByIndex.value.get(index);
940
+ if (!source) return null;
941
+ if (slot) return slot({ source, openSource: onOpenSource });
942
+ return h(CkCitation, { ...source, onOpenSource });
943
+ }
944
+ return { citationPlugins, renderCitationNode };
945
+ }
743
946
  const defaultMarkdownClasses = {
744
947
  p: "my-1 leading-7",
745
948
  a: "underline underline-offset-4",
@@ -759,25 +962,29 @@ const defaultMarkdownClasses = {
759
962
  hr: "my-4"
760
963
  };
761
964
  const TABLE_WRAPPER_CLASS = "max-w-full overflow-x-auto";
762
- function domToVNode(node, slots, classes, tableLabel) {
965
+ function renderCodeBlock(el, ctx) {
966
+ if (el.tagName !== "PRE" || el.firstElementChild?.tagName !== "CODE") {
967
+ return null;
968
+ }
969
+ if (!ctx.slots["code-block"]) return null;
970
+ const codeEl = el.firstElementChild;
971
+ const language = codeEl.className?.match(/language-(\S+)/)?.[1] ?? "";
972
+ const code = codeEl.textContent ?? "";
973
+ return ctx.slots["code-block"]({ code, language });
974
+ }
975
+ function domToVNode(node, ctx) {
763
976
  if (node.nodeType === Node.TEXT_NODE) return node.textContent;
764
977
  if (node.nodeType !== Node.ELEMENT_NODE) return null;
765
978
  const el = node;
766
- if (el.tagName === "PRE" && el.firstElementChild?.tagName === "CODE") {
767
- const codeEl = el.firstElementChild;
768
- const language = codeEl.className?.match(/language-(\S+)/)?.[1] ?? "";
769
- const code = codeEl.textContent ?? "";
770
- if (slots["code-block"]) {
771
- return slots["code-block"]({ code, language });
772
- }
773
- }
774
- const children = Array.from(node.childNodes).map((child) => domToVNode(child, slots, classes, tableLabel)).filter((c) => c != null);
979
+ const special = renderCodeBlock(el, ctx) ?? ctx.renderCitation(el);
980
+ if (special != null) return special;
981
+ const children = Array.from(node.childNodes).map((child) => domToVNode(child, ctx)).filter((c) => c != null);
775
982
  const attrs = {};
776
983
  for (const attr of el.attributes) {
777
984
  attrs[attr.name] = attr.value;
778
985
  }
779
986
  const tag = el.tagName.toLowerCase();
780
- const customClass = classes[tag];
987
+ const customClass = ctx.classes[tag];
781
988
  if (customClass) {
782
989
  attrs.class = attrs.class ? `${attrs.class} ${customClass}` : customClass;
783
990
  }
@@ -789,7 +996,7 @@ function domToVNode(node, slots, classes, tableLabel) {
789
996
  class: TABLE_WRAPPER_CLASS,
790
997
  tabindex: "0",
791
998
  role: "region",
792
- "aria-label": tableLabel
999
+ "aria-label": ctx.tableLabel
793
1000
  },
794
1001
  [vnode]
795
1002
  );
@@ -804,12 +1011,30 @@ const _sfc_main$f = defineComponent({
804
1011
  type: Object,
805
1012
  default: () => ({})
806
1013
  },
807
- plugins: { type: Array, default: void 0 }
1014
+ plugins: { type: Array, default: void 0 },
1015
+ citations: {
1016
+ type: Array,
1017
+ default: void 0
1018
+ }
1019
+ },
1020
+ emits: {
1021
+ "open-source": (url) => typeof url === "string"
808
1022
  },
809
- setup(props, { slots }) {
810
- const { content, plugins } = toRefs(props);
811
- const { html } = useMarkdownParser(content, plugins);
1023
+ setup(props, { slots, emit }) {
1024
+ const { content } = toRefs(props);
812
1025
  const labels = useChatKitLabels();
1026
+ function handleOpenSource(url) {
1027
+ emit("open-source", url);
1028
+ }
1029
+ const { citationPlugins, renderCitationNode } = useCitationRendering(
1030
+ () => props.citations,
1031
+ handleOpenSource
1032
+ );
1033
+ const effectivePlugins = computed(() => [
1034
+ ...props.plugins ?? [],
1035
+ ...citationPlugins.value
1036
+ ]);
1037
+ const { html } = useMarkdownParser(content, effectivePlugins);
813
1038
  const parsedNodes = computed(() => {
814
1039
  const raw = html.value;
815
1040
  if (!raw) return [];
@@ -821,9 +1046,13 @@ const _sfc_main$f = defineComponent({
821
1046
  ...props.classes
822
1047
  }));
823
1048
  return () => {
824
- const elementClasses = mergedClasses.value;
825
- const tableLabel = labels.value.markdownTableLabel ?? defaultChatKitLabels.markdownTableLabel;
826
- const children = parsedNodes.value.map((node) => domToVNode(node, slots, elementClasses, tableLabel)).filter((c) => c != null);
1049
+ const ctx = {
1050
+ slots,
1051
+ classes: mergedClasses.value,
1052
+ tableLabel: labels.value.markdownTableLabel ?? defaultChatKitLabels.markdownTableLabel,
1053
+ renderCitation: (el) => renderCitationNode(el, slots.citation)
1054
+ };
1055
+ const children = parsedNodes.value.map((node) => domToVNode(node, ctx)).filter((c) => c != null);
827
1056
  return h(
828
1057
  "div",
829
1058
  { class: "markdown-renderer min-w-0 break-words" },
@@ -2088,7 +2317,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
2088
2317
  ]),
2089
2318
  "agent-message": withCtx(({ message }) => [
2090
2319
  renderSlot(_ctx.$slots, "agent-message", { message }, () => [
2091
- createVNode(_sfc_main$m, null, createSlots({
2320
+ createVNode(_sfc_main$o, null, createSlots({
2092
2321
  footer: withCtx(() => [
2093
2322
  renderSlot(_ctx.$slots, "agent-message-footer", { message }, () => [
2094
2323
  getMessageText(message) && !isLoading(message) ? (openBlock(), createBlock(CkCopyMessageActionButton, {
@@ -2367,7 +2596,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2367
2596
  }, {
2368
2597
  default: withCtx(() => [
2369
2598
  renderSlot(_ctx.$slots, "stop-icon", {}, () => [
2370
- createVNode(_sfc_main$n)
2599
+ createVNode(_sfc_main$p)
2371
2600
  ])
2372
2601
  ]),
2373
2602
  _: 3
@@ -2377,7 +2606,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2377
2606
  }), {
2378
2607
  default: withCtx(() => [
2379
2608
  renderSlot(_ctx.$slots, "send-icon", {}, () => [
2380
- createVNode(_sfc_main$o)
2609
+ createVNode(_sfc_main$q)
2381
2610
  ])
2382
2611
  ]),
2383
2612
  _: 3
@@ -2413,28 +2642,30 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2413
2642
  }
2414
2643
  });
2415
2644
  export {
2416
- CkCopyMessageActionButton as C,
2417
- _sfc_main$m as _,
2418
- _sfc_main$2 as a,
2419
- _sfc_main$l as b,
2420
- CkDropZoneOverlay as c,
2421
- CkFeedbackButton as d,
2422
- CkFeedbackDialog as e,
2423
- _sfc_main$c as f,
2424
- _sfc_main$1 as g,
2425
- _sfc_main$b as h,
2426
- _sfc_main$a as i,
2427
- _sfc_main as j,
2428
- _sfc_main$f as k,
2429
- _sfc_main$k as l,
2430
- _sfc_main$9 as m,
2431
- CkPromptInput as n,
2432
- _sfc_main$4 as o,
2433
- _sfc_main$7 as p,
2434
- _sfc_main$8 as q,
2435
- _sfc_main$6 as r,
2436
- _sfc_main$o as s,
2437
- _sfc_main$n as t,
2438
- CkUserMessage as u,
2439
- formatRelativeTime as v
2645
+ CkCitation as C,
2646
+ _sfc_main$o as _,
2647
+ _sfc_main$n as a,
2648
+ _sfc_main$2 as b,
2649
+ _sfc_main$l as c,
2650
+ CkCopyMessageActionButton as d,
2651
+ CkDropZoneOverlay as e,
2652
+ CkFeedbackButton as f,
2653
+ CkFeedbackDialog as g,
2654
+ _sfc_main$c as h,
2655
+ _sfc_main$1 as i,
2656
+ _sfc_main$b as j,
2657
+ _sfc_main$a as k,
2658
+ _sfc_main as l,
2659
+ _sfc_main$f as m,
2660
+ _sfc_main$k as n,
2661
+ _sfc_main$9 as o,
2662
+ CkPromptInput as p,
2663
+ _sfc_main$4 as q,
2664
+ _sfc_main$7 as r,
2665
+ _sfc_main$8 as s,
2666
+ _sfc_main$6 as t,
2667
+ _sfc_main$q as u,
2668
+ _sfc_main$p as v,
2669
+ CkUserMessage as w,
2670
+ formatRelativeTime as x
2440
2671
  };