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