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