@inkeep/agents-ui 0.16.0 → 0.16.2
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/color-mode/index.js +4 -4
- package/dist/index.cjs +1 -1
- package/dist/index.js +167 -161
- package/dist/node_modules/.pnpm/use-sync-external-store@1.6.0_react@19.3.0-canary-87ae75b3-20260128/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.cjs +9 -0
- package/dist/node_modules/.pnpm/{use-sync-external-store@1.5.0_react@19.0.0 → use-sync-external-store@1.6.0_react@19.3.0-canary-87ae75b3-20260128}/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js +2 -2
- package/dist/primitives/atoms/cmdk/index.cjs +1 -1
- package/dist/primitives/atoms/cmdk/index.js +14 -2
- package/dist/primitives/atoms/combobox.d.ts +104 -0
- 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/atoms/portal.js +3 -3
- package/dist/primitives/atoms/select.cjs +1 -1
- package/dist/primitives/atoms/select.js +2 -2
- package/dist/primitives/atoms/shadow/context.js +4 -4
- package/dist/primitives/components/embedded-chat/chat-error-helpers.cjs +3 -0
- package/dist/primitives/components/embedded-chat/chat-error-helpers.d.ts +26 -0
- package/dist/primitives/components/embedded-chat/chat-error-helpers.js +32 -0
- package/dist/primitives/components/embedded-chat/file-upload-input.cjs +1 -1
- package/dist/primitives/components/embedded-chat/file-upload-input.d.ts +1 -2
- package/dist/primitives/components/embedded-chat/file-upload-input.js +359 -217
- package/dist/primitives/components/embedded-chat/image-preview-modal.js +3 -3
- 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 -4
- package/dist/primitives/components/embedded-chat/use-inkeep-chat.d.ts +1 -2
- package/dist/primitives/components/embedded-chat/use-inkeep-chat.js +312 -284
- package/dist/primitives/components/embedded-chat/use-stream-processor.cjs +1 -1
- package/dist/primitives/components/embedded-chat/use-stream-processor.js +1 -1
- package/dist/primitives/components/embedded-chat.cjs +3 -3
- package/dist/primitives/components/embedded-chat.d.ts +2 -3
- package/dist/primitives/components/embedded-chat.js +122 -114
- package/dist/primitives/components/embedded-search/search-provider.js +3 -3
- package/dist/primitives/components/embedded-search.cjs +1 -1
- package/dist/primitives/components/embedded-search.d.ts +1 -1
- package/dist/primitives/components/embedded-search.js +3 -3
- package/dist/primitives/components/modal/modal-provider.js +2 -2
- package/dist/primitives/components/modal.js +3 -3
- package/dist/primitives/components/sidebar-chat/index.js +1 -1
- 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 +29 -0
- package/dist/primitives/hooks/use-events-api.js +43 -0
- 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 +23 -22
- 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 +73 -0
- package/dist/primitives/providers/chat-bubble-provider.js +1 -1
- package/dist/primitives/providers/chat-form-provider.d.ts +1 -1
- package/dist/primitives/providers/chat-form-provider.js +4 -4
- package/dist/primitives/providers/chat-history-provider.js +3 -3
- package/dist/primitives/providers/config-provider.js +3 -3
- package/dist/primitives/providers/feedback-provider.cjs +1 -1
- package/dist/primitives/providers/feedback-provider.js +37 -31
- package/dist/primitives/providers/form-field-provider.js +3 -3
- package/dist/primitives/providers/help-menu-provider.js +4 -4
- package/dist/primitives/providers/hover-popover-provider.js +3 -3
- package/dist/primitives/providers/image-preview-provider.js +5 -5
- 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/primitives/providers/markdown-provider.js +2 -2
- package/dist/primitives/providers/message-provider.js +1 -1
- package/dist/primitives/providers/sidebar-chat-provider.js +3 -3
- package/dist/primitives/providers/source-item-provider.js +3 -3
- package/dist/primitives/providers/widget-provider.js +2 -2
- package/dist/primitives/utils/misc.cjs +1 -1
- package/dist/primitives/utils/misc.js +2 -2
- package/dist/react/chat-button.js +1 -1
- package/dist/react/embedded-chat.cjs +1 -1
- package/dist/react/embedded-chat.js +104 -102
- package/dist/react/embedded-search.cjs +1 -1
- package/dist/react/embedded-search.js +18 -18
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.js +167 -161
- package/dist/styled/components/chat-bubble.js +4 -4
- package/dist/styled/components/chat-button.cjs +1 -1
- package/dist/styled/components/chat-button.js +9 -9
- package/dist/styled/components/chat-history.cjs +1 -1
- package/dist/styled/components/chat-history.js +22 -22
- package/dist/styled/components/embedded-chat/file-upload-input.cjs +1 -1
- package/dist/styled/components/embedded-chat/file-upload-input.js +71 -72
- package/dist/styled/components/embedded-chat/image-preview-modal.js +14 -7
- package/dist/styled/components/embedded-chat.cjs +1 -1
- package/dist/styled/components/embedded-chat.js +211 -199
- package/dist/styled/components/embedded-search.cjs +1 -1
- package/dist/styled/components/embedded-search.js +72 -66
- package/dist/styled/components/loading-indicator.cjs +1 -1
- package/dist/styled/components/loading-indicator.js +1 -1
- package/dist/styled/components/message.cjs +1 -1
- package/dist/styled/components/message.js +142 -139
- package/dist/styled/components/modal.js +3 -3
- package/dist/styled/components/searchbar.js +8 -8
- package/dist/styled/components/sidebar-chat.cjs +1 -1
- package/dist/styled/components/sidebar-chat.js +5 -5
- package/dist/styled/index.cjs +1 -1
- package/dist/styled/index.js +155 -149
- package/dist/styled/inkeep.css.cjs +13 -3
- package/dist/styled/inkeep.css.js +13 -3
- package/dist/theme/utils/generate-theme-variables.js +6 -6
- 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
- package/dist/node_modules/.pnpm/use-sync-external-store@1.5.0_react@19.0.0/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.cjs +0 -9
- /package/dist/node_modules/.pnpm/{use-sync-external-store@1.5.0_react@19.0.0 → use-sync-external-store@1.6.0_react@19.3.0-canary-87ae75b3-20260128}/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.cjs +0 -0
- /package/dist/node_modules/.pnpm/{use-sync-external-store@1.5.0_react@19.0.0 → use-sync-external-store@1.6.0_react@19.3.0-canary-87ae75b3-20260128}/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.js +0 -0
- /package/dist/node_modules/.pnpm/{use-sync-external-store@1.5.0_react@19.0.0 → use-sync-external-store@1.6.0_react@19.3.0-canary-87ae75b3-20260128}/node_modules/use-sync-external-store/shim/index.cjs +0 -0
- /package/dist/node_modules/.pnpm/{use-sync-external-store@1.5.0_react@19.0.0 → use-sync-external-store@1.6.0_react@19.3.0-canary-87ae75b3-20260128}/node_modules/use-sync-external-store/shim/index.js +0 -0
|
@@ -1,408 +1,436 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useChat as
|
|
3
|
-
import { normalizeFileType as
|
|
4
|
-
import { DefaultChatTransport as
|
|
5
|
-
import { useRef as l, useEffect as
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
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";
|
|
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";
|
|
16
11
|
import { generateUid as L } from "../../utils/generate-uid.js";
|
|
17
|
-
import { useBaseEvents as
|
|
18
|
-
import { useChatForm as
|
|
19
|
-
import { useWidget as
|
|
20
|
-
import { useControllableState as
|
|
21
|
-
import { useStreamingEvents as
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const p = bt(s, { detail: m });
|
|
33
|
-
return p !== null ? p : s === 401 ? "session" : null;
|
|
34
|
-
}
|
|
35
|
-
const te = `Hmm..
|
|
36
|
-
|
|
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({
|
|
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({
|
|
45
27
|
eventName: "chat_conversation_changed",
|
|
46
28
|
properties: {
|
|
47
|
-
conversationId:
|
|
29
|
+
conversationId: c,
|
|
48
30
|
previousConversationId: e
|
|
49
31
|
}
|
|
50
32
|
});
|
|
51
|
-
}, [
|
|
52
|
-
const [
|
|
53
|
-
|
|
33
|
+
}, [c, f]);
|
|
34
|
+
const [y, C] = M(""), De = (e) => C(e.target.value), {
|
|
35
|
+
shouldBypassCaptcha: Oe,
|
|
54
36
|
filters: ie,
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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;
|
|
86
73
|
const K = l(void 0);
|
|
87
|
-
K.current =
|
|
88
|
-
const
|
|
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(
|
|
78
|
+
(e) => `${e.filename ?? ""}:${e.mediaType}:${e.url.length}:${e.url.slice(0, 64)}:${e.url.slice(-32)}`
|
|
79
|
+
).join(`
|
|
89
80
|
`) ?? "";
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}, [
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
const
|
|
98
|
-
switch (e
|
|
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)) {
|
|
99
90
|
case 400:
|
|
100
|
-
|
|
91
|
+
try {
|
|
92
|
+
const t = JSON.parse(e.message ?? "");
|
|
93
|
+
return t.detail ?? t.error?.message ?? Pe;
|
|
94
|
+
} catch {
|
|
95
|
+
return e.message?.trim() || Pe;
|
|
96
|
+
}
|
|
101
97
|
case 401:
|
|
102
|
-
return
|
|
98
|
+
return ce ? "Authentication failed. Please try again." : ne;
|
|
103
99
|
case 403:
|
|
104
|
-
return `There seems to be a configuration error. Please contact ${
|
|
100
|
+
return `There seems to be a configuration error. Please contact ${oe.organizationDisplayName ?? "Administrator"}`;
|
|
101
|
+
case 429:
|
|
102
|
+
return It;
|
|
105
103
|
default:
|
|
106
|
-
return
|
|
104
|
+
return ne;
|
|
107
105
|
}
|
|
108
|
-
}, [
|
|
109
|
-
() => new
|
|
110
|
-
api:
|
|
106
|
+
}, [P, J] = M([]), Ke = _e(
|
|
107
|
+
() => new rt({
|
|
108
|
+
api: Ce,
|
|
111
109
|
headers: () => {
|
|
112
|
-
const e =
|
|
110
|
+
const e = U ?? H.current ?? z.current;
|
|
113
111
|
return {
|
|
114
112
|
"x-inkeep-client-timezone": Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
115
113
|
"x-inkeep-client-timestamp": (/* @__PURE__ */ new Date()).toISOString(),
|
|
116
|
-
|
|
114
|
+
"x-inkeep-invocation-type": "chat_widget",
|
|
115
|
+
..._ ? { "x-inkeep-app-id": _ } : {},
|
|
117
116
|
...e ? { Authorization: `Bearer ${e}` } : {},
|
|
118
|
-
...
|
|
119
|
-
...
|
|
120
|
-
...ge.current
|
|
117
|
+
...V.current ? { "inkeep-filters": V.current } : {},
|
|
118
|
+
...Se.current
|
|
121
119
|
};
|
|
122
120
|
},
|
|
123
121
|
prepareSendMessagesRequest: async (e) => {
|
|
124
|
-
const
|
|
125
|
-
return t || console.warn(
|
|
122
|
+
const a = await ye.current(), t = e.messages[e.messages.length - 1];
|
|
123
|
+
return t || console.warn(
|
|
124
|
+
"[useInkeepChat] prepareSendMessagesRequest called with empty messages array"
|
|
125
|
+
), {
|
|
126
126
|
body: {
|
|
127
127
|
...e.body,
|
|
128
128
|
id: e.id,
|
|
129
129
|
messages: t ? [t] : [],
|
|
130
130
|
trigger: e.trigger,
|
|
131
|
-
messageId: e.messageId
|
|
131
|
+
messageId: e.messageId,
|
|
132
|
+
...K.current ? { userProperties: K.current } : {},
|
|
133
|
+
...q.current ? { properties: q.current } : {}
|
|
132
134
|
},
|
|
133
135
|
headers: {
|
|
134
136
|
...e.headers,
|
|
135
|
-
...
|
|
137
|
+
...a
|
|
136
138
|
}
|
|
137
139
|
};
|
|
138
140
|
},
|
|
139
141
|
body: {
|
|
140
|
-
requestContext:
|
|
142
|
+
requestContext: he
|
|
141
143
|
}
|
|
142
144
|
}),
|
|
143
|
-
[
|
|
145
|
+
[Ce, he, _, U]
|
|
144
146
|
), {
|
|
145
|
-
messages:
|
|
146
|
-
sendMessage:
|
|
147
|
+
messages: S,
|
|
148
|
+
sendMessage: W,
|
|
147
149
|
addToolApprovalResponse: Q,
|
|
148
|
-
status:
|
|
149
|
-
setMessages:
|
|
150
|
-
stop:
|
|
151
|
-
error:
|
|
152
|
-
} =
|
|
153
|
-
transport:
|
|
150
|
+
status: we,
|
|
151
|
+
setMessages: d,
|
|
152
|
+
stop: N,
|
|
153
|
+
error: D
|
|
154
|
+
} = st({
|
|
155
|
+
transport: Ke,
|
|
154
156
|
onData(e) {
|
|
155
|
-
|
|
157
|
+
x(e.type, e.data);
|
|
156
158
|
},
|
|
157
|
-
async onFinish() {
|
|
158
|
-
|
|
159
|
+
async onFinish({ message: e }) {
|
|
160
|
+
x("completion", { conversationId: c }), await f({
|
|
159
161
|
eventName: "assistant_message_received",
|
|
160
162
|
properties: {
|
|
161
|
-
conversationId:
|
|
163
|
+
conversationId: c,
|
|
164
|
+
messageId: e.id
|
|
162
165
|
}
|
|
163
|
-
}),
|
|
166
|
+
}), f({
|
|
164
167
|
eventName: "assistant_answer_displayed",
|
|
165
168
|
properties: {
|
|
166
|
-
conversationId:
|
|
169
|
+
conversationId: c,
|
|
170
|
+
messageId: e.id
|
|
167
171
|
}
|
|
168
172
|
});
|
|
169
173
|
},
|
|
170
174
|
onError(e) {
|
|
171
175
|
console.error("onError", { code: e.code, message: e.message });
|
|
172
|
-
const
|
|
173
|
-
if (
|
|
174
|
-
|
|
175
|
-
const
|
|
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;
|
|
176
180
|
(async () => {
|
|
177
|
-
if (
|
|
178
|
-
const
|
|
179
|
-
if (!
|
|
180
|
-
|
|
181
|
-
} else if (
|
|
182
|
-
const
|
|
183
|
-
|
|
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
|
+
} else if (a === "session") {
|
|
186
|
+
const i = await de();
|
|
187
|
+
i && (z.current = i);
|
|
184
188
|
} else
|
|
185
|
-
|
|
186
|
-
if (
|
|
187
|
-
Q(
|
|
189
|
+
p();
|
|
190
|
+
if (n) {
|
|
191
|
+
Q(n);
|
|
188
192
|
return;
|
|
189
193
|
}
|
|
190
|
-
|
|
191
|
-
let
|
|
192
|
-
return
|
|
193
|
-
}),
|
|
194
|
-
|
|
195
|
-
{ body:
|
|
194
|
+
s && (d((i) => {
|
|
195
|
+
let r = [...i];
|
|
196
|
+
return r.at(-1)?.role === "assistant" && (r = r.slice(0, -1)), r.at(-1)?.role === "user" && (r = r.slice(0, -1)), r;
|
|
197
|
+
}), W(
|
|
198
|
+
s.files?.length ? { parts: [{ type: "text", text: s.content }, ...s.files] } : { text: s.content },
|
|
199
|
+
{ body: s.body }
|
|
196
200
|
));
|
|
197
201
|
})().catch(() => {
|
|
198
|
-
|
|
199
|
-
const
|
|
200
|
-
if (!
|
|
201
|
-
const
|
|
202
|
-
return
|
|
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({
|
|
203
207
|
id: L(16),
|
|
204
208
|
role: "assistant",
|
|
205
|
-
parts: [{ type: "text", text:
|
|
206
|
-
}) :
|
|
209
|
+
parts: [{ type: "text", text: E }]
|
|
210
|
+
}) : b.parts = [{ type: "text", text: E }], r;
|
|
207
211
|
});
|
|
208
212
|
});
|
|
209
213
|
return;
|
|
210
214
|
}
|
|
211
|
-
|
|
215
|
+
h.current = 0, a !== null && p();
|
|
216
|
+
const t = vt(e), u = He(e);
|
|
217
|
+
if (f({
|
|
212
218
|
eventName: "chat_error",
|
|
213
219
|
properties: {
|
|
214
|
-
conversationId:
|
|
220
|
+
conversationId: c,
|
|
221
|
+
messageId: S.at(-1)?.id,
|
|
215
222
|
error: e.message
|
|
216
223
|
}
|
|
217
|
-
}),
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
return
|
|
224
|
+
}), t) {
|
|
225
|
+
te(
|
|
226
|
+
{ title: "Request failed", message: u },
|
|
227
|
+
yt
|
|
228
|
+
), d((s) => {
|
|
229
|
+
let o = [...s];
|
|
230
|
+
return o.at(-1)?.role === "assistant" && (o = o.slice(0, -1)), o.at(-1)?.role === "user" && (o = o.slice(0, -1)), o;
|
|
231
|
+
});
|
|
232
|
+
const n = j.current?.content;
|
|
233
|
+
n && C(n), ee.current = e;
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
d((n) => {
|
|
237
|
+
const s = [...n], o = s[s.length - 1];
|
|
238
|
+
return o && (o.role === "user" ? s.push({
|
|
239
|
+
id: L(16),
|
|
240
|
+
role: "assistant",
|
|
241
|
+
parts: [{ type: "text", text: u }]
|
|
242
|
+
}) : o.parts = [{ type: "text", text: u }]), s;
|
|
228
243
|
});
|
|
229
244
|
}
|
|
230
|
-
}),
|
|
231
|
-
|
|
232
|
-
const e =
|
|
233
|
-
|
|
234
|
-
}, [
|
|
235
|
-
const be =
|
|
236
|
-
const e = (
|
|
237
|
-
if (!
|
|
238
|
-
const
|
|
239
|
-
return typeof
|
|
240
|
-
}, t = [...
|
|
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(() => {
|
|
251
|
+
const e = (n) => {
|
|
252
|
+
if (!n || typeof n != "object") return !1;
|
|
253
|
+
const s = n;
|
|
254
|
+
return typeof s.type == "string" && s.type.startsWith("tool-");
|
|
255
|
+
}, t = [...S ?? []].reverse().find((n) => n.role === "assistant");
|
|
241
256
|
if (!t) return !1;
|
|
242
|
-
const
|
|
243
|
-
return !(!e(
|
|
244
|
-
}, [
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
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;
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
w(D);
|
|
267
|
+
}
|
|
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;
|
|
277
|
+
const a = P;
|
|
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({
|
|
258
281
|
eventName: "user_message_submitted",
|
|
259
282
|
properties: {
|
|
260
|
-
conversationId:
|
|
283
|
+
conversationId: t
|
|
261
284
|
}
|
|
262
285
|
});
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
let a, r;
|
|
268
|
-
if (n?.length) {
|
|
286
|
+
const u = R.current;
|
|
287
|
+
R.current = void 0;
|
|
288
|
+
let n, s;
|
|
289
|
+
if (u?.length) {
|
|
269
290
|
let o;
|
|
270
291
|
try {
|
|
271
292
|
o = await Promise.all(
|
|
272
|
-
|
|
273
|
-
const
|
|
274
|
-
return new Promise((
|
|
275
|
-
const
|
|
276
|
-
|
|
277
|
-
if (typeof
|
|
278
|
-
|
|
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}"`));
|
|
279
300
|
return;
|
|
280
301
|
}
|
|
281
|
-
|
|
302
|
+
b({
|
|
282
303
|
type: "file",
|
|
283
|
-
url:
|
|
284
|
-
mediaType:
|
|
285
|
-
filename:
|
|
304
|
+
url: T.result,
|
|
305
|
+
mediaType: r.type,
|
|
306
|
+
filename: r.name
|
|
286
307
|
});
|
|
287
|
-
},
|
|
308
|
+
}, T.onerror = () => E(new Error(`Failed to read file "${r.name}"`)), T.readAsDataURL(r);
|
|
288
309
|
});
|
|
289
310
|
})
|
|
290
311
|
);
|
|
291
312
|
} catch {
|
|
292
|
-
|
|
313
|
+
te({
|
|
293
314
|
title: "Failed to attach files",
|
|
294
315
|
message: "Could not read one or more files. Please try again."
|
|
295
316
|
});
|
|
296
317
|
return;
|
|
297
318
|
}
|
|
298
|
-
|
|
299
|
-
} else if (
|
|
319
|
+
s = [...o, ...u], n = e.trim() ? { parts: [{ type: "text", text: e }, ...s] } : { parts: s };
|
|
320
|
+
} else if (a.length > 0) {
|
|
300
321
|
const o = new DataTransfer();
|
|
301
|
-
for (const
|
|
302
|
-
const
|
|
303
|
-
|
|
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 };
|
|
304
325
|
} else
|
|
305
|
-
|
|
306
|
-
|
|
326
|
+
n = { text: e };
|
|
327
|
+
j.current = {
|
|
307
328
|
content: e,
|
|
308
329
|
body: { conversationId: t },
|
|
309
|
-
files:
|
|
310
|
-
},
|
|
330
|
+
files: s
|
|
331
|
+
}, W(n, {
|
|
311
332
|
body: { conversationId: t }
|
|
312
333
|
});
|
|
313
|
-
},
|
|
334
|
+
}, Ye = O(
|
|
314
335
|
(e) => {
|
|
315
|
-
|
|
336
|
+
h.current = 0, G.current = e, X(!1), Q(e);
|
|
316
337
|
},
|
|
317
338
|
[Q]
|
|
318
|
-
),
|
|
319
|
-
|
|
320
|
-
|
|
339
|
+
), re = O(() => {
|
|
340
|
+
X(!0), N().then(() => {
|
|
341
|
+
x("aborted", { conversationId: c });
|
|
321
342
|
});
|
|
322
|
-
}, [
|
|
323
|
-
We(),
|
|
343
|
+
}, [N, c, x]), Me = () => {
|
|
344
|
+
We(), d([]), m(""), p(), R.current = I?.length ? I : void 0, f({
|
|
324
345
|
eventName: "chat_clear_button_clicked",
|
|
325
346
|
properties: {
|
|
326
|
-
conversationId:
|
|
347
|
+
conversationId: c
|
|
327
348
|
}
|
|
328
349
|
});
|
|
329
|
-
},
|
|
330
|
-
(e,
|
|
331
|
-
|
|
350
|
+
}, A = O(
|
|
351
|
+
(e, a) => {
|
|
352
|
+
w(null), d(a), m(e), p(), R.current = void 0;
|
|
332
353
|
},
|
|
333
|
-
[
|
|
334
|
-
),
|
|
335
|
-
async (e,
|
|
336
|
-
|
|
354
|
+
[d, m, p]
|
|
355
|
+
), xe = O(
|
|
356
|
+
async (e, a) => {
|
|
357
|
+
re(), A(e, []), Re(!0);
|
|
337
358
|
try {
|
|
338
|
-
const t = await
|
|
359
|
+
const t = await Ie(e, a);
|
|
339
360
|
if (t === null) return !1;
|
|
340
|
-
const
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
361
|
+
const n = t[t.length - 1]?.role === "user" ? [
|
|
362
|
+
...t,
|
|
363
|
+
{
|
|
364
|
+
id: L(16),
|
|
365
|
+
role: "assistant",
|
|
366
|
+
parts: [
|
|
367
|
+
{
|
|
368
|
+
type: "text",
|
|
369
|
+
text: "This session was interrupted. Please check back in a few minutes or start a new conversation."
|
|
370
|
+
}
|
|
371
|
+
]
|
|
372
|
+
}
|
|
373
|
+
] : t;
|
|
374
|
+
return A(e, n), !0;
|
|
346
375
|
} finally {
|
|
347
|
-
|
|
376
|
+
a?.aborted || Re(!1);
|
|
348
377
|
}
|
|
349
378
|
},
|
|
350
|
-
[
|
|
379
|
+
[A, Ie, re]
|
|
351
380
|
);
|
|
352
|
-
|
|
353
|
-
conversationId:
|
|
354
|
-
effectiveAuthToken:
|
|
355
|
-
loadAndRestoreSession:
|
|
356
|
-
onLoadFailed: () =>
|
|
381
|
+
ct({
|
|
382
|
+
conversationId: v.conversationId,
|
|
383
|
+
effectiveAuthToken: fe,
|
|
384
|
+
loadAndRestoreSession: xe,
|
|
385
|
+
onLoadFailed: () => A("", [])
|
|
357
386
|
});
|
|
358
|
-
const { openForm:
|
|
359
|
-
return
|
|
360
|
-
submitMessage:
|
|
387
|
+
const { openForm: et } = pt(), tt = dt();
|
|
388
|
+
return nt(v.chatFunctionsRef, () => ({
|
|
389
|
+
submitMessage: se,
|
|
361
390
|
updateInputMessage(e) {
|
|
362
|
-
|
|
391
|
+
C(e);
|
|
363
392
|
},
|
|
364
|
-
clearChat:
|
|
393
|
+
clearChat: Me,
|
|
365
394
|
openForm: (e) => {
|
|
366
|
-
|
|
395
|
+
tt?.setView("chat"), et(e, void 0);
|
|
367
396
|
},
|
|
368
397
|
focusInput: () => {
|
|
369
|
-
|
|
398
|
+
ke.current?.focus();
|
|
370
399
|
}
|
|
371
400
|
})), {
|
|
372
|
-
messages:
|
|
373
|
-
sendMessage:
|
|
374
|
-
addToolApprovalResponse:
|
|
401
|
+
messages: S,
|
|
402
|
+
sendMessage: W,
|
|
403
|
+
addToolApprovalResponse: Ye,
|
|
375
404
|
isLoading: be,
|
|
376
|
-
isStreaming:
|
|
377
|
-
isBusy:
|
|
378
|
-
error:
|
|
379
|
-
setError:
|
|
380
|
-
isSubmitDisabled:
|
|
381
|
-
input:
|
|
382
|
-
handleInputChange:
|
|
383
|
-
handleInputKeyDown:
|
|
384
|
-
handleSubmit:
|
|
385
|
-
stop:
|
|
386
|
-
clear:
|
|
387
|
-
inputRef:
|
|
388
|
-
isMobile:
|
|
389
|
-
files:
|
|
390
|
-
setFiles:
|
|
391
|
-
isNewChat:
|
|
392
|
-
conversationId:
|
|
393
|
-
restoreSession:
|
|
394
|
-
loadAndRestoreSession:
|
|
395
|
-
isSessionLoading:
|
|
396
|
-
authToken:
|
|
397
|
-
refreshSession:
|
|
398
|
-
getCaptchaHeader:
|
|
399
|
-
invalidateCaptcha:
|
|
400
|
-
inputNotification:
|
|
401
|
-
showInputNotification:
|
|
402
|
-
clearInputNotification:
|
|
405
|
+
isStreaming: Ee,
|
|
406
|
+
isBusy: Te,
|
|
407
|
+
error: Je,
|
|
408
|
+
setError: w,
|
|
409
|
+
isSubmitDisabled: Y,
|
|
410
|
+
input: y,
|
|
411
|
+
handleInputChange: De,
|
|
412
|
+
handleInputKeyDown: Xe,
|
|
413
|
+
handleSubmit: se,
|
|
414
|
+
stop: re,
|
|
415
|
+
clear: Me,
|
|
416
|
+
inputRef: ke,
|
|
417
|
+
isMobile: Ve,
|
|
418
|
+
files: P,
|
|
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
|
|
403
432
|
};
|
|
404
433
|
};
|
|
405
434
|
export {
|
|
406
|
-
|
|
407
|
-
Kt as useInkeepChat
|
|
435
|
+
$t as useInkeepChat
|
|
408
436
|
};
|