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