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