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

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