@kroos-dev/web 0.1.0 → 0.2.0
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/README.md +1 -1
- package/package.json +37 -8
- package/src/index.d.ts +16 -1
- package/src/index.js +19 -2
- package/src/react.d.ts +1 -1
- package/src/react.js +7 -6
package/README.md
CHANGED
|
@@ -34,4 +34,4 @@ loadKroos({ publishableKey: "kroos_pk_…", tokenUrl: "/api/kroos/token" });
|
|
|
34
34
|
setUserToken(null);
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
Options: `inline` (a CSS selector to render inside instead of floating), `open`, `offset`, `host`, `api`.
|
|
37
|
+
Options: `inline` (a CSS selector to render inside instead of floating), `open`, `offset`, `host`, `api`. Look while loading (your Console settings still apply): `color` and `accent` (`#rrggbb`), `position` (`left` or `right`), `logo` (https image), `icon` (`chat`, `bubbles`, `message`, `help`, `headset`, `sparkle`, `smile`), `invite` (up to 40 characters) and `invitePosition` (`before`, `after`, `above`, `arc`). Language: `lang` (for example `es`), or call `setLanguage("es")` from your own language switch.
|
package/package.json
CHANGED
|
@@ -1,18 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kroos-dev/web",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Add the Kroos AI Chatbot to any website or web app: a framework-agnostic loader and a React component (Next.js, Remix, Vite).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/kroosAI/kroos.git",
|
|
10
|
+
"directory": "sdks/web"
|
|
11
|
+
},
|
|
7
12
|
"homepage": "https://dev.kroos.ai/widget",
|
|
8
13
|
"exports": {
|
|
9
|
-
".": {
|
|
10
|
-
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./src/index.d.ts",
|
|
16
|
+
"default": "./src/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./react": {
|
|
19
|
+
"types": "./src/react.d.ts",
|
|
20
|
+
"default": "./src/react.js"
|
|
21
|
+
}
|
|
11
22
|
},
|
|
12
|
-
"files": [
|
|
23
|
+
"files": [
|
|
24
|
+
"src",
|
|
25
|
+
"README.md",
|
|
26
|
+
"LICENSE"
|
|
27
|
+
],
|
|
13
28
|
"sideEffects": false,
|
|
14
|
-
"peerDependencies": {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"react": ">=17"
|
|
31
|
+
},
|
|
32
|
+
"peerDependenciesMeta": {
|
|
33
|
+
"react": {
|
|
34
|
+
"optional": true
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"test": "node --test test/*.test.js"
|
|
39
|
+
},
|
|
40
|
+
"keywords": [
|
|
41
|
+
"kroos",
|
|
42
|
+
"chatbot",
|
|
43
|
+
"widget",
|
|
44
|
+
"react",
|
|
45
|
+
"nextjs"
|
|
46
|
+
]
|
|
18
47
|
}
|
package/src/index.d.ts
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type KroosIcon = "chat" | "bubbles" | "message" | "help" | "headset" | "sparkle" | "smile";
|
|
2
|
+
export type KroosOptions = {
|
|
3
|
+
publishableKey: string; host?: string; api?: string; tokenUrl?: string; userToken?: string;
|
|
4
|
+
inline?: string; open?: boolean; offset?: number;
|
|
5
|
+
/** Look while loading (the Console settings still apply): main and accent colors as #rrggbb. */
|
|
6
|
+
color?: string; accent?: string;
|
|
7
|
+
position?: "left" | "right";
|
|
8
|
+
/** https image shown on the button instead of the chat icon. */
|
|
9
|
+
logo?: string;
|
|
10
|
+
icon?: KroosIcon;
|
|
11
|
+
/** Invitation beside the button (up to 40 characters), and where it goes. */
|
|
12
|
+
invite?: string; invitePosition?: "before" | "after" | "above" | "arc";
|
|
13
|
+
/** Interface language, e.g. "es" (default: the page's <html lang>). */
|
|
14
|
+
lang?: string;
|
|
15
|
+
};
|
|
2
16
|
export declare function loadKroos(o: KroosOptions): () => void;
|
|
3
17
|
export declare function unloadKroos(): void;
|
|
4
18
|
export declare function setUserToken(token: string | null): void;
|
|
19
|
+
export declare function setLanguage(lang: string | null): void;
|
package/src/index.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
// @kroos-dev/web: load the Kroos AI Chatbot on a page. Browser only; safe to import during SSR (no-ops).
|
|
2
2
|
const SCRIPT_ID = "kroos-widget-script";
|
|
3
3
|
const ROOT_ID = "kroos-concierge";
|
|
4
|
+
const ICONS = ["chat", "bubbles", "message", "help", "headset", "sparkle", "smile"];
|
|
5
|
+
const INVITE_POSITIONS = ["before", "after", "above", "arc"];
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* Load (or reload) the chatbot.
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
+
* Look options (color, accent, position, logo, icon, invite, invitePosition) only avoid a flash of the default
|
|
10
|
+
* look while the page loads: the settings saved in the Kroos Console still apply.
|
|
11
|
+
* @param {import("./index.js").KroosOptions} o
|
|
9
12
|
* @returns {() => void} unload
|
|
10
13
|
*/
|
|
11
14
|
export function loadKroos(o) {
|
|
@@ -24,6 +27,15 @@ export function loadKroos(o) {
|
|
|
24
27
|
if (o.inline) s.setAttribute("data-kroos-inline", o.inline);
|
|
25
28
|
if (o.open) s.setAttribute("data-kroos-open", "true");
|
|
26
29
|
if (o.offset) s.setAttribute("data-kroos-offset", String(o.offset));
|
|
30
|
+
const HEX = /^#[0-9a-f]{6}$/i;
|
|
31
|
+
if (o.color && HEX.test(o.color)) s.setAttribute("data-kroos-color", o.color);
|
|
32
|
+
if (o.accent && HEX.test(o.accent)) s.setAttribute("data-kroos-accent", o.accent);
|
|
33
|
+
if (o.position === "left" || o.position === "right") s.setAttribute("data-kroos-position", o.position);
|
|
34
|
+
if (o.logo && /^https:\/\//.test(o.logo)) s.setAttribute("data-kroos-logo", o.logo);
|
|
35
|
+
if (o.icon && ICONS.includes(o.icon)) s.setAttribute("data-kroos-icon", o.icon);
|
|
36
|
+
if (o.invite) s.setAttribute("data-kroos-invite", String(o.invite).replace(/[<>]/g, "").slice(0, 40));
|
|
37
|
+
if (o.invitePosition && INVITE_POSITIONS.includes(o.invitePosition)) s.setAttribute("data-kroos-invite-position", o.invitePosition);
|
|
38
|
+
if (o.lang && /^[a-z]{2}$/i.test(o.lang)) s.setAttribute("data-kroos-lang", o.lang.toLowerCase());
|
|
27
39
|
document.body.appendChild(s);
|
|
28
40
|
return unloadKroos;
|
|
29
41
|
}
|
|
@@ -35,6 +47,11 @@ export function unloadKroos() {
|
|
|
35
47
|
document.getElementById(SCRIPT_ID)?.remove();
|
|
36
48
|
}
|
|
37
49
|
|
|
50
|
+
/** Follow your own language switch without a reload, e.g. setLanguage("es"); null goes back to the page's language. */
|
|
51
|
+
export function setLanguage(lang) {
|
|
52
|
+
if (typeof window !== "undefined" && window.Kroos && typeof window.Kroos.setLanguage === "function") window.Kroos.setLanguage(lang ?? null);
|
|
53
|
+
}
|
|
54
|
+
|
|
38
55
|
/** Switch the signed-in person without a page load (null after sign-out). */
|
|
39
56
|
export function setUserToken(token) {
|
|
40
57
|
if (typeof window !== "undefined" && window.Kroos && typeof window.Kroos.setUserToken === "function") window.Kroos.setUserToken(token ?? null);
|
package/src/react.d.ts
CHANGED
package/src/react.js
CHANGED
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
// Client component. In the Next.js App Router, render it from a layout (it marks itself "use client").
|
|
3
3
|
"use client";
|
|
4
4
|
import { useEffect } from "react";
|
|
5
|
-
import { loadKroos, setUserToken } from "./index.js";
|
|
5
|
+
import { loadKroos, setUserToken, setLanguage } from "./index.js";
|
|
6
6
|
|
|
7
|
-
export function KroosChat({ publishableKey, host, api, tokenUrl, userToken, inline, open, offset }) {
|
|
8
|
-
useEffect(() => loadKroos({ publishableKey, host, api, tokenUrl, userToken, inline, open, offset }),
|
|
9
|
-
// Reload only when placement or identity source changes; token changes
|
|
10
|
-
[publishableKey, host, api, tokenUrl, inline, open, offset]);
|
|
7
|
+
export function KroosChat({ publishableKey, host, api, tokenUrl, userToken, inline, open, offset, color, accent, position, logo, icon, invite, invitePosition, lang }) {
|
|
8
|
+
useEffect(() => loadKroos({ publishableKey, host, api, tokenUrl, userToken, inline, open, offset, color, accent, position, logo, icon, invite, invitePosition }),
|
|
9
|
+
// Reload only when placement, look or identity source changes; token and language changes don't reload.
|
|
10
|
+
[publishableKey, host, api, tokenUrl, inline, open, offset, color, accent, position, logo, icon, invite, invitePosition]);
|
|
11
|
+
useEffect(() => { if (lang !== undefined) setLanguage(lang); }, [lang]);
|
|
11
12
|
useEffect(() => { if (userToken !== undefined && !tokenUrl) setUserToken(userToken); }, [userToken, tokenUrl]);
|
|
12
13
|
return null;
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
export { setUserToken };
|
|
16
|
+
export { setUserToken, setLanguage };
|