acai-ui-library 0.1.21 → 0.1.22
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/components/app-launcher.cjs +231 -0
- package/dist/components/app-launcher.cjs.map +1 -0
- package/dist/components/app-launcher.d.cts +24 -0
- package/dist/components/app-launcher.d.ts +24 -0
- package/dist/components/app-launcher.js +197 -0
- package/dist/components/app-launcher.js.map +1 -0
- package/dist/components/calendar.cjs +13 -5
- package/dist/components/calendar.cjs.map +1 -1
- package/dist/components/calendar.js +15 -7
- package/dist/components/calendar.js.map +1 -1
- package/dist/components/date-picker.cjs +17 -7
- package/dist/components/date-picker.cjs.map +1 -1
- package/dist/components/date-picker.js +23 -13
- package/dist/components/date-picker.js.map +1 -1
- package/dist/components/date-time-picker.cjs +13 -5
- package/dist/components/date-time-picker.cjs.map +1 -1
- package/dist/components/date-time-picker.js +28 -20
- package/dist/components/date-time-picker.js.map +1 -1
- package/dist/components/help-widget/app-id-typecheck.cjs +34 -0
- package/dist/components/help-widget/app-id-typecheck.cjs.map +1 -0
- package/dist/components/help-widget/app-id-typecheck.d.cts +17 -0
- package/dist/components/help-widget/app-id-typecheck.d.ts +17 -0
- package/dist/components/help-widget/app-id-typecheck.js +8 -0
- package/dist/components/help-widget/app-id-typecheck.js.map +1 -0
- package/dist/components/help-widget/consent-dialog.cjs +276 -0
- package/dist/components/help-widget/consent-dialog.cjs.map +1 -0
- package/dist/components/help-widget/consent-dialog.d.cts +17 -0
- package/dist/components/help-widget/consent-dialog.d.ts +17 -0
- package/dist/components/help-widget/consent-dialog.js +239 -0
- package/dist/components/help-widget/consent-dialog.js.map +1 -0
- package/dist/components/help-widget/help-session-banner.cjs +85 -0
- package/dist/components/help-widget/help-session-banner.cjs.map +1 -0
- package/dist/components/help-widget/help-session-banner.d.cts +17 -0
- package/dist/components/help-widget/help-session-banner.d.ts +17 -0
- package/dist/components/help-widget/help-session-banner.js +50 -0
- package/dist/components/help-widget/help-session-banner.js.map +1 -0
- package/dist/components/help-widget/help-widget.cjs +503 -0
- package/dist/components/help-widget/help-widget.cjs.map +1 -0
- package/dist/components/help-widget/help-widget.d.cts +32 -0
- package/dist/components/help-widget/help-widget.d.ts +32 -0
- package/dist/components/help-widget/help-widget.js +468 -0
- package/dist/components/help-widget/help-widget.js.map +1 -0
- package/dist/components/help-widget/highlight-overlay.cjs +84 -0
- package/dist/components/help-widget/highlight-overlay.cjs.map +1 -0
- package/dist/components/help-widget/highlight-overlay.d.cts +24 -0
- package/dist/components/help-widget/highlight-overlay.d.ts +24 -0
- package/dist/components/help-widget/highlight-overlay.js +49 -0
- package/dist/components/help-widget/highlight-overlay.js.map +1 -0
- package/dist/components/help-widget/use-help-session.cjs +85 -0
- package/dist/components/help-widget/use-help-session.cjs.map +1 -0
- package/dist/components/help-widget/use-help-session.d.cts +46 -0
- package/dist/components/help-widget/use-help-session.d.ts +46 -0
- package/dist/components/help-widget/use-help-session.js +50 -0
- package/dist/components/help-widget/use-help-session.js.map +1 -0
- package/dist/index.cjs +580 -82
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +615 -126
- package/dist/index.js.map +1 -1
- package/dist/lib/app-ids.cjs +58 -0
- package/dist/lib/app-ids.cjs.map +1 -0
- package/dist/lib/app-ids.d.cts +12 -0
- package/dist/lib/app-ids.d.ts +12 -0
- package/dist/lib/app-ids.js +32 -0
- package/dist/lib/app-ids.js.map +1 -0
- package/dist/lib/mask-snapshot.cjs +66 -0
- package/dist/lib/mask-snapshot.cjs.map +1 -0
- package/dist/lib/mask-snapshot.d.cts +16 -0
- package/dist/lib/mask-snapshot.d.ts +16 -0
- package/dist/lib/mask-snapshot.js +41 -0
- package/dist/lib/mask-snapshot.js.map +1 -0
- package/package.json +2 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
interface HighlightTarget {
|
|
4
|
+
/** A CSS selector the agent asked to highlight. Takes precedence over role/name. */
|
|
5
|
+
selector?: string;
|
|
6
|
+
/** Accessible role, matched with an accessible-name fallback when there is no selector. */
|
|
7
|
+
role?: string;
|
|
8
|
+
name?: string;
|
|
9
|
+
}
|
|
10
|
+
interface HighlightOverlayProps {
|
|
11
|
+
/** The current target, or null to clear the highlight. */
|
|
12
|
+
target: HighlightTarget | null;
|
|
13
|
+
/** Called after the overlay clears itself (target becomes null). */
|
|
14
|
+
onDismiss?: () => void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Draws an outline + tooltip around the element the support agent names (acai-ai-platform#2831).
|
|
18
|
+
*
|
|
19
|
+
* It only ever points at something - it never dispatches a click or any other interaction on
|
|
20
|
+
* the user's behalf.
|
|
21
|
+
*/
|
|
22
|
+
declare function HighlightOverlay({ target, onDismiss }: HighlightOverlayProps): react_jsx_runtime.JSX.Element | null;
|
|
23
|
+
|
|
24
|
+
export { HighlightOverlay, type HighlightOverlayProps, type HighlightTarget };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// src/components/help-widget/highlight-overlay.tsx
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
function findTarget({ selector, role, name }) {
|
|
5
|
+
if (selector) return document.querySelector(selector);
|
|
6
|
+
if (role) {
|
|
7
|
+
const candidates = document.querySelectorAll(`[role="${role}"]`);
|
|
8
|
+
for (const el of candidates) {
|
|
9
|
+
const accessibleName = el.getAttribute("aria-label") ?? el.textContent?.trim() ?? "";
|
|
10
|
+
if (!name || accessibleName.includes(name)) return el;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
function HighlightOverlay({ target, onDismiss }) {
|
|
16
|
+
const [rect, setRect] = React.useState(null);
|
|
17
|
+
React.useEffect(() => {
|
|
18
|
+
if (!target) {
|
|
19
|
+
setRect(null);
|
|
20
|
+
onDismiss?.();
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const el = findTarget(target);
|
|
24
|
+
setRect(el ? el.getBoundingClientRect() : null);
|
|
25
|
+
}, [target, onDismiss]);
|
|
26
|
+
if (!target || !rect) return null;
|
|
27
|
+
return /* @__PURE__ */ jsx(
|
|
28
|
+
"div",
|
|
29
|
+
{
|
|
30
|
+
"data-help-widget-highlight": "",
|
|
31
|
+
role: "presentation",
|
|
32
|
+
"aria-hidden": "true",
|
|
33
|
+
style: {
|
|
34
|
+
position: "fixed",
|
|
35
|
+
left: rect.left - 4,
|
|
36
|
+
top: rect.top - 4,
|
|
37
|
+
width: rect.width + 8,
|
|
38
|
+
height: rect.height + 8,
|
|
39
|
+
pointerEvents: "none",
|
|
40
|
+
zIndex: 2147483e3
|
|
41
|
+
},
|
|
42
|
+
className: "rounded-md ring-2 ring-primary ring-offset-2"
|
|
43
|
+
}
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
export {
|
|
47
|
+
HighlightOverlay
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=highlight-overlay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/help-widget/highlight-overlay.tsx"],"sourcesContent":["import * as React from \"react\"\n\nexport interface HighlightTarget {\n /** A CSS selector the agent asked to highlight. Takes precedence over role/name. */\n selector?: string\n /** Accessible role, matched with an accessible-name fallback when there is no selector. */\n role?: string\n name?: string\n}\n\nexport interface HighlightOverlayProps {\n /** The current target, or null to clear the highlight. */\n target: HighlightTarget | null\n /** Called after the overlay clears itself (target becomes null). */\n onDismiss?: () => void\n}\n\nfunction findTarget({ selector, role, name }: HighlightTarget): HTMLElement | null {\n if (selector) return document.querySelector<HTMLElement>(selector)\n if (role) {\n const candidates = document.querySelectorAll<HTMLElement>(`[role=\"${role}\"]`)\n for (const el of candidates) {\n const accessibleName = el.getAttribute(\"aria-label\") ?? el.textContent?.trim() ?? \"\"\n if (!name || accessibleName.includes(name)) return el\n }\n }\n return null\n}\n\n/**\n * Draws an outline + tooltip around the element the support agent names (acai-ai-platform#2831).\n *\n * It only ever points at something - it never dispatches a click or any other interaction on\n * the user's behalf.\n */\nexport function HighlightOverlay({ target, onDismiss }: HighlightOverlayProps) {\n const [rect, setRect] = React.useState<DOMRect | null>(null)\n\n React.useEffect(() => {\n if (!target) {\n setRect(null)\n onDismiss?.()\n return\n }\n const el = findTarget(target)\n setRect(el ? el.getBoundingClientRect() : null)\n }, [target, onDismiss])\n\n if (!target || !rect) return null\n\n return (\n <div\n data-help-widget-highlight=\"\"\n role=\"presentation\"\n aria-hidden=\"true\"\n style={{\n position: \"fixed\",\n left: rect.left - 4,\n top: rect.top - 4,\n width: rect.width + 8,\n height: rect.height + 8,\n pointerEvents: \"none\",\n zIndex: 2147483000,\n }}\n className=\"rounded-md ring-2 ring-primary ring-offset-2\"\n />\n )\n}\n"],"mappings":";AAAA,YAAY,WAAW;AAmDnB;AAlCJ,SAAS,WAAW,EAAE,UAAU,MAAM,KAAK,GAAwC;AACjF,MAAI,SAAU,QAAO,SAAS,cAA2B,QAAQ;AACjE,MAAI,MAAM;AACR,UAAM,aAAa,SAAS,iBAA8B,UAAU,IAAI,IAAI;AAC5E,eAAW,MAAM,YAAY;AAC3B,YAAM,iBAAiB,GAAG,aAAa,YAAY,KAAK,GAAG,aAAa,KAAK,KAAK;AAClF,UAAI,CAAC,QAAQ,eAAe,SAAS,IAAI,EAAG,QAAO;AAAA,IACrD;AAAA,EACF;AACA,SAAO;AACT;AAQO,SAAS,iBAAiB,EAAE,QAAQ,UAAU,GAA0B;AAC7E,QAAM,CAAC,MAAM,OAAO,IAAU,eAAyB,IAAI;AAE3D,EAAM,gBAAU,MAAM;AACpB,QAAI,CAAC,QAAQ;AACX,cAAQ,IAAI;AACZ,kBAAY;AACZ;AAAA,IACF;AACA,UAAM,KAAK,WAAW,MAAM;AAC5B,YAAQ,KAAK,GAAG,sBAAsB,IAAI,IAAI;AAAA,EAChD,GAAG,CAAC,QAAQ,SAAS,CAAC;AAEtB,MAAI,CAAC,UAAU,CAAC,KAAM,QAAO;AAE7B,SACE;AAAA,IAAC;AAAA;AAAA,MACC,8BAA2B;AAAA,MAC3B,MAAK;AAAA,MACL,eAAY;AAAA,MACZ,OAAO;AAAA,QACL,UAAU;AAAA,QACV,MAAM,KAAK,OAAO;AAAA,QAClB,KAAK,KAAK,MAAM;AAAA,QAChB,OAAO,KAAK,QAAQ;AAAA,QACpB,QAAQ,KAAK,SAAS;AAAA,QACtB,eAAe;AAAA,QACf,QAAQ;AAAA,MACV;AAAA,MACA,WAAU;AAAA;AAAA,EACZ;AAEJ;","names":[]}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/components/help-widget/use-help-session.ts
|
|
31
|
+
var use_help_session_exports = {};
|
|
32
|
+
__export(use_help_session_exports, {
|
|
33
|
+
useHelpSession: () => useHelpSession
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(use_help_session_exports);
|
|
36
|
+
var React = __toESM(require("react"), 1);
|
|
37
|
+
function defaultCreateSession(baseUrl) {
|
|
38
|
+
return async (request) => {
|
|
39
|
+
const res = await fetch(`${baseUrl}/support/ai/session`, {
|
|
40
|
+
method: "POST",
|
|
41
|
+
headers: { "Content-Type": "application/json" },
|
|
42
|
+
body: JSON.stringify(request)
|
|
43
|
+
});
|
|
44
|
+
if (!res.ok) throw new Error(`support/ai/session failed: ${res.status}`);
|
|
45
|
+
return await res.json();
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
async function defaultConnectRoom(session) {
|
|
49
|
+
const { Room } = await import("livekit-client");
|
|
50
|
+
const room = new Room();
|
|
51
|
+
await room.connect(session.url, session.token);
|
|
52
|
+
return { disconnect: () => room.disconnect() };
|
|
53
|
+
}
|
|
54
|
+
function useHelpSession({
|
|
55
|
+
appId,
|
|
56
|
+
route,
|
|
57
|
+
createSession,
|
|
58
|
+
connectRoom = defaultConnectRoom,
|
|
59
|
+
baseUrl = ""
|
|
60
|
+
}) {
|
|
61
|
+
const [status, setStatus] = React.useState("idle");
|
|
62
|
+
const [language, setLanguage] = React.useState("en");
|
|
63
|
+
const connectionRef = React.useRef(null);
|
|
64
|
+
const createSessionRef = React.useRef(createSession ?? defaultCreateSession(baseUrl));
|
|
65
|
+
createSessionRef.current = createSession ?? defaultCreateSession(baseUrl);
|
|
66
|
+
const requestSession = React.useCallback(() => setStatus("consent-pending"), []);
|
|
67
|
+
const deny = React.useCallback(() => setStatus("idle"), []);
|
|
68
|
+
const allow = React.useCallback(async () => {
|
|
69
|
+
const session = await createSessionRef.current({ appId, language, route });
|
|
70
|
+
connectionRef.current = await connectRoom(session);
|
|
71
|
+
setStatus("active");
|
|
72
|
+
}, [appId, language, route, connectRoom]);
|
|
73
|
+
const stop = React.useCallback(() => {
|
|
74
|
+
connectionRef.current?.disconnect();
|
|
75
|
+
connectionRef.current = null;
|
|
76
|
+
setStatus("idle");
|
|
77
|
+
}, []);
|
|
78
|
+
React.useEffect(() => () => connectionRef.current?.disconnect(), []);
|
|
79
|
+
return { status, language, setLanguage, requestSession, allow, deny, stop };
|
|
80
|
+
}
|
|
81
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
82
|
+
0 && (module.exports = {
|
|
83
|
+
useHelpSession
|
|
84
|
+
});
|
|
85
|
+
//# sourceMappingURL=use-help-session.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/help-widget/use-help-session.ts"],"sourcesContent":["import * as React from \"react\"\nimport type { SupportAppId } from \"../../lib/app-ids\"\n\nexport type SupportLanguage = \"en\" | \"hi\" | \"mr\"\n\nexport interface SupportSessionRequest {\n appId: SupportAppId\n language: SupportLanguage\n route: string\n}\n\nexport interface SupportSession {\n url: string\n token: string\n}\n\nexport interface SupportRoomConnection {\n disconnect: () => void\n}\n\nexport type CreateSupportSession = (request: SupportSessionRequest) => Promise<SupportSession>\n\nexport type ConnectSupportRoom = (session: SupportSession) => Promise<SupportRoomConnection>\n\nexport type HelpSessionStatus = \"idle\" | \"consent-pending\" | \"active\"\n\nexport interface UseHelpSessionOptions {\n appId: SupportAppId\n route: string\n /** Defaults to POSTing to `${baseUrl}/support/ai/session`. Override in tests, or to point at a different host. */\n createSession?: CreateSupportSession\n /** Defaults to connecting a LiveKit Room. Override in tests - jsdom cannot open a real room. */\n connectRoom?: ConnectSupportRoom\n baseUrl?: string\n}\n\nfunction defaultCreateSession(baseUrl: string): CreateSupportSession {\n return async (request) => {\n const res = await fetch(`${baseUrl}/support/ai/session`, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify(request),\n })\n if (!res.ok) throw new Error(`support/ai/session failed: ${res.status}`)\n return (await res.json()) as SupportSession\n }\n}\n\nasync function defaultConnectRoom(session: SupportSession): Promise<SupportRoomConnection> {\n const { Room } = await import(\"livekit-client\")\n const room = new Room()\n await room.connect(session.url, session.token)\n return { disconnect: () => room.disconnect() }\n}\n\n/**\n * Session/consent/voice state for HelpWidget (acai-ai-platform#2831).\n *\n * `allow()` is the only function that starts a session - it is wired to the consent\n * dialog's Allow button and nothing else calls it, so no code path from chat or voice\n * content can grant consent.\n */\nexport function useHelpSession({\n appId,\n route,\n createSession,\n connectRoom = defaultConnectRoom,\n baseUrl = \"\",\n}: UseHelpSessionOptions) {\n const [status, setStatus] = React.useState<HelpSessionStatus>(\"idle\")\n const [language, setLanguage] = React.useState<SupportLanguage>(\"en\")\n const connectionRef = React.useRef<SupportRoomConnection | null>(null)\n const createSessionRef = React.useRef(createSession ?? defaultCreateSession(baseUrl))\n createSessionRef.current = createSession ?? defaultCreateSession(baseUrl)\n\n const requestSession = React.useCallback(() => setStatus(\"consent-pending\"), [])\n\n const deny = React.useCallback(() => setStatus(\"idle\"), [])\n\n const allow = React.useCallback(async () => {\n const session = await createSessionRef.current({ appId, language, route })\n connectionRef.current = await connectRoom(session)\n setStatus(\"active\")\n }, [appId, language, route, connectRoom])\n\n const stop = React.useCallback(() => {\n connectionRef.current?.disconnect()\n connectionRef.current = null\n setStatus(\"idle\")\n }, [])\n\n React.useEffect(() => () => connectionRef.current?.disconnect(), [])\n\n return { status, language, setLanguage, requestSession, allow, deny, stop }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,YAAuB;AAoCvB,SAAS,qBAAqB,SAAuC;AACnE,SAAO,OAAO,YAAY;AACxB,UAAM,MAAM,MAAM,MAAM,GAAG,OAAO,uBAAuB;AAAA,MACvD,QAAQ;AAAA,MACR,SAAS,EAAE,gBAAgB,mBAAmB;AAAA,MAC9C,MAAM,KAAK,UAAU,OAAO;AAAA,IAC9B,CAAC;AACD,QAAI,CAAC,IAAI,GAAI,OAAM,IAAI,MAAM,8BAA8B,IAAI,MAAM,EAAE;AACvE,WAAQ,MAAM,IAAI,KAAK;AAAA,EACzB;AACF;AAEA,eAAe,mBAAmB,SAAyD;AACzF,QAAM,EAAE,KAAK,IAAI,MAAM,OAAO,gBAAgB;AAC9C,QAAM,OAAO,IAAI,KAAK;AACtB,QAAM,KAAK,QAAQ,QAAQ,KAAK,QAAQ,KAAK;AAC7C,SAAO,EAAE,YAAY,MAAM,KAAK,WAAW,EAAE;AAC/C;AASO,SAAS,eAAe;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA,cAAc;AAAA,EACd,UAAU;AACZ,GAA0B;AACxB,QAAM,CAAC,QAAQ,SAAS,IAAU,eAA4B,MAAM;AACpE,QAAM,CAAC,UAAU,WAAW,IAAU,eAA0B,IAAI;AACpE,QAAM,gBAAsB,aAAqC,IAAI;AACrE,QAAM,mBAAyB,aAAO,iBAAiB,qBAAqB,OAAO,CAAC;AACpF,mBAAiB,UAAU,iBAAiB,qBAAqB,OAAO;AAExE,QAAM,iBAAuB,kBAAY,MAAM,UAAU,iBAAiB,GAAG,CAAC,CAAC;AAE/E,QAAM,OAAa,kBAAY,MAAM,UAAU,MAAM,GAAG,CAAC,CAAC;AAE1D,QAAM,QAAc,kBAAY,YAAY;AAC1C,UAAM,UAAU,MAAM,iBAAiB,QAAQ,EAAE,OAAO,UAAU,MAAM,CAAC;AACzE,kBAAc,UAAU,MAAM,YAAY,OAAO;AACjD,cAAU,QAAQ;AAAA,EACpB,GAAG,CAAC,OAAO,UAAU,OAAO,WAAW,CAAC;AAExC,QAAM,OAAa,kBAAY,MAAM;AACnC,kBAAc,SAAS,WAAW;AAClC,kBAAc,UAAU;AACxB,cAAU,MAAM;AAAA,EAClB,GAAG,CAAC,CAAC;AAEL,EAAM,gBAAU,MAAM,MAAM,cAAc,SAAS,WAAW,GAAG,CAAC,CAAC;AAEnE,SAAO,EAAE,QAAQ,UAAU,aAAa,gBAAgB,OAAO,MAAM,KAAK;AAC5E;","names":[]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { SupportAppId } from '../../lib/app-ids.cjs';
|
|
3
|
+
|
|
4
|
+
type SupportLanguage = "en" | "hi" | "mr";
|
|
5
|
+
interface SupportSessionRequest {
|
|
6
|
+
appId: SupportAppId;
|
|
7
|
+
language: SupportLanguage;
|
|
8
|
+
route: string;
|
|
9
|
+
}
|
|
10
|
+
interface SupportSession {
|
|
11
|
+
url: string;
|
|
12
|
+
token: string;
|
|
13
|
+
}
|
|
14
|
+
interface SupportRoomConnection {
|
|
15
|
+
disconnect: () => void;
|
|
16
|
+
}
|
|
17
|
+
type CreateSupportSession = (request: SupportSessionRequest) => Promise<SupportSession>;
|
|
18
|
+
type ConnectSupportRoom = (session: SupportSession) => Promise<SupportRoomConnection>;
|
|
19
|
+
type HelpSessionStatus = "idle" | "consent-pending" | "active";
|
|
20
|
+
interface UseHelpSessionOptions {
|
|
21
|
+
appId: SupportAppId;
|
|
22
|
+
route: string;
|
|
23
|
+
/** Defaults to POSTing to `${baseUrl}/support/ai/session`. Override in tests, or to point at a different host. */
|
|
24
|
+
createSession?: CreateSupportSession;
|
|
25
|
+
/** Defaults to connecting a LiveKit Room. Override in tests - jsdom cannot open a real room. */
|
|
26
|
+
connectRoom?: ConnectSupportRoom;
|
|
27
|
+
baseUrl?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Session/consent/voice state for HelpWidget (acai-ai-platform#2831).
|
|
31
|
+
*
|
|
32
|
+
* `allow()` is the only function that starts a session - it is wired to the consent
|
|
33
|
+
* dialog's Allow button and nothing else calls it, so no code path from chat or voice
|
|
34
|
+
* content can grant consent.
|
|
35
|
+
*/
|
|
36
|
+
declare function useHelpSession({ appId, route, createSession, connectRoom, baseUrl, }: UseHelpSessionOptions): {
|
|
37
|
+
status: HelpSessionStatus;
|
|
38
|
+
language: SupportLanguage;
|
|
39
|
+
setLanguage: React.Dispatch<React.SetStateAction<SupportLanguage>>;
|
|
40
|
+
requestSession: () => void;
|
|
41
|
+
allow: () => Promise<void>;
|
|
42
|
+
deny: () => void;
|
|
43
|
+
stop: () => void;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export { type ConnectSupportRoom, type CreateSupportSession, type HelpSessionStatus, type SupportLanguage, type SupportRoomConnection, type SupportSession, type SupportSessionRequest, type UseHelpSessionOptions, useHelpSession };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { SupportAppId } from '../../lib/app-ids.js';
|
|
3
|
+
|
|
4
|
+
type SupportLanguage = "en" | "hi" | "mr";
|
|
5
|
+
interface SupportSessionRequest {
|
|
6
|
+
appId: SupportAppId;
|
|
7
|
+
language: SupportLanguage;
|
|
8
|
+
route: string;
|
|
9
|
+
}
|
|
10
|
+
interface SupportSession {
|
|
11
|
+
url: string;
|
|
12
|
+
token: string;
|
|
13
|
+
}
|
|
14
|
+
interface SupportRoomConnection {
|
|
15
|
+
disconnect: () => void;
|
|
16
|
+
}
|
|
17
|
+
type CreateSupportSession = (request: SupportSessionRequest) => Promise<SupportSession>;
|
|
18
|
+
type ConnectSupportRoom = (session: SupportSession) => Promise<SupportRoomConnection>;
|
|
19
|
+
type HelpSessionStatus = "idle" | "consent-pending" | "active";
|
|
20
|
+
interface UseHelpSessionOptions {
|
|
21
|
+
appId: SupportAppId;
|
|
22
|
+
route: string;
|
|
23
|
+
/** Defaults to POSTing to `${baseUrl}/support/ai/session`. Override in tests, or to point at a different host. */
|
|
24
|
+
createSession?: CreateSupportSession;
|
|
25
|
+
/** Defaults to connecting a LiveKit Room. Override in tests - jsdom cannot open a real room. */
|
|
26
|
+
connectRoom?: ConnectSupportRoom;
|
|
27
|
+
baseUrl?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Session/consent/voice state for HelpWidget (acai-ai-platform#2831).
|
|
31
|
+
*
|
|
32
|
+
* `allow()` is the only function that starts a session - it is wired to the consent
|
|
33
|
+
* dialog's Allow button and nothing else calls it, so no code path from chat or voice
|
|
34
|
+
* content can grant consent.
|
|
35
|
+
*/
|
|
36
|
+
declare function useHelpSession({ appId, route, createSession, connectRoom, baseUrl, }: UseHelpSessionOptions): {
|
|
37
|
+
status: HelpSessionStatus;
|
|
38
|
+
language: SupportLanguage;
|
|
39
|
+
setLanguage: React.Dispatch<React.SetStateAction<SupportLanguage>>;
|
|
40
|
+
requestSession: () => void;
|
|
41
|
+
allow: () => Promise<void>;
|
|
42
|
+
deny: () => void;
|
|
43
|
+
stop: () => void;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export { type ConnectSupportRoom, type CreateSupportSession, type HelpSessionStatus, type SupportLanguage, type SupportRoomConnection, type SupportSession, type SupportSessionRequest, type UseHelpSessionOptions, useHelpSession };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// src/components/help-widget/use-help-session.ts
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
function defaultCreateSession(baseUrl) {
|
|
4
|
+
return async (request) => {
|
|
5
|
+
const res = await fetch(`${baseUrl}/support/ai/session`, {
|
|
6
|
+
method: "POST",
|
|
7
|
+
headers: { "Content-Type": "application/json" },
|
|
8
|
+
body: JSON.stringify(request)
|
|
9
|
+
});
|
|
10
|
+
if (!res.ok) throw new Error(`support/ai/session failed: ${res.status}`);
|
|
11
|
+
return await res.json();
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
async function defaultConnectRoom(session) {
|
|
15
|
+
const { Room } = await import("livekit-client");
|
|
16
|
+
const room = new Room();
|
|
17
|
+
await room.connect(session.url, session.token);
|
|
18
|
+
return { disconnect: () => room.disconnect() };
|
|
19
|
+
}
|
|
20
|
+
function useHelpSession({
|
|
21
|
+
appId,
|
|
22
|
+
route,
|
|
23
|
+
createSession,
|
|
24
|
+
connectRoom = defaultConnectRoom,
|
|
25
|
+
baseUrl = ""
|
|
26
|
+
}) {
|
|
27
|
+
const [status, setStatus] = React.useState("idle");
|
|
28
|
+
const [language, setLanguage] = React.useState("en");
|
|
29
|
+
const connectionRef = React.useRef(null);
|
|
30
|
+
const createSessionRef = React.useRef(createSession ?? defaultCreateSession(baseUrl));
|
|
31
|
+
createSessionRef.current = createSession ?? defaultCreateSession(baseUrl);
|
|
32
|
+
const requestSession = React.useCallback(() => setStatus("consent-pending"), []);
|
|
33
|
+
const deny = React.useCallback(() => setStatus("idle"), []);
|
|
34
|
+
const allow = React.useCallback(async () => {
|
|
35
|
+
const session = await createSessionRef.current({ appId, language, route });
|
|
36
|
+
connectionRef.current = await connectRoom(session);
|
|
37
|
+
setStatus("active");
|
|
38
|
+
}, [appId, language, route, connectRoom]);
|
|
39
|
+
const stop = React.useCallback(() => {
|
|
40
|
+
connectionRef.current?.disconnect();
|
|
41
|
+
connectionRef.current = null;
|
|
42
|
+
setStatus("idle");
|
|
43
|
+
}, []);
|
|
44
|
+
React.useEffect(() => () => connectionRef.current?.disconnect(), []);
|
|
45
|
+
return { status, language, setLanguage, requestSession, allow, deny, stop };
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
useHelpSession
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=use-help-session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/help-widget/use-help-session.ts"],"sourcesContent":["import * as React from \"react\"\nimport type { SupportAppId } from \"../../lib/app-ids\"\n\nexport type SupportLanguage = \"en\" | \"hi\" | \"mr\"\n\nexport interface SupportSessionRequest {\n appId: SupportAppId\n language: SupportLanguage\n route: string\n}\n\nexport interface SupportSession {\n url: string\n token: string\n}\n\nexport interface SupportRoomConnection {\n disconnect: () => void\n}\n\nexport type CreateSupportSession = (request: SupportSessionRequest) => Promise<SupportSession>\n\nexport type ConnectSupportRoom = (session: SupportSession) => Promise<SupportRoomConnection>\n\nexport type HelpSessionStatus = \"idle\" | \"consent-pending\" | \"active\"\n\nexport interface UseHelpSessionOptions {\n appId: SupportAppId\n route: string\n /** Defaults to POSTing to `${baseUrl}/support/ai/session`. Override in tests, or to point at a different host. */\n createSession?: CreateSupportSession\n /** Defaults to connecting a LiveKit Room. Override in tests - jsdom cannot open a real room. */\n connectRoom?: ConnectSupportRoom\n baseUrl?: string\n}\n\nfunction defaultCreateSession(baseUrl: string): CreateSupportSession {\n return async (request) => {\n const res = await fetch(`${baseUrl}/support/ai/session`, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify(request),\n })\n if (!res.ok) throw new Error(`support/ai/session failed: ${res.status}`)\n return (await res.json()) as SupportSession\n }\n}\n\nasync function defaultConnectRoom(session: SupportSession): Promise<SupportRoomConnection> {\n const { Room } = await import(\"livekit-client\")\n const room = new Room()\n await room.connect(session.url, session.token)\n return { disconnect: () => room.disconnect() }\n}\n\n/**\n * Session/consent/voice state for HelpWidget (acai-ai-platform#2831).\n *\n * `allow()` is the only function that starts a session - it is wired to the consent\n * dialog's Allow button and nothing else calls it, so no code path from chat or voice\n * content can grant consent.\n */\nexport function useHelpSession({\n appId,\n route,\n createSession,\n connectRoom = defaultConnectRoom,\n baseUrl = \"\",\n}: UseHelpSessionOptions) {\n const [status, setStatus] = React.useState<HelpSessionStatus>(\"idle\")\n const [language, setLanguage] = React.useState<SupportLanguage>(\"en\")\n const connectionRef = React.useRef<SupportRoomConnection | null>(null)\n const createSessionRef = React.useRef(createSession ?? defaultCreateSession(baseUrl))\n createSessionRef.current = createSession ?? defaultCreateSession(baseUrl)\n\n const requestSession = React.useCallback(() => setStatus(\"consent-pending\"), [])\n\n const deny = React.useCallback(() => setStatus(\"idle\"), [])\n\n const allow = React.useCallback(async () => {\n const session = await createSessionRef.current({ appId, language, route })\n connectionRef.current = await connectRoom(session)\n setStatus(\"active\")\n }, [appId, language, route, connectRoom])\n\n const stop = React.useCallback(() => {\n connectionRef.current?.disconnect()\n connectionRef.current = null\n setStatus(\"idle\")\n }, [])\n\n React.useEffect(() => () => connectionRef.current?.disconnect(), [])\n\n return { status, language, setLanguage, requestSession, allow, deny, stop }\n}\n"],"mappings":";AAAA,YAAY,WAAW;AAoCvB,SAAS,qBAAqB,SAAuC;AACnE,SAAO,OAAO,YAAY;AACxB,UAAM,MAAM,MAAM,MAAM,GAAG,OAAO,uBAAuB;AAAA,MACvD,QAAQ;AAAA,MACR,SAAS,EAAE,gBAAgB,mBAAmB;AAAA,MAC9C,MAAM,KAAK,UAAU,OAAO;AAAA,IAC9B,CAAC;AACD,QAAI,CAAC,IAAI,GAAI,OAAM,IAAI,MAAM,8BAA8B,IAAI,MAAM,EAAE;AACvE,WAAQ,MAAM,IAAI,KAAK;AAAA,EACzB;AACF;AAEA,eAAe,mBAAmB,SAAyD;AACzF,QAAM,EAAE,KAAK,IAAI,MAAM,OAAO,gBAAgB;AAC9C,QAAM,OAAO,IAAI,KAAK;AACtB,QAAM,KAAK,QAAQ,QAAQ,KAAK,QAAQ,KAAK;AAC7C,SAAO,EAAE,YAAY,MAAM,KAAK,WAAW,EAAE;AAC/C;AASO,SAAS,eAAe;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA,cAAc;AAAA,EACd,UAAU;AACZ,GAA0B;AACxB,QAAM,CAAC,QAAQ,SAAS,IAAU,eAA4B,MAAM;AACpE,QAAM,CAAC,UAAU,WAAW,IAAU,eAA0B,IAAI;AACpE,QAAM,gBAAsB,aAAqC,IAAI;AACrE,QAAM,mBAAyB,aAAO,iBAAiB,qBAAqB,OAAO,CAAC;AACpF,mBAAiB,UAAU,iBAAiB,qBAAqB,OAAO;AAExE,QAAM,iBAAuB,kBAAY,MAAM,UAAU,iBAAiB,GAAG,CAAC,CAAC;AAE/E,QAAM,OAAa,kBAAY,MAAM,UAAU,MAAM,GAAG,CAAC,CAAC;AAE1D,QAAM,QAAc,kBAAY,YAAY;AAC1C,UAAM,UAAU,MAAM,iBAAiB,QAAQ,EAAE,OAAO,UAAU,MAAM,CAAC;AACzE,kBAAc,UAAU,MAAM,YAAY,OAAO;AACjD,cAAU,QAAQ;AAAA,EACpB,GAAG,CAAC,OAAO,UAAU,OAAO,WAAW,CAAC;AAExC,QAAM,OAAa,kBAAY,MAAM;AACnC,kBAAc,SAAS,WAAW;AAClC,kBAAc,UAAU;AACxB,cAAU,MAAM;AAAA,EAClB,GAAG,CAAC,CAAC;AAEL,EAAM,gBAAU,MAAM,MAAM,cAAc,SAAS,WAAW,GAAG,CAAC,CAAC;AAEnE,SAAO,EAAE,QAAQ,UAAU,aAAa,gBAAgB,OAAO,MAAM,KAAK;AAC5E;","names":[]}
|