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