@kroos-dev/web 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kroos
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,37 @@
1
- # Temporary Holding Version
1
+ # @kroos-dev/web
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Add the Kroos AI Chatbot to any website or web app.
4
+
5
+ ```bash
6
+ npm install @kroos-dev/web
7
+ ```
8
+
9
+ ## React and Next.js
10
+
11
+ ```jsx
12
+ // app/layout.jsx
13
+ import { KroosChat } from "@kroos-dev/web/react";
14
+
15
+ export default function RootLayout({ children }) {
16
+ return (
17
+ <html><body>
18
+ {children}
19
+ <KroosChat publishableKey={process.env.NEXT_PUBLIC_KROOS_PUBLISHABLE_KEY} tokenUrl="/api/kroos/token" />
20
+ </body></html>
21
+ );
22
+ }
23
+ ```
24
+
25
+ `tokenUrl` is optional. It points to a same-origin endpoint that returns `{ token }` for the signed-in user (see `@kroos-dev/node/next`). Without it, every visitor is anonymous.
26
+
27
+ ## Any framework
28
+
29
+ ```js
30
+ import { loadKroos, setUserToken, unloadKroos } from "@kroos-dev/web";
31
+
32
+ loadKroos({ publishableKey: "kroos_pk_…", tokenUrl: "/api/kroos/token" });
33
+ // after sign-out without a page load:
34
+ setUserToken(null);
35
+ ```
36
+
37
+ Options: `inline` (a CSS selector to render inside instead of floating), `open`, `offset`, `host`, `api`.
package/package.json CHANGED
@@ -1,6 +1,18 @@
1
1
  {
2
2
  "name": "@kroos-dev/web",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
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
+ "type": "module",
6
+ "license": "MIT",
7
+ "homepage": "https://dev.kroos.ai/widget",
8
+ "exports": {
9
+ ".": { "types": "./src/index.d.ts", "default": "./src/index.js" },
10
+ "./react": { "types": "./src/react.d.ts", "default": "./src/react.js" }
11
+ },
12
+ "files": ["src", "README.md", "LICENSE"],
13
+ "sideEffects": false,
14
+ "peerDependencies": { "react": ">=17" },
15
+ "peerDependenciesMeta": { "react": { "optional": true } },
16
+ "scripts": { "test": "node --test test/*.test.js" },
17
+ "keywords": ["kroos", "chatbot", "widget", "react", "nextjs"]
18
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export type KroosOptions = { publishableKey: string; host?: string; api?: string; tokenUrl?: string; userToken?: string; inline?: string; open?: boolean; offset?: number };
2
+ export declare function loadKroos(o: KroosOptions): () => void;
3
+ export declare function unloadKroos(): void;
4
+ export declare function setUserToken(token: string | null): void;
package/src/index.js ADDED
@@ -0,0 +1,41 @@
1
+ // @kroos-dev/web: load the Kroos AI Chatbot on a page. Browser only; safe to import during SSR (no-ops).
2
+ const SCRIPT_ID = "kroos-widget-script";
3
+ const ROOT_ID = "kroos-concierge";
4
+
5
+ /**
6
+ * Load (or reload) the chatbot.
7
+ * @param {{ publishableKey: string, host?: string, api?: string, tokenUrl?: string, userToken?: string,
8
+ * inline?: string, open?: boolean, offset?: number }} o
9
+ * @returns {() => void} unload
10
+ */
11
+ export function loadKroos(o) {
12
+ if (typeof document === "undefined") return () => {};
13
+ if (!o || !o.publishableKey || !/^kroos_pk_/.test(o.publishableKey)) throw new TypeError("publishableKey must be your Kroos publishable key (kroos_pk_…).");
14
+ unloadKroos();
15
+ const host = (o.host || "https://kroos.ai").replace(/\/$/, "");
16
+ const s = document.createElement("script");
17
+ s.id = SCRIPT_ID;
18
+ s.src = `${host}/widget.js`;
19
+ s.async = true;
20
+ s.setAttribute("data-kroos-key", o.publishableKey);
21
+ if (o.api) s.setAttribute("data-kroos-api", o.api);
22
+ if (o.tokenUrl) s.setAttribute("data-kroos-token-url", o.tokenUrl);
23
+ else if (o.userToken) s.setAttribute("data-kroos-user-token", o.userToken);
24
+ if (o.inline) s.setAttribute("data-kroos-inline", o.inline);
25
+ if (o.open) s.setAttribute("data-kroos-open", "true");
26
+ if (o.offset) s.setAttribute("data-kroos-offset", String(o.offset));
27
+ document.body.appendChild(s);
28
+ return unloadKroos;
29
+ }
30
+
31
+ /** Remove the chatbot from the page. */
32
+ export function unloadKroos() {
33
+ if (typeof document === "undefined") return;
34
+ document.getElementById(ROOT_ID)?.remove();
35
+ document.getElementById(SCRIPT_ID)?.remove();
36
+ }
37
+
38
+ /** Switch the signed-in person without a page load (null after sign-out). */
39
+ export function setUserToken(token) {
40
+ if (typeof window !== "undefined" && window.Kroos && typeof window.Kroos.setUserToken === "function") window.Kroos.setUserToken(token ?? null);
41
+ }
package/src/react.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import type { KroosOptions } from "./index.js";
2
+ export declare function KroosChat(props: KroosOptions): null;
3
+ export { setUserToken } from "./index.js";
package/src/react.js ADDED
@@ -0,0 +1,15 @@
1
+ // @kroos-dev/web/react: <KroosChat publishableKey="kroos_pk_…" tokenUrl="/api/kroos/token" />
2
+ // Client component. In the Next.js App Router, render it from a layout (it marks itself "use client").
3
+ "use client";
4
+ import { useEffect } from "react";
5
+ import { loadKroos, setUserToken } from "./index.js";
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 go through setUserToken.
10
+ [publishableKey, host, api, tokenUrl, inline, open, offset]);
11
+ useEffect(() => { if (userToken !== undefined && !tokenUrl) setUserToken(userToken); }, [userToken, tokenUrl]);
12
+ return null;
13
+ }
14
+
15
+ export { setUserToken };