@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.
- package/dist/index.cjs +1 -1
- package/dist/index.js +230 -222
- package/dist/primitives/atoms/icons/built-in-icons.cjs +1 -1
- package/dist/primitives/atoms/icons/built-in-icons.d.ts +2 -0
- package/dist/primitives/atoms/icons/built-in-icons.js +33 -31
- package/dist/primitives/atoms/icons/inkeep-default-icons.cjs +1 -1
- package/dist/primitives/atoms/icons/inkeep-default-icons.js +4 -1
- package/dist/primitives/components/chat-history/index.cjs +1 -0
- package/dist/primitives/components/chat-history/index.d.ts +27 -0
- package/dist/primitives/components/chat-history/index.js +105 -0
- package/dist/primitives/components/embedded-chat/use-captcha.cjs +1 -0
- package/dist/primitives/components/embedded-chat/use-captcha.d.ts +23 -6
- package/dist/primitives/components/embedded-chat/use-captcha.js +67 -0
- package/dist/primitives/components/embedded-chat/use-inkeep-chat.cjs +2 -2
- package/dist/primitives/components/embedded-chat/use-inkeep-chat.d.ts +12 -3
- package/dist/primitives/components/embedded-chat/use-inkeep-chat.js +252 -144
- package/dist/primitives/components/embedded-chat/use-stream-processor.cjs +1 -1
- package/dist/primitives/components/embedded-chat/use-stream-processor.d.ts +2 -0
- package/dist/primitives/components/embedded-chat/use-stream-processor.js +120 -70
- package/dist/primitives/components/embedded-chat.cjs +3 -3
- package/dist/primitives/components/embedded-chat.d.ts +5 -2
- package/dist/primitives/components/embedded-chat.js +1010 -967
- package/dist/primitives/components/index.cjs +1 -1
- package/dist/primitives/components/index.d.ts +1 -0
- package/dist/primitives/components/index.js +20 -18
- package/dist/primitives/hooks/use-anonymous-session.cjs +1 -0
- package/dist/primitives/hooks/use-anonymous-session.d.ts +12 -0
- package/dist/primitives/hooks/use-anonymous-session.js +57 -0
- package/dist/primitives/hooks/use-conversation-loader.cjs +1 -0
- package/dist/primitives/hooks/use-conversation-loader.d.ts +13 -0
- package/dist/primitives/hooks/use-conversation-loader.js +36 -0
- package/dist/primitives/hooks/use-inkeep-api-client.cjs +1 -0
- package/dist/primitives/hooks/use-inkeep-api-client.d.ts +33 -0
- package/dist/primitives/hooks/use-inkeep-api-client.js +87 -0
- package/dist/primitives/hooks/use-local-storage.cjs +1 -0
- package/dist/primitives/hooks/use-local-storage.d.ts +8 -0
- package/dist/primitives/hooks/use-local-storage.js +26 -0
- package/dist/primitives/index.cjs +1 -1
- package/dist/primitives/index.js +157 -151
- package/dist/primitives/providers/base-events-provider.cjs +1 -1
- package/dist/primitives/providers/base-events-provider.js +1 -1
- package/dist/primitives/providers/chat-history-provider.cjs +1 -0
- package/dist/primitives/providers/chat-history-provider.d.ts +32 -0
- package/dist/primitives/providers/chat-history-provider.js +105 -0
- package/dist/primitives/providers/index.cjs +1 -1
- package/dist/primitives/providers/index.d.ts +1 -0
- package/dist/primitives/providers/index.js +55 -52
- package/dist/primitives/utils/component-ids.cjs +1 -1
- package/dist/primitives/utils/component-ids.d.ts +32 -0
- package/dist/primitives/utils/component-ids.js +19 -1
- package/dist/primitives/utils/default-settings.cjs +1 -1
- package/dist/primitives/utils/default-settings.d.ts +2 -0
- package/dist/primitives/utils/default-settings.js +6 -4
- package/dist/react/chat-button.cjs +1 -1
- package/dist/react/chat-button.js +42 -38
- package/dist/react/embedded-chat.cjs +1 -1
- package/dist/react/embedded-chat.js +256 -230
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.js +230 -222
- package/dist/react/sidebar-chat.cjs +1 -1
- package/dist/react/sidebar-chat.js +26 -22
- package/dist/styled/components/chat-bubble.cjs +1 -1
- package/dist/styled/components/chat-bubble.js +1 -1
- package/dist/styled/components/chat-history.cjs +1 -0
- package/dist/styled/components/chat-history.d.ts +15 -0
- package/dist/styled/components/chat-history.js +197 -0
- package/dist/styled/components/data-summary-group.cjs +1 -1
- package/dist/styled/components/data-summary-group.js +24 -24
- package/dist/styled/components/embedded-chat/session-loading.cjs +1 -0
- package/dist/styled/components/embedded-chat/session-loading.d.ts +1 -0
- package/dist/styled/components/embedded-chat/session-loading.js +26 -0
- package/dist/styled/components/embedded-chat.cjs +1 -1
- package/dist/styled/components/embedded-chat.d.ts +7 -1
- package/dist/styled/components/embedded-chat.js +615 -563
- package/dist/styled/components/embedded-search.cjs +1 -1
- package/dist/styled/components/embedded-search.js +1 -1
- package/dist/styled/components/index.cjs +1 -1
- package/dist/styled/components/index.d.ts +1 -0
- package/dist/styled/components/index.js +22 -20
- package/dist/styled/components/sidebar-chat.cjs +1 -1
- package/dist/styled/components/sidebar-chat.js +1 -1
- package/dist/styled/components/ui/recipes/ai-chat-page-wrapper.cjs +1 -1
- package/dist/styled/components/ui/recipes/ai-chat-page-wrapper.js +3 -2
- package/dist/styled/index.cjs +1 -1
- package/dist/styled/index.js +193 -185
- package/dist/styled/inkeep.css.cjs +146 -4
- package/dist/styled/inkeep.css.js +146 -4
- package/dist/types/config/ai.d.ts +17 -1
- package/dist/types/config/base.d.ts +21 -0
- package/dist/types/icons/built-in.d.ts +1 -1
- package/dist/types/icons/custom.d.ts +3 -0
- package/package.json +1 -1
|
@@ -1,204 +1,312 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useChat as
|
|
3
|
-
import { DefaultChatTransport as
|
|
4
|
-
import { useState as
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
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
|
|
9
|
-
import { useChatForm as
|
|
10
|
-
import { useWidget as
|
|
11
|
-
import { useControllableState as
|
|
12
|
-
import { useStreamingEvents as
|
|
13
|
-
|
|
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.`,
|
|
16
|
-
const { baseSettings:
|
|
17
|
-
prop:
|
|
18
|
-
defaultProp:
|
|
19
|
-
}), { logEvent:
|
|
20
|
-
|
|
21
|
-
filters:
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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 ${
|
|
77
|
+
return `There seems to be a configuration error. Please contact ${d.organizationDisplayName ?? "Administrator"}`;
|
|
35
78
|
default:
|
|
36
|
-
return
|
|
79
|
+
return pe;
|
|
37
80
|
}
|
|
38
|
-
}, [
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
...
|
|
46
|
-
...
|
|
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:
|
|
110
|
+
requestContext: j
|
|
50
111
|
}
|
|
51
112
|
}),
|
|
52
|
-
[
|
|
113
|
+
[V, j, v, m]
|
|
53
114
|
), {
|
|
54
|
-
messages:
|
|
55
|
-
sendMessage:
|
|
56
|
-
addToolApprovalResponse:
|
|
57
|
-
status:
|
|
58
|
-
setMessages:
|
|
59
|
-
stop:
|
|
60
|
-
error:
|
|
61
|
-
} =
|
|
62
|
-
transport:
|
|
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
|
-
|
|
125
|
+
S(e.type, e.data);
|
|
65
126
|
},
|
|
66
127
|
async onFinish() {
|
|
67
|
-
|
|
128
|
+
S("completion", { conversationId: s }), await h({
|
|
68
129
|
eventName: "assistant_message_received",
|
|
69
130
|
properties: {
|
|
70
|
-
conversationId:
|
|
131
|
+
conversationId: s
|
|
71
132
|
}
|
|
72
|
-
}),
|
|
133
|
+
}), h({
|
|
73
134
|
eventName: "assistant_answer_displayed",
|
|
74
135
|
properties: {
|
|
75
|
-
conversationId:
|
|
136
|
+
conversationId: s
|
|
76
137
|
}
|
|
77
138
|
});
|
|
78
139
|
},
|
|
79
140
|
onError(e) {
|
|
80
|
-
console.
|
|
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:
|
|
177
|
+
conversationId: s,
|
|
84
178
|
error: e.message
|
|
85
179
|
}
|
|
86
|
-
}),
|
|
87
|
-
const
|
|
88
|
-
if (
|
|
89
|
-
const o =
|
|
90
|
-
|
|
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
|
-
}) :
|
|
188
|
+
}) : i.parts = [{ type: "text", text: o }];
|
|
95
189
|
}
|
|
96
|
-
return
|
|
190
|
+
return n;
|
|
97
191
|
});
|
|
98
192
|
}
|
|
99
|
-
}),
|
|
100
|
-
const e = (
|
|
101
|
-
if (!
|
|
102
|
-
const
|
|
103
|
-
return typeof
|
|
104
|
-
},
|
|
105
|
-
if (!
|
|
106
|
-
const
|
|
107
|
-
return !(!e(
|
|
108
|
-
}, [
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}, [
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}, [
|
|
116
|
-
const
|
|
117
|
-
e.key === "Enter" && !e.shiftKey && !
|
|
118
|
-
},
|
|
119
|
-
if (
|
|
120
|
-
|
|
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:
|
|
217
|
+
conversationId: s
|
|
124
218
|
}
|
|
125
219
|
});
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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
|
-
|
|
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
|
-
},
|
|
150
|
-
|
|
151
|
-
|
|
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
|
-
},
|
|
154
|
-
|
|
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:
|
|
243
|
+
conversationId: s
|
|
158
244
|
}
|
|
159
245
|
});
|
|
160
|
-
},
|
|
161
|
-
|
|
162
|
-
|
|
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
|
-
|
|
266
|
+
k(e);
|
|
165
267
|
},
|
|
166
|
-
clearChat:
|
|
268
|
+
clearChat: ie,
|
|
167
269
|
openForm: (e) => {
|
|
168
|
-
|
|
270
|
+
Be?.setView("chat"), Fe(e, void 0);
|
|
169
271
|
},
|
|
170
272
|
focusInput: () => {
|
|
171
|
-
|
|
273
|
+
ae.current?.focus();
|
|
172
274
|
}
|
|
173
275
|
})), {
|
|
174
|
-
messages:
|
|
175
|
-
sendMessage:
|
|
176
|
-
addToolApprovalResponse:
|
|
177
|
-
isLoading:
|
|
178
|
-
isStreaming:
|
|
179
|
-
isBusy:
|
|
180
|
-
error:
|
|
181
|
-
setError:
|
|
182
|
-
isSubmitDisabled:
|
|
183
|
-
input:
|
|
184
|
-
handleInputChange:
|
|
185
|
-
handleInputKeyDown:
|
|
186
|
-
handleSubmit:
|
|
187
|
-
stop:
|
|
188
|
-
clear:
|
|
189
|
-
|
|
190
|
-
|
|
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:
|
|
195
|
-
selectedWorkflow:
|
|
196
|
-
setSelectedWorkflow:
|
|
197
|
-
isNewChat:
|
|
198
|
-
conversationId:
|
|
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
|
-
|
|
203
|
-
|
|
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
|
|
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';
|