@namiruai/react 1.2.0 → 1.4.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 +4 -7
- package/dist/index.d.ts +4 -0
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +2 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
# @
|
|
1
|
+
# @namiruai/react
|
|
2
2
|
|
|
3
3
|
React wrapper for the [Namiru.ai](https://namiru.ai) chat widget -- add AI customer support to your React app.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install @
|
|
8
|
+
npm install @namiruai/react
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
@@ -13,7 +13,7 @@ npm install @namiru/react
|
|
|
13
13
|
### Floating Button (default)
|
|
14
14
|
|
|
15
15
|
```tsx
|
|
16
|
-
import { NamiruChat } from '@
|
|
16
|
+
import { NamiruChat } from '@namiruai/react';
|
|
17
17
|
|
|
18
18
|
function App() {
|
|
19
19
|
return (
|
|
@@ -28,7 +28,7 @@ function App() {
|
|
|
28
28
|
### Inline Mode
|
|
29
29
|
|
|
30
30
|
```tsx
|
|
31
|
-
import { NamiruChat } from '@
|
|
31
|
+
import { NamiruChat } from '@namiruai/react';
|
|
32
32
|
|
|
33
33
|
function App() {
|
|
34
34
|
return (
|
|
@@ -49,13 +49,10 @@ function App() {
|
|
|
49
49
|
| Prop | Type | Description |
|
|
50
50
|
|------|------|-------------|
|
|
51
51
|
| `agentId` | `string` | **Required.** Your Namiru agent ID. |
|
|
52
|
-
| `serverUrl` | `string` | Custom server URL (defaults to Namiru cloud). |
|
|
53
52
|
| `mode` | `'button' \| 'inline'` | Display mode. Default: `'button'`. |
|
|
54
53
|
| `position` | `'bottom-left' \| 'bottom-right'` | Button position. Default: `'bottom-right'`. |
|
|
55
54
|
| `width` | `string` | Width for inline mode. |
|
|
56
55
|
| `height` | `string` | Height for inline mode. |
|
|
57
|
-
| `onLeadCapture` | `(lead) => void` | Callback when a lead is captured. |
|
|
58
|
-
| `onSessionStart` | `(sessionId) => void` | Callback when a chat session starts. |
|
|
59
56
|
|
|
60
57
|
## Documentation
|
|
61
58
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { LeadCaptureData } from "@namiruai/chat";
|
|
2
2
|
export interface NamiruChatProps {
|
|
3
3
|
agentId: string;
|
|
4
|
+
mode?: "button" | "inline";
|
|
5
|
+
position?: "bottom-right" | "bottom-left";
|
|
6
|
+
width?: string;
|
|
7
|
+
height?: string;
|
|
4
8
|
onLeadCapture?: (lead: LeadCaptureData) => void;
|
|
5
9
|
onFeedback?: (rating: "up" | "down") => void;
|
|
6
10
|
onSessionStart?: (sessionId: string) => void;
|
package/dist/index.esm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useRef as
|
|
1
|
+
import{useRef as i,useEffect as d}from"react";import{jsx as s}from"react/jsx-runtime";function g(n){let t=i(null),e=i(null),a=i(n.agentId);return d(()=>{let o=!1;async function r(){let{init:u}=await import("@namiruai/chat");if(o||!t.current)return;let c={agentId:n.agentId,mode:n.mode,position:n.position,width:n.width,height:n.height,container:n.mode==="inline"?t.current:void 0,onLeadCapture:n.onLeadCapture,onFeedback:n.onFeedback,onSessionStart:n.onSessionStart,onSessionEnd:n.onSessionEnd};e.current=u(c)}return r(),()=>{o=!0,e.current?.destroy(),e.current=null}},[n.agentId]),d(()=>{if(a.current!==n.agentId){a.current=n.agentId;return}e.current?.updateConfig({onLeadCapture:n.onLeadCapture,onFeedback:n.onFeedback,onSessionStart:n.onSessionStart,onSessionEnd:n.onSessionEnd})},[n.onLeadCapture,n.onFeedback,n.onSessionStart,n.onSessionEnd]),s("div",{ref:t,style:n.mode==="inline"?{width:n.width,height:n.height}:void 0})}export{g as NamiruChat};
|
|
2
2
|
//# sourceMappingURL=index.esm.js.map
|
package/dist/index.esm.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useRef, useEffect } from \"react\";\nimport type {\n NamiruChatConfig,\n NamiruChatInstance,\n LeadCaptureData,\n} from \"@namiruai/chat\";\n\nexport interface NamiruChatProps {\n agentId: string;\n onLeadCapture?: (lead: LeadCaptureData) => void;\n onFeedback?: (rating: \"up\" | \"down\") => void;\n onSessionStart?: (sessionId: string) => void;\n onSessionEnd?: (sessionId: string) => void;\n}\n\nexport function NamiruChat(props: NamiruChatProps) {\n const containerRef = useRef<HTMLDivElement>(null);\n const instanceRef = useRef<NamiruChatInstance | null>(null);\n const prevAgentIdRef = useRef<string>(props.agentId);\n\n useEffect(() => {\n let destroyed = false;\n\n async function initialize() {\n const { init } = await import(\"@namiruai/chat\");\n\n if (destroyed || !containerRef.current) return;\n\n const config: NamiruChatConfig = {\n agentId: props.agentId,\n onLeadCapture: props.onLeadCapture,\n onFeedback: props.onFeedback,\n onSessionStart: props.onSessionStart,\n onSessionEnd: props.onSessionEnd,\n };\n\n instanceRef.current = init(config);\n }\n\n initialize();\n\n return () => {\n destroyed = true;\n instanceRef.current?.destroy();\n instanceRef.current = null;\n };\n }, [props.agentId]);\n\n // Update callbacks on prop changes (except agentId which triggers re-init)\n useEffect(() => {\n if (prevAgentIdRef.current !== props.agentId) {\n prevAgentIdRef.current = props.agentId;\n return;\n }\n\n instanceRef.current?.updateConfig({\n onLeadCapture: props.onLeadCapture,\n onFeedback: props.onFeedback,\n onSessionStart: props.onSessionStart,\n onSessionEnd: props.onSessionEnd,\n });\n }, [\n props.onLeadCapture,\n props.onFeedback,\n props.onSessionStart,\n props.onSessionEnd,\n ]);\n\n return <div ref={containerRef} />;\n}\n\nexport type { NamiruChatConfig, NamiruChatInstance, LeadCaptureData } from \"@namiruai/chat\";\n"],
|
|
5
|
-
"mappings": "AAAA,OAAS,UAAAA,EAAQ,aAAAC,MAAiB,
|
|
4
|
+
"sourcesContent": ["import { useRef, useEffect } from \"react\";\nimport type {\n NamiruChatConfig,\n NamiruChatInstance,\n LeadCaptureData,\n} from \"@namiruai/chat\";\n\nexport interface NamiruChatProps {\n agentId: string;\n mode?: \"button\" | \"inline\";\n position?: \"bottom-right\" | \"bottom-left\";\n width?: string;\n height?: string;\n onLeadCapture?: (lead: LeadCaptureData) => void;\n onFeedback?: (rating: \"up\" | \"down\") => void;\n onSessionStart?: (sessionId: string) => void;\n onSessionEnd?: (sessionId: string) => void;\n}\n\nexport function NamiruChat(props: NamiruChatProps) {\n const containerRef = useRef<HTMLDivElement>(null);\n const instanceRef = useRef<NamiruChatInstance | null>(null);\n const prevAgentIdRef = useRef<string>(props.agentId);\n\n useEffect(() => {\n let destroyed = false;\n\n async function initialize() {\n const { init } = await import(\"@namiruai/chat\");\n\n if (destroyed || !containerRef.current) return;\n\n const config: NamiruChatConfig = {\n agentId: props.agentId,\n mode: props.mode,\n position: props.position,\n width: props.width,\n height: props.height,\n container: props.mode === \"inline\" ? containerRef.current : undefined,\n onLeadCapture: props.onLeadCapture,\n onFeedback: props.onFeedback,\n onSessionStart: props.onSessionStart,\n onSessionEnd: props.onSessionEnd,\n };\n\n instanceRef.current = init(config);\n }\n\n initialize();\n\n return () => {\n destroyed = true;\n instanceRef.current?.destroy();\n instanceRef.current = null;\n };\n }, [props.agentId]);\n\n // Update callbacks on prop changes (except agentId which triggers re-init)\n useEffect(() => {\n if (prevAgentIdRef.current !== props.agentId) {\n prevAgentIdRef.current = props.agentId;\n return;\n }\n\n instanceRef.current?.updateConfig({\n onLeadCapture: props.onLeadCapture,\n onFeedback: props.onFeedback,\n onSessionStart: props.onSessionStart,\n onSessionEnd: props.onSessionEnd,\n });\n }, [\n props.onLeadCapture,\n props.onFeedback,\n props.onSessionStart,\n props.onSessionEnd,\n ]);\n\n return <div ref={containerRef} style={props.mode === 'inline' ? { width: props.width, height: props.height } : undefined} />;\n}\n\nexport type { NamiruChatConfig, NamiruChatInstance, LeadCaptureData } from \"@namiruai/chat\";\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,UAAAA,EAAQ,aAAAC,MAAiB,QA6EzB,cAAAC,MAAA,oBA1DF,SAASC,EAAWC,EAAwB,CACjD,IAAMC,EAAeL,EAAuB,IAAI,EAC1CM,EAAcN,EAAkC,IAAI,EACpDO,EAAiBP,EAAeI,EAAM,OAAO,EAEnD,OAAAH,EAAU,IAAM,CACd,IAAIO,EAAY,GAEhB,eAAeC,GAAa,CAC1B,GAAM,CAAE,KAAAC,CAAK,EAAI,KAAM,QAAO,gBAAgB,EAE9C,GAAIF,GAAa,CAACH,EAAa,QAAS,OAExC,IAAMM,EAA2B,CAC/B,QAASP,EAAM,QACf,KAAMA,EAAM,KACZ,SAAUA,EAAM,SAChB,MAAOA,EAAM,MACb,OAAQA,EAAM,OACd,UAAWA,EAAM,OAAS,SAAWC,EAAa,QAAU,OAC5D,cAAeD,EAAM,cACrB,WAAYA,EAAM,WAClB,eAAgBA,EAAM,eACtB,aAAcA,EAAM,YACtB,EAEAE,EAAY,QAAUI,EAAKC,CAAM,CACnC,CAEA,OAAAF,EAAW,EAEJ,IAAM,CACXD,EAAY,GACZF,EAAY,SAAS,QAAQ,EAC7BA,EAAY,QAAU,IACxB,CACF,EAAG,CAACF,EAAM,OAAO,CAAC,EAGlBH,EAAU,IAAM,CACd,GAAIM,EAAe,UAAYH,EAAM,QAAS,CAC5CG,EAAe,QAAUH,EAAM,QAC/B,MACF,CAEAE,EAAY,SAAS,aAAa,CAChC,cAAeF,EAAM,cACrB,WAAYA,EAAM,WAClB,eAAgBA,EAAM,eACtB,aAAcA,EAAM,YACtB,CAAC,CACH,EAAG,CACDA,EAAM,cACNA,EAAM,WACNA,EAAM,eACNA,EAAM,YACR,CAAC,EAEMF,EAAC,OAAI,IAAKG,EAAc,MAAOD,EAAM,OAAS,SAAW,CAAE,MAAOA,EAAM,MAAO,OAAQA,EAAM,MAAO,EAAI,OAAW,CAC5H",
|
|
6
6
|
"names": ["useRef", "useEffect", "jsx", "NamiruChat", "props", "containerRef", "instanceRef", "prevAgentIdRef", "destroyed", "initialize", "init", "config"]
|
|
7
7
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var g=Object.create;var d=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,l=Object.prototype.hasOwnProperty;var S=(n,e)=>{for(var t in e)d(n,t,{get:e[t],enumerable:!0})},r=(n,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of m(e))!l.call(n,i)&&i!==t&&d(n,i,{get:()=>e[i],enumerable:!(o=f(e,i))||o.enumerable});return n};var I=(n,e,t)=>(t=n!=null?g(C(n)):{},r(e||!n||!n.__esModule?d(t,"default",{value:n,enumerable:!0}):t,n)),L=n=>r(d({},"__esModule",{value:!0}),n);var N={};S(N,{NamiruChat:()=>b});module.exports=L(N);var a=require("react"),u=require("react/jsx-runtime");function b(n){let e=(0,a.useRef)(null),t=(0,a.useRef)(null),o=(0,a.useRef)(n.agentId);return(0,a.useEffect)(()=>{let i=!1;async function c(){let{init:s}=await import("@namiruai/chat");if(i||!e.current)return;let h={agentId:n.agentId,mode:n.mode,position:n.position,width:n.width,height:n.height,container:n.mode==="inline"?e.current:void 0,onLeadCapture:n.onLeadCapture,onFeedback:n.onFeedback,onSessionStart:n.onSessionStart,onSessionEnd:n.onSessionEnd};t.current=s(h)}return c(),()=>{i=!0,t.current?.destroy(),t.current=null}},[n.agentId]),(0,a.useEffect)(()=>{if(o.current!==n.agentId){o.current=n.agentId;return}t.current?.updateConfig({onLeadCapture:n.onLeadCapture,onFeedback:n.onFeedback,onSessionStart:n.onSessionStart,onSessionEnd:n.onSessionEnd})},[n.onLeadCapture,n.onFeedback,n.onSessionStart,n.onSessionEnd]),(0,u.jsx)("div",{ref:e,style:n.mode==="inline"?{width:n.width,height:n.height}:void 0})}
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useRef, useEffect } from \"react\";\nimport type {\n NamiruChatConfig,\n NamiruChatInstance,\n LeadCaptureData,\n} from \"@namiruai/chat\";\n\nexport interface NamiruChatProps {\n agentId: string;\n onLeadCapture?: (lead: LeadCaptureData) => void;\n onFeedback?: (rating: \"up\" | \"down\") => void;\n onSessionStart?: (sessionId: string) => void;\n onSessionEnd?: (sessionId: string) => void;\n}\n\nexport function NamiruChat(props: NamiruChatProps) {\n const containerRef = useRef<HTMLDivElement>(null);\n const instanceRef = useRef<NamiruChatInstance | null>(null);\n const prevAgentIdRef = useRef<string>(props.agentId);\n\n useEffect(() => {\n let destroyed = false;\n\n async function initialize() {\n const { init } = await import(\"@namiruai/chat\");\n\n if (destroyed || !containerRef.current) return;\n\n const config: NamiruChatConfig = {\n agentId: props.agentId,\n onLeadCapture: props.onLeadCapture,\n onFeedback: props.onFeedback,\n onSessionStart: props.onSessionStart,\n onSessionEnd: props.onSessionEnd,\n };\n\n instanceRef.current = init(config);\n }\n\n initialize();\n\n return () => {\n destroyed = true;\n instanceRef.current?.destroy();\n instanceRef.current = null;\n };\n }, [props.agentId]);\n\n // Update callbacks on prop changes (except agentId which triggers re-init)\n useEffect(() => {\n if (prevAgentIdRef.current !== props.agentId) {\n prevAgentIdRef.current = props.agentId;\n return;\n }\n\n instanceRef.current?.updateConfig({\n onLeadCapture: props.onLeadCapture,\n onFeedback: props.onFeedback,\n onSessionStart: props.onSessionStart,\n onSessionEnd: props.onSessionEnd,\n });\n }, [\n props.onLeadCapture,\n props.onFeedback,\n props.onSessionStart,\n props.onSessionEnd,\n ]);\n\n return <div ref={containerRef} />;\n}\n\nexport type { NamiruChatConfig, NamiruChatInstance, LeadCaptureData } from \"@namiruai/chat\";\n"],
|
|
5
|
-
"mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAkC,
|
|
4
|
+
"sourcesContent": ["import { useRef, useEffect } from \"react\";\nimport type {\n NamiruChatConfig,\n NamiruChatInstance,\n LeadCaptureData,\n} from \"@namiruai/chat\";\n\nexport interface NamiruChatProps {\n agentId: string;\n mode?: \"button\" | \"inline\";\n position?: \"bottom-right\" | \"bottom-left\";\n width?: string;\n height?: string;\n onLeadCapture?: (lead: LeadCaptureData) => void;\n onFeedback?: (rating: \"up\" | \"down\") => void;\n onSessionStart?: (sessionId: string) => void;\n onSessionEnd?: (sessionId: string) => void;\n}\n\nexport function NamiruChat(props: NamiruChatProps) {\n const containerRef = useRef<HTMLDivElement>(null);\n const instanceRef = useRef<NamiruChatInstance | null>(null);\n const prevAgentIdRef = useRef<string>(props.agentId);\n\n useEffect(() => {\n let destroyed = false;\n\n async function initialize() {\n const { init } = await import(\"@namiruai/chat\");\n\n if (destroyed || !containerRef.current) return;\n\n const config: NamiruChatConfig = {\n agentId: props.agentId,\n mode: props.mode,\n position: props.position,\n width: props.width,\n height: props.height,\n container: props.mode === \"inline\" ? containerRef.current : undefined,\n onLeadCapture: props.onLeadCapture,\n onFeedback: props.onFeedback,\n onSessionStart: props.onSessionStart,\n onSessionEnd: props.onSessionEnd,\n };\n\n instanceRef.current = init(config);\n }\n\n initialize();\n\n return () => {\n destroyed = true;\n instanceRef.current?.destroy();\n instanceRef.current = null;\n };\n }, [props.agentId]);\n\n // Update callbacks on prop changes (except agentId which triggers re-init)\n useEffect(() => {\n if (prevAgentIdRef.current !== props.agentId) {\n prevAgentIdRef.current = props.agentId;\n return;\n }\n\n instanceRef.current?.updateConfig({\n onLeadCapture: props.onLeadCapture,\n onFeedback: props.onFeedback,\n onSessionStart: props.onSessionStart,\n onSessionEnd: props.onSessionEnd,\n });\n }, [\n props.onLeadCapture,\n props.onFeedback,\n props.onSessionStart,\n props.onSessionEnd,\n ]);\n\n return <div ref={containerRef} style={props.mode === 'inline' ? { width: props.width, height: props.height } : undefined} />;\n}\n\nexport type { NamiruChatConfig, NamiruChatInstance, LeadCaptureData } from \"@namiruai/chat\";\n"],
|
|
5
|
+
"mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAkC,iBA6EzBC,EAAA,6BA1DF,SAASH,EAAWI,EAAwB,CACjD,IAAMC,KAAe,UAAuB,IAAI,EAC1CC,KAAc,UAAkC,IAAI,EACpDC,KAAiB,UAAeH,EAAM,OAAO,EAEnD,sBAAU,IAAM,CACd,IAAII,EAAY,GAEhB,eAAeC,GAAa,CAC1B,GAAM,CAAE,KAAAC,CAAK,EAAI,KAAM,QAAO,gBAAgB,EAE9C,GAAIF,GAAa,CAACH,EAAa,QAAS,OAExC,IAAMM,EAA2B,CAC/B,QAASP,EAAM,QACf,KAAMA,EAAM,KACZ,SAAUA,EAAM,SAChB,MAAOA,EAAM,MACb,OAAQA,EAAM,OACd,UAAWA,EAAM,OAAS,SAAWC,EAAa,QAAU,OAC5D,cAAeD,EAAM,cACrB,WAAYA,EAAM,WAClB,eAAgBA,EAAM,eACtB,aAAcA,EAAM,YACtB,EAEAE,EAAY,QAAUI,EAAKC,CAAM,CACnC,CAEA,OAAAF,EAAW,EAEJ,IAAM,CACXD,EAAY,GACZF,EAAY,SAAS,QAAQ,EAC7BA,EAAY,QAAU,IACxB,CACF,EAAG,CAACF,EAAM,OAAO,CAAC,KAGlB,aAAU,IAAM,CACd,GAAIG,EAAe,UAAYH,EAAM,QAAS,CAC5CG,EAAe,QAAUH,EAAM,QAC/B,MACF,CAEAE,EAAY,SAAS,aAAa,CAChC,cAAeF,EAAM,cACrB,WAAYA,EAAM,WAClB,eAAgBA,EAAM,eACtB,aAAcA,EAAM,YACtB,CAAC,CACH,EAAG,CACDA,EAAM,cACNA,EAAM,WACNA,EAAM,eACNA,EAAM,YACR,CAAC,KAEM,OAAC,OAAI,IAAKC,EAAc,MAAOD,EAAM,OAAS,SAAW,CAAE,MAAOA,EAAM,MAAO,OAAQA,EAAM,MAAO,EAAI,OAAW,CAC5H",
|
|
6
6
|
"names": ["src_exports", "__export", "NamiruChat", "__toCommonJS", "import_react", "import_jsx_runtime", "props", "containerRef", "instanceRef", "prevAgentIdRef", "destroyed", "initialize", "init", "config"]
|
|
7
7
|
}
|