@inkeep/agents-ui 0.0.0-dev-20260511170227 → 0.0.0-dev-20260511184737

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