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