@inkeep/agents-ui 0.16.0 → 0.16.1
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/color-mode/index.js +4 -4
- package/dist/node_modules/.pnpm/use-sync-external-store@1.6.0_react@19.3.0-canary-87ae75b3-20260128/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.cjs +9 -0
- package/dist/node_modules/.pnpm/{use-sync-external-store@1.5.0_react@19.0.0 → use-sync-external-store@1.6.0_react@19.3.0-canary-87ae75b3-20260128}/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js +2 -2
- package/dist/primitives/atoms/cmdk/index.cjs +1 -1
- package/dist/primitives/atoms/cmdk/index.js +14 -2
- package/dist/primitives/atoms/combobox.d.ts +104 -0
- package/dist/primitives/atoms/portal.js +3 -3
- package/dist/primitives/atoms/select.cjs +1 -1
- package/dist/primitives/atoms/select.js +2 -2
- package/dist/primitives/atoms/shadow/context.js +4 -4
- package/dist/primitives/components/embedded-chat/chat-error-helpers.cjs +3 -0
- package/dist/primitives/components/embedded-chat/chat-error-helpers.d.ts +26 -0
- package/dist/primitives/components/embedded-chat/chat-error-helpers.js +32 -0
- package/dist/primitives/components/embedded-chat/file-upload-input.cjs +1 -1
- package/dist/primitives/components/embedded-chat/file-upload-input.d.ts +1 -1
- package/dist/primitives/components/embedded-chat/file-upload-input.js +119 -116
- package/dist/primitives/components/embedded-chat/image-preview-modal.js +3 -3
- package/dist/primitives/components/embedded-chat/use-inkeep-chat.cjs +2 -4
- package/dist/primitives/components/embedded-chat/use-inkeep-chat.d.ts +1 -2
- package/dist/primitives/components/embedded-chat/use-inkeep-chat.js +305 -278
- package/dist/primitives/components/embedded-chat/use-stream-processor.cjs +1 -1
- package/dist/primitives/components/embedded-chat/use-stream-processor.js +1 -1
- package/dist/primitives/components/embedded-chat.cjs +1 -1
- package/dist/primitives/components/embedded-chat.d.ts +1 -2
- package/dist/primitives/components/embedded-chat.js +23 -23
- package/dist/primitives/components/embedded-search/search-provider.js +3 -3
- package/dist/primitives/components/embedded-search.cjs +1 -1
- package/dist/primitives/components/embedded-search.d.ts +1 -1
- package/dist/primitives/components/embedded-search.js +3 -3
- package/dist/primitives/components/modal/modal-provider.js +2 -2
- package/dist/primitives/components/modal.js +3 -3
- package/dist/primitives/components/sidebar-chat/index.js +1 -1
- package/dist/primitives/providers/base-events-provider.cjs +1 -1
- package/dist/primitives/providers/base-events-provider.js +22 -22
- package/dist/primitives/providers/chat-bubble-provider.js +1 -1
- package/dist/primitives/providers/chat-form-provider.d.ts +1 -1
- package/dist/primitives/providers/chat-form-provider.js +4 -4
- package/dist/primitives/providers/chat-history-provider.js +3 -3
- package/dist/primitives/providers/config-provider.js +3 -3
- package/dist/primitives/providers/feedback-provider.js +3 -3
- package/dist/primitives/providers/form-field-provider.js +3 -3
- package/dist/primitives/providers/help-menu-provider.js +4 -4
- package/dist/primitives/providers/hover-popover-provider.js +3 -3
- package/dist/primitives/providers/image-preview-provider.js +5 -5
- package/dist/primitives/providers/markdown-provider.js +2 -2
- package/dist/primitives/providers/message-provider.js +1 -1
- package/dist/primitives/providers/sidebar-chat-provider.js +3 -3
- package/dist/primitives/providers/source-item-provider.js +3 -3
- package/dist/primitives/providers/widget-provider.js +2 -2
- package/dist/primitives/utils/misc.cjs +1 -1
- package/dist/primitives/utils/misc.js +2 -2
- package/dist/react/chat-button.js +1 -1
- package/dist/react/embedded-chat.cjs +1 -1
- package/dist/react/embedded-chat.js +5 -5
- package/dist/react/embedded-search.cjs +1 -1
- package/dist/react/embedded-search.js +18 -18
- package/dist/styled/components/chat-bubble.js +4 -4
- package/dist/styled/components/chat-button.cjs +1 -1
- package/dist/styled/components/chat-button.js +9 -9
- package/dist/styled/components/chat-history.cjs +1 -1
- package/dist/styled/components/chat-history.js +22 -22
- package/dist/styled/components/embedded-chat/file-upload-input.cjs +1 -1
- package/dist/styled/components/embedded-chat/file-upload-input.js +71 -72
- package/dist/styled/components/embedded-chat/image-preview-modal.js +5 -5
- package/dist/styled/components/embedded-chat.cjs +1 -1
- package/dist/styled/components/embedded-chat.js +198 -198
- package/dist/styled/components/embedded-search.cjs +1 -1
- package/dist/styled/components/embedded-search.js +65 -65
- package/dist/styled/components/loading-indicator.cjs +1 -1
- package/dist/styled/components/loading-indicator.js +1 -1
- package/dist/styled/components/message.cjs +1 -1
- package/dist/styled/components/message.js +90 -90
- package/dist/styled/components/modal.js +3 -3
- package/dist/styled/components/searchbar.js +8 -8
- package/dist/styled/components/sidebar-chat.cjs +1 -1
- package/dist/styled/components/sidebar-chat.js +5 -5
- package/dist/styled/inkeep.css.cjs +13 -3
- package/dist/styled/inkeep.css.js +13 -3
- package/dist/theme/utils/generate-theme-variables.js +6 -6
- package/package.json +1 -1
- package/dist/node_modules/.pnpm/use-sync-external-store@1.5.0_react@19.0.0/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.cjs +0 -9
- /package/dist/node_modules/.pnpm/{use-sync-external-store@1.5.0_react@19.0.0 → use-sync-external-store@1.6.0_react@19.3.0-canary-87ae75b3-20260128}/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.cjs +0 -0
- /package/dist/node_modules/.pnpm/{use-sync-external-store@1.5.0_react@19.0.0 → use-sync-external-store@1.6.0_react@19.3.0-canary-87ae75b3-20260128}/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.js +0 -0
- /package/dist/node_modules/.pnpm/{use-sync-external-store@1.5.0_react@19.0.0 → use-sync-external-store@1.6.0_react@19.3.0-canary-87ae75b3-20260128}/node_modules/use-sync-external-store/shim/index.cjs +0 -0
- /package/dist/node_modules/.pnpm/{use-sync-external-store@1.5.0_react@19.0.0 → use-sync-external-store@1.6.0_react@19.3.0-canary-87ae75b3-20260128}/node_modules/use-sync-external-store/shim/index.js +0 -0
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import P, { useState as C,
|
|
2
|
+
import { jsx as a, jsxs as x } from "react/jsx-runtime";
|
|
3
|
+
import P, { useState as C, useEffect as T, useMemo as w } from "react";
|
|
4
4
|
import { CustomIcon as F } from "../../atoms/icons/custom-icon.js";
|
|
5
5
|
import { useImagePreview as b } from "../../providers/image-preview-provider.js";
|
|
6
|
-
import { useMessage as
|
|
6
|
+
import { useMessage as L } from "../../providers/message-provider.js";
|
|
7
7
|
import { useChat as d } from "./chat-provider.js";
|
|
8
|
-
import {
|
|
8
|
+
import { useFileUploadApi as m, FileUploadRoot as M } from "../../atoms/file-upload.js";
|
|
9
9
|
import { dataAttr as I } from "../../utils/misc.js";
|
|
10
10
|
import { composeEventHandlers as l } from "../../utils/compose-event-handlers.js";
|
|
11
|
-
import { ikp as
|
|
12
|
-
import { useInkeepConfig as
|
|
13
|
-
const
|
|
11
|
+
import { ikp as o } from "../factory.js";
|
|
12
|
+
import { useInkeepConfig as y } from "../../providers/config-provider.js";
|
|
13
|
+
const j = {
|
|
14
14
|
"application/pdf": "filePdf",
|
|
15
15
|
"text/plain": "fileText",
|
|
16
16
|
"text/markdown": "fileMarkdown",
|
|
@@ -33,19 +33,19 @@ const p = {
|
|
|
33
33
|
"text/csv": [".csv"],
|
|
34
34
|
"text/x-log": [".log"],
|
|
35
35
|
"application/json": [".json"]
|
|
36
|
-
},
|
|
36
|
+
}, k = new Set(Object.keys(p)), U = Object.values(p).flat().join(", "), E = 10, N = 1024 * 1024 * 10, R = Object.entries(p).reduce(
|
|
37
37
|
(e, [t, i]) => {
|
|
38
38
|
for (const n of i) e[n] = t;
|
|
39
39
|
return e;
|
|
40
40
|
},
|
|
41
41
|
{}
|
|
42
42
|
);
|
|
43
|
-
function
|
|
43
|
+
function A(e) {
|
|
44
44
|
if (e.type) return e;
|
|
45
|
-
const t = `.${e.name.split(".").pop()?.toLowerCase()}`, i =
|
|
45
|
+
const t = `.${e.name.split(".").pop()?.toLowerCase()}`, i = R[t];
|
|
46
46
|
return i ? new File([e], e.name, { type: i }) : e;
|
|
47
47
|
}
|
|
48
|
-
function
|
|
48
|
+
function O(e) {
|
|
49
49
|
if (!e.length) return null;
|
|
50
50
|
const t = (i) => e.some((n) => n.errors.includes(i));
|
|
51
51
|
return t("TOO_MANY_FILES") ? {
|
|
@@ -53,7 +53,7 @@ function A(e) {
|
|
|
53
53
|
message: `You can only attach up to ${E} files per message.`
|
|
54
54
|
} : t("FILE_INVALID_TYPE") ? {
|
|
55
55
|
title: "Unsupported file type",
|
|
56
|
-
message: `Only ${
|
|
56
|
+
message: `Only ${U} files are supported.`
|
|
57
57
|
} : t("FILE_TOO_LARGE") ? {
|
|
58
58
|
title: "File too large",
|
|
59
59
|
message: `Files must be smaller than ${N / 1024 / 1024}MB.`
|
|
@@ -65,37 +65,37 @@ function A(e) {
|
|
|
65
65
|
message: "This file could not be added."
|
|
66
66
|
};
|
|
67
67
|
}
|
|
68
|
-
const
|
|
68
|
+
const S = o("div", {
|
|
69
69
|
_id: "aiChatMessage__Files"
|
|
70
|
-
}),
|
|
71
|
-
|
|
72
|
-
...t
|
|
73
|
-
}) => {
|
|
74
|
-
const { message: i } = w();
|
|
70
|
+
}), ue = ({ children: e, ...t }) => {
|
|
71
|
+
const { message: i } = L();
|
|
75
72
|
if (i.role !== "user") return null;
|
|
76
73
|
const n = (i.parts ?? []).filter((r) => {
|
|
77
74
|
if (r.type !== "file") return !1;
|
|
78
75
|
const s = r.mediaType;
|
|
79
|
-
return
|
|
76
|
+
return k.has(s ?? "");
|
|
80
77
|
});
|
|
81
|
-
return n.length ? /* @__PURE__ */
|
|
82
|
-
},
|
|
78
|
+
return n.length ? /* @__PURE__ */ a(S, { ...t, children: e(n) }) : null;
|
|
79
|
+
}, D = o("button", {
|
|
83
80
|
_id: "aiChatMessage__File"
|
|
84
|
-
}),
|
|
81
|
+
}), pe = ({
|
|
85
82
|
url: e,
|
|
86
83
|
name: t,
|
|
87
84
|
mediaType: i,
|
|
88
85
|
onClick: n,
|
|
89
86
|
...r
|
|
90
87
|
}) => {
|
|
91
|
-
const { openImagePreview: s } = b(), [c, f] = C(!0), _ =
|
|
92
|
-
|
|
88
|
+
const { openImagePreview: s } = b(), [c, f] = C(!0), _ = w(
|
|
89
|
+
() => new File([], t ?? "file", { type: i }),
|
|
90
|
+
[t, i]
|
|
91
|
+
);
|
|
92
|
+
return /* @__PURE__ */ a(
|
|
93
93
|
v.Provider,
|
|
94
94
|
{
|
|
95
95
|
value: { file: _, objectUrl: e, isLoading: c, setIsLoading: f, onRemove: () => {
|
|
96
96
|
} },
|
|
97
|
-
children: /* @__PURE__ */
|
|
98
|
-
|
|
97
|
+
children: /* @__PURE__ */ a(
|
|
98
|
+
D,
|
|
99
99
|
{
|
|
100
100
|
type: "button",
|
|
101
101
|
"aria-label": g(i ?? "") ? `Preview ${t ?? "file"}` : `Open ${t ?? "file"} in new tab`,
|
|
@@ -115,24 +115,24 @@ const O = a("div", {
|
|
|
115
115
|
)
|
|
116
116
|
}
|
|
117
117
|
);
|
|
118
|
-
},
|
|
118
|
+
}, $ = o("div", {
|
|
119
119
|
_id: "aiChatInput__Fieldset"
|
|
120
|
-
}),
|
|
120
|
+
}), B = (e) => {
|
|
121
121
|
const t = m();
|
|
122
|
-
return /* @__PURE__ */
|
|
123
|
-
|
|
122
|
+
return /* @__PURE__ */ a(
|
|
123
|
+
$,
|
|
124
124
|
{
|
|
125
125
|
...t.getDropzoneProps({ disableClick: !0 }),
|
|
126
126
|
"data-drag-over": I(t.dragging),
|
|
127
127
|
...e
|
|
128
128
|
}
|
|
129
129
|
);
|
|
130
|
-
},
|
|
130
|
+
}, fe = ({
|
|
131
131
|
...e
|
|
132
132
|
}) => {
|
|
133
133
|
const { files: t, setFiles: i, showInputNotification: n } = d();
|
|
134
|
-
return /* @__PURE__ */
|
|
135
|
-
|
|
134
|
+
return /* @__PURE__ */ a(
|
|
135
|
+
M,
|
|
136
136
|
{
|
|
137
137
|
accept: p,
|
|
138
138
|
maxFiles: E,
|
|
@@ -141,38 +141,44 @@ const O = a("div", {
|
|
|
141
141
|
acceptedFiles: t,
|
|
142
142
|
onFileAccept: (r) => i(r.files),
|
|
143
143
|
onFileReject: (r) => {
|
|
144
|
-
const s =
|
|
144
|
+
const s = O(r.files);
|
|
145
145
|
s && n(s);
|
|
146
146
|
},
|
|
147
|
-
children: /* @__PURE__ */
|
|
147
|
+
children: /* @__PURE__ */ a(B, { ...e })
|
|
148
148
|
}
|
|
149
149
|
);
|
|
150
|
-
},
|
|
150
|
+
}, _e = o("div", {
|
|
151
151
|
_id: "aiChatInput__DropZone"
|
|
152
|
-
}),
|
|
152
|
+
}), X = o("div", {
|
|
153
153
|
_id: "aiChatInput__Notification"
|
|
154
|
-
}), _e = (e) => {
|
|
155
|
-
const { inputNotification: t } = d();
|
|
156
|
-
return t ? /* @__PURE__ */ o(B, { role: "alert", ...e }) : null;
|
|
157
|
-
}, X = a("p", {
|
|
158
|
-
_id: "aiChatInput__NotificationTitle"
|
|
159
154
|
}), he = (e) => {
|
|
160
155
|
const { inputNotification: t } = d();
|
|
161
|
-
return t
|
|
162
|
-
}, H =
|
|
156
|
+
return t ? /* @__PURE__ */ a(X, { role: "alert", ...e }) : null;
|
|
157
|
+
}, H = o("p", {
|
|
158
|
+
_id: "aiChatInput__NotificationTitle"
|
|
159
|
+
}), Ce = ({
|
|
160
|
+
children: e,
|
|
161
|
+
...t
|
|
162
|
+
}) => {
|
|
163
|
+
const { inputNotification: i } = d();
|
|
164
|
+
return i?.title ? /* @__PURE__ */ x(H, { ...t, children: [
|
|
165
|
+
e,
|
|
166
|
+
i.title
|
|
167
|
+
] }) : null;
|
|
168
|
+
}, Y = o("p", {
|
|
163
169
|
_id: "aiChatInput__NotificationMessage"
|
|
164
|
-
}),
|
|
170
|
+
}), Fe = (e) => {
|
|
165
171
|
const { inputNotification: t } = d();
|
|
166
|
-
return /* @__PURE__ */
|
|
167
|
-
},
|
|
172
|
+
return /* @__PURE__ */ a(Y, { ...e, children: t?.message });
|
|
173
|
+
}, z = o("button", {
|
|
168
174
|
_id: "aiChatInput__NotificationClose"
|
|
169
|
-
}),
|
|
175
|
+
}), Ie = ({
|
|
170
176
|
onClick: e,
|
|
171
177
|
...t
|
|
172
178
|
}) => {
|
|
173
179
|
const { clearInputNotification: i } = d();
|
|
174
|
-
return /* @__PURE__ */
|
|
175
|
-
|
|
180
|
+
return /* @__PURE__ */ a(
|
|
181
|
+
z,
|
|
176
182
|
{
|
|
177
183
|
type: "button",
|
|
178
184
|
"aria-label": "Dismiss",
|
|
@@ -180,19 +186,19 @@ const O = a("div", {
|
|
|
180
186
|
...t
|
|
181
187
|
}
|
|
182
188
|
);
|
|
183
|
-
},
|
|
189
|
+
}, ve = o("div", {
|
|
184
190
|
_id: "aiChatInput__NotificationContent"
|
|
185
|
-
}),
|
|
191
|
+
}), ge = o("div", {
|
|
186
192
|
_id: "aiChatInput__NotificationHeader"
|
|
187
|
-
}),
|
|
193
|
+
}), Pe = o(F, {
|
|
188
194
|
_id: "aiChatInput__FileUploadButtonIcon",
|
|
189
195
|
iconKey: "fileUpload"
|
|
190
|
-
}),
|
|
196
|
+
}), K = o("button", {
|
|
191
197
|
_id: "aiChatInput__FileUploadButton"
|
|
192
|
-
}),
|
|
193
|
-
const { aiChatSettings: t } =
|
|
194
|
-
return /* @__PURE__ */
|
|
195
|
-
|
|
198
|
+
}), be = (e) => {
|
|
199
|
+
const { aiChatSettings: t } = y(), i = m(), { onClick: n, ...r } = e;
|
|
200
|
+
return /* @__PURE__ */ a(
|
|
201
|
+
K,
|
|
196
202
|
{
|
|
197
203
|
type: "button",
|
|
198
204
|
"aria-label": "Upload file",
|
|
@@ -201,43 +207,40 @@ const O = a("div", {
|
|
|
201
207
|
...r
|
|
202
208
|
}
|
|
203
209
|
);
|
|
204
|
-
},
|
|
210
|
+
}, Z = o("input", {
|
|
205
211
|
_id: "aiChatInput__FileInput"
|
|
206
|
-
}),
|
|
212
|
+
}), Ee = (e) => {
|
|
207
213
|
const t = m();
|
|
208
|
-
return /* @__PURE__ */
|
|
209
|
-
},
|
|
214
|
+
return /* @__PURE__ */ a(Z, { ...e, ...t.getHiddenInputProps() });
|
|
215
|
+
}, V = o("div", {
|
|
210
216
|
_id: "aiChatInput__FileList"
|
|
211
|
-
}),
|
|
212
|
-
children: e,
|
|
213
|
-
...t
|
|
214
|
-
}) => {
|
|
217
|
+
}), Ne = ({ children: e, ...t }) => {
|
|
215
218
|
const n = m().acceptedFiles;
|
|
216
|
-
return n.length ? /* @__PURE__ */
|
|
219
|
+
return n.length ? /* @__PURE__ */ a(V, { ...t, children: e(n) }) : null;
|
|
217
220
|
}, v = P.createContext(null);
|
|
218
221
|
function u() {
|
|
219
222
|
const e = P.useContext(v);
|
|
220
223
|
if (!e) throw new Error("useFileContext must be used within EmbeddedChatPrimitiveFileItem");
|
|
221
224
|
return e;
|
|
222
225
|
}
|
|
223
|
-
const
|
|
226
|
+
const W = o("div", {
|
|
224
227
|
_id: "aiChatInput__FileItem"
|
|
225
|
-
}),
|
|
228
|
+
}), xe = ({ file: e, ...t }) => {
|
|
226
229
|
const i = m(), [n, r] = C(void 0), [s, c] = C(!0);
|
|
227
230
|
T(() => i.createFileUrl(e, (_) => {
|
|
228
231
|
r(_), c(!0);
|
|
229
232
|
}), [e]);
|
|
230
233
|
const f = () => i.deleteFile(e);
|
|
231
|
-
return /* @__PURE__ */
|
|
232
|
-
},
|
|
234
|
+
return /* @__PURE__ */ a(v.Provider, { value: { file: e, objectUrl: n, isLoading: s, setIsLoading: c, onRemove: f }, children: /* @__PURE__ */ a(W, { "data-loading": I(s), ...t }) });
|
|
235
|
+
}, G = o("button", {
|
|
233
236
|
_id: "aiChatInput__FilePreviewTrigger"
|
|
234
|
-
}),
|
|
237
|
+
}), Te = ({
|
|
235
238
|
onClick: e,
|
|
236
239
|
...t
|
|
237
240
|
}) => {
|
|
238
241
|
const { objectUrl: i, file: n } = u(), { openImagePreview: r } = b();
|
|
239
|
-
return /* @__PURE__ */
|
|
240
|
-
|
|
242
|
+
return /* @__PURE__ */ a(
|
|
243
|
+
G,
|
|
241
244
|
{
|
|
242
245
|
type: "button",
|
|
243
246
|
"aria-label": `Preview ${n.name}`,
|
|
@@ -248,17 +251,17 @@ const V = a("div", {
|
|
|
248
251
|
...t
|
|
249
252
|
}
|
|
250
253
|
);
|
|
251
|
-
},
|
|
254
|
+
}, J = o("span", {
|
|
252
255
|
_id: "aiChatInput__FileContent"
|
|
253
|
-
}),
|
|
256
|
+
}), we = (e) => /* @__PURE__ */ a(J, { ...e }), q = o("img", {
|
|
254
257
|
_id: "aiChatInput__FileThumbnail"
|
|
255
|
-
}),
|
|
258
|
+
}), Le = ({
|
|
256
259
|
onLoad: e,
|
|
257
260
|
...t
|
|
258
261
|
}) => {
|
|
259
262
|
const { objectUrl: i, file: n, setIsLoading: r } = u();
|
|
260
|
-
return /* @__PURE__ */
|
|
261
|
-
|
|
263
|
+
return /* @__PURE__ */ a(
|
|
264
|
+
q,
|
|
262
265
|
{
|
|
263
266
|
src: i,
|
|
264
267
|
alt: n.name,
|
|
@@ -266,26 +269,26 @@ const V = a("div", {
|
|
|
266
269
|
...t
|
|
267
270
|
}
|
|
268
271
|
);
|
|
269
|
-
},
|
|
270
|
-
const { file: t } = u(), i =
|
|
271
|
-
return /* @__PURE__ */
|
|
272
|
-
},
|
|
272
|
+
}, Me = ({ className: e }) => {
|
|
273
|
+
const { file: t } = u(), i = j[A(t).type] ?? "fileText";
|
|
274
|
+
return /* @__PURE__ */ a(F, { iconKey: i, className: e });
|
|
275
|
+
}, Q = o("span", {
|
|
273
276
|
_id: "aiChatInput__FileName"
|
|
274
|
-
}),
|
|
277
|
+
}), ye = (e) => {
|
|
275
278
|
const { file: t } = u();
|
|
276
|
-
return /* @__PURE__ */
|
|
277
|
-
},
|
|
279
|
+
return /* @__PURE__ */ a(Q, { ...e, children: t.name });
|
|
280
|
+
}, ee = o("button", {
|
|
278
281
|
_id: "aiChatInput__FileRemove"
|
|
279
|
-
}),
|
|
282
|
+
}), je = o(F, {
|
|
280
283
|
_id: "aiChatInput__FileRemoveIcon",
|
|
281
284
|
iconKey: "close"
|
|
282
|
-
}),
|
|
285
|
+
}), ke = ({
|
|
283
286
|
onClick: e,
|
|
284
287
|
...t
|
|
285
288
|
}) => {
|
|
286
289
|
const { onRemove: i } = u();
|
|
287
|
-
return /* @__PURE__ */
|
|
288
|
-
|
|
290
|
+
return /* @__PURE__ */ a(
|
|
291
|
+
ee,
|
|
289
292
|
{
|
|
290
293
|
type: "button",
|
|
291
294
|
"aria-label": "Remove file",
|
|
@@ -295,34 +298,34 @@ const V = a("div", {
|
|
|
295
298
|
);
|
|
296
299
|
};
|
|
297
300
|
export {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
301
|
+
U as ACCEPTED_FILE_EXTENSIONS,
|
|
302
|
+
k as ACCEPTED_FILE_MIME_TYPES,
|
|
303
|
+
_e as EmbeddedChatPrimitiveDropZone,
|
|
304
|
+
we as EmbeddedChatPrimitiveFileContent,
|
|
305
|
+
Ee as EmbeddedChatPrimitiveFileInput,
|
|
306
|
+
xe as EmbeddedChatPrimitiveFileItem,
|
|
307
|
+
Ne as EmbeddedChatPrimitiveFileList,
|
|
308
|
+
ye as EmbeddedChatPrimitiveFileName,
|
|
309
|
+
Te as EmbeddedChatPrimitiveFilePreviewTrigger,
|
|
310
|
+
ke as EmbeddedChatPrimitiveFileRemove,
|
|
311
|
+
je as EmbeddedChatPrimitiveFileRemoveIcon,
|
|
312
|
+
Le as EmbeddedChatPrimitiveFileThumbnail,
|
|
313
|
+
Me as EmbeddedChatPrimitiveFileTypeIcon,
|
|
314
|
+
be as EmbeddedChatPrimitiveFileUploadButton,
|
|
315
|
+
Pe as EmbeddedChatPrimitiveFileUploadButtonIcon,
|
|
316
|
+
fe as EmbeddedChatPrimitiveInputFieldset,
|
|
317
|
+
he as EmbeddedChatPrimitiveInputNotification,
|
|
318
|
+
Ie as EmbeddedChatPrimitiveInputNotificationClose,
|
|
319
|
+
ve as EmbeddedChatPrimitiveInputNotificationContent,
|
|
320
|
+
ge as EmbeddedChatPrimitiveInputNotificationHeader,
|
|
321
|
+
Fe as EmbeddedChatPrimitiveInputNotificationMessage,
|
|
322
|
+
Ce as EmbeddedChatPrimitiveInputNotificationTitle,
|
|
323
|
+
pe as EmbeddedChatPrimitiveMessageFile,
|
|
324
|
+
ue as EmbeddedChatPrimitiveMessageFiles,
|
|
322
325
|
p as FILE_ACCEPT_MAP,
|
|
323
|
-
|
|
326
|
+
j as FILE_TYPE_ICON_MAP,
|
|
324
327
|
E as MAX_FILES,
|
|
325
328
|
N as MAX_FILE_SIZE,
|
|
326
329
|
g as isImageMimeType,
|
|
327
|
-
|
|
330
|
+
A as normalizeFileType
|
|
328
331
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as r, jsxs as l } from "react/jsx-runtime";
|
|
3
|
-
import {
|
|
3
|
+
import { Close as v, Title as s, Overlay as P, Root as g, Content as c } from "../../atoms/dialog.js";
|
|
4
4
|
import { CustomIcon as w } from "../../atoms/icons/custom-icon.js";
|
|
5
5
|
import { useImagePreview as o } from "../../providers/image-preview-provider.js";
|
|
6
6
|
import { composeEventHandlers as I } from "../../utils/compose-event-handlers.js";
|
|
@@ -19,7 +19,7 @@ const C = a(g, {
|
|
|
19
19
|
...m
|
|
20
20
|
}
|
|
21
21
|
);
|
|
22
|
-
}, O = a(
|
|
22
|
+
}, O = a(P, {
|
|
23
23
|
_id: "aiChatImagePreviewModal__Overlay"
|
|
24
24
|
}), h = a(c, {
|
|
25
25
|
_id: "aiChatImagePreviewModal__Content"
|
|
@@ -56,7 +56,7 @@ const C = a(g, {
|
|
|
56
56
|
}), k = (i) => {
|
|
57
57
|
const { imagePreview: e } = o();
|
|
58
58
|
return /* @__PURE__ */ r(M, { ...i, children: e?.name });
|
|
59
|
-
}, H = a(
|
|
59
|
+
}, H = a(v, {
|
|
60
60
|
_id: "aiChatImagePreviewModal__Close",
|
|
61
61
|
children: /* @__PURE__ */ r(w, { iconKey: "close" })
|
|
62
62
|
});
|
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
2
|
-
|
|
3
|
-
It seems I might be having some issues right now. Please clear the chat and try again.`,vt=()=>{const{baseSettings:m,aiChatSettings:h}=st.useInkeepConfig(),[r="",d]=ft.useControllableState({prop:h.conversationIdOverride,defaultProp:h.conversationIdOverride??""}),ke=Ye.useModal(),we=et.useOptionalChatBubble(),Te=tt.useOptionalSidebarChat(),{logEvent:v}=ct.useBaseEvents(),{setConversationId:Ee,emitToParent:E}=pt.useStreamingEvents(),Y=t.useRef(r);t.useEffect(()=>{const e=Y.current;Y.current=r,e!==r&&v({eventName:"chat_conversation_changed",properties:{conversationId:r,previousConversationId:e}})},[r,v]);const[C,M]=t.useState(""),Me=e=>M(e.target.value),{shouldBypassCaptcha:ee,filters:te,privacyPreferences:qe,userProperties:U}=m,{authToken:q,isLoading:Fe,refreshToken:se}=ot.useAuthToken(),re=!!m.getAuthToken,f=!!q,{onInputMessageChange:xe,filters:ne,baseUrl:F,agentUrl:Pe,context:ae,headers:oe,appId:R,apiKey:y,files:S}=h,Ne=ke?.isOpen??we?.isOpen??Te?.isOpen??!0,{getCaptchaHeader:I,invalidate:c}=rt.useCaptcha({baseUrl:F,shouldBypassCaptcha:ee||!!y,shouldMakeInitialRequest:Ne}),ie=t.useRef(I);ie.current=I;const ue=Pe||`${F}/run/api/chat`,{sessionToken:D,refreshSession:L}=at.useAnonymousSession({baseUrl:F,appId:R,getCaptchaHeader:I,invalidateCaptcha:c,optOutAllAnalytics:qe?.optOutAllAnalytics,enabled:!f&&!Fe}),ce=y??(f?q:D),{loadConversation:le}=it.useConversationLoader({baseUrl:F,appId:R,authToken:ce,getCaptchaHeader:I,invalidateCaptcha:c,refreshSession:y||f?void 0:L}),[Oe,de]=t.useState(!1),$=t.useRef(null);$.current=D;const B=t.useRef(null);B.current=q;const z=t.useRef(void 0);z.current=U&&Object.keys(U).length>0?JSON.stringify(U):void 0;const b=t.useRef(0),fe=t.useRef(null),H=t.useRef(null),A=t.useRef(void 0),_e=S?.map(e=>`${e.filename??""}:${e.mediaType}:${e.url.length}:${e.url.slice(0,64)}:${e.url.slice(-32)}`).join(`
|
|
4
|
-
`)??"";t.useEffect(()=>{A.current=S?.length?S:void 0},[_e]);const pe=t.useRef(oe);pe.current=oe;const K=t.useRef(void 0);K.current=te||ne?JSON.stringify({...te,...ne}):void 0;const Ue=e=>{switch(e.code){case 400:return e.message;case 401:return re?"Authentication failed. Please try again.":_;case 403:return`There seems to be a configuration error. Please contact ${m.organizationDisplayName??"Administrator"}`;default:return _}},[x,j]=t.useState([]),De=t.useMemo(()=>new Xe.DefaultChatTransport({api:ue,headers:()=>{const e=y??B.current??$.current;return{"x-inkeep-client-timezone":Intl.DateTimeFormat().resolvedOptions().timeZone,"x-inkeep-client-timestamp":new Date().toISOString(),...R?{"x-inkeep-app-id":R}:{},...e?{Authorization:`Bearer ${e}`}:{},...K.current?{"inkeep-filters":K.current}:{},...z.current?{"x-inkeep-user-properties":z.current}:{},...pe.current}},prepareSendMessagesRequest:async e=>{const u=await ie.current(),s=e.messages[e.messages.length-1];return s||console.warn("[useInkeepChat] prepareSendMessagesRequest called with empty messages array"),{body:{...e.body,id:e.id,messages:s?[s]:[],trigger:e.trigger,messageId:e.messageId},headers:{...e.headers,...u}}},body:{requestContext:ae}}),[ue,ae,R,y]),{messages:P,sendMessage:J,addToolApprovalResponse:G,status:he,setMessages:g,stop:N,error:Q}=Ze.useChat({transport:De,onData(e){E(e.type,e.data)},async onFinish(){E("completion",{conversationId:r}),await v({eventName:"assistant_message_received",properties:{conversationId:r}}),v({eventName:"assistant_answer_displayed",properties:{conversationId:r}})},onError(e){console.error("onError",{code:e.code,message:e.message});const u=ee||y?null:mt(e);if(u!==null&&b.current<1){b.current++;const s=H.current,a=fe.current;(async()=>{if(u==="session"&&re){const n=await se();if(!n)throw new Error("Auth token refresh failed");B.current=n}else if(u==="session"){const n=await L();n&&($.current=n)}else c();if(s){G(s);return}a&&(g(n=>{let o=[...n];return o.at(-1)?.role==="assistant"&&(o=o.slice(0,-1)),o.at(-1)?.role==="user"&&(o=o.slice(0,-1)),o}),J(a.files?.length?{parts:[{type:"text",text:a.content},...a.files]}:{text:a.content},{body:a.body}))})().catch(()=>{b.current=0,c(),g(n=>{const o=[...n],p=o[o.length-1];if(!p)return o;const l=_;return p.role==="user"?o.push({id:O.generateUid(16),role:"assistant",parts:[{type:"text",text:l}]}):p.parts=[{type:"text",text:l}],o})});return}b.current=0,u!==null&&c(),v({eventName:"chat_error",properties:{conversationId:r,error:e.message}}),g(s=>{const a=[...s],i=a[a.length-1];if(i){const n=Ue(e);i.role==="user"?a.push({id:O.generateUid(16),role:"assistant",parts:[{type:"text",text:n}]}):i.parts=[{type:"text",text:n}]}return a})}}),ge=t.useRef(f);t.useEffect(()=>{const e=ge.current;ge.current=f,e!==f&&(N(),k(null),g([]),d(""),M(""),j([]),c())},[f,N,g,d,c]);const me=he==="submitted",W=he==="streaming",Le=t.useMemo(()=>{const e=i=>{if(!i||typeof i!="object")return!1;const n=i;return typeof n.type=="string"&&n.type.startsWith("tool-")},s=[...P??[]].reverse().find(i=>i.role==="assistant");if(!s)return!1;const a=s.parts?.at(-1);return!(!e(a)||a.state!=="output-available"||!a.approval?.id||W)},[P,W]),ve=W||Le,ye=me||ve,$e=P.length===0,V=!C.trim()&&x.length===0||ye,Be=nt.useMediaQuery("(max-width: 768px)"),[ze,k]=t.useState(null);t.useEffect(()=>{Q&&k(Q)},[Q]);const He=()=>k(null),{inputNotification:Ke,showInputNotification:be,clearInputNotification:je}=gt.useInputNotification(),Ce=t.useRef(null);t.useEffect(()=>{xe?.(C)},[C]);const Je=e=>{e.key==="Enter"&&!e.shiftKey&&!V&&!e.nativeEvent.isComposing&&(e.preventDefault(),Z())},Z=async(e=C)=>{if(V&&(!e||e.trim().length===0)&&x.length===0)return;const u=x;j([]),M(""),b.current=0,H.current=null,await v({eventName:"user_message_submitted",properties:{conversationId:r}});let s=r;s||(s=`conv_${O.generateUid(16)}`,d(s)),Ee(s);const a=A.current;A.current=void 0;let i,n;if(a?.length){let o;try{o=await Promise.all(u.map(p=>{const l=Ae.normalizeFileType(p);return new Promise((Ve,Ie)=>{const T=new FileReader;T.onload=()=>{if(typeof T.result!="string"){Ie(new Error(`Failed to read file "${l.name}"`));return}Ve({type:"file",url:T.result,mediaType:l.type,filename:l.name})},T.onerror=()=>Ie(new Error(`Failed to read file "${l.name}"`)),T.readAsDataURL(l)})}))}catch{be({title:"Failed to attach files",message:"Could not read one or more files. Please try again."});return}n=[...o,...a],i=e.trim()?{parts:[{type:"text",text:e},...n]}:{parts:n}}else if(u.length>0){const o=new DataTransfer;for(const l of u)o.items.add(Ae.normalizeFileType(l));const p=o.files;i=e.trim()?{text:e,files:p}:{files:p}}else i={text:e};fe.current={content:e,body:{conversationId:s},files:n},J(i,{body:{conversationId:s}})},Ge=t.useCallback(e=>{b.current=0,H.current=e,G(e)},[G]),X=t.useCallback(()=>{N().then(()=>{E("aborted",{conversationId:r})})},[N,r,E]),Re=()=>{He(),g([]),d(""),c(),A.current=S?.length?S:void 0,v({eventName:"chat_clear_button_clicked",properties:{conversationId:r}})},w=t.useCallback((e,u)=>{k(null),g(u),d(e),c(),A.current=void 0},[g,d,c]),Se=t.useCallback(async(e,u)=>{X(),w(e,[]),de(!0);try{const s=await le(e,u);if(s===null)return!1;const i=s[s.length-1]?.role==="user"?[...s,{id:O.generateUid(16),role:"assistant",parts:[{type:"text",text:"This session was interrupted. Please check back in a few minutes or start a new conversation."}]}]:s;return w(e,i),!0}finally{u?.aborted||de(!1)}},[w,le,X]);ut.useInitialConversation({conversationId:h.conversationId,effectiveAuthToken:ce,loadAndRestoreSession:Se,onLoadFailed:()=>w("",[])});const{openForm:Qe}=lt.useChatForm(),We=dt.useWidget();return t.useImperativeHandle(h.chatFunctionsRef,()=>({submitMessage:Z,updateInputMessage(e){M(e)},clearChat:Re,openForm:e=>{We?.setView("chat"),Qe(e,void 0)},focusInput:()=>{Ce.current?.focus()}})),{messages:P,sendMessage:J,addToolApprovalResponse:Ge,isLoading:me,isStreaming:ve,isBusy:ye,error:ze,setError:k,isSubmitDisabled:V,input:C,handleInputChange:Me,handleInputKeyDown:Je,handleSubmit:Z,stop:X,clear:Re,inputRef:Ce,isMobile:Be,files:x,setFiles:j,isNewChat:$e,conversationId:r,restoreSession:w,loadAndRestoreSession:Se,isSessionLoading:Oe,authToken:f?q:D,refreshSession:f?se:L,getCaptchaHeader:I,invalidateCaptcha:c,inputNotification:Ke,showInputNotification:be,clearInputNotification:je}};exports.DEFAULT_ERROR_MESSAGE=_;exports.useInkeepChat=vt;
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const et=require("@ai-sdk/react"),we=require("./file-upload-input.cjs"),tt=require("ai"),t=require("react"),st=require("../modal/modal-provider.cjs"),rt=require("../../providers/chat-bubble-provider.cjs"),nt=require("../../providers/sidebar-chat-provider.cjs"),at=require("../../providers/config-provider.cjs"),ot=require("./use-captcha.cjs"),it=require("../../hooks/use-media-query.cjs"),ut=require("../../hooks/use-anonymous-session.cjs"),ct=require("../../hooks/use-auth-token.cjs"),lt=require("../../hooks/use-conversation-loader.cjs"),dt=require("../../hooks/use-initial-conversation.cjs"),D=require("../../utils/generate-uid.cjs"),pt=require("../../providers/base-events-provider.cjs"),ft=require("../../providers/chat-form-provider.cjs"),gt=require("../../providers/widget-provider.cjs"),ht=require("@radix-ui/react-use-controllable-state"),mt=require("../../hooks/use-streaming-events.cjs"),vt=require("../../hooks/use-input-notification.cjs"),p=require("./chat-error-helpers.cjs"),yt=()=>{const{baseSettings:U,aiChatSettings:R}=at.useInkeepConfig(),[u="",m]=ht.useControllableState({prop:R.conversationIdOverride,defaultProp:R.conversationIdOverride??""}),ke=st.useModal(),Me=rt.useOptionalChatBubble(),Fe=nt.useOptionalSidebarChat(),{logEvent:h}=pt.useBaseEvents(),{setConversationId:_e,emitToParent:_}=mt.useStreamingEvents(),ae=t.useRef(u);t.useEffect(()=>{const e=ae.current;ae.current=u,e!==u&&h({eventName:"chat_conversation_changed",properties:{conversationId:u,previousConversationId:e}})},[u,h]);const[C,S]=t.useState(""),qe=e=>S(e.target.value),{shouldBypassCaptcha:oe,filters:ie,privacyPreferences:xe,userProperties:B}=U,{authToken:q,isLoading:Oe,refreshToken:ue}=ct.useAuthToken(),ce=!!U.getAuthToken,f=!!q,{onInputMessageChange:Pe,filters:le,baseUrl:x,agentUrl:Le,context:de,headers:pe,appId:E,apiKey:v,files:A}=R,Ne=ke?.isOpen??Me?.isOpen??Fe?.isOpen??!0,{getCaptchaHeader:b,invalidate:l}=ot.useCaptcha({baseUrl:x,shouldBypassCaptcha:oe||!!v,shouldMakeInitialRequest:Ne}),fe=t.useRef(b);fe.current=b;const ge=Le||`${x}/run/api/chat`,{sessionToken:$,refreshSession:z}=ut.useAnonymousSession({baseUrl:x,appId:E,getCaptchaHeader:b,invalidateCaptcha:l,optOutAllAnalytics:xe?.optOutAllAnalytics,enabled:!f&&!Oe}),he=v??(f?q:$),{loadConversation:me}=lt.useConversationLoader({baseUrl:x,appId:E,authToken:he,getCaptchaHeader:b,invalidateCaptcha:l,refreshSession:v||f?void 0:z}),[De,ve]=t.useState(!1),G=t.useRef(null);G.current=$;const H=t.useRef(null);H.current=q;const K=t.useRef(void 0);K.current=B&&Object.keys(B).length>0?JSON.stringify(B):void 0;const y=t.useRef(0),V=t.useRef(null),j=t.useRef(null),I=t.useRef(void 0),Ue=A?.map(e=>`${e.filename??""}:${e.mediaType}:${e.url.length}:${e.url.slice(0,64)}:${e.url.slice(-32)}`).join(`
|
|
2
|
+
`)??"";t.useEffect(()=>{I.current=A?.length?A:void 0},[Ue]);const ye=t.useRef(pe);ye.current=pe;const J=t.useRef(void 0);J.current=ie||le?JSON.stringify({...ie,...le}):void 0;const Be=e=>{switch(p.resolveHttpStatusCode(e)){case 400:try{const s=JSON.parse(e.message??"");return s.detail??s.error?.message??p.RECOVERABLE_FALLBACK_MESSAGE}catch{return e.message?.trim()||p.RECOVERABLE_FALLBACK_MESSAGE}case 401:return ce?"Authentication failed. Please try again.":p.DEFAULT_ERROR_MESSAGE;case 403:return`There seems to be a configuration error. Please contact ${U.organizationDisplayName??"Administrator"}`;case 429:return p.RATE_LIMIT_MESSAGE;default:return p.DEFAULT_ERROR_MESSAGE}},[O,Q]=t.useState([]),$e=t.useMemo(()=>new tt.DefaultChatTransport({api:ge,headers:()=>{const e=v??H.current??G.current;return{"x-inkeep-client-timezone":Intl.DateTimeFormat().resolvedOptions().timeZone,"x-inkeep-client-timestamp":new Date().toISOString(),"x-inkeep-invocation-type":"chat_widget",...E?{"x-inkeep-app-id":E}:{},...e?{Authorization:`Bearer ${e}`}:{},...J.current?{"inkeep-filters":J.current}:{},...K.current?{"x-inkeep-user-properties":K.current}:{},...ye.current}},prepareSendMessagesRequest:async e=>{const i=await fe.current(),s=e.messages[e.messages.length-1];return s||console.warn("[useInkeepChat] prepareSendMessagesRequest called with empty messages array"),{body:{...e.body,id:e.id,messages:s?[s]:[],trigger:e.trigger,messageId:e.messageId},headers:{...e.headers,...i}}},body:{requestContext:de}}),[ge,de,E,v]),{messages:P,sendMessage:W,addToolApprovalResponse:Z,status:Re,setMessages:g,stop:L,error:N}=et.useChat({transport:$e,onData(e){_(e.type,e.data)},async onFinish(){_("completion",{conversationId:u}),await h({eventName:"assistant_message_received",properties:{conversationId:u}}),h({eventName:"assistant_answer_displayed",properties:{conversationId:u}})},onError(e){console.error("onError",{code:e.code,message:e.message});const i=oe||v?null:p.resolveStreamingAuthError(e);if(i!==null&&y.current<1){y.current++;const a=j.current,r=V.current;(async()=>{if(i==="session"&&ce){const c=await ue();if(!c)throw new Error("Auth token refresh failed");H.current=c}else if(i==="session"){const c=await z();c&&(G.current=c)}else l();if(a){Z(a);return}r&&(g(c=>{let n=[...c];return n.at(-1)?.role==="assistant"&&(n=n.slice(0,-1)),n.at(-1)?.role==="user"&&(n=n.slice(0,-1)),n}),W(r.files?.length?{parts:[{type:"text",text:r.content},...r.files]}:{text:r.content},{body:r.body}))})().catch(()=>{y.current=0,l(),g(c=>{const n=[...c],k=n[n.length-1];if(!k)return n;const M=p.DEFAULT_ERROR_MESSAGE;return k.role==="user"?n.push({id:D.generateUid(16),role:"assistant",parts:[{type:"text",text:M}]}):k.parts=[{type:"text",text:M}],n})});return}y.current=0,i!==null&&l();const s=p.isRecoverableError(e),d=Be(e);if(h({eventName:"chat_error",properties:{conversationId:u,error:e.message}}),s){se({title:"Request failed",message:d},p.RECOVERABLE_NOTIFICATION_DURATION_MS),g(r=>{let o=[...r];return o.at(-1)?.role==="assistant"&&(o=o.slice(0,-1)),o.at(-1)?.role==="user"&&(o=o.slice(0,-1)),o});const a=V.current?.content;a&&S(a),te.current=e;return}g(a=>{const r=[...a],o=r[r.length-1];return o&&(o.role==="user"?r.push({id:D.generateUid(16),role:"assistant",parts:[{type:"text",text:d}]}):o.parts=[{type:"text",text:d}]),r})}}),Ce=t.useRef(f);t.useEffect(()=>{const e=Ce.current;Ce.current=f,e!==f&&(L(),T(null),g([]),m(""),S(""),Q([]),l())},[f,L,g,m,l]);const Se=Re==="submitted",X=Re==="streaming",ze=t.useMemo(()=>{const e=a=>{if(!a||typeof a!="object")return!1;const r=a;return typeof r.type=="string"&&r.type.startsWith("tool-")},s=[...P??[]].reverse().find(a=>a.role==="assistant");if(!s)return!1;const d=s.parts?.at(-1);return!(!e(d)||d.state!=="output-available"||!d.approval?.id||X)},[P,X]),[Ge,Y]=t.useState(!1),Ee=X||ze&&!Ge,Ae=Se||Ee,He=P.length===0,ee=!C.trim()&&O.length===0||Ae,Ke=it.useMediaQuery("(max-width: 768px)"),[Ve,T]=t.useState(null),te=t.useRef(null);t.useEffect(()=>{if(N){if(te.current===N){te.current=null;return}T(N)}},[N]);const je=()=>T(null),{inputNotification:Je,showInputNotification:se,clearInputNotification:Qe}=vt.useInputNotification(),be=t.useRef(null);t.useEffect(()=>{Pe?.(C)},[C]);const We=e=>{e.key==="Enter"&&!e.shiftKey&&!ee&&!e.nativeEvent.isComposing&&(e.preventDefault(),re())},re=async(e=C)=>{if(ee&&(!e||e.trim().length===0)&&O.length===0)return;const i=O;Q([]),S(""),y.current=0,j.current=null,Y(!1),await h({eventName:"user_message_submitted",properties:{conversationId:u}});let s=u;s||(s=`conv_${D.generateUid(16)}`,m(s)),_e(s);const d=I.current;I.current=void 0;let a,r;if(d?.length){let o;try{o=await Promise.all(i.map(c=>{const n=we.normalizeFileType(c);return new Promise((k,M)=>{const F=new FileReader;F.onload=()=>{if(typeof F.result!="string"){M(new Error(`Failed to read file "${n.name}"`));return}k({type:"file",url:F.result,mediaType:n.type,filename:n.name})},F.onerror=()=>M(new Error(`Failed to read file "${n.name}"`)),F.readAsDataURL(n)})}))}catch{se({title:"Failed to attach files",message:"Could not read one or more files. Please try again."});return}r=[...o,...d],a=e.trim()?{parts:[{type:"text",text:e},...r]}:{parts:r}}else if(i.length>0){const o=new DataTransfer;for(const n of i)o.items.add(we.normalizeFileType(n));const c=o.files;a=e.trim()?{text:e,files:c}:{files:c}}else a={text:e};V.current={content:e,body:{conversationId:s},files:r},W(a,{body:{conversationId:s}})},Ze=t.useCallback(e=>{y.current=0,j.current=e,Y(!1),Z(e)},[Z]),ne=t.useCallback(()=>{Y(!0),L().then(()=>{_("aborted",{conversationId:u})})},[L,u,_]),Ie=()=>{je(),g([]),m(""),l(),I.current=A?.length?A:void 0,h({eventName:"chat_clear_button_clicked",properties:{conversationId:u}})},w=t.useCallback((e,i)=>{T(null),g(i),m(e),l(),I.current=void 0},[g,m,l]),Te=t.useCallback(async(e,i)=>{ne(),w(e,[]),ve(!0);try{const s=await me(e,i);if(s===null)return!1;const a=s[s.length-1]?.role==="user"?[...s,{id:D.generateUid(16),role:"assistant",parts:[{type:"text",text:"This session was interrupted. Please check back in a few minutes or start a new conversation."}]}]:s;return w(e,a),!0}finally{i?.aborted||ve(!1)}},[w,me,ne]);dt.useInitialConversation({conversationId:R.conversationId,effectiveAuthToken:he,loadAndRestoreSession:Te,onLoadFailed:()=>w("",[])});const{openForm:Xe}=ft.useChatForm(),Ye=gt.useWidget();return t.useImperativeHandle(R.chatFunctionsRef,()=>({submitMessage:re,updateInputMessage(e){S(e)},clearChat:Ie,openForm:e=>{Ye?.setView("chat"),Xe(e,void 0)},focusInput:()=>{be.current?.focus()}})),{messages:P,sendMessage:W,addToolApprovalResponse:Ze,isLoading:Se,isStreaming:Ee,isBusy:Ae,error:Ve,setError:T,isSubmitDisabled:ee,input:C,handleInputChange:qe,handleInputKeyDown:We,handleSubmit:re,stop:ne,clear:Ie,inputRef:be,isMobile:Ke,files:O,setFiles:Q,isNewChat:He,conversationId:u,restoreSession:w,loadAndRestoreSession:Te,isSessionLoading:De,authToken:f?q:$,refreshSession:f?ue:z,getCaptchaHeader:b,invalidateCaptcha:l,inputNotification:Je,showInputNotification:se,clearInputNotification:Qe}};exports.useInkeepChat=yt;
|
|
@@ -2,12 +2,11 @@ import { KeyboardEvent, Dispatch, SetStateAction, RefObject } from 'react';
|
|
|
2
2
|
import { FileUIPart, ChatRequestOptions } from 'ai';
|
|
3
3
|
import { Message } from '../../../types/index.ts';
|
|
4
4
|
import { InputNotification } from '../../hooks/use-input-notification';
|
|
5
|
-
export declare const DEFAULT_ERROR_MESSAGE = "Hmm.. \n\nIt seems I might be having some issues right now. Please clear the chat and try again.";
|
|
6
5
|
export declare const useInkeepChat: () => {
|
|
7
6
|
messages: Message[];
|
|
8
7
|
sendMessage: (message?: (Omit<Message, "id" | "role"> & {
|
|
9
8
|
id?: string | undefined;
|
|
10
|
-
role?: "
|
|
9
|
+
role?: "user" | "system" | "assistant" | undefined;
|
|
11
10
|
} & {
|
|
12
11
|
text?: never;
|
|
13
12
|
files?: never;
|