@inkeep/agents-ui 0.0.0-dev-20260508234956 → 0.0.0-dev-20260509025038

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 +253 -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 +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 +43 -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 +27 -0
  20. package/dist/primitives/providers/chat-auth-provider.js +46 -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 +65 -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,92 @@
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);
29
- x(() => {
30
- const e = ue.current;
31
- ue.current = i, e !== i && m({
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({
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,
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,
50
55
  context: he,
51
56
  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(
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(
84
78
  (e) => `${e.filename ?? ""}:${e.mediaType}:${e.url.length}:${e.url.slice(0, 64)}:${e.url.slice(-32)}`
85
79
  ).join(`
86
80
  `) ?? "";
87
- 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)) {
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)) {
96
90
  case 400:
97
91
  try {
98
92
  const t = JSON.parse(e.message ?? "");
@@ -101,29 +95,29 @@ const Yt = () => {
101
95
  return e.message?.trim() || Ne;
102
96
  }
103
97
  case 401:
104
- return me ? "Authentication failed. Please try again." : ce;
98
+ return ce ? "Authentication failed. Please try again." : ne;
105
99
  case 403:
106
- return `There seems to be a configuration error. Please contact ${q.organizationDisplayName ?? "Administrator"}`;
100
+ return `There seems to be a configuration error. Please contact ${oe.organizationDisplayName ?? "Administrator"}`;
107
101
  case 429:
108
- return xt;
102
+ return It;
109
103
  default:
110
- return ce;
104
+ return ne;
111
105
  }
112
- }, [P, Y] = F([]), Ve = _e(
113
- () => new lt({
106
+ }, [N, V] = x([]), Ke = _e(
107
+ () => new rt({
114
108
  api: Ce,
115
109
  headers: () => {
116
- const e = h ?? G.current ?? j.current;
110
+ const e = U ?? H.current ?? z.current;
117
111
  return {
118
112
  "x-inkeep-client-timezone": Intl.DateTimeFormat().resolvedOptions().timeZone,
119
113
  "x-inkeep-client-timestamp": (/* @__PURE__ */ new Date()).toISOString(),
120
114
  "x-inkeep-invocation-type": "chat_widget",
121
- ...S ? { "x-inkeep-app-id": S } : {},
115
+ ..._ ? { "x-inkeep-app-id": _ } : {},
122
116
  ...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
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
127
121
  };
128
122
  },
129
123
  prepareSendMessagesRequest: async (e) => {
@@ -148,223 +142,226 @@ const Yt = () => {
148
142
  requestContext: he
149
143
  }
150
144
  }),
151
- [Ce, he, S, h]
145
+ [Ce, he, _, U]
152
146
  ), {
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,
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,
162
156
  onData(e) {
163
- O(e.type, e.data);
157
+ M(e.type, e.data);
164
158
  },
165
- async onFinish() {
166
- O("completion", { conversationId: i }), await m({
159
+ async onFinish({ message: e }) {
160
+ M("completion", { conversationId: c }), await f({
167
161
  eventName: "assistant_message_received",
168
162
  properties: {
169
- conversationId: i
163
+ conversationId: c,
164
+ messageId: e.id
170
165
  }
171
- }), m({
166
+ }), f({
172
167
  eventName: "assistant_answer_displayed",
173
168
  properties: {
174
- conversationId: i
169
+ conversationId: c,
170
+ messageId: e.id
175
171
  }
176
172
  });
177
173
  },
178
174
  onError(e) {
179
175
  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;
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;
184
180
  (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;
181
+ if (a === "session" && ce) {
182
+ const i = await ue();
183
+ if (!i) throw new Error("Auth token refresh failed");
184
+ H.current = i;
189
185
  } else if (a === "session") {
190
- const l = await J();
191
- l && (j.current = l);
186
+ const i = await de();
187
+ i && (z.current = i);
192
188
  } else
193
- u();
189
+ p();
194
190
  if (n) {
195
- te(n);
191
+ Q(n);
196
192
  return;
197
193
  }
198
- s && (f((l) => {
199
- let r = [...l];
194
+ s && (d((i) => {
195
+ let r = [...i];
200
196
  return r.at(-1)?.role === "assistant" && (r = r.slice(0, -1)), r.at(-1)?.role === "user" && (r = r.slice(0, -1)), r;
201
- }), ee(
197
+ }), W(
202
198
  s.files?.length ? { parts: [{ type: "text", text: s.content }, ...s.files] } : { text: s.content },
203
199
  { body: s.body }
204
200
  ));
205
201
  })().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),
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),
212
208
  role: "assistant",
213
209
  parts: [{ type: "text", text: E }]
214
- }) : k.parts = [{ type: "text", text: E }], r;
210
+ }) : b.parts = [{ type: "text", text: E }], r;
215
211
  });
216
212
  });
217
213
  return;
218
214
  }
219
- v.current = 0, a !== null && u();
220
- const t = kt(e), p = Ge(e);
221
- if (m({
215
+ h.current = 0, a !== null && p();
216
+ const t = vt(e), u = He(e);
217
+ if (f({
222
218
  eventName: "chat_error",
223
219
  properties: {
224
- conversationId: i,
220
+ conversationId: c,
221
+ messageId: S.at(-1)?.id,
225
222
  error: e.message
226
223
  }
227
224
  }), t) {
228
- ae(
229
- { title: "Request failed", message: p },
230
- Et
231
- ), f((s) => {
225
+ te(
226
+ { title: "Request failed", message: u },
227
+ yt
228
+ ), d((s) => {
232
229
  let o = [...s];
233
230
  return o.at(-1)?.role === "assistant" && (o = o.slice(0, -1)), o.at(-1)?.role === "user" && (o = o.slice(0, -1)), o;
234
231
  });
235
- const n = Q.current?.content;
236
- n && A(n), oe.current = e;
232
+ const n = J.current?.content;
233
+ n && C(n), ee.current = e;
237
234
  return;
238
235
  }
239
- f((n) => {
236
+ d((n) => {
240
237
  const s = [...n], o = s[s.length - 1];
241
238
  return o && (o.role === "user" ? s.push({
242
- id: U(16),
239
+ id: L(16),
243
240
  role: "assistant",
244
- parts: [{ type: "text", text: p }]
245
- }) : o.parts = [{ type: "text", text: p }]), s;
241
+ parts: [{ type: "text", text: u }]
242
+ }) : o.parts = [{ type: "text", text: u }]), s;
246
243
  });
247
244
  }
248
- }), we = c(d);
249
- 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
+ }), 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(() => {
254
251
  const e = (n) => {
255
252
  if (!n || typeof n != "object") return !1;
256
253
  const s = n;
257
254
  return typeof s.type == "string" && s.type.startsWith("tool-");
258
- }, t = [...L ?? []].reverse().find((n) => n.role === "assistant");
255
+ }, t = [...S ?? []].reverse().find((n) => n.role === "assistant");
259
256
  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);
263
- x(() => {
264
- if (B) {
265
- if (oe.current === B) {
266
- oe.current = null;
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;
267
264
  return;
268
265
  }
269
- w(B);
266
+ w(O);
270
267
  }
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) && P.length === 0) return;
280
- const a = P;
281
- Y([]), A(""), v.current = 0, Z.current = null, re(!1), await m({
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;
277
+ 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({
282
281
  eventName: "user_message_submitted",
283
282
  properties: {
284
- conversationId: i
283
+ conversationId: t
285
284
  }
286
285
  });
287
- let t = i;
288
- t || (t = `conv_${U(16)}`, g(t)), Be(t);
289
- const p = I.current;
290
- I.current = void 0;
286
+ const u = R.current;
287
+ R.current = void 0;
291
288
  let n, s;
292
- if (p?.length) {
289
+ if (u?.length) {
293
290
  let o;
294
291
  try {
295
292
  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") {
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") {
302
299
  E(new Error(`Failed to read file "${r.name}"`));
303
300
  return;
304
301
  }
305
- k({
302
+ b({
306
303
  type: "file",
307
- url: M.result,
304
+ url: T.result,
308
305
  mediaType: r.type,
309
306
  filename: r.name
310
307
  });
311
- }, M.onerror = () => E(new Error(`Failed to read file "${r.name}"`)), M.readAsDataURL(r);
308
+ }, T.onerror = () => E(new Error(`Failed to read file "${r.name}"`)), T.readAsDataURL(r);
312
309
  });
313
310
  })
314
311
  );
315
312
  } catch {
316
- ae({
313
+ te({
317
314
  title: "Failed to attach files",
318
315
  message: "Could not read one or more files. Please try again."
319
316
  });
320
317
  return;
321
318
  }
322
- s = [...o, ...p], n = e.trim() ? { parts: [{ type: "text", text: e }, ...s] } : { parts: s };
319
+ s = [...o, ...u], n = e.trim() ? { parts: [{ type: "text", text: e }, ...s] } : { parts: s };
323
320
  } else if (a.length > 0) {
324
321
  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 };
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 };
328
325
  } else
329
326
  n = { text: e };
330
- Q.current = {
327
+ J.current = {
331
328
  content: e,
332
329
  body: { conversationId: t },
333
330
  files: s
334
- }, ee(n, {
331
+ }, W(n, {
335
332
  body: { conversationId: t }
336
333
  });
337
- }, nt = $(
334
+ }, Ye = D(
338
335
  (e) => {
339
- v.current = 0, Z.current = e, re(!1), te(e);
336
+ h.current = 0, j.current = e, X(!1), Q(e);
340
337
  },
341
- [te]
342
- ), le = $(() => {
343
- re(!0), D().then(() => {
344
- O("aborted", { conversationId: i });
338
+ [Q]
339
+ ), re = D(() => {
340
+ X(!0), P().then(() => {
341
+ M("aborted", { conversationId: c });
345
342
  });
346
- }, [D, i, O]), xe = () => {
347
- et(), f([]), g(""), u(), I.current = b?.length ? b : void 0, m({
343
+ }, [P, c, M]), xe = () => {
344
+ We(), d([]), m(""), p(), R.current = I?.length ? I : void 0, f({
348
345
  eventName: "chat_clear_button_clicked",
349
346
  properties: {
350
- conversationId: i
347
+ conversationId: c
351
348
  }
352
349
  });
353
- }, T = $(
350
+ }, A = D(
354
351
  (e, a) => {
355
- w(null), f(a), g(e), u(), I.current = void 0;
352
+ w(null), d(a), m(e), p(), R.current = void 0;
356
353
  },
357
- [f, g, u]
358
- ), Fe = $(
354
+ [d, m, p]
355
+ ), Me = D(
359
356
  async (e, a) => {
360
- le(), T(e, []), be(!0);
357
+ re(), A(e, []), Re(!0);
361
358
  try {
362
- const t = await Se(e, a);
359
+ const t = await Ie(e, a);
363
360
  if (t === null) return !1;
364
361
  const n = t[t.length - 1]?.role === "user" ? [
365
362
  ...t,
366
363
  {
367
- id: U(16),
364
+ id: L(16),
368
365
  role: "assistant",
369
366
  parts: [
370
367
  {
@@ -374,66 +371,66 @@ const Yt = () => {
374
371
  ]
375
372
  }
376
373
  ] : t;
377
- return T(e, n), !0;
374
+ return A(e, n), !0;
378
375
  } finally {
379
- a?.aborted || be(!1);
376
+ a?.aborted || Re(!1);
380
377
  }
381
378
  },
382
- [T, Se, le]
379
+ [A, Ie, re]
383
380
  );
384
- Ct({
385
- conversationId: y.conversationId,
386
- effectiveAuthToken: Ae,
387
- loadAndRestoreSession: Fe,
388
- onLoadFailed: () => T("", [])
381
+ ct({
382
+ conversationId: v.conversationId,
383
+ effectiveAuthToken: fe,
384
+ loadAndRestoreSession: Me,
385
+ onLoadFailed: () => A("", [])
389
386
  });
390
- const { openForm: ot } = St(), at = bt();
391
- return ct(y.chatFunctionsRef, () => ({
392
- submitMessage: ie,
387
+ const { openForm: et } = pt(), tt = dt();
388
+ return nt(v.chatFunctionsRef, () => ({
389
+ submitMessage: se,
393
390
  updateInputMessage(e) {
394
- A(e);
391
+ C(e);
395
392
  },
396
393
  clearChat: xe,
397
394
  openForm: (e) => {
398
- at?.setView("chat"), ot(e, void 0);
395
+ tt?.setView("chat"), et(e, void 0);
399
396
  },
400
397
  focusInput: () => {
401
- Me.current?.focus();
398
+ ke.current?.focus();
402
399
  }
403
400
  })), {
404
- messages: L,
405
- sendMessage: ee,
406
- addToolApprovalResponse: nt,
407
- isLoading: Te,
408
- isStreaming: ke,
409
- isBusy: Ee,
410
- error: Ye,
401
+ messages: S,
402
+ sendMessage: W,
403
+ addToolApprovalResponse: Ye,
404
+ isLoading: be,
405
+ isStreaming: Ee,
406
+ isBusy: Te,
407
+ error: Ve,
411
408
  setError: w,
412
- isSubmitDisabled: ne,
413
- input: C,
414
- handleInputChange: $e,
415
- handleInputKeyDown: rt,
416
- handleSubmit: ie,
417
- stop: le,
409
+ isSubmitDisabled: Y,
410
+ input: y,
411
+ handleInputChange: Oe,
412
+ handleInputKeyDown: Xe,
413
+ handleSubmit: se,
414
+ stop: re,
418
415
  clear: xe,
419
- inputRef: Me,
420
- isMobile: Xe,
421
- 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
416
+ inputRef: ke,
417
+ isMobile: Ge,
418
+ 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
435
432
  };
436
433
  };
437
434
  export {
438
- Yt as useInkeepChat
435
+ $t as useInkeepChat
439
436
  };