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