@inkeep/agents-ui 0.0.0-dev-20260402200940 → 0.0.0-dev-20260403205747

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