@inkeep/agents-ui 0.0.0-dev-20260501205503 → 0.0.0-dev-20260501222329

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/primitives/components/embedded-chat/chat-error-helpers.d.ts +2 -4
  2. package/dist/primitives/components/embedded-chat/use-captcha.cjs +1 -0
  3. package/dist/primitives/components/embedded-chat/use-captcha.d.ts +30 -0
  4. package/dist/primitives/components/embedded-chat/use-captcha.js +67 -0
  5. package/dist/primitives/components/embedded-chat/use-inkeep-chat.cjs +2 -2
  6. package/dist/primitives/components/embedded-chat/use-inkeep-chat.d.ts +2 -0
  7. package/dist/primitives/components/embedded-chat/use-inkeep-chat.js +262 -237
  8. package/dist/primitives/hooks/use-anonymous-session.cjs +1 -1
  9. package/dist/primitives/hooks/use-anonymous-session.d.ts +3 -1
  10. package/dist/primitives/hooks/use-anonymous-session.js +56 -51
  11. package/dist/primitives/hooks/use-conversation-loader.cjs +1 -1
  12. package/dist/primitives/hooks/use-conversation-loader.d.ts +3 -1
  13. package/dist/primitives/hooks/use-conversation-loader.js +20 -15
  14. package/dist/primitives/hooks/use-feedback-api.cjs +1 -1
  15. package/dist/primitives/hooks/use-feedback-api.d.ts +3 -1
  16. package/dist/primitives/hooks/use-feedback-api.js +22 -16
  17. package/dist/primitives/hooks/use-inkeep-api-client.cjs +1 -1
  18. package/dist/primitives/hooks/use-inkeep-api-client.d.ts +11 -8
  19. package/dist/primitives/hooks/use-inkeep-api-client.js +64 -36
  20. package/dist/primitives/providers/chat-history-provider.cjs +1 -1
  21. package/dist/primitives/providers/chat-history-provider.js +39 -35
  22. package/dist/primitives/providers/feedback-provider.cjs +1 -1
  23. package/dist/primitives/providers/feedback-provider.js +35 -26
  24. package/dist/primitives/providers/root-provider.cjs +1 -1
  25. package/dist/primitives/providers/root-provider.js +9 -13
  26. package/dist/primitives/utils/default-settings.cjs +1 -1
  27. package/dist/primitives/utils/default-settings.d.ts +0 -1
  28. package/dist/primitives/utils/default-settings.js +5 -6
  29. package/dist/types/config/ai.d.ts +0 -8
  30. package/package.json +2 -2
  31. 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 +0 -1
  32. 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 +0 -160
  33. package/dist/primitives/providers/botid-initializer.cjs +0 -1
  34. package/dist/primitives/providers/botid-initializer.d.ts +0 -15
  35. package/dist/primitives/providers/botid-initializer.js +0 -69
@@ -1,148 +1,170 @@
1
1
  "use client";
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({
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({
28
32
  eventName: "chat_conversation_changed",
29
33
  properties: {
30
34
  conversationId: i,
31
35
  previousConversationId: e
32
36
  }
33
37
  });
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,
38
+ }, [i, m]);
39
+ const [C, A] = F(""), De = (e) => A(e.target.value), {
40
+ shouldBypassCaptcha: ce,
37
41
  filters: ue,
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(
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(
62
81
  (e) => `${e.filename ?? ""}:${e.mediaType}:${e.url.length}:${e.url.slice(0, 64)}:${e.url.slice(-32)}`
63
82
  ).join(`
64
83
  `) ?? "";
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)) {
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)) {
74
93
  case 400:
75
94
  try {
76
95
  const t = JSON.parse(e.message ?? "");
77
- return t.detail ?? t.error?.message ?? ke;
96
+ return t.detail ?? t.error?.message ?? _e;
78
97
  } catch {
79
- return e.message?.trim() || ke;
98
+ return e.message?.trim() || _e;
80
99
  }
81
100
  case 401:
82
- return ce ? "Authentication failed. Please try again." : oe;
101
+ return de ? "Authentication failed. Please try again." : ie;
83
102
  case 403:
84
- return `There seems to be a configuration error. Please contact ${$.organizationDisplayName ?? "Administrator"}`;
103
+ return `There seems to be a configuration error. Please contact ${q.organizationDisplayName ?? "Administrator"}`;
85
104
  case 429:
86
- return ht;
105
+ return kt;
87
106
  default:
88
- return oe;
107
+ return ie;
89
108
  }
90
- }, [_, W] = M([]), $e = Ee(
91
- () => new Xe({
92
- api: de,
109
+ }, [P, Z] = F([]), Je = Fe(
110
+ () => new at({
111
+ api: ve,
93
112
  headers: () => {
94
- const e = S ?? G.current ?? q.current;
113
+ const e = h ?? J.current ?? G.current;
95
114
  return {
96
115
  "x-inkeep-client-timezone": Intl.DateTimeFormat().resolvedOptions().timeZone,
97
116
  "x-inkeep-client-timestamp": (/* @__PURE__ */ new Date()).toISOString(),
98
117
  "x-inkeep-invocation-type": "chat_widget",
99
- ...A ? { "x-inkeep-app-id": A } : {},
118
+ ...S ? { "x-inkeep-app-id": S } : {},
100
119
  ...e ? { Authorization: `Bearer ${e}` } : {},
101
- ...H.current ? { "inkeep-filters": H.current } : {},
102
- ...J.current ? { "x-inkeep-user-properties": J.current } : {},
103
- ...ve.current
120
+ ...Q.current ? { "inkeep-filters": Q.current } : {},
121
+ ...V.current ? { "x-inkeep-user-properties": V.current } : {},
122
+ ...Se.current
104
123
  };
105
124
  },
106
- prepareSendMessagesRequest: (e) => {
107
- const o = e.messages[e.messages.length - 1];
108
- return o || console.warn(
125
+ prepareSendMessagesRequest: async (e) => {
126
+ const a = await he.current(), t = e.messages[e.messages.length - 1];
127
+ return t || console.warn(
109
128
  "[useInkeepChat] prepareSendMessagesRequest called with empty messages array"
110
129
  ), {
111
130
  body: {
112
131
  ...e.body,
113
132
  id: e.id,
114
- messages: o ? [o] : [],
133
+ messages: t ? [t] : [],
115
134
  trigger: e.trigger,
116
135
  messageId: e.messageId
117
136
  },
118
- headers: e.headers
137
+ headers: {
138
+ ...e.headers,
139
+ ...a
140
+ }
119
141
  };
120
142
  },
121
143
  body: {
122
- requestContext: pe
144
+ requestContext: me
123
145
  }
124
146
  }),
125
- [de, pe, A, S]
147
+ [ve, me, S, h]
126
148
  ), {
127
- messages: N,
128
- sendMessage: Q,
129
- addToolApprovalResponse: Z,
130
- status: ye,
149
+ messages: L,
150
+ sendMessage: X,
151
+ addToolApprovalResponse: Y,
152
+ status: be,
131
153
  setMessages: f,
132
- stop: O,
133
- error: P
134
- } = Ze({
135
- transport: $e,
154
+ stop: D,
155
+ error: B
156
+ } = ot({
157
+ transport: Je,
136
158
  onData(e) {
137
- x(e.type, e.data);
159
+ _(e.type, e.data);
138
160
  },
139
161
  async onFinish() {
140
- x("completion", { conversationId: i }), await d({
162
+ _("completion", { conversationId: i }), await m({
141
163
  eventName: "assistant_message_received",
142
164
  properties: {
143
165
  conversationId: i
144
166
  }
145
- }), d({
167
+ }), m({
146
168
  eventName: "assistant_answer_displayed",
147
169
  properties: {
148
170
  conversationId: i
@@ -151,193 +173,194 @@ const Pt = () => {
151
173
  },
152
174
  onError(e) {
153
175
  console.error("onError", { code: e.code, message: e.message });
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;
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;
158
180
  (async () => {
159
- if (o === "session" && ce) {
160
- const l = await le();
181
+ if (a === "session" && de) {
182
+ const l = await pe();
161
183
  if (!l) throw new Error("Auth token refresh failed");
162
- G.current = l;
163
- } else if (o === "session") {
184
+ J.current = l;
185
+ } else if (a === "session") {
164
186
  const l = await K();
165
- l && (q.current = l);
166
- }
187
+ l && (G.current = l);
188
+ } else
189
+ u();
167
190
  if (n) {
168
- Z(n);
191
+ Y(n);
169
192
  return;
170
193
  }
171
194
  s && (f((l) => {
172
195
  let r = [...l];
173
196
  return r.at(-1)?.role === "assistant" && (r = r.slice(0, -1)), r.at(-1)?.role === "user" && (r = r.slice(0, -1)), r;
174
- }), Q(
197
+ }), X(
175
198
  s.files?.length ? { parts: [{ type: "text", text: s.content }, ...s.files] } : { text: s.content },
176
199
  { body: s.body }
177
200
  ));
178
201
  })().catch(() => {
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),
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),
185
208
  role: "assistant",
186
- parts: [{ type: "text", text: b }]
187
- }) : w.parts = [{ type: "text", text: b }], r;
209
+ parts: [{ type: "text", text: k }]
210
+ }) : E.parts = [{ type: "text", text: k }], r;
188
211
  });
189
212
  });
190
213
  return;
191
214
  }
192
- g.current = 0;
193
- const t = dt(e), u = De(e);
194
- if (d({
215
+ v.current = 0, a !== null && u();
216
+ const t = wt(e), p = Ge(e);
217
+ if (m({
195
218
  eventName: "chat_error",
196
219
  properties: {
197
220
  conversationId: i,
198
221
  error: e.message
199
222
  }
200
223
  }), t) {
201
- se(
202
- { title: "Request failed", message: u },
203
- mt
224
+ ne(
225
+ { title: "Request failed", message: p },
226
+ Tt
204
227
  ), f((s) => {
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;
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;
207
230
  });
208
- const n = V.current?.content;
209
- n && y(n), te.current = e;
231
+ const n = j.current?.content;
232
+ n && A(n), re.current = e;
210
233
  return;
211
234
  }
212
235
  f((n) => {
213
- const s = [...n], a = s[s.length - 1];
214
- return a && (a.role === "user" ? s.push({
215
- id: D(16),
236
+ const s = [...n], o = s[s.length - 1];
237
+ return o && (o.role === "user" ? s.push({
238
+ id: U(16),
216
239
  role: "assistant",
217
- parts: [{ type: "text", text: u }]
218
- }) : a.parts = [{ type: "text", text: u }]), s;
240
+ parts: [{ type: "text", text: p }]
241
+ }) : o.parts = [{ type: "text", text: p }]), s;
219
242
  });
220
243
  }
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(() => {
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(() => {
227
250
  const e = (n) => {
228
251
  if (!n || typeof n != "object") return !1;
229
252
  const s = n;
230
253
  return typeof s.type == "string" && s.type.startsWith("tool-");
231
- }, t = [...N ?? []].reverse().find((n) => n.role === "assistant");
254
+ }, t = [...L ?? []].reverse().find((n) => n.role === "assistant");
232
255
  if (!t) return !1;
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;
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;
240
263
  return;
241
264
  }
242
- R(P);
265
+ w(B);
243
266
  }
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({
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({
255
278
  eventName: "user_message_submitted",
256
279
  properties: {
257
280
  conversationId: i
258
281
  }
259
282
  });
260
283
  let t = i;
261
- t || (t = `conv_${D(16)}`, m(t)), Me(t);
262
- const u = I.current;
263
- I.current = void 0;
284
+ t || (t = `conv_${U(16)}`, g(t)), Le(t);
285
+ const p = R.current;
286
+ R.current = void 0;
264
287
  let n, s;
265
- if (u?.length) {
266
- let a;
288
+ if (p?.length) {
289
+ let o;
267
290
  try {
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}"`));
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}"`));
276
299
  return;
277
300
  }
278
- w({
301
+ E({
279
302
  type: "file",
280
- url: E.result,
303
+ url: M.result,
281
304
  mediaType: r.type,
282
305
  filename: r.name
283
306
  });
284
- }, E.onerror = () => b(new Error(`Failed to read file "${r.name}"`)), E.readAsDataURL(r);
307
+ }, M.onerror = () => k(new Error(`Failed to read file "${r.name}"`)), M.readAsDataURL(r);
285
308
  });
286
309
  })
287
310
  );
288
311
  } catch {
289
- se({
312
+ ne({
290
313
  title: "Failed to attach files",
291
314
  message: "Could not read one or more files. Please try again."
292
315
  });
293
316
  return;
294
317
  }
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;
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;
300
323
  n = e.trim() ? { text: e, files: l } : { files: l };
301
324
  } else
302
325
  n = { text: e };
303
- V.current = {
326
+ j.current = {
304
327
  content: e,
305
328
  body: { conversationId: t },
306
329
  files: s
307
- }, Q(n, {
330
+ }, X(n, {
308
331
  body: { conversationId: t }
309
332
  });
310
- }, He = L(
333
+ }, st = $(
311
334
  (e) => {
312
- g.current = 0, j.current = e, Y(!1), Z(e);
335
+ v.current = 0, W.current = e, te(!1), Y(e);
313
336
  },
314
- [Z]
315
- ), ne = L(() => {
316
- Y(!0), O().then(() => {
317
- x("aborted", { conversationId: i });
337
+ [Y]
338
+ ), ae = $(() => {
339
+ te(!0), D().then(() => {
340
+ _("aborted", { conversationId: i });
318
341
  });
319
- }, [O, i, x]), Te = () => {
320
- Ge(), f([]), m(""), I.current = C?.length ? C : void 0, d({
342
+ }, [D, i, _]), ke = () => {
343
+ Xe(), f([]), g(""), u(), R.current = b?.length ? b : void 0, m({
321
344
  eventName: "chat_clear_button_clicked",
322
345
  properties: {
323
346
  conversationId: i
324
347
  }
325
348
  });
326
- }, T = L(
327
- (e, o) => {
328
- R(null), f(o), m(e), I.current = void 0;
349
+ }, T = $(
350
+ (e, a) => {
351
+ w(null), f(a), g(e), u(), R.current = void 0;
329
352
  },
330
- [f, m]
331
- ), we = L(
332
- async (e, o) => {
333
- ne(), T(e, []), he(!0);
353
+ [f, g, u]
354
+ ), Me = $(
355
+ async (e, a) => {
356
+ ae(), T(e, []), Ae(!0);
334
357
  try {
335
- const t = await ge(e, o);
358
+ const t = await Ce(e, a);
336
359
  if (t === null) return !1;
337
360
  const n = t[t.length - 1]?.role === "user" ? [
338
361
  ...t,
339
362
  {
340
- id: D(16),
363
+ id: U(16),
341
364
  role: "assistant",
342
365
  parts: [
343
366
  {
@@ -349,62 +372,64 @@ const Pt = () => {
349
372
  ] : t;
350
373
  return T(e, n), !0;
351
374
  } finally {
352
- o?.aborted || he(!1);
375
+ a?.aborted || Ae(!1);
353
376
  }
354
377
  },
355
- [T, ge, ne]
378
+ [T, Ce, ae]
356
379
  );
357
- ot({
358
- conversationId: h.conversationId,
359
- effectiveAuthToken: me,
360
- loadAndRestoreSession: we,
380
+ vt({
381
+ conversationId: y.conversationId,
382
+ effectiveAuthToken: ye,
383
+ loadAndRestoreSession: Me,
361
384
  onLoadFailed: () => T("", [])
362
385
  });
363
- const { openForm: We } = it(), Qe = lt();
364
- return Ye(h.chatFunctionsRef, () => ({
365
- submitMessage: re,
386
+ const { openForm: rt } = Ct(), nt = At();
387
+ return it(y.chatFunctionsRef, () => ({
388
+ submitMessage: oe,
366
389
  updateInputMessage(e) {
367
- y(e);
390
+ A(e);
368
391
  },
369
- clearChat: Te,
392
+ clearChat: ke,
370
393
  openForm: (e) => {
371
- Qe?.setView("chat"), We(e, void 0);
394
+ nt?.setView("chat"), rt(e, void 0);
372
395
  },
373
396
  focusInput: () => {
374
- Re.current?.focus();
397
+ Ee.current?.focus();
375
398
  }
376
399
  })), {
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,
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,
397
420
  conversationId: i,
398
421
  restoreSession: T,
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
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
406
431
  };
407
432
  };
408
433
  export {
409
- Pt as useInkeepChat
434
+ Zt as useInkeepChat
410
435
  };