@inkeep/agents-ui 0.0.0-dev-20260501021535 → 0.0.0-dev-20260501182500

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