@frontera-sdk/chat-ui 1.50.40
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/LICENSE +202 -0
- package/README.md +348 -0
- package/dist/af-DK_CjRn6-OPBHDTNZ.js +197 -0
- package/dist/agent-picker.d.ts +38 -0
- package/dist/agent-picker.js +8 -0
- package/dist/as-BPtSu6VN-O4ZZEAJG.js +11 -0
- package/dist/be-CrQ0smca-5HIE5K27.js +11 -0
- package/dist/bg-CrQqGwni-3IRVPZQ7.js +11 -0
- package/dist/bn-NCLZcWHi-XOZJFNIB.js +11 -0
- package/dist/ca-SUf6Y2Om-V6F2EBCA.js +38 -0
- package/dist/capture-NO5ZIGP6.js +1652 -0
- package/dist/chat.css +3555 -0
- package/dist/chat.d.ts +161 -0
- package/dist/chat.js +60498 -0
- package/dist/chunk-2KEBRV3W.js +191 -0
- package/dist/chunk-6BPHEBCF.js +639 -0
- package/dist/chunk-6HYPVNVA.js +25 -0
- package/dist/chunk-7ADM3CKD.js +10 -0
- package/dist/chunk-AFVU5VT6.js +5601 -0
- package/dist/chunk-BEJ3HQG4.js +93 -0
- package/dist/chunk-CCVPZVFK.js +28 -0
- package/dist/chunk-DGDHKMDB.js +10 -0
- package/dist/chunk-FXKXDR5K.js +2166 -0
- package/dist/chunk-GTQH7MPF.js +129 -0
- package/dist/chunk-I7SXWUAN.js +1258 -0
- package/dist/chunk-IQRPGFLI.js +234 -0
- package/dist/chunk-IXDM5R55.js +23 -0
- package/dist/chunk-JD6ETTXC.js +178 -0
- package/dist/chunk-OP4MLJDA.js +215 -0
- package/dist/chunk-PQZ2CS26.js +2315 -0
- package/dist/chunk-PR4QN5HX.js +38 -0
- package/dist/chunk-PUIVKDV5.js +271 -0
- package/dist/chunk-QSSFBZAS.js +6914 -0
- package/dist/chunk-RAKKA3WU.js +5896 -0
- package/dist/chunk-RB2Y4NYC.js +681 -0
- package/dist/chunk-VDZH5Z3K.js +72 -0
- package/dist/chunk-WMN6BPPS.js +49 -0
- package/dist/chunk-WO6DJLFE.js +10857 -0
- package/dist/chunk-X5E2DJVO.js +47634 -0
- package/dist/chunk-XJFTVKLW.js +2687 -0
- package/dist/chunk-ZS6PXIZP.js +187 -0
- package/dist/client.d.ts +89 -0
- package/dist/client.js +20 -0
- package/dist/composer.d.ts +23 -0
- package/dist/composer.js +89 -0
- package/dist/cop-C3sk0IUo-CIZA2H43.js +11 -0
- package/dist/credential.d.ts +75 -0
- package/dist/credential.js +3 -0
- package/dist/cs-CmAteokq-HAKEQPB4.js +17 -0
- package/dist/cu-CBUlrW6Y-QTZ6ZLA4.js +32 -0
- package/dist/cy-BBPa6z2x-MX6DGDNW.js +11 -0
- package/dist/da-CCDXfXtG-5YEOHMG3.js +11 -0
- package/dist/de-1901-CWoAOigE-63QFSF2A.js +11 -0
- package/dist/de-1996-BL6awyxG-R2PHKMAB.js +11 -0
- package/dist/de-ch-1901-hVThVHVb-JSDB53OZ.js +11 -0
- package/dist/el-monoton-D3aKqTz2-2V4OOFBB.js +11 -0
- package/dist/el-polyton-ogVWcTzh-3U7NGQMT.js +11 -0
- package/dist/en-gb-B7Al27b_-UKCBQFSU.js +21 -0
- package/dist/es-DcaaHPU_-NOBXSOZK.js +11 -0
- package/dist/esm-MHF25KDL.js +3 -0
- package/dist/et-B_spaleu-5UAYIW62.js +11 -0
- package/dist/eu-Ctv_kq9Z-V5DREOPN.js +11 -0
- package/dist/fi-RW5VB8Yp-YSXBK7LW.js +11 -0
- package/dist/fr-BC2onEz9-7KH5T76G.js +11 -0
- package/dist/frame.d.ts +59 -0
- package/dist/frame.js +111 -0
- package/dist/fur-AC12wySk-4PD2Y72H.js +11 -0
- package/dist/ga-Cn6LkudM-RRAAJT3N.js +58 -0
- package/dist/gl-DZGc-K_G-KYSXXTCY.js +11 -0
- package/dist/grc-DOlGgO8T-2HXBZVJ5.js +11 -0
- package/dist/gu-Bjl0l-cf-4CFSVZHZ.js +11 -0
- package/dist/header.d.ts +78 -0
- package/dist/header.js +18 -0
- package/dist/hi-DsAaTPCC-KMCFBWK7.js +11 -0
- package/dist/hr-DT1SBBes-X2TIX6EI.js +11 -0
- package/dist/hsb-DC_ITc1e-PXLERA7R.js +46 -0
- package/dist/hu-DVk7Y_ka-PJPVU54B.js +11 -0
- package/dist/hy-e995ysyO-MZBRFX52.js +11 -0
- package/dist/ia-Cr4TJH0c-D3O2FHGP.js +22 -0
- package/dist/id-DifDyWg9-MZ2BGHWI.js +58 -0
- package/dist/is-BT8UVRze-CZZCKEFI.js +11 -0
- package/dist/it-Bt_Meacx-T4Y5JYV6.js +11 -0
- package/dist/ka-jyoLzyDE-ES6EXZLW.js +11 -0
- package/dist/kmr-Cfwhwuff-TSW2R2KS.js +11 -0
- package/dist/kn-C6Lov-DP-B4BL47CE.js +11 -0
- package/dist/la-DuvHjUWw-6K7TFU6X.js +11 -0
- package/dist/la-x-classic-yTyAOQEt-YWTKMM2L.js +11 -0
- package/dist/la-x-liturgic-CXeQb4FY-B772L5E7.js +11 -0
- package/dist/lib-3ZKX25RJ.js +4511 -0
- package/dist/lt-BBe8DlDF-4YINVOZR.js +11 -0
- package/dist/lv-Q2BBHnzp-TMVQ3MX2.js +11 -0
- package/dist/message.d.ts +64 -0
- package/dist/message.js +18 -0
- package/dist/ml-2xLVYkVY-NGZLAPIN.js +11 -0
- package/dist/mn-cyrl-lHM4n0oC-DGBYYUT3.js +11 -0
- package/dist/mn-cyrl-x-lmc-3aetruI8-QHJABMOO.js +11 -0
- package/dist/mr-CjWJPVmH-X5UHV65O.js +11 -0
- package/dist/mul-ethi-D_CMSMEq-H7UMQSOQ.js +11 -0
- package/dist/nb-DI8u59ch-J4CAVI4Y.js +122 -0
- package/dist/new-session-Dw7JOgzu.d.ts +141 -0
- package/dist/new-session.d.ts +4 -0
- package/dist/new-session.js +10 -0
- package/dist/nl-BHQJ6Gvn-7BH55RA7.js +52 -0
- package/dist/nn-ntZvarUK-KKNCHHJ4.js +122 -0
- package/dist/no-B8ItS0F3-3ZXIRJ6U.js +120 -0
- package/dist/oauth-callback.d.ts +35 -0
- package/dist/oauth-callback.js +18 -0
- package/dist/oc-P_i3-xLA-XZM6E5YZ.js +11 -0
- package/dist/or-50rxpoq4-5VELAFMJ.js +11 -0
- package/dist/pa-C54UG8eN-WEJPMZ6Z.js +11 -0
- package/dist/parts.d.ts +49 -0
- package/dist/parts.js +106 -0
- package/dist/pdf-cover-thumbnail-inner-4N2Q5AAG.js +36 -0
- package/dist/pdf-deck-view-inner-FZVLAEQR.js +575 -0
- package/dist/pdf-document-view-inner-6DF54JWK.js +585 -0
- package/dist/pdf-viewer-inner-GPES3KG2.js +256 -0
- package/dist/pending-cards.d.ts +26 -0
- package/dist/pending-cards.js +9 -0
- package/dist/pi-B9cgjyG1-GD5ASDDU.js +11 -0
- package/dist/pl-9fg-ESVt-UMX7MCJM.js +32 -0
- package/dist/platform.css +4013 -0
- package/dist/pms-BRGfm5gS-SSE3AUW5.js +11 -0
- package/dist/pt-Cum2_NUC-W35JYVR4.js +11 -0
- package/dist/rm-C0MIK9N4-IWL4YTNT.js +11 -0
- package/dist/ro-0fmdH0HA-46WUTOYH.js +11 -0
- package/dist/ru-v4l-ayaq-BUGK6XCN.js +196 -0
- package/dist/sa-CKY9c_Vq-4KIJOI5Y.js +11 -0
- package/dist/sh-cyrl-BpCRFOmq-DSLQ4UY2.js +128 -0
- package/dist/sh-latn-sRy4Tuaj-UNQOR63V.js +128 -0
- package/dist/sk-_iOeDNrQ-NCTQKH25.js +17 -0
- package/dist/sl-DpiklF-D-6GG5TDVN.js +11 -0
- package/dist/sr-cyrl-Dpzrbd0W-4Q5226YJ.js +142 -0
- package/dist/sv-CFm5y56M-VTWNPZ7I.js +11 -0
- package/dist/ta-BcghgTbD-NRT35DW6.js +11 -0
- package/dist/te-B5Spl2Jk-5VE6CLN4.js +11 -0
- package/dist/th-DWX5iPSo-N5GMOQOP.js +11 -0
- package/dist/theme.d.ts +49 -0
- package/dist/theme.js +3 -0
- package/dist/tk-BMbKB10q-HGWWY5L3.js +11 -0
- package/dist/tr-CIHIuzqc-6ISBNYLV.js +11 -0
- package/dist/types-BDqLaBfH.d.ts +60 -0
- package/dist/uk-Dir3oxLs-YQ3QZRI4.js +11 -0
- package/dist/univer-workbook-BSSUE5TG.css +3555 -0
- package/dist/univer-workbook-N5IIN7CH.js +290849 -0
- package/dist/vega-chart-block-NQADYNWQ.js +2857 -0
- package/dist/zh-latn-pinyin-BdYb-Ey_-RB542AHF.js +11 -0
- package/package.json +137 -0
- package/src/styles.css +996 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useState, useRef, useMemo, useEffect, useCallback } from 'react';
|
|
3
|
+
import { FronteraClient } from '@frontera-sdk/core/client';
|
|
4
|
+
import { createTokenSession } from '@frontera-sdk/chat/token-session';
|
|
5
|
+
|
|
6
|
+
// src/credential.ts
|
|
7
|
+
function useChatCredential(props) {
|
|
8
|
+
const [ready, setReady] = useState(false);
|
|
9
|
+
const [error, setError] = useState(null);
|
|
10
|
+
const clientRef = useRef(null);
|
|
11
|
+
const sessionRef = useRef(null);
|
|
12
|
+
const suppliedClient = props.client;
|
|
13
|
+
const staticToken = props.token;
|
|
14
|
+
const apiBaseUrl = props.apiBaseUrl;
|
|
15
|
+
const tokenEndpoint = props.tokenEndpoint;
|
|
16
|
+
const getToken = props.getToken;
|
|
17
|
+
const staticClient = useMemo(() => {
|
|
18
|
+
if (!suppliedClient) return null;
|
|
19
|
+
return typeof suppliedClient === "function" ? suppliedClient : () => suppliedClient;
|
|
20
|
+
}, [suppliedClient]);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (staticClient) {
|
|
23
|
+
setReady(true);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (staticToken) {
|
|
27
|
+
if (!apiBaseUrl) {
|
|
28
|
+
setError(new Error("Passing `token` also requires `apiBaseUrl`"));
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
clientRef.current = new FronteraClient({
|
|
32
|
+
apiBaseUrl,
|
|
33
|
+
credential: { kind: "token", token: staticToken }
|
|
34
|
+
});
|
|
35
|
+
setReady(true);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (!tokenEndpoint && !getToken) {
|
|
39
|
+
setError(new Error("Pass one of: tokenEndpoint, token + apiBaseUrl, getToken, or client"));
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
let disposed = false;
|
|
43
|
+
let session = null;
|
|
44
|
+
async function loadFromHost() {
|
|
45
|
+
if (getToken) return getToken();
|
|
46
|
+
const response = await fetch(tokenEndpoint, { method: "POST", credentials: "same-origin" });
|
|
47
|
+
if (!response.ok) {
|
|
48
|
+
throw new Error(
|
|
49
|
+
`Token endpoint answered ${response.status}. It must return { token, expiresAt } for the signed-in user.`
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
return await response.json();
|
|
53
|
+
}
|
|
54
|
+
async function start() {
|
|
55
|
+
try {
|
|
56
|
+
const first = await loadFromHost();
|
|
57
|
+
if (disposed) return;
|
|
58
|
+
const base = first.apiBaseUrl ?? apiBaseUrl;
|
|
59
|
+
if (!base) throw new Error("No apiBaseUrl: pass one, or return it from your token endpoint");
|
|
60
|
+
session = createTokenSession({
|
|
61
|
+
apiBaseUrl: base,
|
|
62
|
+
initialToken: { token: first.token, expiresAt: first.expiresAt },
|
|
63
|
+
getToken: loadFromHost,
|
|
64
|
+
onToken: () => {
|
|
65
|
+
if (!disposed) setError(null);
|
|
66
|
+
},
|
|
67
|
+
onExpired: (err) => {
|
|
68
|
+
if (!disposed) setError(err instanceof Error ? err : new Error(String(err)));
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
sessionRef.current = session;
|
|
72
|
+
setReady(true);
|
|
73
|
+
setError(null);
|
|
74
|
+
} catch (err) {
|
|
75
|
+
if (!disposed) setError(err);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
void start();
|
|
79
|
+
return () => {
|
|
80
|
+
disposed = true;
|
|
81
|
+
session?.dispose();
|
|
82
|
+
sessionRef.current = null;
|
|
83
|
+
};
|
|
84
|
+
}, [staticClient, staticToken, apiBaseUrl, tokenEndpoint, getToken]);
|
|
85
|
+
const getClient = useMemo(
|
|
86
|
+
() => staticClient ? () => staticClient() : () => sessionRef.current?.getClient() ?? clientRef.current,
|
|
87
|
+
[staticClient]
|
|
88
|
+
);
|
|
89
|
+
const refresh = useCallback(async () => sessionRef.current?.refresh(), []);
|
|
90
|
+
return { getClient, ready, error, refresh };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export { useChatCredential };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
// src/token-subject.ts
|
|
3
|
+
function subjectOfChatToken(token) {
|
|
4
|
+
const parts = token.split(".");
|
|
5
|
+
if (parts.length !== 3) return null;
|
|
6
|
+
try {
|
|
7
|
+
const padded = parts[1].replace(/-/g, "+").replace(/_/g, "/");
|
|
8
|
+
const json = atob(padded.padEnd(padded.length + (4 - padded.length % 4) % 4, "="));
|
|
9
|
+
const claims = JSON.parse(json);
|
|
10
|
+
return typeof claims.sub === "string" && claims.sub ? claims.sub : null;
|
|
11
|
+
} catch {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function capabilitiesOfChatToken(token) {
|
|
16
|
+
const parts = token.split(".");
|
|
17
|
+
if (parts.length !== 3) return [];
|
|
18
|
+
try {
|
|
19
|
+
const padded = parts[1].replace(/-/g, "+").replace(/_/g, "/");
|
|
20
|
+
const json = atob(padded.padEnd(padded.length + (4 - padded.length % 4) % 4, "="));
|
|
21
|
+
const claims = JSON.parse(json);
|
|
22
|
+
return Array.isArray(claims.caps) ? claims.caps.filter((c) => typeof c === "string") : [];
|
|
23
|
+
} catch {
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { capabilitiesOfChatToken, subjectOfChatToken };
|