@8wave/ai-elements 0.103.0-beta.2 → 0.103.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,802 @@
1
+ import { a as e, n as t, t as n } from "./useChatbotStore-DhWHlZwO.js";
2
+ import { t as r } from "./src-BbpxM17m.js";
3
+ import { t as i } from "./PkChatbotMessages-BgsyN-mB.js";
4
+ import { t as a } from "./useLocalizedString-PfaKjIQY.js";
5
+ import { t as o } from "./PkAvatar-paEJByEA.js";
6
+ import { r as s } from "./utils-CgxndZld.js";
7
+ import { n as c, t as l } from "./PkChatbotInput-CpSSAW2z.js";
8
+ import { t as u } from "./PkChatbotEmptyState-Brs9qhwj.js";
9
+ import { VvIcon as d } from "@volverjs/ui-vue/components";
10
+ import { Fragment as f, Transition as p, computed as m, createBlock as h, createCommentVNode as g, createElementBlock as _, createElementVNode as v, createSlots as y, createTextVNode as b, createVNode as x, defineAsyncComponent as S, defineComponent as C, isRef as w, nextTick as ee, normalizeClass as T, onBeforeUnmount as te, onMounted as ne, onScopeDispose as re, onUnmounted as ie, openBlock as E, ref as D, renderList as ae, shallowRef as O, toDisplayString as k, toValue as A, unref as j, useTemplateRef as oe, watch as se, withCtx as M } from "vue";
11
+ import { useI18n as ce } from "vue-i18n";
12
+ import { useDropZone as le } from "@vueuse/core";
13
+ import { storeToRefs as ue } from "pinia";
14
+ //#region ../../packages/composable/src/chatbot/useGreeting.ts
15
+ function de(e, t) {
16
+ let { locale: n, t: r, te: i } = ce({ useScope: "global" });
17
+ return m(() => {
18
+ let a = A(e);
19
+ return N(a?.greeting?.[0]?.[n.value] || a?.initialMessage?.[n.value] || (i("message.defaultAgentWelcome") ? r("message.defaultAgentWelcome") : ""), A(t));
20
+ });
21
+ }
22
+ function N(e, t) {
23
+ return (t ? e.replace(/\{name\}/g, t) : e.replace(/[,\s]*\{name\}[!?]?/g, "")).trim();
24
+ }
25
+ //#endregion
26
+ //#region ../../packages/components/src/chat/PkAuroraCanvas.vue?vue&type=script&setup=true&lang.ts
27
+ var P = {
28
+ class: "pk-aurora",
29
+ "aria-hidden": "true"
30
+ }, F = {
31
+ key: 1,
32
+ class: "pk-aurora__fallback"
33
+ }, fe = "\nattribute vec2 a_position;\nvoid main() {\n gl_Position = vec4(a_position, 0.0, 1.0);\n}", pe = "\nprecision mediump float;\nuniform vec2 u_resolution;\nuniform float u_time;\nuniform vec3 u_color;\nuniform vec2 u_center;\nuniform vec2 u_half;\nuniform float u_spread;\n\nvec3 permute(vec3 x) { return mod(((x * 34.0) + 1.0) * x, 289.0); }\n\nfloat snoise(vec2 v) {\n const vec4 C = vec4(0.211324865405187, 0.366025403784439,\n -0.577350269189626, 0.024390243902439);\n vec2 i = floor(v + dot(v, C.yy));\n vec2 x0 = v - i + dot(i, C.xx);\n vec2 i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);\n vec4 x12 = x0.xyxy + C.xxzz;\n x12.xy -= i1;\n i = mod(i, 289.0);\n vec3 p = permute(permute(i.y + vec3(0.0, i1.y, 1.0))\n + i.x + vec3(0.0, i1.x, 1.0));\n vec3 m = max(0.5 - vec3(dot(x0, x0), dot(x12.xy, x12.xy),\n dot(x12.zw, x12.zw)), 0.0);\n m = m * m;\n m = m * m;\n vec3 x = 2.0 * fract(p * C.www) - 1.0;\n vec3 h = abs(x) - 0.5;\n vec3 ox = floor(x + 0.5);\n vec3 a0 = x - ox;\n m *= 1.79284291400159 - 0.85373472095314 * (a0 * a0 + h * h);\n vec3 g;\n g.x = a0.x * x0.x + h.x * x0.y;\n g.yz = a0.yz * x12.xz + h.yz * x12.yw;\n return 130.0 * dot(m, g);\n}\n\nvoid main() {\n vec2 px = gl_FragCoord.xy;\n vec2 rel = px - u_center;\n\n // Ignition: the ellipse lights up expanding from the center on mount\n float intro = smoothstep(0.0, 1.4, u_time);\n\n // Breathing: size and brightness oscillate gently but visibly\n float breath = 1.0\n + 0.12 * sin(u_time * 0.55)\n + 0.06 * snoise(vec2(u_time * 0.1, 3.7));\n float pulse = 1.0 + 0.2 * sin(u_time * 0.55 + 1.3);\n\n // Keep it simple (Gemini-style): one huge soft elliptical glow\n // centered on the pill\n vec2 radii = vec2(u_half.x * 0.95, u_half.y * 6.5)\n * u_spread\n * breath\n * mix(0.15, 1.0, intro);\n float r = length(rel / max(radii, vec2(1.0)));\n float glow = exp(-r * r * 2.2);\n\n // Never cut hard against the canvas bounds\n vec2 m = min(px, u_resolution - px);\n glow *= smoothstep(0.0, 32.0, min(m.x, m.y));\n\n // Dither: breaks the 8-bit banding rings of the very soft gradient\n // (no CSS blur on the canvas, the noise must fully mask the bands)\n glow = max(glow + (snoise(px * 0.9) - 0.5) * 0.03, 0.0);\n\n float alpha = glow * 0.2 * pulse * intro;\n\n // Premultiplied alpha (default canvas compositing)\n gl_FragColor = vec4(u_color * alpha, alpha);\n}", me = /* @__PURE__ */ C({
34
+ __name: "PkAuroraCanvas",
35
+ props: { sourceSelector: {} },
36
+ setup(e) {
37
+ let t = e, n = oe("canvasEl"), r = D(!1), i = null, a = 0, o = null, s = null, c = null, l = null, u = null, d = null, f = performance.now(), p = (e, t) => {
38
+ if (!i) return null;
39
+ let n = i.createShader(e);
40
+ return !n || (i.shaderSource(n, t), i.compileShader(n), !i.getShaderParameter(n, i.COMPILE_STATUS)) ? null : n;
41
+ }, m = () => {
42
+ if (!n.value) return null;
43
+ let e = getComputedStyle(n.value).color.match(/rgba?\(([\d.]+)[,\s]+([\d.]+)[,\s]+([\d.]+)/);
44
+ return e ? [
45
+ Number(e[1]) / 255,
46
+ Number(e[2]) / 255,
47
+ Number(e[3]) / 255
48
+ ] : null;
49
+ }, h = () => {
50
+ if (!i || !n.value) return;
51
+ let e = Math.min(window.devicePixelRatio || 1, 1.5), { clientWidth: r, clientHeight: a } = n.value;
52
+ n.value.width = Math.max(1, Math.round(r * e)), n.value.height = Math.max(1, Math.round(a * e)), i.viewport(0, 0, n.value.width, n.value.height);
53
+ let o = n.value.parentElement?.offsetParent, s = (t.sourceSelector ? o?.querySelector(t.sourceSelector) : o) ?? o, c = n.value.getBoundingClientRect(), f = s?.getBoundingClientRect();
54
+ if (f && c.width > 0) {
55
+ let e = n.value.width / c.width, t = n.value.height / c.height, r = (f.left + f.width / 2 - c.left) * e, a = (c.bottom - (f.top + f.height / 2)) * t, o = f.width / 2 * e, s = f.height / 2 * t;
56
+ i.uniform2f(l, r, a), i.uniform2f(u, o, s);
57
+ let p = Number.parseFloat(getComputedStyle(n.value).getPropertyValue("--aurora-spread"));
58
+ i.uniform1f(d, Number.isNaN(p) ? 1 : p);
59
+ }
60
+ v(g() ? 10 : void 0);
61
+ }, g = () => window.matchMedia("(prefers-reduced-motion: reduce)").matches, v = (e) => {
62
+ !i || !n.value || (i.uniform1f(s, e ?? (performance.now() - f) / 1e3), i.uniform2f(c, n.value.width, n.value.height), i.drawArrays(i.TRIANGLE_STRIP, 0, 4));
63
+ }, y = () => {
64
+ v(), a = requestAnimationFrame(y);
65
+ };
66
+ return ne(() => {
67
+ let e = n.value;
68
+ i = e?.getContext("webgl", { alpha: !0 }) ?? null;
69
+ let t = m();
70
+ if (!e || !i || !t) {
71
+ r.value = !0;
72
+ return;
73
+ }
74
+ let a = p(i.VERTEX_SHADER, fe), f = p(i.FRAGMENT_SHADER, pe), _ = i.createProgram();
75
+ if (!a || !f || !_) {
76
+ r.value = !0;
77
+ return;
78
+ }
79
+ if (i.attachShader(_, a), i.attachShader(_, f), i.linkProgram(_), !i.getProgramParameter(_, i.LINK_STATUS)) {
80
+ r.value = !0;
81
+ return;
82
+ }
83
+ i.useProgram(_);
84
+ let b = i.createBuffer();
85
+ i.bindBuffer(i.ARRAY_BUFFER, b), i.bufferData(i.ARRAY_BUFFER, new Float32Array([
86
+ -1,
87
+ -1,
88
+ 1,
89
+ -1,
90
+ -1,
91
+ 1,
92
+ 1,
93
+ 1
94
+ ]), i.STATIC_DRAW);
95
+ let x = i.getAttribLocation(_, "a_position");
96
+ if (i.enableVertexAttribArray(x), i.vertexAttribPointer(x, 2, i.FLOAT, !1, 0, 0), s = i.getUniformLocation(_, "u_time"), c = i.getUniformLocation(_, "u_resolution"), l = i.getUniformLocation(_, "u_center"), u = i.getUniformLocation(_, "u_half"), d = i.getUniformLocation(_, "u_spread"), i.uniform3f(i.getUniformLocation(_, "u_color"), ...t), o = new ResizeObserver(h), o.observe(e), h(), ee(h), g()) {
97
+ v(10);
98
+ return;
99
+ }
100
+ y();
101
+ }), te(() => {
102
+ cancelAnimationFrame(a), o?.disconnect();
103
+ }), ie(() => {
104
+ let e = i;
105
+ i = null, setTimeout(() => {
106
+ e?.getExtension("WEBGL_lose_context")?.loseContext();
107
+ }, 150);
108
+ }), (e, t) => (E(), _("div", P, [r.value ? (E(), _("div", F)) : (E(), _("canvas", {
109
+ key: 0,
110
+ ref_key: "canvasEl",
111
+ ref: n,
112
+ class: "pk-aurora__canvas"
113
+ }, null, 512))]));
114
+ }
115
+ }), I = .18, he = .35, L = /* @__PURE__ */ C({
116
+ __name: "PkVoiceOrb",
117
+ props: {
118
+ sample: {},
119
+ spectrum: {
120
+ type: Function,
121
+ default: void 0
122
+ },
123
+ state: {},
124
+ bars: { default: 5 }
125
+ },
126
+ setup(e) {
127
+ let t = e, n = oe("barsEl"), r = Array.from({ length: t.bars }, () => I), i, a = () => typeof window < "u" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches === !0, o = () => {
128
+ let e = Math.min(1, Math.max(0, t.sample())), n = t.spectrum?.(), i = r.length;
129
+ if (!n?.length) {
130
+ let t = Date.now() / 260;
131
+ return Array.from({ length: i }, (n, r) => {
132
+ let i = .65 + .35 * Math.sin(t + r * .9);
133
+ return I + e * 2.4 * i;
134
+ });
135
+ }
136
+ let a = Math.max(1, Math.floor(n.length / 2)), o = Math.max(1, Math.floor(a / i));
137
+ return Array.from({ length: i }, (e, t) => {
138
+ let r = 0;
139
+ for (let e = 0; e < o; e += 1) r += n[t * o + e] ?? 0;
140
+ return I + r / o / 255 * 2.2;
141
+ });
142
+ }, s = () => {
143
+ let e = n.value?.children;
144
+ e && r.forEach((t, n) => {
145
+ e[n]?.style.setProperty("--pk-voice-orb-scale", String(t));
146
+ });
147
+ }, c = () => {
148
+ let e = o();
149
+ r = r.map((t, n) => t + (Math.min(1, Math.max(I, e[n] ?? I)) - t) * he), s(), i = requestAnimationFrame(c);
150
+ }, l = () => {
151
+ i !== void 0 && (cancelAnimationFrame(i), i = void 0);
152
+ };
153
+ return se(() => t.state, async (e) => {
154
+ if (e !== "listening" && e !== "speaking" || a()) {
155
+ l(), r = r.map(() => I * 1.6), await ee(), s();
156
+ return;
157
+ }
158
+ i === void 0 && (i = requestAnimationFrame(c));
159
+ }, { immediate: !0 }), te(l), (t, r) => (E(), _("div", {
160
+ class: T(["pk-voice-orb", `pk-voice-orb--${e.state}`]),
161
+ "aria-hidden": "true"
162
+ }, [v("div", {
163
+ ref_key: "barsEl",
164
+ ref: n,
165
+ class: "pk-voice-orb__bars"
166
+ }, [(E(!0), _(f, null, ae(e.bars, (e) => (E(), _("span", {
167
+ key: e,
168
+ class: "pk-voice-orb__bar"
169
+ }))), 128))], 512)], 2));
170
+ }
171
+ }), ge = {
172
+ key: 0,
173
+ class: "pk-voice-session__badge",
174
+ "aria-hidden": "true"
175
+ }, _e = {
176
+ class: "pk-voice-session__status",
177
+ role: "status"
178
+ }, ve = {
179
+ key: 0,
180
+ class: "pk-voice-session__live-dot",
181
+ "aria-hidden": "true"
182
+ }, ye = ["title"], be = ["title"], xe = { class: "pk-voice-session__actions" }, Se = /* @__PURE__ */ C({
183
+ __name: "PkVoiceSession",
184
+ props: {
185
+ state: {},
186
+ sample: { type: Function },
187
+ spectrum: { type: Function },
188
+ remainingSeconds: {},
189
+ muted: { type: Boolean },
190
+ error: {},
191
+ rawError: {},
192
+ live: { type: Boolean }
193
+ },
194
+ emits: [
195
+ "toggle-mute",
196
+ "hang-up",
197
+ "retry",
198
+ "dismiss"
199
+ ],
200
+ setup(e, { emit: t }) {
201
+ let n = e, r = t, { t: i } = ce({ useScope: "global" }), a = m(() => n.error ? i("message.voiceFailed") : n.state === "connecting" ? i("message.voiceConnecting") : n.state === "speaking" ? i("message.voiceSpeaking") : n.muted ? i("message.voiceMuted") : i("message.voiceListening")), o = m(() => {
202
+ if (n.remainingSeconds === void 0) return;
203
+ let e = Math.floor(n.remainingSeconds / 60), t = n.remainingSeconds % 60;
204
+ return `${e}:${String(t).padStart(2, "0")}`;
205
+ }), s = m(() => n.remainingSeconds !== void 0 && n.remainingSeconds <= 30), l = m(() => !n.error && (n.state === "listening" || n.state === "speaking")), u = m(() => {
206
+ if (l.value) return n.state === "speaking" ? "speaking" : n.muted ? void 0 : "listening";
207
+ });
208
+ return (t, n) => {
209
+ let p = d;
210
+ return E(), _("div", { class: T(["pk-voice-session", { "pk-voice-session--failed": !!e.error }]) }, [
211
+ e.error ? (E(), _("span", ge, [x(p, { name: "ri:error-warning-line" })])) : (E(), h(L, {
212
+ key: 1,
213
+ state: e.state,
214
+ sample: e.sample,
215
+ spectrum: e.spectrum
216
+ }, null, 8, [
217
+ "state",
218
+ "sample",
219
+ "spectrum"
220
+ ])),
221
+ v("div", _e, [v("span", { class: T(["pk-voice-session__state", u.value && `pk-voice-session__state--${u.value}`]) }, [l.value ? (E(), _("span", ve)) : g("", !0), b(" " + k(a.value), 1)], 2), e.error ? (E(), _("p", {
222
+ key: 0,
223
+ class: "pk-voice-session__detail",
224
+ title: e.rawError ?? e.error
225
+ }, k(e.error), 9, ye)) : g("", !0)]),
226
+ o.value ? (E(), _("span", {
227
+ key: 2,
228
+ class: T(["pk-voice-session__timer", { "pk-voice-session__timer--warning": s.value }]),
229
+ title: j(i)("hint.voiceRemaining"),
230
+ "aria-hidden": "true"
231
+ }, k(o.value), 11, be)) : g("", !0),
232
+ v("div", xe, [e.error ? (E(), _(f, { key: 0 }, [x(c, {
233
+ icon: "ri:refresh-line",
234
+ label: j(i)("action.retry"),
235
+ onClick: n[0] ||= (e) => r("retry")
236
+ }, null, 8, ["label"]), e.live ? (E(), h(c, {
237
+ key: 0,
238
+ icon: "ri:stop-circle-line",
239
+ modifiers: "danger",
240
+ title: j(i)("action.hangUp"),
241
+ "aria-label": j(i)("action.hangUp"),
242
+ onClick: n[1] ||= (e) => r("hang-up")
243
+ }, null, 8, ["title", "aria-label"])) : (E(), h(c, {
244
+ key: 1,
245
+ icon: "ri:close-line",
246
+ label: j(i)("action.close"),
247
+ onClick: n[2] ||= (e) => r("dismiss")
248
+ }, null, 8, ["label"]))], 64)) : (E(), _(f, { key: 1 }, [x(c, {
249
+ icon: e.muted ? "ri:mic-off-line" : "ri:mic-line",
250
+ title: e.muted ? j(i)("action.unmute") : j(i)("action.mute"),
251
+ "aria-label": e.muted ? j(i)("action.unmute") : j(i)("action.mute"),
252
+ "aria-pressed": e.muted,
253
+ onClick: n[3] ||= (e) => r("toggle-mute")
254
+ }, null, 8, [
255
+ "icon",
256
+ "title",
257
+ "aria-label",
258
+ "aria-pressed"
259
+ ]), x(c, {
260
+ icon: "ri:stop-circle-line",
261
+ modifiers: "danger",
262
+ title: j(i)("action.hangUp"),
263
+ "aria-label": j(i)("action.hangUp"),
264
+ onClick: n[4] ||= (e) => r("hang-up")
265
+ }, null, 8, ["title", "aria-label"])], 64))])
266
+ ], 2);
267
+ };
268
+ }
269
+ }), Ce = (e) => {
270
+ let t = O(), n = D("disconnected"), i = D("listening"), a = D(), o = D([]), s = D(), c = D(), l, u, d = 0, f = !1, p = () => {
271
+ u &&= (clearInterval(u), void 0), s.value = void 0;
272
+ }, h = (e) => {
273
+ let t = Date.now() + e * 1e3, n = () => {
274
+ let e = Math.max(0, Math.ceil((t - Date.now()) / 1e3));
275
+ s.value = e, e === 0 && _();
276
+ };
277
+ n(), u = setInterval(n, 1e3);
278
+ }, g = async (t) => {
279
+ t && (l === t && (l = void 0), await e.closeGrant?.(t).catch(() => void 0));
280
+ }, _ = async () => {
281
+ d += 1, p();
282
+ let e = l;
283
+ l = void 0;
284
+ let r = t.value;
285
+ t.value = void 0, await r?.endSession().catch(() => void 0), await g(e), n.value = "disconnected", i.value = "listening";
286
+ }, v = async () => {
287
+ if (f || t.value || n.value === "connecting") return;
288
+ a.value = void 0, o.value = [], i.value = "listening", c.value = void 0, n.value = "connecting", d += 1;
289
+ let r = d, s = () => r === d && !f, u;
290
+ try {
291
+ let r = import("./web-BMnEaWK7.js");
292
+ r.catch(() => void 0);
293
+ let d = await e.fetchGrant();
294
+ if (!s()) {
295
+ await e.closeGrant?.(d.sessionId).catch(() => void 0);
296
+ return;
297
+ }
298
+ l = d.sessionId, u = d.sessionId, c.value = d.chatId;
299
+ let { VoiceConversation: f } = await r;
300
+ if (!s()) {
301
+ await g(d.sessionId);
302
+ return;
303
+ }
304
+ let m = await f.startSession({
305
+ signedUrl: d.signedUrl,
306
+ customLlmExtraBody: { voice_session_id: d.sessionId },
307
+ onStatusChange: ({ status: e }) => {
308
+ s() && (n.value = e);
309
+ },
310
+ onModeChange: ({ mode: t }) => {
311
+ if (!s()) return;
312
+ let n = i.value === "speaking";
313
+ i.value = t, n && t !== "speaking" && e.onTurnEnd?.();
314
+ },
315
+ onMessage: ({ message: t, role: n }) => {
316
+ if (!s()) return;
317
+ let r = {
318
+ role: n,
319
+ text: t
320
+ };
321
+ o.value = [...o.value, r], e.onTranscript?.(r);
322
+ },
323
+ onError: (e) => {
324
+ s() && (a.value = e);
325
+ },
326
+ onDisconnect: (r) => {
327
+ s() && (p(), t.value = void 0, n.value = "disconnected", i.value = "listening", r.reason === "error" && (a.value = r.message), g(d.sessionId), e.onTurnEnd?.());
328
+ }
329
+ });
330
+ if (!s()) {
331
+ await m.endSession().catch(() => void 0), await g(d.sessionId);
332
+ return;
333
+ }
334
+ t.value = m, h(d.maxSessionSeconds);
335
+ } catch (e) {
336
+ if (await g(u), !s()) return;
337
+ t.value = void 0, p(), n.value = "disconnected", a.value = e instanceof Error ? e.message : String(e);
338
+ }
339
+ }, y = () => {
340
+ a.value = void 0;
341
+ }, b = (e) => {
342
+ t.value?.setMicMuted(e);
343
+ }, x = (e) => {
344
+ let n = t.value;
345
+ if (!n || !e.trim()) return !1;
346
+ try {
347
+ return n.sendUserMessage(e), !0;
348
+ } catch (e) {
349
+ return r.warn("The spoken answer could not be sent", e), !1;
350
+ }
351
+ }, S = (e) => {
352
+ let n = t.value;
353
+ if (!n) return 0;
354
+ try {
355
+ return e === "input" ? n.getInputVolume() : n.getOutputVolume();
356
+ } catch {
357
+ return 0;
358
+ }
359
+ }, C = (e) => {
360
+ let n = t.value;
361
+ if (n) try {
362
+ return e === "input" ? n.getInputByteFrequencyData() : n.getOutputByteFrequencyData();
363
+ } catch {
364
+ return;
365
+ }
366
+ }, w = () => {
367
+ let e = l;
368
+ l = void 0, d += 1, p(), g(e);
369
+ let r = t.value;
370
+ t.value = void 0, r?.endSession().catch(() => void 0), n.value = "disconnected";
371
+ };
372
+ return typeof window < "u" && window.addEventListener("pagehide", w), re(() => {
373
+ f = !0, typeof window < "u" && window.removeEventListener("pagehide", w), _();
374
+ }), {
375
+ status: n,
376
+ mode: i,
377
+ error: a,
378
+ transcript: o,
379
+ remainingSeconds: s,
380
+ chatId: c,
381
+ isActive: m(() => n.value === "connected" || n.value === "connecting"),
382
+ isConnecting: m(() => n.value === "connecting"),
383
+ isSpeaking: m(() => n.value === "connected" && i.value === "speaking"),
384
+ isListening: m(() => n.value === "connected" && i.value === "listening"),
385
+ start: v,
386
+ stop: _,
387
+ dismissError: y,
388
+ setMuted: b,
389
+ sendUserMessage: x,
390
+ readLevel: S,
391
+ readSpectrum: C
392
+ };
393
+ }, we = { class: "pk-chatbot-view-chat__input-stage" }, Te = {
394
+ key: 0,
395
+ class: "p-md border-t border-surface-3 text-center text-12 text-danger-darken-2 bg-surface-danger"
396
+ }, Ee = { class: "pk-chatbot-view-chat__agent-chip" }, De = {
397
+ key: 0,
398
+ class: "pk-chatbot-view-chat__agent-chip-name"
399
+ }, Oe = {
400
+ key: 0,
401
+ class: "pk-chatbot-view-chat__drop-overlay"
402
+ }, ke = 3e3, Ae = 6e4, je = 3e5, Me = 6e5, Ne = /* @__PURE__ */ C({
403
+ __name: "PkChatbotViewChat",
404
+ props: {
405
+ agentId: {},
406
+ modifier: {},
407
+ userName: {}
408
+ },
409
+ emits: ["show-info", "revise"],
410
+ setup(r, { emit: c }) {
411
+ let f = S(() => import("./PkToolShowForm-CpY1KKUt.js").then((e) => e.n)), b = S(() => import("./PkToolShowContactForm-CMK4zR2J.js").then((e) => e.n)), C = S(() => import("./PkToolShowSuggestedReply-B-QwwART.js").then((e) => e.n)), ee = S(() => import("./PkToolShowSources-CLsbqcDd.js").then((e) => e.n)), ne = S(() => import("./PkToolRequestGeolocation-CsQghLEb.js")), re = S(() => import("./PkToolRequestOAuthConnection-D5Jq6UZh.js")), ie = S(() => import("./PkToolShowLocation-BBdeY0Ae.js").then((e) => e.n)), ae = S(() => import("./PkToolShowDiagram-DoklcF3f.js")), O = r, A = c, N = t(O.agentId), { agentInterface: P, agentFileUpload: F, agentVoice: fe, actions: pe, revisedAnswers: I, messages: he, chat: L, messageFeedbacks: ge, feedbackDialogMessage: _e, isFeedbackSubmitting: ve, isFeedbackSubmitted: ye, feedbackSubmitError: be, isLeadSubmitted: xe, isLoadingSubmitLead: Ne, submitLeadError: Pe, input: R, inputMessagePlaceholder: Fe, isConversationBlocked: Ie, baseUrl: Le, pendingAttachments: Re, isAttachmentLimitReached: ze, fileLimitError: Be, apiClient: z, isDark: Ve } = ue(N), { handleSubmit: He, stopGeneration: Ue, regenerate: We, onUpvote: Ge, onDownvote: Ke, onFeedback: qe, onFeedbackSubmit: Je, onLeadSubmit: Ye, startNewChat: Xe, addToolOutput: B, addToolApprovalResponse: Ze, handleFileSelect: Qe, clearFileLimitError: $e, refreshMessages: et, appendMessage: tt } = N, { t: V } = ce({ useScope: "global" }), nt = m(() => {
412
+ let e = Be.value;
413
+ if (e) return e.reason === "per-chat" ? V("message.fileLimitPerChat", { max: e.max }) : V("message.fileLimitPerMessage", { max: e.max });
414
+ }), rt = a(() => P.value?.dismissableNotice), it = m(() => he.value.some((e) => e.role === "user")), at = m(() => O.modifier === "fullscreen" && !it.value), ot = de(P, () => O.userName), st = oe("chatViewEl"), ct = async (e) => (await z.value.expandSourceContext(O.agentId, e.documentId, e.chunkIndex)).content, lt = async (e) => {
415
+ let t = await z.value.downloadSourceDocument(O.agentId, e);
416
+ window.open(t.downloadUrl, "_blank");
417
+ }, { isOverDropZone: ut } = le(st, {
418
+ dataTypes: m(() => F.value?.allowedMimeTypes ?? []),
419
+ onDrop: (e) => {
420
+ if (!(!F.value?.enabled || !e)) for (let t of e) Qe(t);
421
+ }
422
+ }), H = D(!1), U = !1, W = D(!1), dt = [
423
+ 3e3,
424
+ 5e3,
425
+ 1e4
426
+ ], G, K, q = !1, J = 0, ft = !1;
427
+ function pt() {
428
+ clearTimeout(G), G = void 0, K = void 0, q = !1, J = 0, W.value = !1;
429
+ }
430
+ function Y(e) {
431
+ U || (clearTimeout(G), G = setTimeout(() => {
432
+ mt();
433
+ }, e));
434
+ }
435
+ async function mt() {
436
+ if (U || ft) return;
437
+ ft = !0;
438
+ let e;
439
+ try {
440
+ e = await et();
441
+ } finally {
442
+ ft = !1;
443
+ }
444
+ if (U) return;
445
+ if (e === "caught-up" && (W.value = !1), X.isActive.value) {
446
+ K = void 0, q = !1, J = 0, Y(ke);
447
+ return;
448
+ }
449
+ K === void 0 && (K = Date.now(), q = !!X.error.value);
450
+ let t = Date.now() - K;
451
+ if (e === "caught-up" && t >= (q ? je : Ae) || t >= Me) {
452
+ pt();
453
+ return;
454
+ }
455
+ let n = dt[Math.min(J, dt.length - 1)];
456
+ J += 1, Y(n);
457
+ }
458
+ let ht = (e = 1200) => {
459
+ Y(e);
460
+ }, X = Ce({
461
+ fetchGrant: async () => {
462
+ let e = await z.value.createVoiceSession(O.agentId, N.localChatId, {
463
+ deviceContext: N.buildDeviceContext(),
464
+ externalContext: N.externalContext
465
+ });
466
+ return e.chatId !== N.localChatId && (N.localChatId = e.chatId), e;
467
+ },
468
+ closeGrant: (e) => z.value.closeVoiceSession(O.agentId, e),
469
+ onTranscript: (t) => {
470
+ if (t.role !== "user") {
471
+ W.value = !1;
472
+ return;
473
+ }
474
+ W.value = !0, tt({
475
+ id: `${n}user-${e()}`,
476
+ role: "user",
477
+ parts: [{
478
+ type: "text",
479
+ text: t.text
480
+ }]
481
+ });
482
+ },
483
+ onTurnEnd: () => {
484
+ ht();
485
+ }
486
+ });
487
+ se(() => X.error.value, (e) => {
488
+ e && (W.value = !1);
489
+ });
490
+ let gt = m(() => fe.value?.enabled === !0), _t = m(() => X.error.value ? "error" : X.isConnecting.value ? "connecting" : X.isSpeaking.value ? "speaking" : X.isActive.value ? "listening" : "idle"), vt = m(() => {
491
+ let e = X.error.value;
492
+ if (e) return /took too long/i.test(e) ? V("message.voiceTookTooLong") : /cascade|no response|custom_llm_error/i.test(e) ? V("message.voiceNoAnswer") : V("message.voiceInterrupted");
493
+ }), yt = m(() => X.isSpeaking.value ? "output" : "input"), bt = () => X.readLevel(yt.value), xt = () => X.readSpectrum(yt.value), St = async () => {
494
+ H.value = !1, await X.start(), X.isActive.value && (pt(), Y(ke));
495
+ }, Ct = async () => {
496
+ W.value = !1, await X.stop(), !U && ht(0);
497
+ }, wt = () => {
498
+ X.dismissError();
499
+ }, Tt = async () => {
500
+ X.dismissError(), await X.stop(), await St();
501
+ }, Z = (e) => e?.toolCallId ?? "", Q = D(/* @__PURE__ */ new Set()), Et = (e) => Q.value.has(Z(e)), Dt = D(/* @__PURE__ */ new Map()), $ = (e, t) => X.isActive.value ? !X.sendUserMessage(t) || (Q.value = new Set(Q.value).add(Z(e)), ht(), !0) : !1, Ot = (e, t, n) => {
502
+ $(t, s(t, n)) || B({
503
+ tool: e,
504
+ toolCallId: Z(t),
505
+ output: n
506
+ });
507
+ }, kt = (e) => {
508
+ let t = e.confirmed ? V("message.voiceConfirmed") : V("message.voiceCancelled");
509
+ if ($({ toolCallId: e.toolCallId }, t)) {
510
+ Q.value.has(e.toolCallId) && (Dt.value = new Map(Dt.value).set(e.toolCallId, e.confirmed));
511
+ return;
512
+ }
513
+ B({
514
+ tool: "requestConfirm",
515
+ toolCallId: e.toolCallId,
516
+ output: e.confirmed ? "confirmed" : "cancelled"
517
+ });
518
+ }, At = (e, t) => {
519
+ $(e, t) || (R.value = t, He());
520
+ }, jt = (e, t) => {
521
+ let n = t.error ? V("message.voiceLocationRefused") : V("message.voiceLocationShared", { place: t.displayName ?? `${t.latitude}, ${t.longitude}` });
522
+ $(e, n) || B({
523
+ tool: "requestGeolocation",
524
+ toolCallId: Z(e),
525
+ output: t
526
+ });
527
+ }, Mt = (e, t) => {
528
+ $(e, V("message.voiceConnectionDone")) || B({
529
+ tool: "requestOAuthConnection",
530
+ toolCallId: Z(e),
531
+ output: {
532
+ connected: !0,
533
+ mcpServerId: t
534
+ }
535
+ });
536
+ }, Nt = () => {
537
+ H.value = !H.value, X.setMuted(H.value);
538
+ };
539
+ return te(() => {
540
+ U = !0, pt();
541
+ }), (e, t) => {
542
+ let n = d;
543
+ return E(), _("div", {
544
+ ref_key: "chatViewEl",
545
+ ref: st,
546
+ class: T(["pk-chatbot-view-chat", {
547
+ "pk-chatbot-view-chat--dragover": j(ut) && j(F)?.enabled,
548
+ "pk-chatbot-view-chat--empty": at.value
549
+ }])
550
+ }, [
551
+ x(p, {
552
+ name: "pk-chatbot-view-chat-fade",
553
+ mode: "out-in"
554
+ }, {
555
+ default: M(() => [at.value ? (E(), h(u, {
556
+ key: 0,
557
+ greeting: j(ot),
558
+ logo: j(P)?.logo,
559
+ name: j(N).name
560
+ }, null, 8, [
561
+ "greeting",
562
+ "logo",
563
+ "name"
564
+ ])) : (E(), h(i, {
565
+ key: 1,
566
+ class: "flex flex-col flex-1 min-h-0 p-md overflow-y-auto",
567
+ interactive: "",
568
+ messages: j(he),
569
+ "confirm-verdicts-on-call": Dt.value,
570
+ status: j(L).status,
571
+ error: j(L).error,
572
+ "main-color": j(P)?.mainColor,
573
+ "text-color": j(P)?.textColor,
574
+ "revised-answers": j(I),
575
+ actions: j(pe),
576
+ "message-feedbacks": j(ge),
577
+ "feedback-message-id": j(_e)?.id,
578
+ "feedback-loading": j(ve),
579
+ "feedback-submitted": j(ye),
580
+ "feedback-error": j(be),
581
+ "show-extended-steps": j(P)?.showExtendedSteps,
582
+ "awaiting-spoken-answer": W.value,
583
+ "is-dark": j(Ve),
584
+ "show-scroll-to-bottom": r.modifier === "fullscreen",
585
+ onFeedbackSubmit: t[0] ||= (e) => j(Je)(e),
586
+ onFeedbackClose: t[1] ||= (e) => _e.value = void 0,
587
+ onRegenerate: j(We),
588
+ onAutoRetry: j(We),
589
+ onResetChat: j(Xe),
590
+ onShowInfo: t[2] ||= (e) => A("show-info", e),
591
+ onRevise: t[3] ||= (e) => A("revise", e),
592
+ onUpvote: j(Ge),
593
+ onDownvote: j(Ke),
594
+ onFeedback: j(qe),
595
+ onApprovalRespond: j(Ze),
596
+ onConfirmRespond: kt
597
+ }, {
598
+ "tool-showContactForm": M(({ part: e }) => [x(j(b), {
599
+ part: e,
600
+ readonly: !j(Le),
601
+ submitted: j(xe),
602
+ loading: j(Ne),
603
+ error: j(Pe),
604
+ "privacy-policy-notice": j(P)?.privacyPolicyNotice,
605
+ onSubmit: j(Ye)
606
+ }, null, 8, [
607
+ "part",
608
+ "readonly",
609
+ "submitted",
610
+ "loading",
611
+ "error",
612
+ "privacy-policy-notice",
613
+ "onSubmit"
614
+ ])]),
615
+ "tool-showSuggestedReply": M(({ part: e }) => [x(j(C), {
616
+ part: e,
617
+ onSelect: (t) => At(e, t)
618
+ }, null, 8, ["part", "onSelect"])]),
619
+ "tool-showSources": M(({ part: e }) => [x(j(ee), {
620
+ part: e,
621
+ "on-expand-context": ct,
622
+ "on-download": lt
623
+ }, null, 8, ["part"])]),
624
+ "tool-showForm": M(({ part: e }) => [x(p, { mode: "out-in" }, {
625
+ default: M(() => [x(j(f), {
626
+ part: e,
627
+ answered: Et(e),
628
+ onSelect: (t) => Ot("showForm", e, t)
629
+ }, null, 8, [
630
+ "part",
631
+ "answered",
632
+ "onSelect"
633
+ ])]),
634
+ _: 2
635
+ }, 1024)]),
636
+ "tool-showMultipleChoice": M(({ part: e }) => [x(p, { mode: "out-in" }, {
637
+ default: M(() => [x(j(f), {
638
+ part: e,
639
+ "allow-custom-answer": "",
640
+ answered: Et(e),
641
+ onSelect: (t) => Ot("showMultipleChoice", e, t)
642
+ }, null, 8, [
643
+ "part",
644
+ "answered",
645
+ "onSelect"
646
+ ])]),
647
+ _: 2
648
+ }, 1024)]),
649
+ "tool-requestOAuthConnection": M(({ part: e }) => [x(j(re), {
650
+ part: e,
651
+ "resolve-connection": (e) => j(z).getOAuthAuthorizeUrl(O.agentId, e),
652
+ "check-connection": (e) => j(z).getOAuthConnectionStatus(O.agentId, e),
653
+ onConnected: (t) => Mt(e, t)
654
+ }, null, 8, [
655
+ "part",
656
+ "resolve-connection",
657
+ "check-connection",
658
+ "onConnected"
659
+ ])]),
660
+ "tool-requestGeolocation": M(({ part: e }) => [x(j(ne), {
661
+ part: e,
662
+ "call-live": j(X).isActive.value,
663
+ "reverse-geocode": (e, t) => j(z).reverseGeocode(e, t),
664
+ onResult: (t) => jt(e, t)
665
+ }, null, 8, [
666
+ "part",
667
+ "call-live",
668
+ "reverse-geocode",
669
+ "onResult"
670
+ ])]),
671
+ "tool-showLocation": M(({ part: e }) => [x(j(ie), {
672
+ part: e,
673
+ "is-dark": j(Ve),
674
+ "main-color": j(P)?.mainColor,
675
+ "forward-geocode": (e, t) => j(z).forwardGeocode(e, t)
676
+ }, null, 8, [
677
+ "part",
678
+ "is-dark",
679
+ "main-color",
680
+ "forward-geocode"
681
+ ])]),
682
+ "tool-showDiagram": M(({ part: e }) => [x(j(ae), {
683
+ part: e,
684
+ "is-dark": j(Ve)
685
+ }, null, 8, ["part", "is-dark"])]),
686
+ _: 1
687
+ }, 8, [
688
+ "messages",
689
+ "confirm-verdicts-on-call",
690
+ "status",
691
+ "error",
692
+ "main-color",
693
+ "text-color",
694
+ "revised-answers",
695
+ "actions",
696
+ "message-feedbacks",
697
+ "feedback-message-id",
698
+ "feedback-loading",
699
+ "feedback-submitted",
700
+ "feedback-error",
701
+ "show-extended-steps",
702
+ "awaiting-spoken-answer",
703
+ "is-dark",
704
+ "show-scroll-to-bottom",
705
+ "onRegenerate",
706
+ "onAutoRetry",
707
+ "onResetChat",
708
+ "onUpvote",
709
+ "onDownvote",
710
+ "onFeedback",
711
+ "onApprovalRespond"
712
+ ]))]),
713
+ _: 1
714
+ }),
715
+ v("div", we, [x(p, { name: "pk-chatbot-view-chat-fade" }, {
716
+ default: M(() => [at.value ? (E(), h(me, {
717
+ key: 0,
718
+ class: "pk-chatbot-view-chat__aurora",
719
+ "source-selector": ".pk-chatbot-input__form"
720
+ })) : g("", !0)]),
721
+ _: 1
722
+ }), j(Ie) ? (E(), _("div", Te, k(j(V)("message.chatErrorConversationBlocked")), 1)) : _t.value === "idle" ? (E(), h(l, {
723
+ key: 2,
724
+ modelValue: j(R),
725
+ "onUpdate:modelValue": t[4] ||= (e) => w(R) ? R.value = e : null,
726
+ "pending-attachments": j(Re),
727
+ "onUpdate:pendingAttachments": t[5] ||= (e) => w(Re) ? Re.value = e : null,
728
+ placeholder: j(Fe),
729
+ "dismissable-notice": j(rt) && j(L).messages.length <= 1 ? j(rt) : void 0,
730
+ status: j(L).status,
731
+ "max-message-length": j(P)?.maxMessageLength,
732
+ "file-upload": j(F),
733
+ "attachment-limit-reached": j(ze),
734
+ "attachment-notice": nt.value,
735
+ "voice-enabled": gt.value,
736
+ onStopGeneration: j(Ue),
737
+ onSubmit: j(He),
738
+ onFileSelect: j(Qe),
739
+ onDismissAttachmentNotice: j($e),
740
+ onVoiceStart: St
741
+ }, y({ _: 2 }, [r.modifier === "fullscreen" ? {
742
+ name: "prepend",
743
+ fn: M(() => [v("span", Ee, [x(o, {
744
+ modifiers: "surface",
745
+ class: "pk-chatbot-view-chat__agent-chip-avatar",
746
+ "img-src": j(P)?.logo,
747
+ name: j(N).name
748
+ }, null, 8, ["img-src", "name"]), j(N).name ? (E(), _("strong", De, k(j(N).name), 1)) : g("", !0)])]),
749
+ key: "0"
750
+ } : void 0]), 1032, [
751
+ "modelValue",
752
+ "pending-attachments",
753
+ "placeholder",
754
+ "dismissable-notice",
755
+ "status",
756
+ "max-message-length",
757
+ "file-upload",
758
+ "attachment-limit-reached",
759
+ "attachment-notice",
760
+ "voice-enabled",
761
+ "onStopGeneration",
762
+ "onSubmit",
763
+ "onFileSelect",
764
+ "onDismissAttachmentNotice"
765
+ ])) : (E(), h(Se, {
766
+ key: 1,
767
+ state: _t.value,
768
+ sample: bt,
769
+ spectrum: xt,
770
+ "remaining-seconds": j(X).remainingSeconds.value,
771
+ muted: H.value,
772
+ error: vt.value,
773
+ "raw-error": j(X).error.value,
774
+ live: j(X).isActive.value,
775
+ class: "pk-chatbot-view-chat__voice",
776
+ onToggleMute: Nt,
777
+ onHangUp: Ct,
778
+ onRetry: Tt,
779
+ onDismiss: wt
780
+ }, null, 8, [
781
+ "state",
782
+ "remaining-seconds",
783
+ "muted",
784
+ "error",
785
+ "raw-error",
786
+ "live"
787
+ ]))]),
788
+ x(p, null, {
789
+ default: M(() => [j(ut) && j(F)?.enabled ? (E(), _("div", Oe, [x(n, {
790
+ name: "ri:upload-cloud-2-line",
791
+ class: "pk-chatbot-view-chat__drop-overlay-icon"
792
+ }), v("span", null, k(j(V)("action.dropFile")), 1)])) : g("", !0)]),
793
+ _: 1
794
+ })
795
+ ], 2);
796
+ };
797
+ }
798
+ });
799
+ //#endregion
800
+ export { me as i, Se as n, L as r, Ne as t };
801
+
802
+ //# sourceMappingURL=PkChatbotViewChat-0g30_sQH.js.map