@inkeep/agents-ui 0.16.1 → 0.16.3

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