@aleph-alpha/chat-kit 3.1.3 → 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.
- package/dist/{CkInput.vue_vue_type_script_setup_true_lang-LPrW7CSQ.js → CkInput.vue_vue_type_script_setup_true_lang-BAcBFs6I.js} +302 -71
- package/dist/adapters/responses-api.d.ts.map +1 -1
- package/dist/adapters/responses-api.js +63 -37
- package/dist/chat-kit.css +6 -0
- package/dist/components/base/CkAgentMessage/CkAgentMessage.stories.d.ts +7 -0
- package/dist/components/base/CkAgentMessage/CkAgentMessage.stories.d.ts.map +1 -1
- package/dist/components/base/CkCitation/CkCitation.stories.d.ts +47 -0
- package/dist/components/base/CkCitation/CkCitation.stories.d.ts.map +1 -0
- package/dist/components/base/CkCitation/CkCitation.vue.d.ts +15 -0
- package/dist/components/base/CkCitation/CkCitation.vue.d.ts.map +1 -0
- package/dist/components/base/CkCitation/index.d.ts +3 -0
- package/dist/components/base/CkCitation/index.d.ts.map +1 -0
- package/dist/components/base/CkCitation/types.d.ts +79 -0
- package/dist/components/base/CkCitation/types.d.ts.map +1 -0
- package/dist/components/base/CkCitationCard/CkCitationCard.stories.d.ts +51 -0
- package/dist/components/base/CkCitationCard/CkCitationCard.stories.d.ts.map +1 -0
- package/dist/components/base/CkCitationCard/CkCitationCard.vue.d.ts +13 -0
- package/dist/components/base/CkCitationCard/CkCitationCard.vue.d.ts.map +1 -0
- package/dist/components/base/CkCitationCard/index.d.ts +3 -0
- package/dist/components/base/CkCitationCard/index.d.ts.map +1 -0
- package/dist/components/base/CkCitationCard/types.d.ts +51 -0
- package/dist/components/base/CkCitationCard/types.d.ts.map +1 -0
- package/dist/components/base/CkDropZoneOverlay/CkDropZoneOverlay.vue.d.ts +1 -1
- package/dist/components/base/CkFeedbackDialog/CkFeedbackDialog.vue.d.ts +2 -2
- package/dist/components/base/CkFileItemsList/CkFileItemsList.vue.d.ts +1 -1
- package/dist/components/base/CkMarkdownRenderer/CkMarkdownRenderer.stories.d.ts +15 -0
- package/dist/components/base/CkMarkdownRenderer/CkMarkdownRenderer.stories.d.ts.map +1 -1
- package/dist/components/base/CkMarkdownRenderer/CkMarkdownRenderer.vue.d.ts +16 -2
- package/dist/components/base/CkMarkdownRenderer/CkMarkdownRenderer.vue.d.ts.map +1 -1
- package/dist/components/base/CkMarkdownRenderer/index.d.ts +1 -1
- package/dist/components/base/CkMarkdownRenderer/index.d.ts.map +1 -1
- package/dist/components/base/CkMarkdownRenderer/types.d.ts +25 -0
- package/dist/components/base/CkMarkdownRenderer/types.d.ts.map +1 -1
- package/dist/components/base/CkMarkdownRenderer/useCitationRendering.d.ts +17 -0
- package/dist/components/base/CkMarkdownRenderer/useCitationRendering.d.ts.map +1 -0
- package/dist/components/base/CkPromptSendButton/CkPromptSendButton.vue.d.ts +1 -1
- package/dist/components/base/index.d.ts +5 -1
- package/dist/components/base/index.d.ts.map +1 -1
- package/dist/components/composed/CkInput/CkInput.vue.d.ts +1 -1
- package/dist/components/index.d.ts +2 -2
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +25 -23
- package/dist/composables/fileUpload/types.d.ts +3 -0
- package/dist/composables/fileUpload/types.d.ts.map +1 -1
- package/dist/composables/fileUpload/useFileUpload.d.ts.map +1 -1
- package/dist/composables/fileUpload/useFileUploadWrapper.d.ts.map +1 -1
- package/dist/composables/index.js +1 -1
- package/dist/handlers/index.d.ts +3 -0
- package/dist/handlers/index.d.ts.map +1 -1
- package/dist/handlers/index.js +4 -1
- package/dist/handlers/useChatKitLabels.d.ts +11 -0
- package/dist/handlers/useChatKitLabels.d.ts.map +1 -1
- package/dist/handlers/useMarkdownParser.d.ts.map +1 -1
- package/dist/helpers/unified/remarkCitations.d.ts +17 -0
- package/dist/helpers/unified/remarkCitations.d.ts.map +1 -0
- package/dist/helpers/unified/remarkNormalizeMath.d.ts +24 -0
- package/dist/helpers/unified/remarkNormalizeMath.d.ts.map +1 -0
- package/dist/{index-DVxCNAs3.js → index-C6njJ8EB.js} +96 -49
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +28 -26
- package/dist/{useChatKitLabels-Ctz1dHpx.js → useChatKitLabels-BM2I7-9o.js} +126 -3
- package/package.json +6 -3
- package/src/adapters/responses-api.spec.ts +156 -0
- package/src/adapters/responses-api.ts +125 -58
- package/src/components/base/CkAgentMessage/CkAgentMessage.stories.ts +112 -0
- package/src/components/base/CkCitation/CkCitation.spec.ts +79 -0
- package/src/components/base/CkCitation/CkCitation.stories.ts +136 -0
- package/src/components/base/CkCitation/CkCitation.vue +145 -0
- package/src/components/base/CkCitation/index.ts +2 -0
- package/src/components/base/CkCitation/types.ts +80 -0
- package/src/components/base/CkCitationCard/CkCitationCard.spec.ts +77 -0
- package/src/components/base/CkCitationCard/CkCitationCard.stories.ts +144 -0
- package/src/components/base/CkCitationCard/CkCitationCard.vue +76 -0
- package/src/components/base/CkCitationCard/index.ts +2 -0
- package/src/components/base/CkCitationCard/types.ts +51 -0
- package/src/components/base/CkMarkdownRenderer/CkMarkdownRenderer.spec.ts +124 -0
- package/src/components/base/CkMarkdownRenderer/CkMarkdownRenderer.stories.ts +118 -0
- package/src/components/base/CkMarkdownRenderer/CkMarkdownRenderer.vue +70 -28
- package/src/components/base/CkMarkdownRenderer/index.ts +1 -0
- package/src/components/base/CkMarkdownRenderer/types.ts +26 -0
- package/src/components/base/CkMarkdownRenderer/useCitationRendering.spec.ts +94 -0
- package/src/components/base/CkMarkdownRenderer/useCitationRendering.ts +52 -0
- package/src/components/base/index.ts +12 -0
- package/src/components/index.ts +8 -0
- package/src/composables/fileUpload/types.ts +6 -0
- package/src/composables/fileUpload/useFileUpload.spec.ts +2 -61
- package/src/composables/fileUpload/useFileUpload.ts +9 -10
- package/src/composables/fileUpload/useFileUploadWrapper.spec.ts +241 -10
- package/src/composables/fileUpload/useFileUploadWrapper.ts +126 -53
- package/src/handlers/index.ts +6 -0
- package/src/handlers/useChatKitLabels.ts +13 -0
- package/src/handlers/useMarkdownParser.spec.ts +34 -0
- package/src/handlers/useMarkdownParser.ts +15 -3
- package/src/helpers/unified/remarkCitations.spec.ts +112 -0
- package/src/helpers/unified/remarkCitations.ts +55 -0
- package/src/helpers/unified/remarkNormalizeMath.spec.ts +84 -0
- package/src/helpers/unified/remarkNormalizeMath.ts +134 -0
- 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,
|
|
2
|
-
import { UiIcon, UiButton, UiTooltip, formatFileSize, UiDialog, UiDialogContent, UiDialogDescription, UiFieldLabel, UiToggleGroup, UiToggleGroupItem, UiField, UiTextarea, UiFileItem,
|
|
3
|
-
import { u as useChatKitLabels, d as defaultChatKitLabels, a as useMarkdownParser } from "./useChatKitLabels-
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
70
|
-
const _hoisted_2$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
95
|
-
_ctx.$slots.icon || _ctx.$slots.header ? (openBlock(), createElementBlock("div", _hoisted_2$
|
|
96
|
-
_ctx.$slots.icon ? (openBlock(), createElementBlock("div", _hoisted_3$
|
|
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$
|
|
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$
|
|
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
|
|
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
|
-
|
|
767
|
-
|
|
768
|
-
|
|
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
|
|
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
|
|
825
|
-
|
|
826
|
-
|
|
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$
|
|
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$
|
|
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$
|
|
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
|
-
|
|
2417
|
-
_sfc_main$
|
|
2418
|
-
_sfc_main$
|
|
2419
|
-
_sfc_main$
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
_sfc_main$
|
|
2426
|
-
_sfc_main$
|
|
2427
|
-
_sfc_main as j,
|
|
2428
|
-
_sfc_main$
|
|
2429
|
-
_sfc_main
|
|
2430
|
-
_sfc_main$
|
|
2431
|
-
|
|
2432
|
-
_sfc_main$
|
|
2433
|
-
|
|
2434
|
-
_sfc_main$
|
|
2435
|
-
_sfc_main$
|
|
2436
|
-
_sfc_main$
|
|
2437
|
-
_sfc_main$
|
|
2438
|
-
|
|
2439
|
-
|
|
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
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"responses-api.d.ts","sourceRoot":"","sources":["../../src/adapters/responses-api.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EACV,gBAAgB,EAEhB,eAAe,EAEf,WAAW,EACZ,MAAM,UAAU,CAAC;AAMlB;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,aAAa,GAAG,MAAM,CAAC;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,kBAAkB,EAAE,CAAC;CACpC;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,cAAc,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,kBAAkB,EAAE,CAAC;CACpC;AAED;;;;;;GAMG;AACH,MAAM,WAAW,0BAA0B;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM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
147
|
+
function appendNode(treeNodes, node, parentId) {
|
|
148
|
+
treeNodes[node.id] = {
|
|
149
|
+
id: node.id,
|
|
150
|
+
parentId,
|
|
151
|
+
childrenIds: [],
|
|
152
|
+
activeChildIndex: 0,
|
|
153
|
+
role: node.role,
|
|
154
|
+
content: node.content,
|
|
155
|
+
status: "completed",
|
|
156
|
+
createdAt: node.createdAt,
|
|
157
|
+
metadata: node.metadata
|
|
158
|
+
};
|
|
159
|
+
if (parentId === null) return;
|
|
160
|
+
const parent = treeNodes[parentId];
|
|
161
|
+
if (!parent) return;
|
|
162
|
+
parent.childrenIds.push(node.id);
|
|
163
|
+
parent.activeChildIndex = parent.childrenIds.length - 1;
|
|
164
|
+
}
|
|
165
|
+
function responseHasUserInput(resp) {
|
|
166
|
+
return (resp.request_input ?? []).some(
|
|
167
|
+
(input) => input.role === "user"
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
function isAssistantContinuation(parentNode, messageNodes, resp) {
|
|
171
|
+
return parentNode.role === "assistant" && messageNodes.length > 0 && messageNodes.every((node) => node.role === "assistant") && !responseHasUserInput(resp);
|
|
172
|
+
}
|
|
173
|
+
function foldContinuation(parentNode, messageNodes) {
|
|
174
|
+
for (const node of messageNodes) {
|
|
175
|
+
parentNode.content.push(...node.content);
|
|
176
|
+
if (node.createdAt.getTime() > parentNode.createdAt.getTime()) {
|
|
177
|
+
parentNode.createdAt = node.createdAt;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function linkResponse(state, resp) {
|
|
182
|
+
const { treeNodes, tailMessageByResponse } = state;
|
|
183
|
+
const parentResponseId = resp.previous_response_id && tailMessageByResponse.has(resp.previous_response_id) ? resp.previous_response_id : null;
|
|
184
|
+
let chainParent = parentResponseId !== null ? tailMessageByResponse.get(parentResponseId) ?? null : null;
|
|
185
|
+
const messageNodes = responseToMessageNodes(resp);
|
|
186
|
+
const parentNode = chainParent !== null ? treeNodes[chainParent] : null;
|
|
187
|
+
if (parentNode && isAssistantContinuation(parentNode, messageNodes, resp)) {
|
|
188
|
+
foldContinuation(parentNode, messageNodes);
|
|
189
|
+
tailMessageByResponse.set(resp.id, parentNode.id);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
let firstId = null;
|
|
193
|
+
for (const node of messageNodes) {
|
|
194
|
+
appendNode(treeNodes, node, chainParent);
|
|
195
|
+
if (firstId === null) firstId = node.id;
|
|
196
|
+
chainParent = node.id;
|
|
197
|
+
}
|
|
198
|
+
if (state.rootMessageId === null && firstId !== null) {
|
|
199
|
+
state.rootMessageId = firstId;
|
|
200
|
+
}
|
|
201
|
+
tailMessageByResponse.set(resp.id, chainParent);
|
|
202
|
+
}
|
|
147
203
|
function responsesToTree(responses) {
|
|
148
204
|
if (responses.length === 0) {
|
|
149
205
|
return { nodes: {}, rootId: null };
|
|
150
206
|
}
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
id: node.id,
|
|
157
|
-
parentId,
|
|
158
|
-
childrenIds: [],
|
|
159
|
-
activeChildIndex: 0,
|
|
160
|
-
role: node.role,
|
|
161
|
-
content: node.content,
|
|
162
|
-
status: "completed",
|
|
163
|
-
createdAt: node.createdAt,
|
|
164
|
-
metadata: node.metadata
|
|
165
|
-
};
|
|
166
|
-
if (parentId !== null) {
|
|
167
|
-
const parent = treeNodes[parentId];
|
|
168
|
-
if (parent) {
|
|
169
|
-
parent.childrenIds.push(node.id);
|
|
170
|
-
parent.activeChildIndex = parent.childrenIds.length - 1;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
207
|
+
const state = {
|
|
208
|
+
treeNodes: {},
|
|
209
|
+
tailMessageByResponse: /* @__PURE__ */ new Map(),
|
|
210
|
+
rootMessageId: null
|
|
211
|
+
};
|
|
174
212
|
for (const resp of responses) {
|
|
175
|
-
|
|
176
|
-
let chainParent = parentResponseId !== null ? tailMessageByResponse.get(parentResponseId) ?? null : null;
|
|
177
|
-
const messageNodes = responseToMessageNodes(resp);
|
|
178
|
-
let firstId = null;
|
|
179
|
-
for (const node of messageNodes) {
|
|
180
|
-
appendNode(node, chainParent);
|
|
181
|
-
if (firstId === null) firstId = node.id;
|
|
182
|
-
chainParent = node.id;
|
|
183
|
-
}
|
|
184
|
-
if (rootMessageId === null && firstId !== null) {
|
|
185
|
-
rootMessageId = firstId;
|
|
186
|
-
}
|
|
187
|
-
tailMessageByResponse.set(resp.id, chainParent);
|
|
213
|
+
linkResponse(state, resp);
|
|
188
214
|
}
|
|
189
|
-
return { nodes: treeNodes, rootId: rootMessageId };
|
|
215
|
+
return { nodes: state.treeNodes, rootId: state.rootMessageId };
|
|
190
216
|
}
|
|
191
217
|
export {
|
|
192
218
|
responsesToTree
|