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