@inkeep/agents-ui 0.0.0-dev-20260721222136 → 0.0.0-dev-20260804222744
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/primitives/atoms/markdown/index.cjs +1 -1
- package/dist/primitives/atoms/markdown/index.d.ts +14 -2
- package/dist/primitives/atoms/markdown/index.js +105 -99
- package/dist/primitives/components/embedded-chat/chat-error-helpers.cjs +2 -2
- package/dist/primitives/components/embedded-chat/chat-error-helpers.d.ts +1 -0
- package/dist/primitives/components/embedded-chat/chat-error-helpers.js +15 -14
- package/dist/primitives/components/embedded-chat/use-inkeep-chat.cjs +2 -2
- package/dist/primitives/components/embedded-chat/use-inkeep-chat.js +191 -185
- 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-base-events-provider.cjs +1 -1
- package/dist/primitives/providers/chat-base-events-provider.js +1 -1
- package/dist/react/embedded-chat.cjs +1 -1
- package/dist/react/embedded-chat.js +279 -261
- package/package.json +1 -1
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useChat as
|
|
3
|
-
import { normalizeFileType as
|
|
4
|
-
import { DefaultChatTransport as
|
|
5
|
-
import { useRef as i, useEffect as
|
|
6
|
-
import { useInkeepConfig as
|
|
7
|
-
import { useChatAuth as
|
|
8
|
-
import { useMediaQuery as
|
|
9
|
-
import { useConversationLoader as
|
|
10
|
-
import { useInitialConversation as
|
|
2
|
+
import { useChat as lt } from "@ai-sdk/react";
|
|
3
|
+
import { normalizeFileType as ut } from "./file-upload-input.js";
|
|
4
|
+
import { DefaultChatTransport as dt } from "ai";
|
|
5
|
+
import { useRef as i, useEffect as b, useState as k, useMemo as Oe, useCallback as $, useImperativeHandle as pt } from "react";
|
|
6
|
+
import { useInkeepConfig as ft } from "../../providers/config-provider.js";
|
|
7
|
+
import { useChatAuth as mt } from "../../providers/chat-auth-provider.js";
|
|
8
|
+
import { useMediaQuery as gt } from "../../hooks/use-media-query.js";
|
|
9
|
+
import { useConversationLoader as ht } from "../../hooks/use-conversation-loader.js";
|
|
10
|
+
import { useInitialConversation as vt } from "../../hooks/use-initial-conversation.js";
|
|
11
11
|
import { generateUid as F } from "../../utils/generate-uid.js";
|
|
12
|
-
import { useBaseEvents as
|
|
13
|
-
import { useChatForm as
|
|
14
|
-
import { useWidget as
|
|
15
|
-
import { useControllableState as
|
|
12
|
+
import { useBaseEvents as yt } from "../../providers/base-events-provider.js";
|
|
13
|
+
import { useChatForm as Rt } from "../../providers/chat-form-provider.js";
|
|
14
|
+
import { useWidget as Et } from "../../providers/widget-provider.js";
|
|
15
|
+
import { useControllableState as St } from "@radix-ui/react-use-controllable-state";
|
|
16
16
|
import { useStreamingEvents as It } from "../../hooks/use-streaming-events.js";
|
|
17
17
|
import { useInputNotification as Ct } from "../../hooks/use-input-notification.js";
|
|
18
|
-
import { resolveStreamingAuthError as
|
|
19
|
-
const
|
|
20
|
-
const { baseSettings: ae, aiChatSettings: v } =
|
|
18
|
+
import { resolveStreamingAuthError as At, DEFAULT_ERROR_MESSAGE as ne, isRecoverableError as Tt, isNetworkError as Ne, RECOVERABLE_NOTIFICATION_DURATION_MS as Pe, PAYLOAD_TOO_LARGE_MESSAGE as oe, RATE_LIMIT_MESSAGE as Be, NETWORK_ERROR_MESSAGE as De, NETWORK_ERROR_WITH_FILES_MESSAGE as Le, resolveHttpStatusCode as _t, RECOVERABLE_FALLBACK_MESSAGE as $e, estimateRequestBodyBytes as wt, MAX_REQUEST_BODY_BYTES as Mt } from "./chat-error-helpers.js";
|
|
19
|
+
const bt = 50, jt = () => {
|
|
20
|
+
const { baseSettings: ae, aiChatSettings: v } = ft(), [c = "", y] = St({
|
|
21
21
|
prop: v.conversationIdOverride,
|
|
22
22
|
defaultProp: v.conversationIdOverride ?? ""
|
|
23
|
-
}), { logEvent: g } =
|
|
24
|
-
|
|
23
|
+
}), { logEvent: g } = yt(), { setConversationId: Ue, emitToParent: x } = It(), ie = i(c);
|
|
24
|
+
b(() => {
|
|
25
25
|
const e = ie.current;
|
|
26
26
|
ie.current = c, e !== c && g({
|
|
27
27
|
eventName: "chat_conversation_changed",
|
|
@@ -31,10 +31,10 @@ const Ht = () => {
|
|
|
31
31
|
}
|
|
32
32
|
});
|
|
33
33
|
}, [c, g]);
|
|
34
|
-
const [
|
|
35
|
-
shouldBypassCaptcha:
|
|
34
|
+
const [C, A] = k(""), Ge = (e) => A(e.target.value), {
|
|
35
|
+
shouldBypassCaptcha: He,
|
|
36
36
|
filters: ce,
|
|
37
|
-
userProperties:
|
|
37
|
+
userProperties: U,
|
|
38
38
|
analyticsProperties: G
|
|
39
39
|
} = ae, {
|
|
40
40
|
authToken: le,
|
|
@@ -46,80 +46,80 @@ const Ht = () => {
|
|
|
46
46
|
getCaptchaHeader: O,
|
|
47
47
|
invalidateCaptcha: d,
|
|
48
48
|
effectiveAuthToken: me,
|
|
49
|
-
applicableRefreshSession:
|
|
50
|
-
} =
|
|
51
|
-
onInputMessageChange:
|
|
49
|
+
applicableRefreshSession: Ke
|
|
50
|
+
} = mt(), {
|
|
51
|
+
onInputMessageChange: ze,
|
|
52
52
|
filters: ge,
|
|
53
53
|
baseUrl: he,
|
|
54
|
-
agentUrl:
|
|
54
|
+
agentUrl: qe,
|
|
55
55
|
context: ve,
|
|
56
56
|
headers: ye,
|
|
57
57
|
appId: N,
|
|
58
|
-
apiKey:
|
|
59
|
-
files:
|
|
58
|
+
apiKey: H,
|
|
59
|
+
files: T
|
|
60
60
|
} = v, Re = i(O);
|
|
61
61
|
Re.current = O;
|
|
62
|
-
const
|
|
62
|
+
const Ee = qe || `${he}/run/api/chat`, { loadConversation: Se } = ht({
|
|
63
63
|
baseUrl: he,
|
|
64
64
|
appId: N,
|
|
65
65
|
authToken: me,
|
|
66
66
|
getCaptchaHeader: O,
|
|
67
67
|
invalidateCaptcha: d,
|
|
68
|
-
refreshSession:
|
|
69
|
-
}), [
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
const
|
|
68
|
+
refreshSession: Ke
|
|
69
|
+
}), [We, Ie] = k(!1), K = i(null);
|
|
70
|
+
K.current = pe;
|
|
71
|
+
const z = i(null);
|
|
72
|
+
z.current = le;
|
|
73
|
+
const q = i(void 0);
|
|
74
|
+
q.current = U && Object.keys(U).length > 0 ? U : void 0;
|
|
75
|
+
const W = i(void 0);
|
|
76
|
+
W.current = G && Object.keys(G).length > 0 ? G : void 0;
|
|
77
|
+
const E = i(0), P = i(null), j = i(null), h = i(void 0), je = T?.map(
|
|
78
78
|
(e) => `${e.filename ?? ""}:${e.mediaType}:${e.url.length}:${e.url.slice(0, 64)}:${e.url.slice(-32)}`
|
|
79
79
|
).join(`
|
|
80
80
|
`) ?? "";
|
|
81
|
-
|
|
82
|
-
h.current =
|
|
83
|
-
}, [
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
const
|
|
81
|
+
b(() => {
|
|
82
|
+
h.current = T?.length ? T : void 0;
|
|
83
|
+
}, [je]);
|
|
84
|
+
const Ce = i(ye);
|
|
85
|
+
Ce.current = ye;
|
|
86
|
+
const V = i(void 0);
|
|
87
|
+
V.current = ce || ge ? JSON.stringify({ ...ce, ...ge }) : void 0;
|
|
88
|
+
const Ve = (e) => {
|
|
89
89
|
if (Ne(e))
|
|
90
|
-
return P.current?.files?.length ?
|
|
91
|
-
switch (
|
|
90
|
+
return P.current?.files?.length ? Le : De;
|
|
91
|
+
switch (_t(e)) {
|
|
92
92
|
case 400:
|
|
93
93
|
try {
|
|
94
94
|
const t = JSON.parse(e.message ?? "");
|
|
95
|
-
return t.detail ?? t.error?.message ??
|
|
95
|
+
return t.detail ?? t.error?.message ?? $e;
|
|
96
96
|
} catch {
|
|
97
|
-
return e.message?.trim() ||
|
|
97
|
+
return e.message?.trim() || $e;
|
|
98
98
|
}
|
|
99
99
|
case 401:
|
|
100
|
-
return ue ? "Authentication failed. Please try again." :
|
|
100
|
+
return ue ? "Authentication failed. Please try again." : ne;
|
|
101
101
|
case 403:
|
|
102
102
|
return `There seems to be a configuration error. Please contact ${ae.organizationDisplayName ?? "Administrator"}`;
|
|
103
103
|
case 413:
|
|
104
|
-
return
|
|
104
|
+
return oe;
|
|
105
105
|
case 429:
|
|
106
106
|
return Be;
|
|
107
107
|
default:
|
|
108
|
-
return
|
|
108
|
+
return ne;
|
|
109
109
|
}
|
|
110
|
-
}, [
|
|
111
|
-
() => new
|
|
112
|
-
api:
|
|
110
|
+
}, [S, Y] = k([]), Ye = Oe(
|
|
111
|
+
() => new dt({
|
|
112
|
+
api: Ee,
|
|
113
113
|
headers: () => {
|
|
114
|
-
const e =
|
|
114
|
+
const e = H ?? z.current ?? K.current;
|
|
115
115
|
return {
|
|
116
116
|
"x-inkeep-client-timezone": Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
117
117
|
"x-inkeep-client-timestamp": (/* @__PURE__ */ new Date()).toISOString(),
|
|
118
118
|
"x-inkeep-invocation-type": "chat_widget",
|
|
119
119
|
...N ? { "x-inkeep-app-id": N } : {},
|
|
120
120
|
...e ? { Authorization: `Bearer ${e}` } : {},
|
|
121
|
-
...
|
|
122
|
-
...
|
|
121
|
+
...V.current ? { "inkeep-filters": V.current } : {},
|
|
122
|
+
...Ce.current
|
|
123
123
|
};
|
|
124
124
|
},
|
|
125
125
|
prepareSendMessagesRequest: async (e) => {
|
|
@@ -133,8 +133,8 @@ const Ht = () => {
|
|
|
133
133
|
messages: t ? [t] : [],
|
|
134
134
|
trigger: e.trigger,
|
|
135
135
|
messageId: e.messageId,
|
|
136
|
-
...
|
|
137
|
-
...
|
|
136
|
+
...q.current ? { userProperties: q.current } : {},
|
|
137
|
+
...W.current ? { properties: W.current } : {}
|
|
138
138
|
},
|
|
139
139
|
headers: {
|
|
140
140
|
...e.headers,
|
|
@@ -146,17 +146,23 @@ const Ht = () => {
|
|
|
146
146
|
requestContext: ve
|
|
147
147
|
}
|
|
148
148
|
}),
|
|
149
|
-
[
|
|
149
|
+
[Ee, ve, N, H]
|
|
150
150
|
), {
|
|
151
|
-
messages:
|
|
152
|
-
sendMessage:
|
|
153
|
-
addToolApprovalResponse:
|
|
151
|
+
messages: _,
|
|
152
|
+
sendMessage: J,
|
|
153
|
+
addToolApprovalResponse: Q,
|
|
154
154
|
status: Ae,
|
|
155
155
|
setMessages: m,
|
|
156
156
|
stop: B,
|
|
157
157
|
error: D
|
|
158
|
-
} =
|
|
159
|
-
transport:
|
|
158
|
+
} = lt({
|
|
159
|
+
transport: Ye,
|
|
160
|
+
// The SDK notifies React once per streamed chunk, which at typical token
|
|
161
|
+
// rates is 20-60 renders/sec of the whole chat tree. Coalescing to ~20fps
|
|
162
|
+
// is imperceptible while streaming text but caps the render work that grows
|
|
163
|
+
// with conversation length. Does not affect what is streamed, only how
|
|
164
|
+
// often React is told about it.
|
|
165
|
+
experimental_throttle: bt,
|
|
160
166
|
onData(e) {
|
|
161
167
|
x(e.type, e.data);
|
|
162
168
|
},
|
|
@@ -177,42 +183,42 @@ const Ht = () => {
|
|
|
177
183
|
},
|
|
178
184
|
onError(e) {
|
|
179
185
|
console.error("onError", { code: e.code, message: e.message });
|
|
180
|
-
const l =
|
|
181
|
-
if (l !== null &&
|
|
182
|
-
|
|
183
|
-
const o =
|
|
186
|
+
const l = He || H ? null : At(e);
|
|
187
|
+
if (l !== null && E.current < 1) {
|
|
188
|
+
E.current++;
|
|
189
|
+
const o = j.current, r = P.current;
|
|
184
190
|
(async () => {
|
|
185
191
|
if (l === "session" && ue) {
|
|
186
|
-
const
|
|
187
|
-
if (!
|
|
188
|
-
|
|
192
|
+
const n = await de();
|
|
193
|
+
if (!n) throw new Error("Auth token refresh failed");
|
|
194
|
+
z.current = n;
|
|
189
195
|
} else if (l === "session") {
|
|
190
|
-
const
|
|
191
|
-
|
|
196
|
+
const n = await fe();
|
|
197
|
+
n && (K.current = n);
|
|
192
198
|
} else
|
|
193
199
|
d();
|
|
194
200
|
if (o) {
|
|
195
|
-
|
|
201
|
+
Q(o);
|
|
196
202
|
return;
|
|
197
203
|
}
|
|
198
|
-
|
|
199
|
-
let a = [...
|
|
204
|
+
r && (m((n) => {
|
|
205
|
+
let a = [...n];
|
|
200
206
|
return a.at(-1)?.role === "assistant" && (a = a.slice(0, -1)), a.at(-1)?.role === "user" && (a = a.slice(0, -1)), a;
|
|
201
|
-
}),
|
|
207
|
+
}), J(
|
|
202
208
|
{
|
|
203
|
-
id:
|
|
209
|
+
id: r.messageId,
|
|
204
210
|
parts: [
|
|
205
|
-
...
|
|
206
|
-
...
|
|
211
|
+
...r.content.trim() ? [{ type: "text", text: r.content }] : [],
|
|
212
|
+
...r.files ?? []
|
|
207
213
|
]
|
|
208
214
|
},
|
|
209
|
-
{ body:
|
|
215
|
+
{ body: r.body }
|
|
210
216
|
));
|
|
211
217
|
})().catch(() => {
|
|
212
|
-
|
|
213
|
-
const a = [...
|
|
218
|
+
E.current = 0, d(), m((n) => {
|
|
219
|
+
const a = [...n], f = a[a.length - 1];
|
|
214
220
|
if (!f) return a;
|
|
215
|
-
const u =
|
|
221
|
+
const u = ne;
|
|
216
222
|
return f.role === "user" ? a.push({
|
|
217
223
|
id: F(16),
|
|
218
224
|
role: "assistant",
|
|
@@ -222,111 +228,111 @@ const Ht = () => {
|
|
|
222
228
|
});
|
|
223
229
|
return;
|
|
224
230
|
}
|
|
225
|
-
|
|
226
|
-
const t =
|
|
231
|
+
E.current = 0, l !== null && d();
|
|
232
|
+
const t = Tt(e) || Ne(e), s = Ve(e);
|
|
227
233
|
if (g({
|
|
228
234
|
eventName: "chat_error",
|
|
229
235
|
properties: {
|
|
230
236
|
conversationId: c,
|
|
231
|
-
messageId:
|
|
237
|
+
messageId: _.at(-1)?.id,
|
|
232
238
|
error: e.message
|
|
233
239
|
}
|
|
234
240
|
}), t) {
|
|
235
241
|
L(
|
|
236
|
-
{ title:
|
|
242
|
+
{ title: s === oe ? "Message too large" : s === Be ? "Rate limit reached" : s === De || s === Le ? "Connection error" : "Request failed", message: s },
|
|
237
243
|
Pe
|
|
238
244
|
), m((p) => {
|
|
239
|
-
let
|
|
240
|
-
return
|
|
245
|
+
let n = [...p];
|
|
246
|
+
return n.at(-1)?.role === "assistant" && (n = n.slice(0, -1)), n.at(-1)?.role === "user" && (n = n.slice(0, -1)), n;
|
|
241
247
|
});
|
|
242
|
-
const
|
|
243
|
-
|
|
248
|
+
const r = P.current?.content;
|
|
249
|
+
r && A(r), te.current = e;
|
|
244
250
|
return;
|
|
245
251
|
}
|
|
246
252
|
m((o) => {
|
|
247
|
-
const
|
|
248
|
-
return p && (p.role === "user" ?
|
|
253
|
+
const r = [...o], p = r[r.length - 1];
|
|
254
|
+
return p && (p.role === "user" ? r.push({
|
|
249
255
|
id: F(16),
|
|
250
256
|
role: "assistant",
|
|
251
|
-
parts: [{ type: "text", text:
|
|
252
|
-
}) : p.parts = [{ type: "text", text:
|
|
257
|
+
parts: [{ type: "text", text: s }]
|
|
258
|
+
}) : p.parts = [{ type: "text", text: s }]), r;
|
|
253
259
|
});
|
|
254
260
|
}
|
|
255
|
-
}),
|
|
256
|
-
|
|
257
|
-
const e =
|
|
258
|
-
|
|
261
|
+
}), Te = i(R);
|
|
262
|
+
b(() => {
|
|
263
|
+
const e = Te.current;
|
|
264
|
+
Te.current = R, e !== R && (B(), w(null), m([]), y(""), A(""), Y([]), d());
|
|
259
265
|
}, [R, B, m, y, d]);
|
|
260
|
-
const
|
|
266
|
+
const _e = Ae === "submitted", X = Ae === "streaming", Je = Oe(() => {
|
|
261
267
|
const e = (o) => {
|
|
262
268
|
if (!o || typeof o != "object") return !1;
|
|
263
|
-
const
|
|
264
|
-
return typeof
|
|
265
|
-
}, t = [...
|
|
269
|
+
const r = o;
|
|
270
|
+
return typeof r.type == "string" && r.type.startsWith("tool-");
|
|
271
|
+
}, t = [..._ ?? []].reverse().find((o) => o.role === "assistant");
|
|
266
272
|
if (!t) return !1;
|
|
267
|
-
const
|
|
268
|
-
return !(!e(
|
|
269
|
-
}, [
|
|
270
|
-
|
|
273
|
+
const s = t.parts?.at(-1);
|
|
274
|
+
return !(!e(s) || s.state !== "output-available" || !s.approval?.id || X);
|
|
275
|
+
}, [_, X]), [Qe, Z] = k(!1), we = X || Je && !Qe, Me = _e || we, Xe = _.length === 0, ee = !C.trim() && S.length === 0 || Me, Ze = gt("(max-width: 768px)"), [et, w] = k(null), te = i(null);
|
|
276
|
+
b(() => {
|
|
271
277
|
if (D) {
|
|
272
|
-
if (
|
|
273
|
-
|
|
278
|
+
if (te.current === D) {
|
|
279
|
+
te.current = null;
|
|
274
280
|
return;
|
|
275
281
|
}
|
|
276
|
-
|
|
282
|
+
w(D);
|
|
277
283
|
}
|
|
278
284
|
}, [D]);
|
|
279
|
-
const
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
}, [
|
|
283
|
-
const
|
|
284
|
-
e.key === "Enter" && !e.shiftKey && !
|
|
285
|
-
},
|
|
286
|
-
if (
|
|
285
|
+
const tt = () => w(null), { inputNotification: st, showInputNotification: L, clearInputNotification: rt } = Ct(), be = i(null);
|
|
286
|
+
b(() => {
|
|
287
|
+
ze?.(C);
|
|
288
|
+
}, [C]);
|
|
289
|
+
const nt = (e) => {
|
|
290
|
+
e.key === "Enter" && !e.shiftKey && !ee && !e.nativeEvent.isComposing && (e.preventDefault(), se());
|
|
291
|
+
}, se = async (e = C) => {
|
|
292
|
+
if (ee && (!e || e.trim().length === 0) && S.length === 0 || !e.trim() && !S.length && !h.current?.length)
|
|
287
293
|
return;
|
|
288
|
-
if (
|
|
294
|
+
if (wt({
|
|
289
295
|
text: e,
|
|
290
|
-
rawFileBytes:
|
|
296
|
+
rawFileBytes: S.reduce((f, u) => f + u.size, 0),
|
|
291
297
|
encodedPartsBytes: (h.current ?? []).reduce(
|
|
292
298
|
(f, u) => f + u.url.length,
|
|
293
299
|
0
|
|
294
300
|
)
|
|
295
|
-
}) >
|
|
301
|
+
}) > Mt) {
|
|
296
302
|
L(
|
|
297
|
-
{ title: "Message too large", message:
|
|
303
|
+
{ title: "Message too large", message: oe },
|
|
298
304
|
Pe
|
|
299
305
|
);
|
|
300
306
|
return;
|
|
301
307
|
}
|
|
302
|
-
const t =
|
|
303
|
-
|
|
304
|
-
let
|
|
305
|
-
|
|
308
|
+
const t = S;
|
|
309
|
+
Y([]), A(""), E.current = 0, j.current = null, Z(!1);
|
|
310
|
+
let s = c;
|
|
311
|
+
s || (s = `conv_${F(16)}`, y(s));
|
|
306
312
|
const o = F(21);
|
|
307
|
-
|
|
313
|
+
Ue(s), await g({
|
|
308
314
|
eventName: "user_message_submitted",
|
|
309
315
|
properties: {
|
|
310
|
-
conversationId:
|
|
316
|
+
conversationId: s,
|
|
311
317
|
messageId: o
|
|
312
318
|
}
|
|
313
319
|
});
|
|
314
|
-
const
|
|
320
|
+
const r = h.current;
|
|
315
321
|
h.current = void 0;
|
|
316
322
|
let p = [];
|
|
317
323
|
if (t.length > 0)
|
|
318
324
|
try {
|
|
319
325
|
p = await Promise.all(
|
|
320
326
|
t.map((f) => {
|
|
321
|
-
const u =
|
|
322
|
-
return new Promise((
|
|
327
|
+
const u = ut(f);
|
|
328
|
+
return new Promise((ct, xe) => {
|
|
323
329
|
const M = new FileReader();
|
|
324
330
|
M.onload = () => {
|
|
325
331
|
if (typeof M.result != "string") {
|
|
326
332
|
xe(new Error(`Failed to read file "${u.name}"`));
|
|
327
333
|
return;
|
|
328
334
|
}
|
|
329
|
-
|
|
335
|
+
ct({
|
|
330
336
|
type: "file",
|
|
331
337
|
url: M.result,
|
|
332
338
|
mediaType: u.type,
|
|
@@ -343,42 +349,42 @@ const Ht = () => {
|
|
|
343
349
|
});
|
|
344
350
|
return;
|
|
345
351
|
}
|
|
346
|
-
const
|
|
352
|
+
const n = p.length || r?.length ? [...p, ...r ?? []] : void 0, a = [
|
|
347
353
|
...e.trim() ? [{ type: "text", text: e }] : [],
|
|
348
|
-
...
|
|
354
|
+
...n ?? []
|
|
349
355
|
];
|
|
350
356
|
P.current = {
|
|
351
357
|
content: e,
|
|
352
358
|
messageId: o,
|
|
353
|
-
body: { conversationId:
|
|
354
|
-
files:
|
|
355
|
-
},
|
|
356
|
-
},
|
|
359
|
+
body: { conversationId: s },
|
|
360
|
+
files: n
|
|
361
|
+
}, J({ id: o, parts: a }, { body: { conversationId: s } });
|
|
362
|
+
}, ot = $(
|
|
357
363
|
(e) => {
|
|
358
|
-
|
|
364
|
+
E.current = 0, j.current = e, Z(!1), Q(e);
|
|
359
365
|
},
|
|
360
|
-
[
|
|
361
|
-
),
|
|
362
|
-
|
|
366
|
+
[Q]
|
|
367
|
+
), re = $(() => {
|
|
368
|
+
Z(!0), B().then(() => {
|
|
363
369
|
x("aborted", { conversationId: c });
|
|
364
370
|
});
|
|
365
371
|
}, [B, c, x]), ke = () => {
|
|
366
|
-
|
|
372
|
+
tt(), m([]), y(""), d(), h.current = T?.length ? T : void 0, g({
|
|
367
373
|
eventName: "chat_clear_button_clicked",
|
|
368
374
|
properties: {
|
|
369
375
|
conversationId: c
|
|
370
376
|
}
|
|
371
377
|
});
|
|
372
|
-
},
|
|
378
|
+
}, I = $(
|
|
373
379
|
(e, l) => {
|
|
374
|
-
|
|
380
|
+
w(null), m(l), y(e), d(), h.current = void 0;
|
|
375
381
|
},
|
|
376
382
|
[m, y, d]
|
|
377
383
|
), Fe = $(
|
|
378
384
|
async (e, l) => {
|
|
379
|
-
|
|
385
|
+
re(), I(e, []), Ie(!0);
|
|
380
386
|
try {
|
|
381
|
-
const t = await
|
|
387
|
+
const t = await Se(e, l);
|
|
382
388
|
if (t === null) return !1;
|
|
383
389
|
const o = t[t.length - 1]?.role === "user" ? [
|
|
384
390
|
...t,
|
|
@@ -393,68 +399,68 @@ const Ht = () => {
|
|
|
393
399
|
]
|
|
394
400
|
}
|
|
395
401
|
] : t;
|
|
396
|
-
return
|
|
402
|
+
return I(e, o), !0;
|
|
397
403
|
} finally {
|
|
398
|
-
l?.aborted ||
|
|
404
|
+
l?.aborted || Ie(!1);
|
|
399
405
|
}
|
|
400
406
|
},
|
|
401
|
-
[
|
|
407
|
+
[I, Se, re]
|
|
402
408
|
);
|
|
403
|
-
|
|
409
|
+
vt({
|
|
404
410
|
conversationId: v.conversationId,
|
|
405
411
|
fetchedConversation: v.fetchedConversation,
|
|
406
412
|
effectiveAuthToken: me,
|
|
407
|
-
restoreSession:
|
|
413
|
+
restoreSession: I,
|
|
408
414
|
loadAndRestoreSession: Fe,
|
|
409
|
-
onLoadFailed: () =>
|
|
415
|
+
onLoadFailed: () => I("", [])
|
|
410
416
|
});
|
|
411
|
-
const { openForm:
|
|
412
|
-
return
|
|
413
|
-
submitMessage:
|
|
417
|
+
const { openForm: at } = Rt(), it = Et();
|
|
418
|
+
return pt(v.chatFunctionsRef, () => ({
|
|
419
|
+
submitMessage: se,
|
|
414
420
|
updateInputMessage(e) {
|
|
415
421
|
A(e);
|
|
416
422
|
},
|
|
417
423
|
clearChat: ke,
|
|
418
424
|
openForm: (e) => {
|
|
419
|
-
|
|
425
|
+
it?.setView("chat"), at(e, void 0);
|
|
420
426
|
},
|
|
421
427
|
focusInput: () => {
|
|
422
|
-
|
|
428
|
+
be.current?.focus();
|
|
423
429
|
}
|
|
424
430
|
})), {
|
|
425
|
-
messages:
|
|
426
|
-
sendMessage:
|
|
427
|
-
addToolApprovalResponse:
|
|
428
|
-
isLoading:
|
|
429
|
-
isStreaming:
|
|
431
|
+
messages: _,
|
|
432
|
+
sendMessage: J,
|
|
433
|
+
addToolApprovalResponse: ot,
|
|
434
|
+
isLoading: _e,
|
|
435
|
+
isStreaming: we,
|
|
430
436
|
isBusy: Me,
|
|
431
|
-
error:
|
|
432
|
-
setError:
|
|
433
|
-
isSubmitDisabled:
|
|
434
|
-
input:
|
|
435
|
-
handleInputChange:
|
|
436
|
-
handleInputKeyDown:
|
|
437
|
-
handleSubmit:
|
|
438
|
-
stop:
|
|
437
|
+
error: et,
|
|
438
|
+
setError: w,
|
|
439
|
+
isSubmitDisabled: ee,
|
|
440
|
+
input: C,
|
|
441
|
+
handleInputChange: Ge,
|
|
442
|
+
handleInputKeyDown: nt,
|
|
443
|
+
handleSubmit: se,
|
|
444
|
+
stop: re,
|
|
439
445
|
clear: ke,
|
|
440
|
-
inputRef:
|
|
441
|
-
isMobile:
|
|
442
|
-
files:
|
|
443
|
-
setFiles:
|
|
444
|
-
isNewChat:
|
|
446
|
+
inputRef: be,
|
|
447
|
+
isMobile: Ze,
|
|
448
|
+
files: S,
|
|
449
|
+
setFiles: Y,
|
|
450
|
+
isNewChat: Xe,
|
|
445
451
|
conversationId: c,
|
|
446
|
-
restoreSession:
|
|
452
|
+
restoreSession: I,
|
|
447
453
|
loadAndRestoreSession: Fe,
|
|
448
|
-
isSessionLoading:
|
|
454
|
+
isSessionLoading: We,
|
|
449
455
|
authToken: R ? le : pe,
|
|
450
456
|
refreshSession: R ? de : fe,
|
|
451
457
|
getCaptchaHeader: O,
|
|
452
458
|
invalidateCaptcha: d,
|
|
453
|
-
inputNotification:
|
|
459
|
+
inputNotification: st,
|
|
454
460
|
showInputNotification: L,
|
|
455
|
-
clearInputNotification:
|
|
461
|
+
clearInputNotification: rt
|
|
456
462
|
};
|
|
457
463
|
};
|
|
458
464
|
export {
|
|
459
|
-
|
|
465
|
+
jt as useInkeepChat
|
|
460
466
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react/jsx-runtime"),t=require("react"),p=require("./config-provider.cjs"),n=t.createContext(void 0),g=({children:e})=>{const{baseSettings:s,componentType:o}=p.useInkeepConfig(),{tags:r,analyticsProperties:i}=s,c="0.17.
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react/jsx-runtime"),t=require("react"),p=require("./config-provider.cjs"),n=t.createContext(void 0),g=({children:e})=>{const{baseSettings:s,componentType:o}=p.useInkeepConfig(),{tags:r,analyticsProperties:i}=s,c="0.17.7",a=t.useMemo(()=>({widgetLibraryVersion:c,componentType:o,tags:r}),[o,r,c]),v={logEvent:t.useCallback(async u=>{const E={...a,...u.properties,...i},d={eventName:u.eventName,properties:E};return s.onEvent?.(d)},[s,a,i])};return l.jsx(n.Provider,{value:v,children:e})},m=()=>{const e=t.useContext(n);if(!e)throw new Error("useBaseEvents must be used within a BaseEventsProvider");return e};exports.BaseEventsContext=n;exports.BaseEventsProvider=g;exports.useBaseEvents=m;
|
|
@@ -3,7 +3,7 @@ import { jsx as u } from "react/jsx-runtime";
|
|
|
3
3
|
import { createContext as E, useMemo as d, useCallback as l, useContext as g } from "react";
|
|
4
4
|
import { useInkeepConfig as x } from "./config-provider.js";
|
|
5
5
|
const c = E(void 0), b = ({ children: e }) => {
|
|
6
|
-
const { baseSettings: t, componentType: o } = x(), { tags: s, analyticsProperties: n } = t, r = "0.17.
|
|
6
|
+
const { baseSettings: t, componentType: o } = x(), { tags: s, analyticsProperties: n } = t, r = "0.17.7", i = d(
|
|
7
7
|
() => ({
|
|
8
8
|
widgetLibraryVersion: r,
|
|
9
9
|
componentType: o,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const j=require("react/jsx-runtime"),u=require("react"),B=require("./config-provider.cjs"),O=require("./chat-auth-provider.cjs"),U=require("../hooks/use-events-api.cjs"),x=require("./base-events-provider.cjs"),M=({children:g})=>{const{baseSettings:n,aiChatSettings:h,componentType:i}=B.useInkeepConfig(),{tags:t,analyticsProperties:r,privacyPreferences:y,userProperties:o}=n,c="0.17.
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const j=require("react/jsx-runtime"),u=require("react"),B=require("./config-provider.cjs"),O=require("./chat-auth-provider.cjs"),U=require("../hooks/use-events-api.cjs"),x=require("./base-events-provider.cjs"),M=({children:g})=>{const{baseSettings:n,aiChatSettings:h,componentType:i}=B.useInkeepConfig(),{tags:t,analyticsProperties:r,privacyPreferences:y,userProperties:o}=n,c="0.17.7",a=u.useMemo(()=>({widgetLibraryVersion:c,componentType:i}),[i,c]),{effectiveAuthToken:b,applicableRefreshSession:f,getCaptchaHeader:E,invalidateCaptcha:P}=O.useChatAuth(),{baseUrl:m,appId:A,analyticsApiBaseUrl:C,headers:I}=h,p=y?.optOutAllAnalytics??!1,{logEvent:l}=U.useEventsApi({baseUrl:C??m,appId:A,authToken:b,getCaptchaHeader:E,invalidateCaptcha:P,refreshSession:f,headers:I}),k={logEvent:u.useCallback(async s=>{const q={eventName:s.eventName,properties:{...a,...t?{tags:t}:{},...s.properties,...r}};if(!p){const e=s.properties??{},v=typeof e.conversationId=="string"?e.conversationId:void 0,d=typeof e.messageId=="string"?e.messageId:void 0,S=!!o&&Object.keys(o).length>0,w={...t?{tags:t}:{},...r??{}},T={...a,...s.properties};l({body:{type:s.eventName,...v?{conversationId:v}:{},...d?{messageId:d}:{},...S?{userProperties:o}:{},properties:w,metadata:T}})}try{return await n.onEvent?.(q)}catch(e){console.warn("[events] onEvent callback threw",e)}},[n,a,t,r,l,p,o])};return j.jsx(x.BaseEventsContext.Provider,{value:k,children:g})};exports.ChatBaseEventsProvider=M;
|
|
@@ -6,7 +6,7 @@ import { useChatAuth as O } from "./chat-auth-provider.js";
|
|
|
6
6
|
import { useEventsApi as j } from "../hooks/use-events-api.js";
|
|
7
7
|
import { BaseEventsContext as M } from "./base-events-provider.js";
|
|
8
8
|
const F = ({ children: m }) => {
|
|
9
|
-
const { baseSettings: r, aiChatSettings: g, componentType: i } = N(), { tags: t, analyticsProperties: n, privacyPreferences: f, userProperties: o } = r, c = "0.17.
|
|
9
|
+
const { baseSettings: r, aiChatSettings: g, componentType: i } = N(), { tags: t, analyticsProperties: n, privacyPreferences: f, userProperties: o } = r, c = "0.17.7", a = x(
|
|
10
10
|
() => ({
|
|
11
11
|
widgetLibraryVersion: c,
|
|
12
12
|
componentType: i
|