@inkeep/agents-ui 0.17.7 → 0.17.8
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/use-inkeep-chat.cjs +2 -2
- package/dist/primitives/components/embedded-chat/use-inkeep-chat.js +109 -100
- 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/dist/styled/components/embedded-chat.cjs +1 -1
- package/dist/styled/components/embedded-chat.js +321 -321
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { useChat as lt } from "@ai-sdk/react";
|
|
3
3
|
import { normalizeFileType as ut } from "./file-upload-input.js";
|
|
4
4
|
import { DefaultChatTransport as dt } from "ai";
|
|
5
|
-
import { useRef as i, useEffect as
|
|
5
|
+
import { useRef as i, useEffect as b, useState as k, useMemo as Oe, useCallback as $, useImperativeHandle as pt } from "react";
|
|
6
6
|
import { useInkeepConfig as ft } from "../../providers/config-provider.js";
|
|
7
7
|
import { useChatAuth as mt } from "../../providers/chat-auth-provider.js";
|
|
8
8
|
import { useMediaQuery as gt } from "../../hooks/use-media-query.js";
|
|
@@ -12,16 +12,16 @@ import { generateUid as F } from "../../utils/generate-uid.js";
|
|
|
12
12
|
import { useBaseEvents as yt } from "../../providers/base-events-provider.js";
|
|
13
13
|
import { useChatForm as Rt } from "../../providers/chat-form-provider.js";
|
|
14
14
|
import { useWidget as Et } from "../../providers/widget-provider.js";
|
|
15
|
-
import { useControllableState as
|
|
16
|
-
import { useStreamingEvents as
|
|
15
|
+
import { useControllableState as St } from "@radix-ui/react-use-controllable-state";
|
|
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 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
|
|
19
|
-
const
|
|
20
|
-
const { baseSettings: ae, aiChatSettings: v } = ft(), [c = "", y] =
|
|
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 } = yt(), { setConversationId: Ue, emitToParent: x } =
|
|
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",
|
|
@@ -32,7 +32,7 @@ const Wt = () => {
|
|
|
32
32
|
});
|
|
33
33
|
}, [c, g]);
|
|
34
34
|
const [C, A] = k(""), Ge = (e) => A(e.target.value), {
|
|
35
|
-
shouldBypassCaptcha:
|
|
35
|
+
shouldBypassCaptcha: He,
|
|
36
36
|
filters: ce,
|
|
37
37
|
userProperties: U,
|
|
38
38
|
analyticsProperties: G
|
|
@@ -46,30 +46,30 @@ const Wt = () => {
|
|
|
46
46
|
getCaptchaHeader: O,
|
|
47
47
|
invalidateCaptcha: d,
|
|
48
48
|
effectiveAuthToken: me,
|
|
49
|
-
applicableRefreshSession:
|
|
49
|
+
applicableRefreshSession: Ke
|
|
50
50
|
} = mt(), {
|
|
51
|
-
onInputMessageChange:
|
|
51
|
+
onInputMessageChange: ze,
|
|
52
52
|
filters: ge,
|
|
53
53
|
baseUrl: he,
|
|
54
54
|
agentUrl: qe,
|
|
55
55
|
context: ve,
|
|
56
56
|
headers: ye,
|
|
57
57
|
appId: N,
|
|
58
|
-
apiKey:
|
|
58
|
+
apiKey: H,
|
|
59
59
|
files: T
|
|
60
60
|
} = v, Re = i(O);
|
|
61
61
|
Re.current = O;
|
|
62
|
-
const Ee = qe || `${he}/run/api/chat`, { loadConversation:
|
|
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
|
-
}), [We,
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
|
|
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
73
|
const q = i(void 0);
|
|
74
74
|
q.current = U && Object.keys(U).length > 0 ? U : void 0;
|
|
75
75
|
const W = i(void 0);
|
|
@@ -78,7 +78,7 @@ const Wt = () => {
|
|
|
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
|
-
|
|
81
|
+
b(() => {
|
|
82
82
|
h.current = T?.length ? T : void 0;
|
|
83
83
|
}, [je]);
|
|
84
84
|
const Ce = i(ye);
|
|
@@ -88,11 +88,11 @@ const Wt = () => {
|
|
|
88
88
|
const Ve = (e) => {
|
|
89
89
|
if (Ne(e))
|
|
90
90
|
return P.current?.files?.length ? Le : De;
|
|
91
|
-
switch (
|
|
91
|
+
switch (_t(e)) {
|
|
92
92
|
case 400:
|
|
93
93
|
try {
|
|
94
|
-
const
|
|
95
|
-
return
|
|
94
|
+
const s = JSON.parse(e.message ?? "");
|
|
95
|
+
return s.detail ?? s.error?.message ?? $e;
|
|
96
96
|
} catch {
|
|
97
97
|
return e.message?.trim() || $e;
|
|
98
98
|
}
|
|
@@ -107,11 +107,11 @@ const Wt = () => {
|
|
|
107
107
|
default:
|
|
108
108
|
return ne;
|
|
109
109
|
}
|
|
110
|
-
}, [
|
|
110
|
+
}, [S, Y] = k([]), Ye = Oe(
|
|
111
111
|
() => new dt({
|
|
112
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(),
|
|
@@ -123,14 +123,14 @@ const Wt = () => {
|
|
|
123
123
|
};
|
|
124
124
|
},
|
|
125
125
|
prepareSendMessagesRequest: async (e) => {
|
|
126
|
-
const l = await Re.current(),
|
|
127
|
-
return
|
|
126
|
+
const l = await Re.current(), s = e.messages[e.messages.length - 1];
|
|
127
|
+
return s || console.warn(
|
|
128
128
|
"[useInkeepChat] prepareSendMessagesRequest called with empty messages array"
|
|
129
129
|
), {
|
|
130
130
|
body: {
|
|
131
131
|
...e.body,
|
|
132
132
|
id: e.id,
|
|
133
|
-
messages:
|
|
133
|
+
messages: s ? [s] : [],
|
|
134
134
|
trigger: e.trigger,
|
|
135
135
|
messageId: e.messageId,
|
|
136
136
|
...q.current ? { userProperties: q.current } : {},
|
|
@@ -146,9 +146,9 @@ const Wt = () => {
|
|
|
146
146
|
requestContext: ve
|
|
147
147
|
}
|
|
148
148
|
}),
|
|
149
|
-
[Ee, ve, N,
|
|
149
|
+
[Ee, ve, N, H]
|
|
150
150
|
), {
|
|
151
|
-
messages:
|
|
151
|
+
messages: _,
|
|
152
152
|
sendMessage: J,
|
|
153
153
|
addToolApprovalResponse: Q,
|
|
154
154
|
status: Ae,
|
|
@@ -157,6 +157,12 @@ const Wt = () => {
|
|
|
157
157
|
error: D
|
|
158
158
|
} = lt({
|
|
159
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,36 +183,36 @@ const Wt = () => {
|
|
|
177
183
|
},
|
|
178
184
|
onError(e) {
|
|
179
185
|
console.error("onError", { code: e.code, message: e.message });
|
|
180
|
-
const l =
|
|
186
|
+
const l = He || H ? null : At(e);
|
|
181
187
|
if (l !== null && E.current < 1) {
|
|
182
188
|
E.current++;
|
|
183
|
-
const o = j.current,
|
|
189
|
+
const o = j.current, t = P.current;
|
|
184
190
|
(async () => {
|
|
185
191
|
if (l === "session" && ue) {
|
|
186
192
|
const n = await de();
|
|
187
193
|
if (!n) throw new Error("Auth token refresh failed");
|
|
188
|
-
|
|
194
|
+
z.current = n;
|
|
189
195
|
} else if (l === "session") {
|
|
190
196
|
const n = await fe();
|
|
191
|
-
n && (
|
|
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
|
-
|
|
204
|
+
t && (m((n) => {
|
|
199
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: t.messageId,
|
|
204
210
|
parts: [
|
|
205
|
-
...
|
|
206
|
-
...
|
|
211
|
+
...t.content.trim() ? [{ type: "text", text: t.content }] : [],
|
|
212
|
+
...t.files ?? []
|
|
207
213
|
]
|
|
208
214
|
},
|
|
209
|
-
{ body:
|
|
215
|
+
{ body: t.body }
|
|
210
216
|
));
|
|
211
217
|
})().catch(() => {
|
|
212
218
|
E.current = 0, d(), m((n) => {
|
|
@@ -217,77 +223,80 @@ const Wt = () => {
|
|
|
217
223
|
id: F(16),
|
|
218
224
|
role: "assistant",
|
|
219
225
|
parts: [{ type: "text", text: u }]
|
|
220
|
-
}) :
|
|
226
|
+
}) : a[a.length - 1] = { ...f, parts: [{ type: "text", text: u }] }, a;
|
|
221
227
|
});
|
|
222
228
|
});
|
|
223
229
|
return;
|
|
224
230
|
}
|
|
225
231
|
E.current = 0, l !== null && d();
|
|
226
|
-
const
|
|
232
|
+
const s = Tt(e) || Ne(e), r = 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
|
+
}), s) {
|
|
235
241
|
L(
|
|
236
|
-
{ title:
|
|
242
|
+
{ title: r === oe ? "Message too large" : r === Be ? "Rate limit reached" : r === De || r === Le ? "Connection error" : "Request failed", message: r },
|
|
237
243
|
Pe
|
|
238
244
|
), m((p) => {
|
|
239
245
|
let n = [...p];
|
|
240
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 t = P.current?.content;
|
|
249
|
+
t && A(t), te.current = e;
|
|
244
250
|
return;
|
|
245
251
|
}
|
|
246
252
|
m((o) => {
|
|
247
|
-
const
|
|
248
|
-
return p && (p.role === "user" ?
|
|
253
|
+
const t = [...o], p = t[t.length - 1];
|
|
254
|
+
return p && (p.role === "user" ? t.push({
|
|
249
255
|
id: F(16),
|
|
250
256
|
role: "assistant",
|
|
251
|
-
parts: [{ type: "text", text:
|
|
252
|
-
}) :
|
|
257
|
+
parts: [{ type: "text", text: r }]
|
|
258
|
+
}) : t[t.length - 1] = {
|
|
259
|
+
...p,
|
|
260
|
+
parts: [{ type: "text", text: r }]
|
|
261
|
+
}), t;
|
|
253
262
|
});
|
|
254
263
|
}
|
|
255
264
|
}), Te = i(R);
|
|
256
|
-
|
|
265
|
+
b(() => {
|
|
257
266
|
const e = Te.current;
|
|
258
|
-
Te.current = R, e !== R && (B(),
|
|
267
|
+
Te.current = R, e !== R && (B(), w(null), m([]), y(""), A(""), Y([]), d());
|
|
259
268
|
}, [R, B, m, y, d]);
|
|
260
|
-
const
|
|
269
|
+
const _e = Ae === "submitted", X = Ae === "streaming", Je = Oe(() => {
|
|
261
270
|
const e = (o) => {
|
|
262
271
|
if (!o || typeof o != "object") return !1;
|
|
263
|
-
const
|
|
264
|
-
return typeof
|
|
265
|
-
},
|
|
266
|
-
if (!
|
|
267
|
-
const
|
|
268
|
-
return !(!e(
|
|
269
|
-
}, [
|
|
270
|
-
|
|
272
|
+
const t = o;
|
|
273
|
+
return typeof t.type == "string" && t.type.startsWith("tool-");
|
|
274
|
+
}, s = [..._ ?? []].reverse().find((o) => o.role === "assistant");
|
|
275
|
+
if (!s) return !1;
|
|
276
|
+
const r = s.parts?.at(-1);
|
|
277
|
+
return !(!e(r) || r.state !== "output-available" || !r.approval?.id || X);
|
|
278
|
+
}, [_, 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);
|
|
279
|
+
b(() => {
|
|
271
280
|
if (D) {
|
|
272
281
|
if (te.current === D) {
|
|
273
282
|
te.current = null;
|
|
274
283
|
return;
|
|
275
284
|
}
|
|
276
|
-
|
|
285
|
+
w(D);
|
|
277
286
|
}
|
|
278
287
|
}, [D]);
|
|
279
|
-
const tt = () =>
|
|
280
|
-
|
|
281
|
-
|
|
288
|
+
const tt = () => w(null), { inputNotification: st, showInputNotification: L, clearInputNotification: rt } = Ct(), be = i(null);
|
|
289
|
+
b(() => {
|
|
290
|
+
ze?.(C);
|
|
282
291
|
}, [C]);
|
|
283
292
|
const nt = (e) => {
|
|
284
293
|
e.key === "Enter" && !e.shiftKey && !ee && !e.nativeEvent.isComposing && (e.preventDefault(), se());
|
|
285
294
|
}, se = async (e = C) => {
|
|
286
|
-
if (ee && (!e || e.trim().length === 0) &&
|
|
295
|
+
if (ee && (!e || e.trim().length === 0) && S.length === 0 || !e.trim() && !S.length && !h.current?.length)
|
|
287
296
|
return;
|
|
288
|
-
if (
|
|
297
|
+
if (wt({
|
|
289
298
|
text: e,
|
|
290
|
-
rawFileBytes:
|
|
299
|
+
rawFileBytes: S.reduce((f, u) => f + u.size, 0),
|
|
291
300
|
encodedPartsBytes: (h.current ?? []).reduce(
|
|
292
301
|
(f, u) => f + u.url.length,
|
|
293
302
|
0
|
|
@@ -299,25 +308,25 @@ const Wt = () => {
|
|
|
299
308
|
);
|
|
300
309
|
return;
|
|
301
310
|
}
|
|
302
|
-
const
|
|
311
|
+
const s = S;
|
|
303
312
|
Y([]), A(""), E.current = 0, j.current = null, Z(!1);
|
|
304
|
-
let
|
|
305
|
-
|
|
313
|
+
let r = c;
|
|
314
|
+
r || (r = `conv_${F(16)}`, y(r));
|
|
306
315
|
const o = F(21);
|
|
307
|
-
Ue(
|
|
316
|
+
Ue(r), await g({
|
|
308
317
|
eventName: "user_message_submitted",
|
|
309
318
|
properties: {
|
|
310
|
-
conversationId:
|
|
319
|
+
conversationId: r,
|
|
311
320
|
messageId: o
|
|
312
321
|
}
|
|
313
322
|
});
|
|
314
|
-
const
|
|
323
|
+
const t = h.current;
|
|
315
324
|
h.current = void 0;
|
|
316
325
|
let p = [];
|
|
317
|
-
if (
|
|
326
|
+
if (s.length > 0)
|
|
318
327
|
try {
|
|
319
328
|
p = await Promise.all(
|
|
320
|
-
|
|
329
|
+
s.map((f) => {
|
|
321
330
|
const u = ut(f);
|
|
322
331
|
return new Promise((ct, xe) => {
|
|
323
332
|
const M = new FileReader();
|
|
@@ -343,16 +352,16 @@ const Wt = () => {
|
|
|
343
352
|
});
|
|
344
353
|
return;
|
|
345
354
|
}
|
|
346
|
-
const n = p.length ||
|
|
355
|
+
const n = p.length || t?.length ? [...p, ...t ?? []] : void 0, a = [
|
|
347
356
|
...e.trim() ? [{ type: "text", text: e }] : [],
|
|
348
357
|
...n ?? []
|
|
349
358
|
];
|
|
350
359
|
P.current = {
|
|
351
360
|
content: e,
|
|
352
361
|
messageId: o,
|
|
353
|
-
body: { conversationId:
|
|
362
|
+
body: { conversationId: r },
|
|
354
363
|
files: n
|
|
355
|
-
}, J({ id: o, parts: a }, { body: { conversationId:
|
|
364
|
+
}, J({ id: o, parts: a }, { body: { conversationId: r } });
|
|
356
365
|
}, ot = $(
|
|
357
366
|
(e) => {
|
|
358
367
|
E.current = 0, j.current = e, Z(!1), Q(e);
|
|
@@ -369,19 +378,19 @@ const Wt = () => {
|
|
|
369
378
|
conversationId: c
|
|
370
379
|
}
|
|
371
380
|
});
|
|
372
|
-
},
|
|
381
|
+
}, I = $(
|
|
373
382
|
(e, l) => {
|
|
374
|
-
|
|
383
|
+
w(null), m(l), y(e), d(), h.current = void 0;
|
|
375
384
|
},
|
|
376
385
|
[m, y, d]
|
|
377
386
|
), Fe = $(
|
|
378
387
|
async (e, l) => {
|
|
379
|
-
re(),
|
|
388
|
+
re(), I(e, []), Ie(!0);
|
|
380
389
|
try {
|
|
381
|
-
const
|
|
382
|
-
if (
|
|
383
|
-
const o =
|
|
384
|
-
...
|
|
390
|
+
const s = await Se(e, l);
|
|
391
|
+
if (s === null) return !1;
|
|
392
|
+
const o = s[s.length - 1]?.role === "user" ? [
|
|
393
|
+
...s,
|
|
385
394
|
{
|
|
386
395
|
id: F(16),
|
|
387
396
|
role: "assistant",
|
|
@@ -392,21 +401,21 @@ const Wt = () => {
|
|
|
392
401
|
}
|
|
393
402
|
]
|
|
394
403
|
}
|
|
395
|
-
] :
|
|
396
|
-
return
|
|
404
|
+
] : s;
|
|
405
|
+
return I(e, o), !0;
|
|
397
406
|
} finally {
|
|
398
|
-
l?.aborted ||
|
|
407
|
+
l?.aborted || Ie(!1);
|
|
399
408
|
}
|
|
400
409
|
},
|
|
401
|
-
[
|
|
410
|
+
[I, Se, re]
|
|
402
411
|
);
|
|
403
412
|
vt({
|
|
404
413
|
conversationId: v.conversationId,
|
|
405
414
|
fetchedConversation: v.fetchedConversation,
|
|
406
415
|
effectiveAuthToken: me,
|
|
407
|
-
restoreSession:
|
|
416
|
+
restoreSession: I,
|
|
408
417
|
loadAndRestoreSession: Fe,
|
|
409
|
-
onLoadFailed: () =>
|
|
418
|
+
onLoadFailed: () => I("", [])
|
|
410
419
|
});
|
|
411
420
|
const { openForm: at } = Rt(), it = Et();
|
|
412
421
|
return pt(v.chatFunctionsRef, () => ({
|
|
@@ -419,17 +428,17 @@ const Wt = () => {
|
|
|
419
428
|
it?.setView("chat"), at(e, void 0);
|
|
420
429
|
},
|
|
421
430
|
focusInput: () => {
|
|
422
|
-
|
|
431
|
+
be.current?.focus();
|
|
423
432
|
}
|
|
424
433
|
})), {
|
|
425
|
-
messages:
|
|
434
|
+
messages: _,
|
|
426
435
|
sendMessage: J,
|
|
427
436
|
addToolApprovalResponse: ot,
|
|
428
|
-
isLoading:
|
|
429
|
-
isStreaming:
|
|
437
|
+
isLoading: _e,
|
|
438
|
+
isStreaming: we,
|
|
430
439
|
isBusy: Me,
|
|
431
440
|
error: et,
|
|
432
|
-
setError:
|
|
441
|
+
setError: w,
|
|
433
442
|
isSubmitDisabled: ee,
|
|
434
443
|
input: C,
|
|
435
444
|
handleInputChange: Ge,
|
|
@@ -437,13 +446,13 @@ const Wt = () => {
|
|
|
437
446
|
handleSubmit: se,
|
|
438
447
|
stop: re,
|
|
439
448
|
clear: ke,
|
|
440
|
-
inputRef:
|
|
449
|
+
inputRef: be,
|
|
441
450
|
isMobile: Ze,
|
|
442
|
-
files:
|
|
451
|
+
files: S,
|
|
443
452
|
setFiles: Y,
|
|
444
453
|
isNewChat: Xe,
|
|
445
454
|
conversationId: c,
|
|
446
|
-
restoreSession:
|
|
455
|
+
restoreSession: I,
|
|
447
456
|
loadAndRestoreSession: Fe,
|
|
448
457
|
isSessionLoading: We,
|
|
449
458
|
authToken: R ? le : pe,
|
|
@@ -456,5 +465,5 @@ const Wt = () => {
|
|
|
456
465
|
};
|
|
457
466
|
};
|
|
458
467
|
export {
|
|
459
|
-
|
|
468
|
+
jt as useInkeepChat
|
|
460
469
|
};
|
|
@@ -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.8",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.8", 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.8",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.8", a = x(
|
|
10
10
|
() => ({
|
|
11
11
|
widgetLibraryVersion: c,
|
|
12
12
|
componentType: i
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),p=require("react"),s=require("../styled/components/embedded-chat.cjs"),a=require("../styled/components/chat-history.cjs"),b=require("../styled/components/modal.cjs"),w=require("../styled/components/shadow.cjs"),E=require("../styled/components/message.cjs"),k=require("../primitives/providers/chat-auth-provider.cjs"),P=require("../primitives/providers/chat-base-events-provider.cjs"),f=require("../primitives/providers/chat-history-provider.cjs"),F=require("../primitives/providers/config-provider.cjs"),B=require("../primitives/providers/root-provider.cjs"),q=require("../primitives/providers/widget-provider.cjs"),y=require("../primitives/components/embedded-chat/chat-provider.cjs"),L=require("../primitives/components/modal/modal-provider.cjs"),g=require("../primitives/utils/misc.cjs"),T=require("../primitives/atoms/portal-with-theme.cjs"),D=require("../primitives/atoms/error-boundary.cjs"),W=require("./modal.cjs"),N=require("../primitives/providers/image-preview-provider.cjs"),V=require("./widget-toggle.cjs"),v=require("../primitives/components/embedded-chat/file-upload-input.cjs"),i=require("../styled/components/embedded-chat/file-upload-input.cjs"),m=require("../styled/components/embedded-chat/image-preview-modal.cjs");function R(r){const{baseSettings:t,aiChatSettings:n}=r;return e.jsx(D.ErrorBoundary,{children:e.jsx(w.Shadow,{wrapperStyles:{height:"inherit",width:"inherit"},children:e.jsx(B.RootProvider,{config:{baseSettings:t,aiChatSettings:n},componentType:F.WebWidgetInteractionType.EmbeddedChat,children:e.jsx(A,{...r})})})})}function S(r){const{children:t,onToggleView:n,isHidden:o,shouldAutoFocusInput:d=!n}=r;return e.jsx(k.ChatAuthProvider,{children:e.jsx(P.ChatBaseEventsProvider,{children:e.jsx(s.Provider,{isHidden:o,shouldAutoFocusInput:d,children:t})})})}function A(r){return e.jsx(S,{...r,children:e.jsx(H,{...r})})}function H(r){const{onToggleView:t,variant:n,header:o=$}=r,d=L.useModal(),c=q.useWidget(),x=d&&!c?W.ModalContent:p.Fragment;return e.jsx(N.ImagePreviewProvider,{children:e.jsx(x,{children:e.jsxs(s.Wrapper,{variant:n??(t?"no-shadow":"container-with-shadow"),"data-composite":g.dataAttr(!!r.onToggleView||d?.isOpen),children:[e.jsx(Y,{}),e.jsxs(s.Root,{children:[o&&e.jsx(o,{...r}),e.jsx(_,{}),e.jsx(z,{})]}),e.jsx(ee,{}),e.jsx(U,{}),e.jsx(se,{})]})})})}const $=r=>{const{onToggleView:t,askAILabel:n,searchLabel:o}=r,{aiChatSettings:d}=F.useInkeepConfig(),c=d.isChatHistoryButtonVisible,x=!!t||c;return e.jsx(s.Header,{"data-show-toolbar":g.dataAttr(x),children:x?e.jsxs(s.HeaderToolbar,{"data-show-widget-toggle":g.dataAttr(!!t),children:[e.jsx(s.HeaderToolbarWrapper,{children:c&&e.jsx(s.ChatHistoryTrigger,{})}),t&&e.jsx(V.WidgetToggle,{onToggleView:t,askAILabel:n,searchLabel:o,view:"chat"}),e.jsx(b.Close,{})]}):e.jsx(b.Close,{})})};function _(){const{isSessionLoading:r}=y.useChat();return e.jsx(s.Content,{children:e.jsxs(s.ContentScrollArea,{children:[e.jsx(s.ContentScrollAreaViewport,{children:r?e.jsx(s.MessagesSessionLoading,{}):e.jsx(Q,{})}),e.jsx(s.ContentScrollAreaScrollbar,{children:e.jsx(s.ContentScrollAreaThumb,{})}),e.jsx(s.ContentScrollAreaCorner,{})]})})}function Q(){const{aiChatSettings:{components:r}}=F.useInkeepConfig();return e.jsx(s.Messages,{children:({messages:t,isLoading:n,isStreaming:o})=>{const d=t.at(-1),c=l=>(h,C)=>{const j=r?.[h];if(!j)return console.warn(`Component "${h}" not found in components config`),null;const I={...C,messageId:l.id};try{if(typeof j=="function"&&j.length<=1)return p.createElement(j,I);const u=j(I,document.createElement("div"),null);return p.isValidElement(u)||typeof u=="string"?u:null}catch(u){return console.error(`🔍 [renderComponent] Error rendering component "${h}":`,u),null}},x=l=>e.jsx(s.Markdown,{text:l});return e.jsxs(e.Fragment,{children:[e.jsx(O,{}),t.map(l=>{const h=d?.id===l.id,C=c(l);return e.jsxs(s.MessageWrapper,{message:l,children:[e.jsx(M,{}),e.jsxs(s.MessageContentWrapper,{children:[e.jsx(s.MessageContent,{children:r?.IkpMessage?e.jsx(s.DynamicComponent,{name:"IkpMessage",props:{message:l,renderComponent:C,renderMarkdown:x},componentDef:r.IkpMessage}):e.jsxs(e.Fragment,{children:[e.jsx(E.EmbeddedChatMessagePart,{isLast:h}),(!o||!h)&&e.jsx(Z,{})]})}),e.jsx(G,{}),e.jsx(K,{})]})]},l.id)}),n&&d?.role==="user"&&d?.parts.length&&e.jsxs(s.MessageWrapper,{message:{id:"___loader___",role:"assistant",parts:[{type:"text",text:"Thinking..."}]},children:[e.jsx(M,{}),e.jsx(s.MessageLoading,{})]})]})}})}function O(){return e.jsxs(s.IntroMessageWrapper,{children:[e.jsxs(s.MessageHeader,{children:[e.jsx(s.MessageAvatar,{children:e.jsx(s.MessageAvatarContent,{children:e.jsx(s.MessageAvatarImage,{})})}),e.jsx(s.MessageName,{})]}),e.jsxs(s.MessageContentWrapper,{children:[e.jsx(s.MessageContent,{children:e.jsx(E.EmbeddedChatMessagePart,{isLast:!1})}),e.jsxs(s.Disclaimer,{children:[e.jsx(s.DisclaimerLabel,{}),e.jsx(s.DisclaimerTrigger,{}),e.jsxs(s.DisclaimerContent,{children:[e.jsx(s.DisclaimerText,{}),e.jsx(s.DisclaimerArrow,{})]})]}),e.jsxs(s.ExampleQuestions,{children:[e.jsx(s.ExampleQuestionsLabel,{}),e.jsx(s.ExampleQuestionsList,{children:r=>r.map(t=>e.jsx(s.ExampleQuestion,{children:e.jsx(s.ExampleQuestionButton,{question:t})},typeof t=="object"?t.label:t))})]})]})]})}function M(){return e.jsxs(s.MessageHeader,{children:[e.jsx(s.MessageAvatar,{children:e.jsx(s.MessageAvatarContent,{children:e.jsx(s.MessageAvatarImage,{})})}),e.jsx(s.MessageName,{})]})}function U(){return e.jsx(T.PortalWithTheme,{children:e.jsx(m.EmbeddedChatImagePreviewModal,{children:e.jsx(m.EmbeddedChatImagePreviewModalOverlay,{children:e.jsxs(m.EmbeddedChatImagePreviewModalContent,{children:[e.jsx(m.EmbeddedChatImagePreviewModalClose,{}),e.jsx(m.EmbeddedChatImagePreviewModalImage,{}),e.jsx(m.EmbeddedChatImagePreviewModalFooter,{children:e.jsx(m.EmbeddedChatImagePreviewModalFileName,{})})]})})})})}function G(){return e.jsx(i.EmbeddedChatMessageFiles,{children:r=>r.map((t,n)=>{const o=t.url,d=t.mediaType??"",c=d.split("/").pop(),x=t.filename??(c?`untitled.${c}`:"untitled"),l=v.isImageMimeType(d);return e.jsxs(i.EmbeddedChatMessageFile,{url:o,name:x,mediaType:d,children:[l?e.jsx(i.EmbeddedChatFileThumbnail,{}):e.jsx(i.EmbeddedChatFileTypeIcon,{}),e.jsx(i.EmbeddedChatFileName,{})]},o||n)})})}function K(){return e.jsxs(s.MessageToolbar,{children:[e.jsx(s.MessageCustomActions,{children:r=>r.map((t,n)=>e.jsx(s.MessageCustomAction,{action:t},`action-${n}`))}),e.jsx(s.MessageAction,{action:"copy"}),e.jsx(s.MessageAction,{action:"upvote"}),e.jsx(s.MessageAction,{action:"downvote"})]})}function Z(){return e.jsxs(s.MessageSources,{children:[e.jsx(s.MessageSourcesHeader,{}),e.jsx(s.MessageSourcesList,{children:r=>r.map((t,n)=>e.jsxs(s.MessageSourceItem,{href:t.url,source:t,children:[e.jsx(s.MessageSourceItemBreadcrumbs,{children:t.breadcrumbs?.map(o=>e.jsxs(p.Fragment,{children:[o,e.jsx(s.MessageSourceItemBreadcrumbIcon,{})]},o))}),e.jsx(s.MessageSourceItemIcon,{}),e.jsx(s.MessageSourceItemTitle,{}),e.jsx(s.MessageSourceItemTag,{}),e.jsx(s.MessageSourceItemDescription,{children:o=>o.map((d,c)=>e.jsx(s.MessageSourceItemDescriptionPart,{descriptionPart:d},`part-${c}`))}),e.jsx(s.MessageSourceItemIndicator,{})]},n))})]})}function z(){return e.jsxs(s.Footer,{children:[e.jsx(i.EmbeddedChatInputNotification,{children:e.jsxs(i.EmbeddedChatInputNotificationContent,{children:[e.jsxs(i.EmbeddedChatInputNotificationHeader,{children:[e.jsx(i.EmbeddedChatInputNotificationTitle,{}),e.jsx(i.EmbeddedChatInputNotificationClose,{})]}),e.jsx(i.EmbeddedChatInputNotificationMessage,{})]})}),e.jsx(J,{}),e.jsx(X,{})]})}function J(){return e.jsxs(s.InputFieldset,{children:[e.jsx(i.EmbeddedChatFileInput,{}),e.jsx(i.EmbeddedChatDropZone,{children:"Drop files here to add to chat"}),e.jsx(i.EmbeddedChatFileList,{children:r=>r.map((t,n)=>{const o=v.isImageMimeType(t.type);return e.jsxs(i.EmbeddedChatFileItem,{file:t,children:[o?e.jsxs(i.EmbeddedChatFilePreviewTrigger,{children:[e.jsx(i.EmbeddedChatFileThumbnail,{}),e.jsx(i.EmbeddedChatFileName,{})]}):e.jsxs(i.EmbeddedChatFileContent,{children:[e.jsx(i.EmbeddedChatFileTypeIcon,{}),e.jsx(i.EmbeddedChatFileName,{})]}),e.jsx(i.EmbeddedChatFileRemove,{})]},`${t.name}-${t.lastModified}-${n}`)})}),e.jsxs(s.InputGroup,{children:[e.jsx(i.EmbeddedChatFileUploadButton,{}),e.jsx(s.Input,{}),e.jsx(s.SendButton,{children:e.jsx(s.SendButtonIcon,{})})]})]})}function X(){return e.jsxs(s.ActionBar,{children:[e.jsxs(s.TaglineContainer,{children:[e.jsx(s.TaglineText,{}),e.jsx(s.TaglineLogo,{})]}),e.jsxs(s.Actions,{children:[e.jsx(s.HelpActions,{children:({pinned:r,unpinned:t})=>e.jsxs(e.Fragment,{children:[r.map(n=>e.jsx(s.HelpAction,{action:n},n.name)),t.length>0&&e.jsx(s.HelpActionsTrigger,{}),e.jsxs(s.HelpActionsMenu,{children:[e.jsx(s.HelpActionsMenuArrow,{}),t.map(n=>e.jsxs(s.HelpActionsMenuItem,{action:n,children:[e.jsx(s.HelpActionsMenuItemIcon,{action:n}),n.name]},n.name))]})]})}),e.jsxs(s.ChatAction,{action:"copy",children:[e.jsx(s.ChatActionLabel,{action:"copy"}),e.jsx(s.ChatActionFeedback,{action:"copy"})]}),e.jsx(s.ChatAction,{action:"clear"}),e.jsx(s.ChatAction,{action:"stop"})]})]})}function Y(){const{sessions:r}=f.useChatHistory(),{conversationId:t}=y.useChat();return e.jsxs(a.EmbeddedChatHistoryRoot,{children:[e.jsxs(a.EmbeddedChatHistoryHeader,{children:[e.jsxs(a.EmbeddedChatHistoryBackButton,{children:[e.jsx(a.EmbeddedChatHistoryBackButtonIcon,{iconKey:"backToChat"}),"Back to chat"]}),e.jsx(a.EmbeddedChatHistoryTitle,{}),e.jsx(b.Close,{})]}),e.jsxs(a.EmbeddedChatHistoryList,{children:[r.map(n=>e.jsxs(a.EmbeddedChatHistoryItem,{sessionId:n.id,"data-active":g.dataAttr(n.id===t),children:[e.jsx(a.EmbeddedChatHistoryItemTitle,{children:n.title}),e.jsx(a.EmbeddedChatHistoryItemDate,{children:a.formatSessionDate(n.updatedAt)})]},n.id)),e.jsx(a.EmbeddedChatHistoryEmptyState,{}),e.jsx(a.EmbeddedChatHistoryLoadingState,{})]}),e.jsx(a.EmbeddedChatHistoryFooter,{children:e.jsx(a.EmbeddedChatHistoryNewConversationButton,{})})]})}function ee(){return e.jsx(T.PortalWithTheme,{children:e.jsx(s.FeedbackModal,{children:e.jsx(s.FeedbackModalOverlay,{children:e.jsxs(s.FeedbackModalContent,{children:[e.jsx(s.FeedbackModalHeader,{}),e.jsx(s.FeedbackModalClose,{}),e.jsx(s.FeedbackModalBody,{children:e.jsxs(s.FeedbackForm,{children:[e.jsxs(s.FeedbackField,{children:[e.jsx(s.FeedbackItemLabel,{}),e.jsx(s.FeedbackItemDescription,{})]}),e.jsx(s.FeedbackSubmitButton,{})]})})]})})})})}function se(){return e.jsxs(s.FormWrapper,{children:[e.jsx(s.FormClose,{}),e.jsxs(s.Form,{children:[e.jsxs(s.FormHeader,{children:[e.jsx(s.FormHeading,{}),e.jsx(s.FormDescription,{})]}),e.jsx(s.FormContent,{children:r=>e.jsxs(e.Fragment,{children:[r.map((t,n)=>e.jsxs(s.FormField,{field:t,autoFocus:n===0,children:[e.jsx(s.FormFieldLabel,{}),t.inputType==="text"&&e.jsx(s.FormFieldText,{}),t.inputType==="email"&&e.jsx(s.FormFieldEmail,{}),t.inputType==="file"&&e.jsx(s.FormFieldFile,{}),t.inputType==="textarea"&&e.jsx(s.FormFieldTextArea,{}),t.inputType==="checkbox"&&e.jsx(s.FormFieldCheckbox,{children:e.jsx(s.FormFieldCheckboxIndicator,{})}),t.inputType==="select"&&e.jsxs(s.FormFieldSelect,{children:[e.jsxs(s.FormFieldSelectTrigger,{children:[e.jsx(s.FormFieldSelectValue,{}),e.jsx(s.FormFieldSelectIcon,{})]}),e.jsx(s.FormFieldSelectContent,{children:e.jsx(s.FormFieldSelectViewport,{children:t.items.map(o=>e.jsxs(s.FormFieldSelectItem,{value:o.value,children:[e.jsx(s.FormFieldSelectItemText,{children:o.label}),e.jsx(s.FormFieldSelectItemIndicator,{})]},o.value))})})]}),t.inputType==="combobox"&&e.jsxs(s.FormFieldCombobox,{children:[e.jsxs(s.FormFieldComboboxControl,{children:["multiple"in t&&t.multiple&&e.jsx(s.FormFieldComboboxSelectedTags,{}),e.jsx(s.FormFieldComboboxInput,{}),e.jsx(s.FormFieldComboboxTrigger,{})]}),e.jsx(s.FormFieldComboboxPositioner,{children:e.jsx(s.FormFieldComboboxContent,{children:e.jsx(s.FormFieldComboboxList,{children:e.jsx(s.FormFieldComboboxListItems,{children:o=>o.length===0?e.jsx(s.FormFieldComboboxListEmpty,{}):o.map(d=>e.jsxs(s.FormFieldComboboxItem,{item:d,children:[e.jsx(s.FormFieldComboboxItemText,{children:d.label}),e.jsx(s.FormFieldComboboxItemIndicator,{})]},d.value))})})})})]}),e.jsx(s.FormFieldDescription,{}),e.jsx(s.FormFieldError,{})]},t.name)),e.jsx(s.FormError,{})]})}),e.jsxs(s.FormFooter,{children:[e.jsx(s.FormCancel,{}),e.jsx(s.FormSubmit,{})]})]}),e.jsxs(s.FormSuccess,{children:[e.jsx(s.FormSuccessHeading,{}),e.jsx(s.FormSuccessMessage,{}),e.jsx(s.FormSuccessButton,{})]})]})}exports.InkeepEmbeddedChat=R;exports.InkeepEmbeddedChatImpl=A;exports.InkeepEmbeddedChatImplContent=H;exports.InkeepEmbeddedChatProvider=S;
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),j=require("react"),s=require("../styled/components/embedded-chat.cjs"),a=require("../styled/components/chat-history.cjs"),g=require("../styled/components/modal.cjs"),A=require("../styled/components/shadow.cjs"),F=require("../styled/components/message.cjs"),H=require("../primitives/providers/chat-auth-provider.cjs"),w=require("../primitives/providers/chat-base-events-provider.cjs"),f=require("../primitives/providers/chat-history-provider.cjs"),p=require("../primitives/providers/config-provider.cjs"),k=require("../primitives/providers/root-provider.cjs"),P=require("../primitives/providers/widget-provider.cjs"),C=require("../primitives/components/embedded-chat/chat-provider.cjs"),B=require("../primitives/components/modal/modal-provider.cjs"),u=require("../primitives/utils/misc.cjs"),I=require("../primitives/atoms/portal-with-theme.cjs"),q=require("../primitives/atoms/error-boundary.cjs"),L=require("./modal.cjs"),D=require("../primitives/providers/image-preview-provider.cjs"),W=require("./widget-toggle.cjs"),M=require("../primitives/components/embedded-chat/file-upload-input.cjs"),i=require("../styled/components/embedded-chat/file-upload-input.cjs"),m=require("../styled/components/embedded-chat/image-preview-modal.cjs");function N(r){const{baseSettings:t,aiChatSettings:n}=r;return e.jsx(q.ErrorBoundary,{children:e.jsx(A.Shadow,{wrapperStyles:{height:"inherit",width:"inherit"},children:e.jsx(k.RootProvider,{config:{baseSettings:t,aiChatSettings:n},componentType:p.WebWidgetInteractionType.EmbeddedChat,children:e.jsx(y,{...r})})})})}function E(r){const{children:t,onToggleView:n,isHidden:o,shouldAutoFocusInput:d=!n}=r;return e.jsx(H.ChatAuthProvider,{children:e.jsx(w.ChatBaseEventsProvider,{children:e.jsx(s.Provider,{isHidden:o,shouldAutoFocusInput:d,children:t})})})}function y(r){return e.jsx(E,{...r,children:e.jsx(T,{...r})})}function T(r){const{onToggleView:t,variant:n,header:o=V}=r,d=B.useModal(),c=P.useWidget(),l=d&&!c?L.ModalContent:j.Fragment;return e.jsx(D.ImagePreviewProvider,{children:e.jsx(l,{children:e.jsxs(s.Wrapper,{variant:n??(t?"no-shadow":"container-with-shadow"),"data-composite":u.dataAttr(!!r.onToggleView||d?.isOpen),children:[e.jsx(Y,{}),e.jsxs(s.Root,{children:[o&&e.jsx(o,{...r}),e.jsx($,{}),e.jsx(z,{})]}),e.jsx(ee,{}),e.jsx(G,{}),e.jsx(se,{})]})})})}const V=r=>{const{onToggleView:t,askAILabel:n,searchLabel:o}=r,{aiChatSettings:d}=p.useInkeepConfig(),c=d.isChatHistoryButtonVisible,l=!!t||c;return e.jsx(s.Header,{"data-show-toolbar":u.dataAttr(l),children:l?e.jsxs(s.HeaderToolbar,{"data-show-widget-toggle":u.dataAttr(!!t),children:[e.jsx(s.HeaderToolbarWrapper,{children:c&&e.jsx(s.ChatHistoryTrigger,{})}),t&&e.jsx(W.WidgetToggle,{onToggleView:t,askAILabel:n,searchLabel:o,view:"chat"}),e.jsx(g.Close,{})]}):e.jsx(g.Close,{})})};function $(){const{isSessionLoading:r}=C.useChat();return e.jsx(s.Content,{children:e.jsxs(s.ContentScrollArea,{children:[e.jsx(s.ContentScrollAreaViewport,{children:r?e.jsx(s.MessagesSessionLoading,{}):e.jsx(O,{})}),e.jsx(s.ContentScrollAreaScrollbar,{children:e.jsx(s.ContentScrollAreaThumb,{})}),e.jsx(s.ContentScrollAreaCorner,{})]})})}const R=r=>e.jsx(s.Markdown,{text:r});function _(){const{isStreaming:r}=C.useChat();return r?null:e.jsx(S,{})}const Q=j.memo(function({message:t,isLast:n,components:o}){const d=(c,l)=>{const x=o?.[c];if(!x)return console.warn(`Component "${c}" not found in components config`),null;const b={...l,messageId:t.id};try{if(typeof x=="function"&&x.length<=1)return j.createElement(x,b);const h=x(b,document.createElement("div"),null);return j.isValidElement(h)||typeof h=="string"?h:null}catch(h){return console.error(`🔍 [renderComponent] Error rendering component "${c}":`,h),null}};return e.jsxs(s.MessageWrapper,{message:t,children:[e.jsx(v,{}),e.jsxs(s.MessageContentWrapper,{children:[e.jsx(s.MessageContent,{children:o?.IkpMessage?e.jsx(s.DynamicComponent,{name:"IkpMessage",props:{message:t,renderComponent:d,renderMarkdown:R},componentDef:o.IkpMessage}):e.jsxs(e.Fragment,{children:[e.jsx(F.EmbeddedChatMessagePart,{isLast:n}),n?e.jsx(_,{}):e.jsx(S,{})]})}),e.jsx(K,{}),e.jsx(Z,{})]})]})});function O(){const{aiChatSettings:{components:r}}=p.useInkeepConfig();return e.jsx(s.Messages,{children:({messages:t,isLoading:n})=>{const o=t.at(-1);return e.jsxs(e.Fragment,{children:[e.jsx(U,{}),t.map(d=>e.jsx(Q,{message:d,isLast:o?.id===d.id,components:r},d.id)),n&&o?.role==="user"&&o?.parts.length&&e.jsxs(s.MessageWrapper,{message:{id:"___loader___",role:"assistant",parts:[{type:"text",text:"Thinking..."}]},children:[e.jsx(v,{}),e.jsx(s.MessageLoading,{})]})]})}})}function U(){return e.jsxs(s.IntroMessageWrapper,{children:[e.jsxs(s.MessageHeader,{children:[e.jsx(s.MessageAvatar,{children:e.jsx(s.MessageAvatarContent,{children:e.jsx(s.MessageAvatarImage,{})})}),e.jsx(s.MessageName,{})]}),e.jsxs(s.MessageContentWrapper,{children:[e.jsx(s.MessageContent,{children:e.jsx(F.EmbeddedChatMessagePart,{isLast:!1})}),e.jsxs(s.Disclaimer,{children:[e.jsx(s.DisclaimerLabel,{}),e.jsx(s.DisclaimerTrigger,{}),e.jsxs(s.DisclaimerContent,{children:[e.jsx(s.DisclaimerText,{}),e.jsx(s.DisclaimerArrow,{})]})]}),e.jsxs(s.ExampleQuestions,{children:[e.jsx(s.ExampleQuestionsLabel,{}),e.jsx(s.ExampleQuestionsList,{children:r=>r.map(t=>e.jsx(s.ExampleQuestion,{children:e.jsx(s.ExampleQuestionButton,{question:t})},typeof t=="object"?t.label:t))})]})]})]})}function v(){return e.jsxs(s.MessageHeader,{children:[e.jsx(s.MessageAvatar,{children:e.jsx(s.MessageAvatarContent,{children:e.jsx(s.MessageAvatarImage,{})})}),e.jsx(s.MessageName,{})]})}function G(){return e.jsx(I.PortalWithTheme,{children:e.jsx(m.EmbeddedChatImagePreviewModal,{children:e.jsx(m.EmbeddedChatImagePreviewModalOverlay,{children:e.jsxs(m.EmbeddedChatImagePreviewModalContent,{children:[e.jsx(m.EmbeddedChatImagePreviewModalClose,{}),e.jsx(m.EmbeddedChatImagePreviewModalImage,{}),e.jsx(m.EmbeddedChatImagePreviewModalFooter,{children:e.jsx(m.EmbeddedChatImagePreviewModalFileName,{})})]})})})})}function K(){return e.jsx(i.EmbeddedChatMessageFiles,{children:r=>r.map((t,n)=>{const o=t.url,d=t.mediaType??"",c=d.split("/").pop(),l=t.filename??(c?`untitled.${c}`:"untitled"),x=M.isImageMimeType(d);return e.jsxs(i.EmbeddedChatMessageFile,{url:o,name:l,mediaType:d,children:[x?e.jsx(i.EmbeddedChatFileThumbnail,{}):e.jsx(i.EmbeddedChatFileTypeIcon,{}),e.jsx(i.EmbeddedChatFileName,{})]},o||n)})})}function Z(){return e.jsxs(s.MessageToolbar,{children:[e.jsx(s.MessageCustomActions,{children:r=>r.map((t,n)=>e.jsx(s.MessageCustomAction,{action:t},`action-${n}`))}),e.jsx(s.MessageAction,{action:"copy"}),e.jsx(s.MessageAction,{action:"upvote"}),e.jsx(s.MessageAction,{action:"downvote"})]})}function S(){return e.jsxs(s.MessageSources,{children:[e.jsx(s.MessageSourcesHeader,{}),e.jsx(s.MessageSourcesList,{children:r=>r.map((t,n)=>e.jsxs(s.MessageSourceItem,{href:t.url,source:t,children:[e.jsx(s.MessageSourceItemBreadcrumbs,{children:t.breadcrumbs?.map(o=>e.jsxs(j.Fragment,{children:[o,e.jsx(s.MessageSourceItemBreadcrumbIcon,{})]},o))}),e.jsx(s.MessageSourceItemIcon,{}),e.jsx(s.MessageSourceItemTitle,{}),e.jsx(s.MessageSourceItemTag,{}),e.jsx(s.MessageSourceItemDescription,{children:o=>o.map((d,c)=>e.jsx(s.MessageSourceItemDescriptionPart,{descriptionPart:d},`part-${c}`))}),e.jsx(s.MessageSourceItemIndicator,{})]},n))})]})}function z(){return e.jsxs(s.Footer,{children:[e.jsx(i.EmbeddedChatInputNotification,{children:e.jsxs(i.EmbeddedChatInputNotificationContent,{children:[e.jsxs(i.EmbeddedChatInputNotificationHeader,{children:[e.jsx(i.EmbeddedChatInputNotificationTitle,{}),e.jsx(i.EmbeddedChatInputNotificationClose,{})]}),e.jsx(i.EmbeddedChatInputNotificationMessage,{})]})}),e.jsx(J,{}),e.jsx(X,{})]})}function J(){return e.jsxs(s.InputFieldset,{children:[e.jsx(i.EmbeddedChatFileInput,{}),e.jsx(i.EmbeddedChatDropZone,{children:"Drop files here to add to chat"}),e.jsx(i.EmbeddedChatFileList,{children:r=>r.map((t,n)=>{const o=M.isImageMimeType(t.type);return e.jsxs(i.EmbeddedChatFileItem,{file:t,children:[o?e.jsxs(i.EmbeddedChatFilePreviewTrigger,{children:[e.jsx(i.EmbeddedChatFileThumbnail,{}),e.jsx(i.EmbeddedChatFileName,{})]}):e.jsxs(i.EmbeddedChatFileContent,{children:[e.jsx(i.EmbeddedChatFileTypeIcon,{}),e.jsx(i.EmbeddedChatFileName,{})]}),e.jsx(i.EmbeddedChatFileRemove,{})]},`${t.name}-${t.lastModified}-${n}`)})}),e.jsxs(s.InputGroup,{children:[e.jsx(i.EmbeddedChatFileUploadButton,{}),e.jsx(s.Input,{}),e.jsx(s.SendButton,{children:e.jsx(s.SendButtonIcon,{})})]})]})}function X(){return e.jsxs(s.ActionBar,{children:[e.jsxs(s.TaglineContainer,{children:[e.jsx(s.TaglineText,{}),e.jsx(s.TaglineLogo,{})]}),e.jsxs(s.Actions,{children:[e.jsx(s.HelpActions,{children:({pinned:r,unpinned:t})=>e.jsxs(e.Fragment,{children:[r.map(n=>e.jsx(s.HelpAction,{action:n},n.name)),t.length>0&&e.jsx(s.HelpActionsTrigger,{}),e.jsxs(s.HelpActionsMenu,{children:[e.jsx(s.HelpActionsMenuArrow,{}),t.map(n=>e.jsxs(s.HelpActionsMenuItem,{action:n,children:[e.jsx(s.HelpActionsMenuItemIcon,{action:n}),n.name]},n.name))]})]})}),e.jsxs(s.ChatAction,{action:"copy",children:[e.jsx(s.ChatActionLabel,{action:"copy"}),e.jsx(s.ChatActionFeedback,{action:"copy"})]}),e.jsx(s.ChatAction,{action:"clear"}),e.jsx(s.ChatAction,{action:"stop"})]})]})}function Y(){const{sessions:r}=f.useChatHistory(),{conversationId:t}=C.useChat();return e.jsxs(a.EmbeddedChatHistoryRoot,{children:[e.jsxs(a.EmbeddedChatHistoryHeader,{children:[e.jsxs(a.EmbeddedChatHistoryBackButton,{children:[e.jsx(a.EmbeddedChatHistoryBackButtonIcon,{iconKey:"backToChat"}),"Back to chat"]}),e.jsx(a.EmbeddedChatHistoryTitle,{}),e.jsx(g.Close,{})]}),e.jsxs(a.EmbeddedChatHistoryList,{children:[r.map(n=>e.jsxs(a.EmbeddedChatHistoryItem,{sessionId:n.id,"data-active":u.dataAttr(n.id===t),children:[e.jsx(a.EmbeddedChatHistoryItemTitle,{children:n.title}),e.jsx(a.EmbeddedChatHistoryItemDate,{children:a.formatSessionDate(n.updatedAt)})]},n.id)),e.jsx(a.EmbeddedChatHistoryEmptyState,{}),e.jsx(a.EmbeddedChatHistoryLoadingState,{})]}),e.jsx(a.EmbeddedChatHistoryFooter,{children:e.jsx(a.EmbeddedChatHistoryNewConversationButton,{})})]})}function ee(){return e.jsx(I.PortalWithTheme,{children:e.jsx(s.FeedbackModal,{children:e.jsx(s.FeedbackModalOverlay,{children:e.jsxs(s.FeedbackModalContent,{children:[e.jsx(s.FeedbackModalHeader,{}),e.jsx(s.FeedbackModalClose,{}),e.jsx(s.FeedbackModalBody,{children:e.jsxs(s.FeedbackForm,{children:[e.jsxs(s.FeedbackField,{children:[e.jsx(s.FeedbackItemLabel,{}),e.jsx(s.FeedbackItemDescription,{})]}),e.jsx(s.FeedbackSubmitButton,{})]})})]})})})})}function se(){return e.jsxs(s.FormWrapper,{children:[e.jsx(s.FormClose,{}),e.jsxs(s.Form,{children:[e.jsxs(s.FormHeader,{children:[e.jsx(s.FormHeading,{}),e.jsx(s.FormDescription,{})]}),e.jsx(s.FormContent,{children:r=>e.jsxs(e.Fragment,{children:[r.map((t,n)=>e.jsxs(s.FormField,{field:t,autoFocus:n===0,children:[e.jsx(s.FormFieldLabel,{}),t.inputType==="text"&&e.jsx(s.FormFieldText,{}),t.inputType==="email"&&e.jsx(s.FormFieldEmail,{}),t.inputType==="file"&&e.jsx(s.FormFieldFile,{}),t.inputType==="textarea"&&e.jsx(s.FormFieldTextArea,{}),t.inputType==="checkbox"&&e.jsx(s.FormFieldCheckbox,{children:e.jsx(s.FormFieldCheckboxIndicator,{})}),t.inputType==="select"&&e.jsxs(s.FormFieldSelect,{children:[e.jsxs(s.FormFieldSelectTrigger,{children:[e.jsx(s.FormFieldSelectValue,{}),e.jsx(s.FormFieldSelectIcon,{})]}),e.jsx(s.FormFieldSelectContent,{children:e.jsx(s.FormFieldSelectViewport,{children:t.items.map(o=>e.jsxs(s.FormFieldSelectItem,{value:o.value,children:[e.jsx(s.FormFieldSelectItemText,{children:o.label}),e.jsx(s.FormFieldSelectItemIndicator,{})]},o.value))})})]}),t.inputType==="combobox"&&e.jsxs(s.FormFieldCombobox,{children:[e.jsxs(s.FormFieldComboboxControl,{children:["multiple"in t&&t.multiple&&e.jsx(s.FormFieldComboboxSelectedTags,{}),e.jsx(s.FormFieldComboboxInput,{}),e.jsx(s.FormFieldComboboxTrigger,{})]}),e.jsx(s.FormFieldComboboxPositioner,{children:e.jsx(s.FormFieldComboboxContent,{children:e.jsx(s.FormFieldComboboxList,{children:e.jsx(s.FormFieldComboboxListItems,{children:o=>o.length===0?e.jsx(s.FormFieldComboboxListEmpty,{}):o.map(d=>e.jsxs(s.FormFieldComboboxItem,{item:d,children:[e.jsx(s.FormFieldComboboxItemText,{children:d.label}),e.jsx(s.FormFieldComboboxItemIndicator,{})]},d.value))})})})})]}),e.jsx(s.FormFieldDescription,{}),e.jsx(s.FormFieldError,{})]},t.name)),e.jsx(s.FormError,{})]})}),e.jsxs(s.FormFooter,{children:[e.jsx(s.FormCancel,{}),e.jsx(s.FormSubmit,{})]})]}),e.jsxs(s.FormSuccess,{children:[e.jsx(s.FormSuccessHeading,{}),e.jsx(s.FormSuccessMessage,{}),e.jsx(s.FormSuccessButton,{})]})]})}exports.InkeepEmbeddedChat=N;exports.InkeepEmbeddedChatImpl=y;exports.InkeepEmbeddedChatImplContent=T;exports.InkeepEmbeddedChatProvider=E;
|