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