@inkeep/agents-ui 0.15.13 → 0.15.14

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 (92) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.js +230 -222
  3. package/dist/primitives/atoms/icons/built-in-icons.cjs +1 -1
  4. package/dist/primitives/atoms/icons/built-in-icons.d.ts +2 -0
  5. package/dist/primitives/atoms/icons/built-in-icons.js +33 -31
  6. package/dist/primitives/atoms/icons/inkeep-default-icons.cjs +1 -1
  7. package/dist/primitives/atoms/icons/inkeep-default-icons.js +4 -1
  8. package/dist/primitives/components/chat-history/index.cjs +1 -0
  9. package/dist/primitives/components/chat-history/index.d.ts +27 -0
  10. package/dist/primitives/components/chat-history/index.js +105 -0
  11. package/dist/primitives/components/embedded-chat/use-captcha.cjs +1 -0
  12. package/dist/primitives/components/embedded-chat/use-captcha.d.ts +23 -6
  13. package/dist/primitives/components/embedded-chat/use-captcha.js +67 -0
  14. package/dist/primitives/components/embedded-chat/use-inkeep-chat.cjs +2 -2
  15. package/dist/primitives/components/embedded-chat/use-inkeep-chat.d.ts +12 -3
  16. package/dist/primitives/components/embedded-chat/use-inkeep-chat.js +252 -144
  17. package/dist/primitives/components/embedded-chat/use-stream-processor.cjs +1 -1
  18. package/dist/primitives/components/embedded-chat/use-stream-processor.d.ts +2 -0
  19. package/dist/primitives/components/embedded-chat/use-stream-processor.js +120 -70
  20. package/dist/primitives/components/embedded-chat.cjs +3 -3
  21. package/dist/primitives/components/embedded-chat.d.ts +5 -2
  22. package/dist/primitives/components/embedded-chat.js +1010 -967
  23. package/dist/primitives/components/index.cjs +1 -1
  24. package/dist/primitives/components/index.d.ts +1 -0
  25. package/dist/primitives/components/index.js +20 -18
  26. package/dist/primitives/hooks/use-anonymous-session.cjs +1 -0
  27. package/dist/primitives/hooks/use-anonymous-session.d.ts +12 -0
  28. package/dist/primitives/hooks/use-anonymous-session.js +57 -0
  29. package/dist/primitives/hooks/use-conversation-loader.cjs +1 -0
  30. package/dist/primitives/hooks/use-conversation-loader.d.ts +13 -0
  31. package/dist/primitives/hooks/use-conversation-loader.js +36 -0
  32. package/dist/primitives/hooks/use-inkeep-api-client.cjs +1 -0
  33. package/dist/primitives/hooks/use-inkeep-api-client.d.ts +33 -0
  34. package/dist/primitives/hooks/use-inkeep-api-client.js +87 -0
  35. package/dist/primitives/hooks/use-local-storage.cjs +1 -0
  36. package/dist/primitives/hooks/use-local-storage.d.ts +8 -0
  37. package/dist/primitives/hooks/use-local-storage.js +26 -0
  38. package/dist/primitives/index.cjs +1 -1
  39. package/dist/primitives/index.js +157 -151
  40. package/dist/primitives/providers/base-events-provider.cjs +1 -1
  41. package/dist/primitives/providers/base-events-provider.js +1 -1
  42. package/dist/primitives/providers/chat-history-provider.cjs +1 -0
  43. package/dist/primitives/providers/chat-history-provider.d.ts +32 -0
  44. package/dist/primitives/providers/chat-history-provider.js +105 -0
  45. package/dist/primitives/providers/index.cjs +1 -1
  46. package/dist/primitives/providers/index.d.ts +1 -0
  47. package/dist/primitives/providers/index.js +55 -52
  48. package/dist/primitives/utils/component-ids.cjs +1 -1
  49. package/dist/primitives/utils/component-ids.d.ts +32 -0
  50. package/dist/primitives/utils/component-ids.js +19 -1
  51. package/dist/primitives/utils/default-settings.cjs +1 -1
  52. package/dist/primitives/utils/default-settings.d.ts +2 -0
  53. package/dist/primitives/utils/default-settings.js +6 -4
  54. package/dist/react/chat-button.cjs +1 -1
  55. package/dist/react/chat-button.js +42 -38
  56. package/dist/react/embedded-chat.cjs +1 -1
  57. package/dist/react/embedded-chat.js +256 -230
  58. package/dist/react/index.cjs +1 -1
  59. package/dist/react/index.js +230 -222
  60. package/dist/react/sidebar-chat.cjs +1 -1
  61. package/dist/react/sidebar-chat.js +26 -22
  62. package/dist/styled/components/chat-bubble.cjs +1 -1
  63. package/dist/styled/components/chat-bubble.js +1 -1
  64. package/dist/styled/components/chat-history.cjs +1 -0
  65. package/dist/styled/components/chat-history.d.ts +15 -0
  66. package/dist/styled/components/chat-history.js +197 -0
  67. package/dist/styled/components/data-summary-group.cjs +1 -1
  68. package/dist/styled/components/data-summary-group.js +24 -24
  69. package/dist/styled/components/embedded-chat/session-loading.cjs +1 -0
  70. package/dist/styled/components/embedded-chat/session-loading.d.ts +1 -0
  71. package/dist/styled/components/embedded-chat/session-loading.js +26 -0
  72. package/dist/styled/components/embedded-chat.cjs +1 -1
  73. package/dist/styled/components/embedded-chat.d.ts +7 -1
  74. package/dist/styled/components/embedded-chat.js +615 -563
  75. package/dist/styled/components/embedded-search.cjs +1 -1
  76. package/dist/styled/components/embedded-search.js +1 -1
  77. package/dist/styled/components/index.cjs +1 -1
  78. package/dist/styled/components/index.d.ts +1 -0
  79. package/dist/styled/components/index.js +22 -20
  80. package/dist/styled/components/sidebar-chat.cjs +1 -1
  81. package/dist/styled/components/sidebar-chat.js +1 -1
  82. package/dist/styled/components/ui/recipes/ai-chat-page-wrapper.cjs +1 -1
  83. package/dist/styled/components/ui/recipes/ai-chat-page-wrapper.js +3 -2
  84. package/dist/styled/index.cjs +1 -1
  85. package/dist/styled/index.js +193 -185
  86. package/dist/styled/inkeep.css.cjs +146 -4
  87. package/dist/styled/inkeep.css.js +146 -4
  88. package/dist/types/config/ai.d.ts +17 -1
  89. package/dist/types/config/base.d.ts +21 -0
  90. package/dist/types/icons/built-in.d.ts +1 -1
  91. package/dist/types/icons/custom.d.ts +3 -0
  92. package/package.json +1 -1
@@ -1,204 +1,312 @@
1
1
  "use client";
2
- import { useChat as re } from "@ai-sdk/react";
3
- import { DefaultChatTransport as ae } from "ai";
4
- import { useState as m, useMemo as H, useEffect as O, useRef as ie, useImperativeHandle as le } from "react";
5
- import { useInkeepConfig as ce } from "../../providers/config-provider.js";
6
- import { useMediaQuery as me } from "../../hooks/use-media-query.js";
2
+ import { useChat as De } from "@ai-sdk/react";
3
+ import { DefaultChatTransport as Pe } from "ai";
4
+ import { useState as C, useRef as l, useMemo as le, useEffect as ue, useCallback as x, useImperativeHandle as He } from "react";
5
+ import { useModal as Le } from "../modal/modal-provider.js";
6
+ import { useOptionalChatBubble as Ue } from "../../providers/chat-bubble-provider.js";
7
+ import { useOptionalSidebarChat as $e } from "../../providers/sidebar-chat-provider.js";
8
+ import { useInkeepConfig as ze } from "../../providers/config-provider.js";
9
+ import { useCaptcha as We } from "./use-captcha.js";
10
+ import { useMediaQuery as qe } from "../../hooks/use-media-query.js";
11
+ import { useAnonymousSession as Ke } from "../../hooks/use-anonymous-session.js";
12
+ import { useConversationLoader as Je } from "../../hooks/use-conversation-loader.js";
7
13
  import { generateUid as W } from "../../utils/generate-uid.js";
8
- import { useBaseEvents as pe } from "../../providers/base-events-provider.js";
9
- import { useChatForm as ue } from "../../providers/chat-form-provider.js";
10
- import { useWidget as fe } from "../../providers/widget-provider.js";
11
- import { useControllableState as ge } from "@radix-ui/react-use-controllable-state";
12
- import { useStreamingEvents as de } from "../../hooks/use-streaming-events.js";
13
- const he = `Hmm..
14
+ import { useBaseEvents as je } from "../../providers/base-events-provider.js";
15
+ import { useChatForm as Ge } from "../../providers/chat-form-provider.js";
16
+ import { useWidget as Qe } from "../../providers/widget-provider.js";
17
+ import { useControllableState as Ve } from "@radix-ui/react-use-controllable-state";
18
+ import { useStreamingEvents as Ze } from "../../hooks/use-streaming-events.js";
19
+ import { parseAuthError as Xe } from "../../hooks/use-inkeep-api-client.js";
20
+ function Ye(d) {
21
+ const u = d.message ?? "";
22
+ let s = Number(d.code) || Number(d.statusCode);
23
+ if (Number.isNaN(s))
24
+ try {
25
+ s = Number(JSON.parse(u).status);
26
+ } catch {
27
+ }
28
+ const p = Xe(s, { detail: u });
29
+ return p !== null ? p : s === 401 ? "session" : null;
30
+ }
31
+ const pe = `Hmm..
14
32
 
15
- It seems I might be having some issues right now. Please clear the chat and try again.`, Fe = () => {
16
- const { baseSettings: S, aiChatSettings: c } = ce(), [n = "", E] = ge({
17
- prop: c.conversationId,
18
- defaultProp: c.conversationId ?? ""
19
- }), { logEvent: r } = pe(), { setConversationId: q, emitToParent: p } = de(), [a, u] = m(""), z = (e) => u(e.target.value), {
20
- /* shouldBypassCaptcha, */
21
- filters: w
22
- } = S, {
23
- onInputMessageChange: K,
24
- filters: M,
25
- agentUrl: x,
26
- context: f,
27
- headers: g,
28
- apiKey: d
29
- } = c, U = (e) => {
33
+ It seems I might be having some issues right now. Please clear the chat and try again.`, vt = () => {
34
+ const { baseSettings: d, aiChatSettings: u } = ze(), [s = "", p] = Ve({
35
+ prop: u.conversationId,
36
+ defaultProp: u.conversationId ?? ""
37
+ }), me = Le(), de = Ue(), fe = $e(), { logEvent: h } = je(), { setConversationId: ge, emitToParent: S } = Ze(), [y, k] = C(""), he = (e) => k(e.target.value), { shouldBypassCaptcha: q, filters: K, privacyPreferences: ye } = d, {
38
+ onInputMessageChange: ve,
39
+ filters: J,
40
+ baseUrl: I,
41
+ agentUrl: be,
42
+ context: j,
43
+ headers: G,
44
+ appId: v,
45
+ apiKey: m
46
+ } = u, Ce = me?.isOpen ?? de?.isOpen ?? fe?.isOpen ?? !0, { getCaptchaHeader: b, invalidate: c } = We({
47
+ baseUrl: I,
48
+ shouldBypassCaptcha: q || !!m,
49
+ shouldMakeInitialRequest: Ce
50
+ }), Q = l(b);
51
+ Q.current = b;
52
+ const V = be || `${I}/run/api/chat`, { sessionToken: N, refreshSession: T } = Ke({
53
+ baseUrl: I,
54
+ appId: v,
55
+ getCaptchaHeader: b,
56
+ invalidateCaptcha: c,
57
+ optOutAllAnalytics: ye?.optOutAllAnalytics
58
+ }), { loadConversation: Z } = Je({
59
+ baseUrl: I,
60
+ appId: v,
61
+ authToken: m ?? N,
62
+ getCaptchaHeader: b,
63
+ invalidateCaptcha: c,
64
+ // Only pass refreshSession for anonymous-session flows; API key auth has no token to refresh.
65
+ refreshSession: m ? void 0 : T
66
+ }), [Se, X] = C(!1), A = l(null);
67
+ A.current = N;
68
+ const f = l(0), Y = l(null), O = l(null), ee = l(G);
69
+ ee.current = G;
70
+ const _ = l(void 0);
71
+ _.current = K || J ? JSON.stringify({ ...K, ...J }) : void 0;
72
+ const Ie = (e) => {
30
73
  switch (e.code) {
31
74
  case 400:
32
75
  return e.message;
33
76
  case 403:
34
- return `There seems to be a configuration error. Please contact ${S.organizationDisplayName ?? "Administrator"}`;
77
+ return `There seems to be a configuration error. Please contact ${d.organizationDisplayName ?? "Administrator"}`;
35
78
  default:
36
- return he;
79
+ return pe;
37
80
  }
38
- }, [$, h] = m([]), [L, _] = m(null), j = () => ({
39
- "x-inkeep-client-timezone": Intl.DateTimeFormat().resolvedOptions().timeZone,
40
- "x-inkeep-client-timestamp": (/* @__PURE__ */ new Date()).toISOString()
41
- }), G = H(
42
- () => new ae({
43
- api: x,
44
- headers: {
45
- ...d ? { Authorization: `Bearer ${d}` } : {},
46
- ...g
81
+ }, [Ae, R] = C([]), [Re, F] = C(null), we = le(
82
+ () => new Pe({
83
+ api: V,
84
+ headers: () => ({
85
+ "x-inkeep-client-timezone": Intl.DateTimeFormat().resolvedOptions().timeZone,
86
+ "x-inkeep-client-timestamp": (/* @__PURE__ */ new Date()).toISOString(),
87
+ ...v ? { "x-inkeep-app-id": v } : {},
88
+ ...A.current ? { Authorization: `Bearer ${A.current}` } : {},
89
+ ...m ? { Authorization: `Bearer ${m}` } : {},
90
+ ..._.current ? { "inkeep-filters": _.current } : {},
91
+ ...ee.current
92
+ }),
93
+ prepareSendMessagesRequest: async (e) => {
94
+ const t = await Q.current();
95
+ return {
96
+ body: {
97
+ ...e.body,
98
+ id: e.id,
99
+ messages: e.messages,
100
+ trigger: e.trigger,
101
+ messageId: e.messageId
102
+ },
103
+ headers: {
104
+ ...e.headers,
105
+ ...t
106
+ }
107
+ };
47
108
  },
48
109
  body: {
49
- requestContext: f
110
+ requestContext: j
50
111
  }
51
112
  }),
52
- [x, d, g, f]
113
+ [V, j, v, m]
53
114
  ), {
54
- messages: i,
55
- sendMessage: F,
56
- addToolApprovalResponse: J,
57
- status: k,
58
- setMessages: A,
59
- stop: Q,
60
- error: v
61
- } = re({
62
- transport: G,
115
+ messages: w,
116
+ sendMessage: B,
117
+ addToolApprovalResponse: D,
118
+ status: te,
119
+ setMessages: g,
120
+ stop: se,
121
+ error: P
122
+ } = De({
123
+ transport: we,
63
124
  onData(e) {
64
- p(e.type, e.data);
125
+ S(e.type, e.data);
65
126
  },
66
127
  async onFinish() {
67
- p("completion", { conversationId: n }), await r({
128
+ S("completion", { conversationId: s }), await h({
68
129
  eventName: "assistant_message_received",
69
130
  properties: {
70
- conversationId: n
131
+ conversationId: s
71
132
  }
72
- }), r({
133
+ }), h({
73
134
  eventName: "assistant_answer_displayed",
74
135
  properties: {
75
- conversationId: n
136
+ conversationId: s
76
137
  }
77
138
  });
78
139
  },
79
140
  onError(e) {
80
- console.log("onError", e.message), r({
141
+ console.error("onError", { code: e.code, message: e.message });
142
+ const t = q || m ? null : Ye(e);
143
+ if (t !== null && f.current < 1) {
144
+ f.current++;
145
+ const a = O.current, n = Y.current;
146
+ (async () => {
147
+ if (t === "session") {
148
+ const o = await T();
149
+ o && (A.current = o);
150
+ } else
151
+ c();
152
+ if (a) {
153
+ D(a);
154
+ return;
155
+ }
156
+ n && (g((o) => {
157
+ let r = [...o];
158
+ return r.at(-1)?.role === "assistant" && (r = r.slice(0, -1)), r.at(-1)?.role === "user" && (r = r.slice(0, -1)), r;
159
+ }), B({ text: n.content }, { body: n.body }));
160
+ })().catch(() => {
161
+ f.current = 0, c(), g((o) => {
162
+ const r = [...o], z = r[r.length - 1];
163
+ if (!z) return r;
164
+ const ce = pe;
165
+ return z.role === "user" ? r.push({
166
+ id: W(16),
167
+ role: "assistant",
168
+ parts: [{ type: "text", text: ce }]
169
+ }) : z.parts = [{ type: "text", text: ce }], r;
170
+ });
171
+ });
172
+ return;
173
+ }
174
+ f.current = 0, t !== null && c(), h({
81
175
  eventName: "chat_error",
82
176
  properties: {
83
- conversationId: n,
177
+ conversationId: s,
84
178
  error: e.message
85
179
  }
86
- }), A((l) => {
87
- const s = [...l], t = s[s.length - 1];
88
- if (t) {
89
- const o = U(e);
90
- t.role === "user" ? s.push({
180
+ }), g((a) => {
181
+ const n = [...a], i = n[n.length - 1];
182
+ if (i) {
183
+ const o = Ie(e);
184
+ i.role === "user" ? n.push({
91
185
  id: W(16),
92
186
  role: "assistant",
93
187
  parts: [{ type: "text", text: o }]
94
- }) : t.parts = [{ type: "text", text: o }];
188
+ }) : i.parts = [{ type: "text", text: o }];
95
189
  }
96
- return s;
190
+ return n;
97
191
  });
98
192
  }
99
- }), D = k === "submitted", y = k === "streaming", V = H(() => {
100
- const e = (o) => {
101
- if (!o || typeof o != "object") return !1;
102
- const B = o;
103
- return typeof B.type == "string" && B.type.startsWith("tool-");
104
- }, s = [...i ?? []].reverse().find((o) => o.role === "assistant");
105
- if (!s) return !1;
106
- const t = s.parts?.at(-1);
107
- return !(!e(t) || t.state !== "output-available" || !t.approval?.id || y);
108
- }, [i, y]), N = y || V, T = D || N, Z = i.length === 0, I = !a.trim() || T, X = me("(max-width: 768px)"), [Y, C] = m(null);
109
- O(() => {
110
- v && C(v);
111
- }, [v]);
112
- const ee = () => C(null), R = ie(null);
113
- O(() => {
114
- K?.(a);
115
- }, [a]);
116
- const te = (e) => {
117
- e.key === "Enter" && !e.shiftKey && !I && !e.nativeEvent.isComposing && (e.preventDefault(), b());
118
- }, b = async (e = a) => {
119
- if (I && (!e || e.trim().length === 0)) return;
120
- h([]), u(""), await r({
193
+ }), re = te === "submitted", H = te === "streaming", Me = le(() => {
194
+ const e = (i) => {
195
+ if (!i || typeof i != "object") return !1;
196
+ const o = i;
197
+ return typeof o.type == "string" && o.type.startsWith("tool-");
198
+ }, a = [...w ?? []].reverse().find((i) => i.role === "assistant");
199
+ if (!a) return !1;
200
+ const n = a.parts?.at(-1);
201
+ return !(!e(n) || n.state !== "output-available" || !n.approval?.id || H);
202
+ }, [w, H]), ne = H || Me, oe = re || ne, Ee = w.length === 0, L = !y.trim() || oe, xe = qe("(max-width: 768px)"), [ke, M] = C(null);
203
+ ue(() => {
204
+ P && M(P);
205
+ }, [P]);
206
+ const Ne = () => M(null), ae = l(null);
207
+ ue(() => {
208
+ ve?.(y);
209
+ }, [y]);
210
+ const Te = (e) => {
211
+ e.key === "Enter" && !e.shiftKey && !L && !e.nativeEvent.isComposing && (e.preventDefault(), U());
212
+ }, U = async (e = y) => {
213
+ if (L && (!e || e.trim().length === 0)) return;
214
+ R([]), k(""), f.current = 0, O.current = null, await h({
121
215
  eventName: "user_message_submitted",
122
216
  properties: {
123
- conversationId: n
217
+ conversationId: s
124
218
  }
125
219
  });
126
- const l = w || M ? JSON.stringify({
127
- ...w,
128
- ...M
129
- }) : void 0, s = {
130
- ...g
131
- };
132
- l && (s["inkeep-filters"] = l);
133
- let t = n;
134
- t || (t = `conv_${W(16)}`, E(t)), q(t), F(
220
+ let t = s;
221
+ t || (t = `conv_${W(16)}`, p(t)), ge(t), Y.current = {
222
+ content: e,
223
+ body: { conversationId: t }
224
+ }, B(
225
+ { text: e },
135
226
  {
136
- text: e
137
- },
138
- {
139
- headers: {
140
- ...j(),
141
- ...s
142
- },
143
- body: {
144
- conversationId: t,
145
- requestContext: f
146
- }
227
+ body: { conversationId: t }
147
228
  }
148
229
  );
149
- }, se = () => {
150
- Q().then(() => {
151
- p("aborted", { conversationId: n });
230
+ }, Oe = x(
231
+ (e) => {
232
+ f.current = 0, O.current = e, D(e);
233
+ },
234
+ [D]
235
+ ), $ = x(() => {
236
+ se().then(() => {
237
+ S("aborted", { conversationId: s });
152
238
  });
153
- }, P = () => {
154
- ee(), A([]), E(""), h([]), _(null), r({
239
+ }, [se, s, S]), ie = () => {
240
+ Ne(), g([]), p(""), R([]), F(null), c(), h({
155
241
  eventName: "chat_clear_button_clicked",
156
242
  properties: {
157
- conversationId: n
243
+ conversationId: s
158
244
  }
159
245
  });
160
- }, { openForm: ne } = ue(), oe = fe();
161
- return le(c.chatFunctionsRef, () => ({
162
- submitMessage: b,
246
+ }, E = x(
247
+ (e, t) => {
248
+ M(null), g(t), p(e), R([]), F(null), c();
249
+ },
250
+ [g, p, c]
251
+ ), _e = x(
252
+ async (e, t) => {
253
+ $(), E(e, []), X(!0);
254
+ try {
255
+ const a = await Z(e, t);
256
+ a !== null && E(e, a);
257
+ } finally {
258
+ t?.aborted || X(!1);
259
+ }
260
+ },
261
+ [E, Z, $]
262
+ ), { openForm: Fe } = Ge(), Be = Qe();
263
+ return He(u.chatFunctionsRef, () => ({
264
+ submitMessage: U,
163
265
  updateInputMessage(e) {
164
- u(e);
266
+ k(e);
165
267
  },
166
- clearChat: P,
268
+ clearChat: ie,
167
269
  openForm: (e) => {
168
- oe?.setView("chat"), ne(e, void 0);
270
+ Be?.setView("chat"), Fe(e, void 0);
169
271
  },
170
272
  focusInput: () => {
171
- R.current?.focus();
273
+ ae.current?.focus();
172
274
  }
173
275
  })), {
174
- messages: i,
175
- sendMessage: F,
176
- addToolApprovalResponse: J,
177
- isLoading: D,
178
- isStreaming: N,
179
- isBusy: T,
180
- error: Y,
181
- setError: C,
182
- isSubmitDisabled: I,
183
- input: a,
184
- handleInputChange: z,
185
- handleInputKeyDown: te,
186
- handleSubmit: b,
187
- stop: se,
188
- clear: P,
189
- isEmpty: i.length === 0,
190
- inputRef: R,
191
- isMobile: X,
276
+ messages: w,
277
+ sendMessage: B,
278
+ addToolApprovalResponse: Oe,
279
+ isLoading: re,
280
+ isStreaming: ne,
281
+ isBusy: oe,
282
+ error: ke,
283
+ setError: M,
284
+ isSubmitDisabled: L,
285
+ input: y,
286
+ handleInputChange: he,
287
+ handleInputKeyDown: Te,
288
+ handleSubmit: U,
289
+ stop: $,
290
+ clear: ie,
291
+ inputRef: ae,
292
+ isMobile: xe,
192
293
  // Additional state for attachments and workflow
193
- messageAttachments: $,
194
- setMessageAttachments: h,
195
- selectedWorkflow: L,
196
- setSelectedWorkflow: _,
197
- isNewChat: Z,
198
- conversationId: n
294
+ messageAttachments: Ae,
295
+ setMessageAttachments: R,
296
+ selectedWorkflow: Re,
297
+ setSelectedWorkflow: F,
298
+ isNewChat: Ee,
299
+ conversationId: s,
300
+ restoreSession: E,
301
+ loadAndRestoreSession: _e,
302
+ isSessionLoading: Se,
303
+ sessionToken: N,
304
+ refreshSession: T,
305
+ getCaptchaHeader: b,
306
+ invalidateCaptcha: c
199
307
  };
200
308
  };
201
309
  export {
202
- he as DEFAULT_ERROR_MESSAGE,
203
- Fe as useInkeepChat
310
+ pe as DEFAULT_ERROR_MESSAGE,
311
+ vt as useInkeepChat
204
312
  };
@@ -1 +1 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react"),A=require("./use-inkeep-chat.cjs");function E(m,u,S){const[T,d]=n.useState(!1),x=n.useRef(0),C=n.useRef(0),w=n.useRef(Date.now()),c=n.useRef(new Map),h=n.useRef(null),{processedParts:p,summaryTimings:b}=n.useMemo(()=>{const s=[];let e="",o=[],y=!1;m.length>x.current&&(w.current=Date.now(),x.current=m.length),C.current=0;const i=new Map,l=(r=!1)=>{if(o.length>0){const t=`group-${C.current++}`,a=c.current.get(t);a?i.set(t,{...a,isCompleted:r}):i.set(t,{isCompleted:r}),s.push({type:"summary-group",summaries:[...o],groupKey:t}),o=[]}};for(const r of m)if(r.type==="text")l(!0),e+=r.text||"";else if(r.type==="data-summary")e.trim()&&(s.push({type:"text",text:e}),e=""),o.push(r.data);else if(r.type==="data-operation"){e.trim()&&(s.push({type:"text",text:e}),e="");const t=r.data;if(t?.type){if((t.type==="tool_call"||t.type==="tool_result")&&t.details?.data?.inDelegatedAgent===!1)continue;switch(t.type){case"agent_initializing":break;case"completion":{const{type:f}=t;o.push({type:f,label:"Completed"}),l(!0);break}case"error":{const f=t.message||"Unknown error";if(console.warn("Data operation error:",f),!s.length)l(!0),h.current=f,y||(s.push({type:"text",text:A.DEFAULT_ERROR_MESSAGE}),y=!0);else{const{type:g,label:v}=t;o.push({type:g,label:v})}break}default:{const{type:f,label:g}=t;o.push({type:f,label:g});break}}}}else if(r.type==="data-artifact")if(r.data?.type?.toLowerCase()==="citation"){const t=r.data,a=t.artifactSummary||{title:t.name};e+=` ^${a?.title||t.name}^`}else e.trim()&&(s.push({type:"text",text:e}),e=""),s.push(r);else r.type==="data-component"?(e.trim()&&(s.push({type:"text",text:e}),e=""),l(!0),s.push(r)):(e.trim()&&(s.push({type:"text",text:e}),e=""),l(!0),s.push(r));if(l(!u),e.trim()&&s.push({type:"text",text:e}),!u)for(const[r,t]of i.entries())t.isCompleted||i.set(r,{...t,isCompleted:!0});const D=i.size!==c.current.size||Array.from(i.entries()).some(([r,t])=>{const a=c.current.get(r);return!a||a.isCompleted!==t.isCompleted})?i:c.current;return c.current=D,{processedParts:s,summaryTimings:D}},[m,u]);n.useEffect(()=>{h.current&&(S(new Error(h.current)),h.current=null)});const R=n.useCallback(()=>{const s=Date.now()-w.current,e=Array.from(c.current.values()).some(y=>!y.isCompleted),o=s>1e3&&!e;d(o)},[]);n.useEffect(()=>{if(!u){d(!1);return}if(!(p.length>0)){d(!1);return}const e=setInterval(R,200);return()=>clearInterval(e)},[u,R,p.length]);const k=n.useMemo(()=>!!(!(p.length>0)&&u),[p.length,u]);return{processedParts:p,summaryTimings:b,shouldShowInitialLoading:k,shouldShowStreamDelayLoading:T}}exports.useStreamProcessor=E;
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react"),O=require("./use-inkeep-chat.cjs");function R(a,n){if(n)return a.findIndex(h=>h.type==="tool_call"&&h.toolCallId===n);const d=a.length-1;return d>=0&&a[d].type==="tool_call"?d:-1}function G(a){const n=a.ctx,h=a.details?.data,y=n?.toolCallId??n?.callId??a.toolCallId??h?.toolCallId;return typeof y=="string"?y:void 0}function q(a,n,d){const[h,y]=l.useState(!1),D=l.useRef(0),v=l.useRef(0),A=l.useRef(Date.now()),g=l.useRef(new Map),k=l.useRef(null),{processedParts:b,summaryTimings:P}=l.useMemo(()=>{const r=[];let t="",o=[],w=!1;a.length>D.current&&(A.current=Date.now(),D.current=a.length),v.current=0;const f=new Map,x=(s=!1)=>{if(o.length>0){const e=`group-${v.current++}`,u=g.current.get(e);u?f.set(e,{...u,isCompleted:s}):f.set(e,{isCompleted:s}),r.push({type:"summary-group",summaries:[...o],groupKey:e}),o=[]}};for(const s of a)if(s.type==="text")x(!0),t+=s.text||"";else if(s.type==="data-summary")t.trim()&&(r.push({type:"text",text:t}),t=""),o.push(s.data);else if(s.type==="data-operation"){t.trim()&&(r.push({type:"text",text:t}),t="");const e=s.data;if(e?.type){if((e.type==="tool_call"||e.type==="tool_result")&&e.details?.data?.inDelegatedAgent===!1)continue;switch(e.type){case"agent_initializing":break;case"completion":{const{type:i}=e;o.push({type:i,label:"Completed"}),x(!0);break}case"error":{const i=e.message||"Unknown error";if(console.warn("Data operation error:",i),!r.length)x(!0),k.current=i,w||(r.push({type:"text",text:O.DEFAULT_ERROR_MESSAGE}),w=!0);else{const{type:p,label:c}=e;o.push({type:p,label:c})}break}case"tool_call":{const{type:i,label:p}=e,c=G(e);o.push({type:i,label:p,...c&&{toolCallId:c}});break}case"tool_result":{const{type:i,label:p}=e,c=G(e),S={type:i,label:p},M=R(o,c);if(M>=0){o[M]=S;break}const T=r.filter(I=>I?.type==="summary-group");if(c){let I=!1;for(let m=T.length-1;m>=0;m--){const C=T[m].summaries;if(C?.length){const L=R(C,c);if(L>=0){C[L]=S,I=!0;break}}}if(I)break}else{const m=T[T.length-1]?.summaries;if(m?.length){const C=R(m,void 0);if(C>=0){m[C]=S;break}}}o.push(S);break}default:{const{type:i,label:p}=e;o.push({type:i,label:p});break}}}}else if(s.type==="data-artifact")if(s.data?.type?.toLowerCase()==="citation"){const e=s.data,u=e.artifactSummary||{title:e.name};t+=` ^${u?.title||e.name}^`}else t.trim()&&(r.push({type:"text",text:t}),t=""),r.push(s);else s.type==="data-component"?(t.trim()&&(r.push({type:"text",text:t}),t=""),x(!0),r.push(s)):(t.trim()&&(r.push({type:"text",text:t}),t=""),x(!0),r.push(s));if(x(!n),t.trim()&&r.push({type:"text",text:t}),!n)for(const[s,e]of f.entries())e.isCompleted||f.set(s,{...e,isCompleted:!0});const _=f.size!==g.current.size||Array.from(f.entries()).some(([s,e])=>{const u=g.current.get(s);return!u||u.isCompleted!==e.isCompleted})?f:g.current;return g.current=_,{processedParts:r,summaryTimings:_}},[a,n]);l.useEffect(()=>{k.current&&(d(new Error(k.current)),k.current=null)});const E=l.useCallback(()=>{const r=Date.now()-A.current,t=Array.from(g.current.values()).some(w=>!w.isCompleted),o=r>1e3&&!t;y(o)},[]);l.useEffect(()=>{if(!n){y(!1);return}if(!(b.length>0)){y(!1);return}const t=setInterval(E,200);return()=>clearInterval(t)},[n,E,b.length]);const z=l.useMemo(()=>!!(!(b.length>0)&&n),[b.length,n]);return{processedParts:b,summaryTimings:P,shouldShowInitialLoading:z,shouldShowStreamDelayLoading:h}}exports.useStreamProcessor=q;
@@ -6,6 +6,8 @@ interface DataSummary {
6
6
  type: string;
7
7
  label?: string;
8
8
  details?: Record<string, unknown>;
9
+ /** Used to match tool_result to tool_call when they're in different groups (e.g. approval in between) or parallel */
10
+ toolCallId?: string;
9
11
  }
10
12
  interface TextPart {
11
13
  type: 'text';