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