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

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