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