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