@livelayer/react 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/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # @livelayer/react
2
+
3
+ React component wrapper for the LiveLayer agent widget.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @livelayer/react
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```tsx
14
+ import { LiveLayerWidget } from "@livelayer/react";
15
+
16
+ function App() {
17
+ return (
18
+ <LiveLayerWidget
19
+ agentId="your_agent_id"
20
+ onAgentEvent={(e) => console.log(e.eventName, e.data)}
21
+ />
22
+ );
23
+ }
24
+ ```
25
+
26
+ ## Props
27
+
28
+ | Prop | Type | Required | Description |
29
+ | --------------- | --------------------------------------- | -------- | --------------------------------------------------- |
30
+ | `agentId` | `string` | Yes | The published agent ID to connect to |
31
+ | `mode` | `"WIDGET" \| "EMBEDDED"` | No | Override the experience mode from the agent config |
32
+ | `onAgentEvent` | `(event: AgentEventDetail) => void` | No | Callback fired when the agent emits a data channel event |
33
+ | `className` | `string` | No | CSS class name on the wrapper div |
34
+ | `style` | `React.CSSProperties` | No | Inline styles on the wrapper div |
35
+
36
+ ### AgentEventDetail
37
+
38
+ ```ts
39
+ interface AgentEventDetail {
40
+ eventName: string;
41
+ data: Record<string, unknown>;
42
+ }
43
+ ```
44
+
45
+ ## Peer Dependencies
46
+
47
+ This package requires React 18 or later:
48
+
49
+ ```json
50
+ {
51
+ "react": ">=18.0.0",
52
+ "react-dom": ">=18.0.0"
53
+ }
54
+ ```
55
+
56
+ ## License
57
+
58
+ MIT
@@ -0,0 +1,41 @@
1
+ import { FC } from 'react';
2
+
3
+ export declare interface AgentEventDetail {
4
+ eventName: string;
5
+ data: Record<string, unknown>;
6
+ }
7
+
8
+ /**
9
+ * React component that renders a `<livelayer-widget>` custom element.
10
+ *
11
+ * @example
12
+ * ```tsx
13
+ * <LiveLayerWidget
14
+ * agentId="agent_xxx"
15
+ * onAgentEvent={(e) => console.log(e.eventName, e.data)}
16
+ * />
17
+ * ```
18
+ */
19
+ export declare const LiveLayerWidget: FC<LiveLayerWidgetProps>;
20
+
21
+ export declare interface LiveLayerWidgetProps {
22
+ /** The agent ID to connect to */
23
+ agentId: string;
24
+ /** Base URL of the Live Layer API (e.g. "https://app.livelayer.studio") */
25
+ baseUrl?: string;
26
+ /** API key for cross-origin authentication */
27
+ apiKey?: string;
28
+ /**
29
+ * Override the experience mode from the published config.
30
+ * If not set, the mode from the agent's published config is used.
31
+ */
32
+ mode?: "WIDGET" | "EMBEDDED";
33
+ /** Callback fired when the agent emits an event via the data channel */
34
+ onAgentEvent?: (event: AgentEventDetail) => void;
35
+ /** Additional CSS class name on the wrapper div */
36
+ className?: string;
37
+ /** Inline styles on the wrapper div */
38
+ style?: React.CSSProperties;
39
+ }
40
+
41
+ export { }
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("react/jsx-runtime"),t=require("react");require("@livelayer/sdk");const m=({agentId:s,baseUrl:c,apiKey:l,mode:r,onAgentEvent:o,className:v,style:g})=>{const a=t.useRef(null),n=t.useRef(null),u=t.useRef(o);u.current=o;const d=t.useCallback(i=>{var f;const e=i.detail;(f=u.current)==null||f.call(u,e)},[]);return t.useEffect(()=>{const i=a.current;if(!i)return;const e=document.createElement("livelayer-widget");return e.setAttribute("agent-id",s),c&&e.setAttribute("base-url",c),l&&e.setAttribute("api-key",l),r&&e.setAttribute("mode",r),e.addEventListener("agent-event",d),i.appendChild(e),n.current=e,()=>{e.removeEventListener("agent-event",d),i.removeChild(e),n.current=null}},[s]),t.useEffect(()=>{n.current&&(r?n.current.setAttribute("mode",r):n.current.removeAttribute("mode"))},[r]),b.jsx("div",{ref:a,className:v,style:g})};exports.LiveLayerWidget=m;
package/dist/index.mjs ADDED
@@ -0,0 +1,33 @@
1
+ import { jsx as g } from "react/jsx-runtime";
2
+ import { useRef as u, useCallback as p, useEffect as v } from "react";
3
+ import "@livelayer/sdk";
4
+ const h = ({
5
+ agentId: c,
6
+ baseUrl: s,
7
+ apiKey: o,
8
+ mode: t,
9
+ onAgentEvent: l,
10
+ className: m,
11
+ style: b
12
+ }) => {
13
+ const d = u(null), r = u(null), i = u(l);
14
+ i.current = l;
15
+ const f = p((n) => {
16
+ var a;
17
+ const e = n.detail;
18
+ (a = i.current) == null || a.call(i, e);
19
+ }, []);
20
+ return v(() => {
21
+ const n = d.current;
22
+ if (!n) return;
23
+ const e = document.createElement("livelayer-widget");
24
+ return e.setAttribute("agent-id", c), s && e.setAttribute("base-url", s), o && e.setAttribute("api-key", o), t && e.setAttribute("mode", t), e.addEventListener("agent-event", f), n.appendChild(e), r.current = e, () => {
25
+ e.removeEventListener("agent-event", f), n.removeChild(e), r.current = null;
26
+ };
27
+ }, [c]), v(() => {
28
+ r.current && (t ? r.current.setAttribute("mode", t) : r.current.removeAttribute("mode"));
29
+ }, [t]), /* @__PURE__ */ g("div", { ref: d, className: m, style: b });
30
+ };
31
+ export {
32
+ h as LiveLayerWidget
33
+ };
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@livelayer/react",
3
+ "version": "0.1.0",
4
+ "description": "React component wrapper for the LiveLayer agent widget",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "peerDependencies": {
19
+ "react": ">=18.0.0",
20
+ "react-dom": ">=18.0.0"
21
+ },
22
+ "dependencies": {
23
+ "@livelayer/sdk": "0.1.0"
24
+ },
25
+ "devDependencies": {
26
+ "@types/react": "^19.0.0",
27
+ "@types/react-dom": "^19.0.0",
28
+ "react": "^19.2.4",
29
+ "react-dom": "^19.2.4",
30
+ "typescript": "^5.0.0",
31
+ "vite": "^6.3.0",
32
+ "vite-plugin-dts": "^4.5.0",
33
+ "vitest": "^4.1.0"
34
+ },
35
+ "license": "MIT",
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "https://github.com/Fusion-Studios-Code/live-layer.git",
39
+ "directory": "packages/react"
40
+ },
41
+ "scripts": {
42
+ "build": "vite build",
43
+ "test": "vitest run",
44
+ "test:watch": "vitest"
45
+ }
46
+ }