@inkeep/agents-ui 0.0.0-dev-20260508233535 → 0.0.0-dev-20260508234956
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/index.cjs +1 -1
- package/dist/index.js +153 -156
- package/dist/primitives/components/embedded-chat/use-inkeep-chat.cjs +2 -2
- package/dist/primitives/components/embedded-chat/use-inkeep-chat.js +242 -226
- package/dist/primitives/components/embedded-chat.d.ts +1 -1
- package/dist/primitives/index.cjs +1 -1
- package/dist/primitives/index.js +141 -144
- package/dist/primitives/providers/index.cjs +1 -1
- package/dist/primitives/providers/index.d.ts +0 -1
- package/dist/primitives/providers/index.js +48 -51
- package/dist/react/embedded-chat.cjs +1 -1
- package/dist/react/embedded-chat.js +74 -75
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.js +153 -156
- package/dist/styled/index.cjs +1 -1
- package/dist/styled/index.js +145 -148
- package/package.json +1 -1
- package/dist/primitives/providers/chat-auth-provider.cjs +0 -1
- package/dist/primitives/providers/chat-auth-provider.d.ts +0 -15
- package/dist/primitives/providers/chat-auth-provider.js +0 -44
|
@@ -1,29 +1,34 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useChat as
|
|
3
|
-
import { normalizeFileType as
|
|
4
|
-
import { DefaultChatTransport as
|
|
5
|
-
import { useRef as c, useEffect as
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
2
|
+
import { useChat as it } from "@ai-sdk/react";
|
|
3
|
+
import { normalizeFileType as Oe } from "./file-upload-input.js";
|
|
4
|
+
import { DefaultChatTransport as lt } from "ai";
|
|
5
|
+
import { useRef as c, useEffect as x, useState as F, useMemo as _e, useCallback as $, useImperativeHandle as ct } from "react";
|
|
6
|
+
import { useModal as ut } from "../modal/modal-provider.js";
|
|
7
|
+
import { useOptionalChatBubble as pt } from "../../providers/chat-bubble-provider.js";
|
|
8
|
+
import { useOptionalSidebarChat as dt } from "../../providers/sidebar-chat-provider.js";
|
|
9
|
+
import { useInkeepConfig as ft } from "../../providers/config-provider.js";
|
|
10
|
+
import { useCaptcha as mt } from "./use-captcha.js";
|
|
11
|
+
import { useMediaQuery as gt } from "../../hooks/use-media-query.js";
|
|
12
|
+
import { useAnonymousSession as ht } from "../../hooks/use-anonymous-session.js";
|
|
13
|
+
import { useAuthToken as vt } from "../../hooks/use-auth-token.js";
|
|
14
|
+
import { useConversationLoader as yt } from "../../hooks/use-conversation-loader.js";
|
|
15
|
+
import { useInitialConversation as Ct } from "../../hooks/use-initial-conversation.js";
|
|
16
|
+
import { generateUid as U } from "../../utils/generate-uid.js";
|
|
17
|
+
import { useBaseEvents as At } from "../../providers/base-events-provider.js";
|
|
18
|
+
import { useChatForm as St } from "../../providers/chat-form-provider.js";
|
|
19
|
+
import { useWidget as bt } from "../../providers/widget-provider.js";
|
|
20
|
+
import { useControllableState as Rt } from "@radix-ui/react-use-controllable-state";
|
|
21
|
+
import { useStreamingEvents as It } from "../../hooks/use-streaming-events.js";
|
|
22
|
+
import { useInputNotification as wt } from "../../hooks/use-input-notification.js";
|
|
23
|
+
import { resolveStreamingAuthError as Tt, DEFAULT_ERROR_MESSAGE as ce, isRecoverableError as kt, RECOVERABLE_NOTIFICATION_DURATION_MS as Et, resolveHttpStatusCode as Mt, RATE_LIMIT_MESSAGE as xt, RECOVERABLE_FALLBACK_MESSAGE as Ne } from "./chat-error-helpers.js";
|
|
24
|
+
const Yt = () => {
|
|
25
|
+
const { baseSettings: q, aiChatSettings: y } = ft(), [i = "", g] = Rt({
|
|
26
|
+
prop: y.conversationIdOverride,
|
|
27
|
+
defaultProp: y.conversationIdOverride ?? ""
|
|
28
|
+
}), Pe = ut(), Le = pt(), De = dt(), { logEvent: m } = At(), { setConversationId: Be, emitToParent: O } = It(), ue = c(i);
|
|
29
|
+
x(() => {
|
|
30
|
+
const e = ue.current;
|
|
31
|
+
ue.current = i, e !== i && m({
|
|
27
32
|
eventName: "chat_conversation_changed",
|
|
28
33
|
properties: {
|
|
29
34
|
conversationId: i,
|
|
@@ -31,87 +36,98 @@ const Dt = () => {
|
|
|
31
36
|
}
|
|
32
37
|
});
|
|
33
38
|
}, [i, m]);
|
|
34
|
-
const [
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
getCaptchaHeader:
|
|
60
|
-
invalidateCaptcha:
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
K
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
39
|
+
const [C, A] = F(""), $e = (e) => A(e.target.value), {
|
|
40
|
+
shouldBypassCaptcha: pe,
|
|
41
|
+
filters: de,
|
|
42
|
+
privacyPreferences: Ue,
|
|
43
|
+
userProperties: z,
|
|
44
|
+
analyticsProperties: H
|
|
45
|
+
} = q, { authToken: _, isLoading: qe, refreshToken: fe } = vt(), me = !!q.getAuthToken, d = !!_, {
|
|
46
|
+
onInputMessageChange: ze,
|
|
47
|
+
filters: ge,
|
|
48
|
+
baseUrl: N,
|
|
49
|
+
agentUrl: He,
|
|
50
|
+
context: he,
|
|
51
|
+
headers: ve,
|
|
52
|
+
appId: S,
|
|
53
|
+
apiKey: h,
|
|
54
|
+
files: b
|
|
55
|
+
} = y, Ke = Pe?.isOpen ?? Le?.isOpen ?? De?.isOpen ?? !0, { getCaptchaHeader: R, invalidate: u } = mt({
|
|
56
|
+
baseUrl: N,
|
|
57
|
+
shouldBypassCaptcha: pe || !!h,
|
|
58
|
+
shouldMakeInitialRequest: Ke
|
|
59
|
+
}), ye = c(R);
|
|
60
|
+
ye.current = R;
|
|
61
|
+
const Ce = He || `${N}/run/api/chat`, { sessionToken: K, refreshSession: J } = ht({
|
|
62
|
+
baseUrl: N,
|
|
63
|
+
appId: S,
|
|
64
|
+
getCaptchaHeader: R,
|
|
65
|
+
invalidateCaptcha: u,
|
|
66
|
+
optOutAllAnalytics: Ue?.optOutAllAnalytics,
|
|
67
|
+
enabled: !d && !qe
|
|
68
|
+
}), Ae = h ?? (d ? _ : K), { loadConversation: Se } = yt({
|
|
69
|
+
baseUrl: N,
|
|
70
|
+
appId: S,
|
|
71
|
+
authToken: Ae,
|
|
72
|
+
getCaptchaHeader: R,
|
|
73
|
+
invalidateCaptcha: u,
|
|
74
|
+
refreshSession: h || d ? void 0 : J
|
|
75
|
+
}), [Je, be] = F(!1), j = c(null);
|
|
76
|
+
j.current = K;
|
|
77
|
+
const G = c(null);
|
|
78
|
+
G.current = _;
|
|
79
|
+
const V = c(void 0);
|
|
80
|
+
V.current = z && Object.keys(z).length > 0 ? JSON.stringify(z) : void 0;
|
|
81
|
+
const W = c(void 0);
|
|
82
|
+
W.current = H && Object.keys(H).length > 0 ? JSON.stringify(H) : void 0;
|
|
83
|
+
const v = c(0), Q = c(null), Z = c(null), I = c(void 0), je = b?.map(
|
|
69
84
|
(e) => `${e.filename ?? ""}:${e.mediaType}:${e.url.length}:${e.url.slice(0, 64)}:${e.url.slice(-32)}`
|
|
70
85
|
).join(`
|
|
71
86
|
`) ?? "";
|
|
72
|
-
|
|
73
|
-
I.current =
|
|
74
|
-
}, [
|
|
75
|
-
const Re = c(
|
|
76
|
-
Re.current =
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
switch (
|
|
87
|
+
x(() => {
|
|
88
|
+
I.current = b?.length ? b : void 0;
|
|
89
|
+
}, [je]);
|
|
90
|
+
const Re = c(ve);
|
|
91
|
+
Re.current = ve;
|
|
92
|
+
const X = c(void 0);
|
|
93
|
+
X.current = de || ge ? JSON.stringify({ ...de, ...ge }) : void 0;
|
|
94
|
+
const Ge = (e) => {
|
|
95
|
+
switch (Mt(e)) {
|
|
81
96
|
case 400:
|
|
82
97
|
try {
|
|
83
98
|
const t = JSON.parse(e.message ?? "");
|
|
84
|
-
return t.detail ?? t.error?.message ??
|
|
99
|
+
return t.detail ?? t.error?.message ?? Ne;
|
|
85
100
|
} catch {
|
|
86
|
-
return e.message?.trim() ||
|
|
101
|
+
return e.message?.trim() || Ne;
|
|
87
102
|
}
|
|
88
103
|
case 401:
|
|
89
|
-
return
|
|
104
|
+
return me ? "Authentication failed. Please try again." : ce;
|
|
90
105
|
case 403:
|
|
91
|
-
return `There seems to be a configuration error. Please contact ${
|
|
106
|
+
return `There seems to be a configuration error. Please contact ${q.organizationDisplayName ?? "Administrator"}`;
|
|
92
107
|
case 429:
|
|
93
|
-
return
|
|
108
|
+
return xt;
|
|
94
109
|
default:
|
|
95
|
-
return
|
|
110
|
+
return ce;
|
|
96
111
|
}
|
|
97
|
-
}, [
|
|
98
|
-
() => new
|
|
99
|
-
api:
|
|
112
|
+
}, [P, Y] = F([]), Ve = _e(
|
|
113
|
+
() => new lt({
|
|
114
|
+
api: Ce,
|
|
100
115
|
headers: () => {
|
|
101
|
-
const e =
|
|
116
|
+
const e = h ?? G.current ?? j.current;
|
|
102
117
|
return {
|
|
103
118
|
"x-inkeep-client-timezone": Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
104
119
|
"x-inkeep-client-timestamp": (/* @__PURE__ */ new Date()).toISOString(),
|
|
105
120
|
"x-inkeep-invocation-type": "chat_widget",
|
|
106
|
-
...
|
|
121
|
+
...S ? { "x-inkeep-app-id": S } : {},
|
|
107
122
|
...e ? { Authorization: `Bearer ${e}` } : {},
|
|
108
|
-
...
|
|
109
|
-
...
|
|
123
|
+
...X.current ? { "inkeep-filters": X.current } : {},
|
|
124
|
+
...V.current ? { "x-inkeep-user-properties": V.current } : {},
|
|
125
|
+
...W.current ? { "x-inkeep-properties": W.current } : {},
|
|
110
126
|
...Re.current
|
|
111
127
|
};
|
|
112
128
|
},
|
|
113
129
|
prepareSendMessagesRequest: async (e) => {
|
|
114
|
-
const a = await
|
|
130
|
+
const a = await ye.current(), t = e.messages[e.messages.length - 1];
|
|
115
131
|
return t || console.warn(
|
|
116
132
|
"[useInkeepChat] prepareSendMessagesRequest called with empty messages array"
|
|
117
133
|
), {
|
|
@@ -129,25 +145,25 @@ const Dt = () => {
|
|
|
129
145
|
};
|
|
130
146
|
},
|
|
131
147
|
body: {
|
|
132
|
-
requestContext:
|
|
148
|
+
requestContext: he
|
|
133
149
|
}
|
|
134
150
|
}),
|
|
135
|
-
[
|
|
151
|
+
[Ce, he, S, h]
|
|
136
152
|
), {
|
|
137
|
-
messages:
|
|
138
|
-
sendMessage:
|
|
139
|
-
addToolApprovalResponse:
|
|
140
|
-
status:
|
|
153
|
+
messages: L,
|
|
154
|
+
sendMessage: ee,
|
|
155
|
+
addToolApprovalResponse: te,
|
|
156
|
+
status: Ie,
|
|
141
157
|
setMessages: f,
|
|
142
158
|
stop: D,
|
|
143
|
-
error:
|
|
144
|
-
} =
|
|
145
|
-
transport:
|
|
159
|
+
error: B
|
|
160
|
+
} = it({
|
|
161
|
+
transport: Ve,
|
|
146
162
|
onData(e) {
|
|
147
|
-
|
|
163
|
+
O(e.type, e.data);
|
|
148
164
|
},
|
|
149
165
|
async onFinish() {
|
|
150
|
-
|
|
166
|
+
O("completion", { conversationId: i }), await m({
|
|
151
167
|
eventName: "assistant_message_received",
|
|
152
168
|
properties: {
|
|
153
169
|
conversationId: i
|
|
@@ -161,47 +177,47 @@ const Dt = () => {
|
|
|
161
177
|
},
|
|
162
178
|
onError(e) {
|
|
163
179
|
console.error("onError", { code: e.code, message: e.message });
|
|
164
|
-
const a =
|
|
165
|
-
if (a !== null &&
|
|
166
|
-
|
|
167
|
-
const n =
|
|
180
|
+
const a = pe || h ? null : Tt(e);
|
|
181
|
+
if (a !== null && v.current < 1) {
|
|
182
|
+
v.current++;
|
|
183
|
+
const n = Z.current, s = Q.current;
|
|
168
184
|
(async () => {
|
|
169
|
-
if (a === "session" &&
|
|
170
|
-
const l = await
|
|
185
|
+
if (a === "session" && me) {
|
|
186
|
+
const l = await fe();
|
|
171
187
|
if (!l) throw new Error("Auth token refresh failed");
|
|
172
|
-
|
|
188
|
+
G.current = l;
|
|
173
189
|
} else if (a === "session") {
|
|
174
|
-
const l = await
|
|
175
|
-
l && (
|
|
190
|
+
const l = await J();
|
|
191
|
+
l && (j.current = l);
|
|
176
192
|
} else
|
|
177
|
-
|
|
193
|
+
u();
|
|
178
194
|
if (n) {
|
|
179
|
-
|
|
195
|
+
te(n);
|
|
180
196
|
return;
|
|
181
197
|
}
|
|
182
198
|
s && (f((l) => {
|
|
183
199
|
let r = [...l];
|
|
184
200
|
return r.at(-1)?.role === "assistant" && (r = r.slice(0, -1)), r.at(-1)?.role === "user" && (r = r.slice(0, -1)), r;
|
|
185
|
-
}),
|
|
201
|
+
}), ee(
|
|
186
202
|
s.files?.length ? { parts: [{ type: "text", text: s.content }, ...s.files] } : { text: s.content },
|
|
187
203
|
{ body: s.body }
|
|
188
204
|
));
|
|
189
205
|
})().catch(() => {
|
|
190
|
-
|
|
191
|
-
const r = [...l],
|
|
192
|
-
if (!
|
|
193
|
-
const
|
|
194
|
-
return
|
|
195
|
-
id:
|
|
206
|
+
v.current = 0, u(), f((l) => {
|
|
207
|
+
const r = [...l], k = r[r.length - 1];
|
|
208
|
+
if (!k) return r;
|
|
209
|
+
const E = ce;
|
|
210
|
+
return k.role === "user" ? r.push({
|
|
211
|
+
id: U(16),
|
|
196
212
|
role: "assistant",
|
|
197
|
-
parts: [{ type: "text", text:
|
|
198
|
-
}) :
|
|
213
|
+
parts: [{ type: "text", text: E }]
|
|
214
|
+
}) : k.parts = [{ type: "text", text: E }], r;
|
|
199
215
|
});
|
|
200
216
|
});
|
|
201
217
|
return;
|
|
202
218
|
}
|
|
203
|
-
|
|
204
|
-
const t =
|
|
219
|
+
v.current = 0, a !== null && u();
|
|
220
|
+
const t = kt(e), p = Ge(e);
|
|
205
221
|
if (m({
|
|
206
222
|
eventName: "chat_error",
|
|
207
223
|
properties: {
|
|
@@ -209,146 +225,146 @@ const Dt = () => {
|
|
|
209
225
|
error: e.message
|
|
210
226
|
}
|
|
211
227
|
}), t) {
|
|
212
|
-
|
|
213
|
-
{ title: "Request failed", message:
|
|
214
|
-
|
|
228
|
+
ae(
|
|
229
|
+
{ title: "Request failed", message: p },
|
|
230
|
+
Et
|
|
215
231
|
), f((s) => {
|
|
216
232
|
let o = [...s];
|
|
217
233
|
return o.at(-1)?.role === "assistant" && (o = o.slice(0, -1)), o.at(-1)?.role === "user" && (o = o.slice(0, -1)), o;
|
|
218
234
|
});
|
|
219
|
-
const n =
|
|
220
|
-
n &&
|
|
235
|
+
const n = Q.current?.content;
|
|
236
|
+
n && A(n), oe.current = e;
|
|
221
237
|
return;
|
|
222
238
|
}
|
|
223
239
|
f((n) => {
|
|
224
240
|
const s = [...n], o = s[s.length - 1];
|
|
225
241
|
return o && (o.role === "user" ? s.push({
|
|
226
|
-
id:
|
|
242
|
+
id: U(16),
|
|
227
243
|
role: "assistant",
|
|
228
|
-
parts: [{ type: "text", text:
|
|
229
|
-
}) : o.parts = [{ type: "text", text:
|
|
244
|
+
parts: [{ type: "text", text: p }]
|
|
245
|
+
}) : o.parts = [{ type: "text", text: p }]), s;
|
|
230
246
|
});
|
|
231
247
|
}
|
|
232
|
-
}),
|
|
233
|
-
|
|
234
|
-
const e =
|
|
235
|
-
|
|
236
|
-
}, [d, D, f, g,
|
|
237
|
-
const
|
|
248
|
+
}), we = c(d);
|
|
249
|
+
x(() => {
|
|
250
|
+
const e = we.current;
|
|
251
|
+
we.current = d, e !== d && (D(), w(null), f([]), g(""), A(""), Y([]), u());
|
|
252
|
+
}, [d, D, f, g, u]);
|
|
253
|
+
const Te = Ie === "submitted", se = Ie === "streaming", We = _e(() => {
|
|
238
254
|
const e = (n) => {
|
|
239
255
|
if (!n || typeof n != "object") return !1;
|
|
240
256
|
const s = n;
|
|
241
257
|
return typeof s.type == "string" && s.type.startsWith("tool-");
|
|
242
|
-
}, t = [...
|
|
258
|
+
}, t = [...L ?? []].reverse().find((n) => n.role === "assistant");
|
|
243
259
|
if (!t) return !1;
|
|
244
|
-
const
|
|
245
|
-
return !(!e(
|
|
246
|
-
}, [
|
|
247
|
-
|
|
248
|
-
if (
|
|
249
|
-
if (
|
|
250
|
-
|
|
260
|
+
const p = t.parts?.at(-1);
|
|
261
|
+
return !(!e(p) || p.state !== "output-available" || !p.approval?.id || se);
|
|
262
|
+
}, [L, se]), [Qe, re] = F(!1), ke = se || We && !Qe, Ee = Te || ke, Ze = L.length === 0, ne = !C.trim() && P.length === 0 || Ee, Xe = gt("(max-width: 768px)"), [Ye, w] = F(null), oe = c(null);
|
|
263
|
+
x(() => {
|
|
264
|
+
if (B) {
|
|
265
|
+
if (oe.current === B) {
|
|
266
|
+
oe.current = null;
|
|
251
267
|
return;
|
|
252
268
|
}
|
|
253
|
-
w(
|
|
269
|
+
w(B);
|
|
254
270
|
}
|
|
255
|
-
}, [
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
}, [
|
|
260
|
-
const
|
|
261
|
-
e.key === "Enter" && !e.shiftKey && !
|
|
262
|
-
},
|
|
263
|
-
if (
|
|
264
|
-
const a =
|
|
265
|
-
|
|
271
|
+
}, [B]);
|
|
272
|
+
const et = () => w(null), { inputNotification: tt, showInputNotification: ae, clearInputNotification: st } = wt(), Me = c(null);
|
|
273
|
+
x(() => {
|
|
274
|
+
ze?.(C);
|
|
275
|
+
}, [C]);
|
|
276
|
+
const rt = (e) => {
|
|
277
|
+
e.key === "Enter" && !e.shiftKey && !ne && !e.nativeEvent.isComposing && (e.preventDefault(), ie());
|
|
278
|
+
}, ie = async (e = C) => {
|
|
279
|
+
if (ne && (!e || e.trim().length === 0) && P.length === 0) return;
|
|
280
|
+
const a = P;
|
|
281
|
+
Y([]), A(""), v.current = 0, Z.current = null, re(!1), await m({
|
|
266
282
|
eventName: "user_message_submitted",
|
|
267
283
|
properties: {
|
|
268
284
|
conversationId: i
|
|
269
285
|
}
|
|
270
286
|
});
|
|
271
287
|
let t = i;
|
|
272
|
-
t || (t = `conv_${
|
|
273
|
-
const
|
|
288
|
+
t || (t = `conv_${U(16)}`, g(t)), Be(t);
|
|
289
|
+
const p = I.current;
|
|
274
290
|
I.current = void 0;
|
|
275
291
|
let n, s;
|
|
276
|
-
if (
|
|
292
|
+
if (p?.length) {
|
|
277
293
|
let o;
|
|
278
294
|
try {
|
|
279
295
|
o = await Promise.all(
|
|
280
296
|
a.map((l) => {
|
|
281
|
-
const r =
|
|
282
|
-
return new Promise((
|
|
283
|
-
const
|
|
284
|
-
|
|
285
|
-
if (typeof
|
|
286
|
-
|
|
297
|
+
const r = Oe(l);
|
|
298
|
+
return new Promise((k, E) => {
|
|
299
|
+
const M = new FileReader();
|
|
300
|
+
M.onload = () => {
|
|
301
|
+
if (typeof M.result != "string") {
|
|
302
|
+
E(new Error(`Failed to read file "${r.name}"`));
|
|
287
303
|
return;
|
|
288
304
|
}
|
|
289
|
-
|
|
305
|
+
k({
|
|
290
306
|
type: "file",
|
|
291
|
-
url:
|
|
307
|
+
url: M.result,
|
|
292
308
|
mediaType: r.type,
|
|
293
309
|
filename: r.name
|
|
294
310
|
});
|
|
295
|
-
},
|
|
311
|
+
}, M.onerror = () => E(new Error(`Failed to read file "${r.name}"`)), M.readAsDataURL(r);
|
|
296
312
|
});
|
|
297
313
|
})
|
|
298
314
|
);
|
|
299
315
|
} catch {
|
|
300
|
-
|
|
316
|
+
ae({
|
|
301
317
|
title: "Failed to attach files",
|
|
302
318
|
message: "Could not read one or more files. Please try again."
|
|
303
319
|
});
|
|
304
320
|
return;
|
|
305
321
|
}
|
|
306
|
-
s = [...o, ...
|
|
322
|
+
s = [...o, ...p], n = e.trim() ? { parts: [{ type: "text", text: e }, ...s] } : { parts: s };
|
|
307
323
|
} else if (a.length > 0) {
|
|
308
324
|
const o = new DataTransfer();
|
|
309
|
-
for (const r of a) o.items.add(
|
|
325
|
+
for (const r of a) o.items.add(Oe(r));
|
|
310
326
|
const l = o.files;
|
|
311
327
|
n = e.trim() ? { text: e, files: l } : { files: l };
|
|
312
328
|
} else
|
|
313
329
|
n = { text: e };
|
|
314
|
-
|
|
330
|
+
Q.current = {
|
|
315
331
|
content: e,
|
|
316
332
|
body: { conversationId: t },
|
|
317
333
|
files: s
|
|
318
|
-
},
|
|
334
|
+
}, ee(n, {
|
|
319
335
|
body: { conversationId: t }
|
|
320
336
|
});
|
|
321
|
-
},
|
|
337
|
+
}, nt = $(
|
|
322
338
|
(e) => {
|
|
323
|
-
|
|
339
|
+
v.current = 0, Z.current = e, re(!1), te(e);
|
|
324
340
|
},
|
|
325
|
-
[
|
|
326
|
-
),
|
|
327
|
-
|
|
328
|
-
|
|
341
|
+
[te]
|
|
342
|
+
), le = $(() => {
|
|
343
|
+
re(!0), D().then(() => {
|
|
344
|
+
O("aborted", { conversationId: i });
|
|
329
345
|
});
|
|
330
|
-
}, [D, i,
|
|
331
|
-
|
|
346
|
+
}, [D, i, O]), xe = () => {
|
|
347
|
+
et(), f([]), g(""), u(), I.current = b?.length ? b : void 0, m({
|
|
332
348
|
eventName: "chat_clear_button_clicked",
|
|
333
349
|
properties: {
|
|
334
350
|
conversationId: i
|
|
335
351
|
}
|
|
336
352
|
});
|
|
337
|
-
},
|
|
353
|
+
}, T = $(
|
|
338
354
|
(e, a) => {
|
|
339
|
-
w(null), f(a), g(e),
|
|
355
|
+
w(null), f(a), g(e), u(), I.current = void 0;
|
|
340
356
|
},
|
|
341
|
-
[f, g,
|
|
342
|
-
),
|
|
357
|
+
[f, g, u]
|
|
358
|
+
), Fe = $(
|
|
343
359
|
async (e, a) => {
|
|
344
|
-
|
|
360
|
+
le(), T(e, []), be(!0);
|
|
345
361
|
try {
|
|
346
|
-
const t = await
|
|
362
|
+
const t = await Se(e, a);
|
|
347
363
|
if (t === null) return !1;
|
|
348
364
|
const n = t[t.length - 1]?.role === "user" ? [
|
|
349
365
|
...t,
|
|
350
366
|
{
|
|
351
|
-
id:
|
|
367
|
+
id: U(16),
|
|
352
368
|
role: "assistant",
|
|
353
369
|
parts: [
|
|
354
370
|
{
|
|
@@ -358,66 +374,66 @@ const Dt = () => {
|
|
|
358
374
|
]
|
|
359
375
|
}
|
|
360
376
|
] : t;
|
|
361
|
-
return
|
|
377
|
+
return T(e, n), !0;
|
|
362
378
|
} finally {
|
|
363
|
-
a?.aborted ||
|
|
379
|
+
a?.aborted || be(!1);
|
|
364
380
|
}
|
|
365
381
|
},
|
|
366
|
-
[
|
|
382
|
+
[T, Se, le]
|
|
367
383
|
);
|
|
368
|
-
|
|
369
|
-
conversationId:
|
|
370
|
-
effectiveAuthToken:
|
|
371
|
-
loadAndRestoreSession:
|
|
372
|
-
onLoadFailed: () =>
|
|
384
|
+
Ct({
|
|
385
|
+
conversationId: y.conversationId,
|
|
386
|
+
effectiveAuthToken: Ae,
|
|
387
|
+
loadAndRestoreSession: Fe,
|
|
388
|
+
onLoadFailed: () => T("", [])
|
|
373
389
|
});
|
|
374
|
-
const { openForm:
|
|
375
|
-
return
|
|
376
|
-
submitMessage:
|
|
390
|
+
const { openForm: ot } = St(), at = bt();
|
|
391
|
+
return ct(y.chatFunctionsRef, () => ({
|
|
392
|
+
submitMessage: ie,
|
|
377
393
|
updateInputMessage(e) {
|
|
378
|
-
|
|
394
|
+
A(e);
|
|
379
395
|
},
|
|
380
|
-
clearChat:
|
|
396
|
+
clearChat: xe,
|
|
381
397
|
openForm: (e) => {
|
|
382
|
-
|
|
398
|
+
at?.setView("chat"), ot(e, void 0);
|
|
383
399
|
},
|
|
384
400
|
focusInput: () => {
|
|
385
|
-
|
|
401
|
+
Me.current?.focus();
|
|
386
402
|
}
|
|
387
403
|
})), {
|
|
388
|
-
messages:
|
|
389
|
-
sendMessage:
|
|
390
|
-
addToolApprovalResponse:
|
|
391
|
-
isLoading:
|
|
392
|
-
isStreaming:
|
|
404
|
+
messages: L,
|
|
405
|
+
sendMessage: ee,
|
|
406
|
+
addToolApprovalResponse: nt,
|
|
407
|
+
isLoading: Te,
|
|
408
|
+
isStreaming: ke,
|
|
393
409
|
isBusy: Ee,
|
|
394
|
-
error:
|
|
410
|
+
error: Ye,
|
|
395
411
|
setError: w,
|
|
396
|
-
isSubmitDisabled:
|
|
397
|
-
input:
|
|
398
|
-
handleInputChange:
|
|
399
|
-
handleInputKeyDown:
|
|
400
|
-
handleSubmit:
|
|
401
|
-
stop:
|
|
402
|
-
clear:
|
|
403
|
-
inputRef:
|
|
404
|
-
isMobile:
|
|
405
|
-
files:
|
|
406
|
-
setFiles:
|
|
407
|
-
isNewChat:
|
|
412
|
+
isSubmitDisabled: ne,
|
|
413
|
+
input: C,
|
|
414
|
+
handleInputChange: $e,
|
|
415
|
+
handleInputKeyDown: rt,
|
|
416
|
+
handleSubmit: ie,
|
|
417
|
+
stop: le,
|
|
418
|
+
clear: xe,
|
|
419
|
+
inputRef: Me,
|
|
420
|
+
isMobile: Xe,
|
|
421
|
+
files: P,
|
|
422
|
+
setFiles: Y,
|
|
423
|
+
isNewChat: Ze,
|
|
408
424
|
conversationId: i,
|
|
409
|
-
restoreSession:
|
|
410
|
-
loadAndRestoreSession:
|
|
411
|
-
isSessionLoading:
|
|
412
|
-
authToken: d ?
|
|
413
|
-
refreshSession: d ?
|
|
414
|
-
getCaptchaHeader:
|
|
415
|
-
invalidateCaptcha:
|
|
416
|
-
inputNotification:
|
|
417
|
-
showInputNotification:
|
|
418
|
-
clearInputNotification:
|
|
425
|
+
restoreSession: T,
|
|
426
|
+
loadAndRestoreSession: Fe,
|
|
427
|
+
isSessionLoading: Je,
|
|
428
|
+
authToken: d ? _ : K,
|
|
429
|
+
refreshSession: d ? fe : J,
|
|
430
|
+
getCaptchaHeader: R,
|
|
431
|
+
invalidateCaptcha: u,
|
|
432
|
+
inputNotification: tt,
|
|
433
|
+
showInputNotification: ae,
|
|
434
|
+
clearInputNotification: st
|
|
419
435
|
};
|
|
420
436
|
};
|
|
421
437
|
export {
|
|
422
|
-
|
|
438
|
+
Yt as useInkeepChat
|
|
423
439
|
};
|