@namiruai/react 1.12.0 → 1.13.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/dist/index.d.ts CHANGED
@@ -1,43 +1,16 @@
1
- export interface LeadCaptureData {
2
- email?: string;
3
- name?: string;
4
- phone?: string;
5
- company?: string;
6
- }
7
- export interface NamiruChatConfig {
8
- agentId: string;
9
- mode?: "button" | "inline";
10
- position?: "bottom-right" | "bottom-left";
11
- width?: string;
12
- height?: string;
13
- container?: HTMLElement;
14
- serverUrl?: string;
15
- wsUrl?: string;
16
- onLeadCapture?: (lead: LeadCaptureData) => void;
17
- onFeedback?: (rating: "up" | "down") => void;
18
- onSessionStart?: (sessionId: string) => void;
19
- onSessionEnd?: (sessionId: string) => void;
20
- }
21
- export interface NamiruChatInstance {
22
- destroy: () => void;
23
- updateConfig: (config: Partial<NamiruChatConfig>) => void;
24
- }
25
1
  export interface NamiruChatProps {
26
2
  agentId: string;
27
3
  mode?: "button" | "inline";
28
4
  position?: "bottom-right" | "bottom-left";
29
5
  width?: string;
30
6
  height?: string;
31
- serverUrl?: string;
32
- onLeadCapture?: (lead: LeadCaptureData) => void;
33
- onFeedback?: (rating: "up" | "down") => void;
34
- onSessionStart?: (sessionId: string) => void;
35
- onSessionEnd?: (sessionId: string) => void;
36
7
  }
37
8
  declare global {
38
9
  interface Window {
39
10
  NamiruChat?: {
40
- init: (config: NamiruChatConfig) => NamiruChatInstance;
11
+ init: (config: Record<string, unknown>) => {
12
+ destroy: () => void;
13
+ };
41
14
  };
42
15
  }
43
16
  }
package/dist/index.esm.js CHANGED
@@ -1,2 +1,2 @@
1
- import{useRef as a,useEffect as o}from"react";import{jsx as g}from"react/jsx-runtime";var d="https://namiru.ai/widget.js";function c(){return new Promise((n,i)=>{if(window.NamiruChat){n();return}let e=document.querySelector(`script[src="${d}"]`);if(e){e.addEventListener("load",()=>n()),e.addEventListener("error",()=>i(new Error("Failed to load Namiru widget script")));return}let t=document.createElement("script");t.src=d,t.async=!0,t.onload=()=>n(),t.onerror=()=>i(new Error("Failed to load Namiru widget script")),document.head.appendChild(t)})}function m(n){let i=a(null),e=a(null),t=a(n.agentId);return o(()=>{let r=!1;async function s(){if(await c(),r||!i.current||!window.NamiruChat)return;let u={agentId:n.agentId,mode:n.mode,position:n.position,width:n.width,height:n.height,serverUrl:n.serverUrl,container:n.mode==="inline"?i.current:void 0,onLeadCapture:n.onLeadCapture,onFeedback:n.onFeedback,onSessionStart:n.onSessionStart,onSessionEnd:n.onSessionEnd};e.current=window.NamiruChat.init(u)}return s(),()=>{r=!0,e.current?.destroy(),e.current=null}},[n.agentId]),o(()=>{if(t.current!==n.agentId){t.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]),g("div",{ref:i,style:n.mode==="inline"?{width:n.width,height:n.height}:void 0})}export{m as NamiruChat};
1
+ import{useRef as r,useEffect as a}from"react";import{jsx as c}from"react/jsx-runtime";var o="https://namiru.ai/widget.js";function u(){return new Promise((t,n)=>{if(window.NamiruChat){t();return}let i=document.querySelector(`script[src="${o}"]`);if(i){i.addEventListener("load",()=>t()),i.addEventListener("error",()=>n(new Error("Failed to load Namiru widget script")));return}let e=document.createElement("script");e.src=o,e.async=!0,e.onload=()=>t(),e.onerror=()=>n(new Error("Failed to load Namiru widget script")),document.head.appendChild(e)})}function s(t){let n=r(null),i=r(null);return a(()=>{let e=!1;async function d(){await u(),!(e||!n.current||!window.NamiruChat)&&(i.current=window.NamiruChat.init({agentId:t.agentId,mode:t.mode,position:t.position,width:t.width,height:t.height,container:t.mode==="inline"?n.current:void 0}))}return d(),()=>{e=!0,i.current?.destroy(),i.current=null}},[t.agentId]),c("div",{ref:n,style:t.mode==="inline"?{width:t.width,height:t.height}:void 0})}export{s as NamiruChat};
2
2
  //# sourceMappingURL=index.esm.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.tsx"],
4
- "sourcesContent": ["import { useRef, useEffect } from \"react\";\n\nexport interface LeadCaptureData {\n email?: string;\n name?: string;\n phone?: string;\n company?: string;\n}\n\nexport interface NamiruChatConfig {\n agentId: string;\n mode?: \"button\" | \"inline\";\n position?: \"bottom-right\" | \"bottom-left\";\n width?: string;\n height?: string;\n container?: HTMLElement;\n serverUrl?: string;\n wsUrl?: 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 interface NamiruChatInstance {\n destroy: () => void;\n updateConfig: (config: Partial<NamiruChatConfig>) => void;\n}\n\nexport interface NamiruChatProps {\n agentId: string;\n mode?: \"button\" | \"inline\";\n position?: \"bottom-right\" | \"bottom-left\";\n width?: string;\n height?: string;\n serverUrl?: string;\n onLeadCapture?: (lead: LeadCaptureData) => void;\n onFeedback?: (rating: \"up\" | \"down\") => void;\n onSessionStart?: (sessionId: string) => void;\n onSessionEnd?: (sessionId: string) => void;\n}\n\ndeclare global {\n interface Window {\n NamiruChat?: {\n init: (config: NamiruChatConfig) => NamiruChatInstance;\n };\n }\n}\n\nconst WIDGET_SCRIPT_URL = \"https://namiru.ai/widget.js\";\n\nfunction loadWidgetScript(): Promise<void> {\n return new Promise((resolve, reject) => {\n // Already loaded\n if (window.NamiruChat) {\n resolve();\n return;\n }\n\n // Check if script tag already exists\n const existing = document.querySelector(`script[src=\"${WIDGET_SCRIPT_URL}\"]`);\n if (existing) {\n existing.addEventListener(\"load\", () => resolve());\n existing.addEventListener(\"error\", () => reject(new Error(\"Failed to load Namiru widget script\")));\n return;\n }\n\n const script = document.createElement(\"script\");\n script.src = WIDGET_SCRIPT_URL;\n script.async = true;\n script.onload = () => resolve();\n script.onerror = () => reject(new Error(\"Failed to load Namiru widget script\"));\n document.head.appendChild(script);\n });\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 await loadWidgetScript();\n\n if (destroyed || !containerRef.current || !window.NamiruChat) 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 serverUrl: props.serverUrl,\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 = window.NamiruChat.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"],
5
- "mappings": "AAAA,OAAS,UAAAA,EAAQ,aAAAC,MAAiB,QAwIzB,cAAAC,MAAA,oBAtFT,IAAMC,EAAoB,8BAE1B,SAASC,GAAkC,CACzC,OAAO,IAAI,QAAQ,CAACC,EAASC,IAAW,CAEtC,GAAI,OAAO,WAAY,CACrBD,EAAQ,EACR,MACF,CAGA,IAAME,EAAW,SAAS,cAAc,eAAeJ,CAAiB,IAAI,EAC5E,GAAII,EAAU,CACZA,EAAS,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M,eACtB,aAAcA,EAAM,YACtB,CAAC,CACH,EAAG,CACDA,EAAM,cACNA,EAAM,WACNA,EAAM,eACNA,EAAM,YACR,CAAC,EAEMR,EAAC,OAAI,IAAKS,EAAc,MAAOD,EAAM,OAAS,SAAW,CAAE,MAAOA,EAAM,MAAO,OAAQA,EAAM,MAAO,EAAI,OAAW,CAC5H",
6
- "names": ["useRef", "useEffect", "jsx", "WIDGET_SCRIPT_URL", "loadWidgetScript", "resolve", "reject", "existing", "script", "NamiruChat", "props", "containerRef", "instanceRef", "prevAgentIdRef", "destroyed", "initialize", "config"]
4
+ "sourcesContent": ["import { useRef, useEffect } from \"react\";\n\nexport interface NamiruChatProps {\n agentId: string;\n mode?: \"button\" | \"inline\";\n position?: \"bottom-right\" | \"bottom-left\";\n width?: string;\n height?: string;\n}\n\ndeclare global {\n interface Window {\n NamiruChat?: {\n init: (config: Record<string, unknown>) => { destroy: () => void };\n };\n }\n}\n\nconst WIDGET_SCRIPT_URL = \"https://namiru.ai/widget.js\";\n\nfunction loadWidgetScript(): Promise<void> {\n return new Promise((resolve, reject) => {\n if (window.NamiruChat) { resolve(); return; }\n const existing = document.querySelector(`script[src=\"${WIDGET_SCRIPT_URL}\"]`);\n if (existing) {\n existing.addEventListener(\"load\", () => resolve());\n existing.addEventListener(\"error\", () => reject(new Error(\"Failed to load Namiru widget script\")));\n return;\n }\n const script = document.createElement(\"script\");\n script.src = WIDGET_SCRIPT_URL;\n script.async = true;\n script.onload = () => resolve();\n script.onerror = () => reject(new Error(\"Failed to load Namiru widget script\"));\n document.head.appendChild(script);\n });\n}\n\nexport function NamiruChat(props: NamiruChatProps) {\n const containerRef = useRef<HTMLDivElement>(null);\n const instanceRef = useRef<{ destroy: () => void } | null>(null);\n\n useEffect(() => {\n let destroyed = false;\n\n async function initialize() {\n await loadWidgetScript();\n if (destroyed || !containerRef.current || !window.NamiruChat) return;\n\n instanceRef.current = window.NamiruChat.init({\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 });\n }\n\n initialize();\n\n return () => {\n destroyed = true;\n instanceRef.current?.destroy();\n instanceRef.current = null;\n };\n }, [props.agentId]);\n\n return <div ref={containerRef} style={props.mode === 'inline' ? { width: props.width, height: props.height } : undefined} />;\n}\n"],
5
+ "mappings": "AAAA,OAAS,UAAAA,EAAQ,aAAAC,MAAiB,QAoEzB,cAAAC,MAAA,oBAlDT,IAAMC,EAAoB,8BAE1B,SAASC,GAAkC,CACzC,OAAO,IAAI,QAAQ,CAACC,EAASC,IAAW,CACtC,GAAI,OAAO,WAAY,CAAED,EAAQ,EAAG,MAAQ,CAC5C,IAAME,EAAW,SAAS,cAAc,eAAeJ,CAAiB,IAAI,EAC5E,GAAII,EAAU,CACZA,EAAS,iBAAiB,OAAQ,IAAMF,EAAQ,CAAC,EACjDE,EAAS,iBAAiB,QAAS,IAAMD,EAAO,IAAI,MAAM,qCAAqC,CAAC,CAAC,EACjG,MACF,CACA,IAAME,EAAS,SAAS,cAAc,QAAQ,EAC9CA,EAAO,IAAML,EACbK,EAAO,MAAQ,GACfA,EAAO,OAAS,IAAMH,EAAQ,EAC9BG,EAAO,QAAU,IAAMF,EAAO,IAAI,MAAM,qCAAqC,CAAC,EAC9E,SAAS,KAAK,YAAYE,CAAM,CAClC,CAAC,CACH,CAEO,SAASC,EAAWC,EAAwB,CACjD,IAAMC,EAAeX,EAAuB,IAAI,EAC1CY,EAAcZ,EAAuC,IAAI,EAE/D,OAAAC,EAAU,IAAM,CACd,IAAIY,EAAY,GAEhB,eAAeC,GAAa,CAC1B,MAAMV,EAAiB,EACnB,EAAAS,GAAa,CAACF,EAAa,SAAW,CAAC,OAAO,cAElDC,EAAY,QAAU,OAAO,WAAW,KAAK,CAC3C,QAASF,EAAM,QACf,KAAMA,EAAM,KACZ,SAAUA,EAAM,SAChB,MAAOA,EAAM,MACb,OAAQA,EAAM,OACd,UAAWA,EAAM,OAAS,SAAWC,EAAa,QAAU,MAC9D,CAAC,EACH,CAEA,OAAAG,EAAW,EAEJ,IAAM,CACXD,EAAY,GACZD,EAAY,SAAS,QAAQ,EAC7BA,EAAY,QAAU,IACxB,CACF,EAAG,CAACF,EAAM,OAAO,CAAC,EAEXR,EAAC,OAAI,IAAKS,EAAc,MAAOD,EAAM,OAAS,SAAW,CAAE,MAAOA,EAAM,MAAO,OAAQA,EAAM,MAAO,EAAI,OAAW,CAC5H",
6
+ "names": ["useRef", "useEffect", "jsx", "WIDGET_SCRIPT_URL", "loadWidgetScript", "resolve", "reject", "existing", "script", "NamiruChat", "props", "containerRef", "instanceRef", "destroyed", "initialize"]
7
7
  }
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var o=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var h=(n,e)=>{for(var t in e)o(n,t,{get:e[t],enumerable:!0})},f=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of l(e))!m.call(n,a)&&a!==t&&o(n,a,{get:()=>e[a],enumerable:!(i=g(e,a))||i.enumerable});return n};var C=n=>f(o({},"__esModule",{value:!0}),n);var v={};h(v,{NamiruChat:()=>w});module.exports=C(v);var r=require("react"),s=require("react/jsx-runtime"),d="https://namiru.ai/widget.js";function S(){return new Promise((n,e)=>{if(window.NamiruChat){n();return}let t=document.querySelector(`script[src="${d}"]`);if(t){t.addEventListener("load",()=>n()),t.addEventListener("error",()=>e(new Error("Failed to load Namiru widget script")));return}let i=document.createElement("script");i.src=d,i.async=!0,i.onload=()=>n(),i.onerror=()=>e(new Error("Failed to load Namiru widget script")),document.head.appendChild(i)})}function w(n){let e=(0,r.useRef)(null),t=(0,r.useRef)(null),i=(0,r.useRef)(n.agentId);return(0,r.useEffect)(()=>{let a=!1;async function u(){if(await S(),a||!e.current||!window.NamiruChat)return;let c={agentId:n.agentId,mode:n.mode,position:n.position,width:n.width,height:n.height,serverUrl:n.serverUrl,container:n.mode==="inline"?e.current:void 0,onLeadCapture:n.onLeadCapture,onFeedback:n.onFeedback,onSessionStart:n.onSessionStart,onSessionEnd:n.onSessionEnd};t.current=window.NamiruChat.init(c)}return u(),()=>{a=!0,t.current?.destroy(),t.current=null}},[n.agentId]),(0,r.useEffect)(()=>{if(i.current!==n.agentId){i.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,s.jsx)("div",{ref:e,style:n.mode==="inline"?{width:n.width,height:n.height}:void 0})}
1
+ "use strict";var d=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var s=Object.prototype.hasOwnProperty;var h=(t,e)=>{for(var i in e)d(t,i,{get:e[i],enumerable:!0})},m=(t,e,i,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of l(e))!s.call(t,r)&&r!==i&&d(t,r,{get:()=>e[r],enumerable:!(n=c(e,r))||n.enumerable});return t};var g=t=>m(d({},"__esModule",{value:!0}),t);var C={};h(C,{NamiruChat:()=>w});module.exports=g(C);var o=require("react"),u=require("react/jsx-runtime"),a="https://namiru.ai/widget.js";function f(){return new Promise((t,e)=>{if(window.NamiruChat){t();return}let i=document.querySelector(`script[src="${a}"]`);if(i){i.addEventListener("load",()=>t()),i.addEventListener("error",()=>e(new Error("Failed to load Namiru widget script")));return}let n=document.createElement("script");n.src=a,n.async=!0,n.onload=()=>t(),n.onerror=()=>e(new Error("Failed to load Namiru widget script")),document.head.appendChild(n)})}function w(t){let e=(0,o.useRef)(null),i=(0,o.useRef)(null);return(0,o.useEffect)(()=>{let n=!1;async function r(){await f(),!(n||!e.current||!window.NamiruChat)&&(i.current=window.NamiruChat.init({agentId:t.agentId,mode:t.mode,position:t.position,width:t.width,height:t.height,container:t.mode==="inline"?e.current:void 0}))}return r(),()=>{n=!0,i.current?.destroy(),i.current=null}},[t.agentId]),(0,u.jsx)("div",{ref:e,style:t.mode==="inline"?{width:t.width,height:t.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\";\n\nexport interface LeadCaptureData {\n email?: string;\n name?: string;\n phone?: string;\n company?: string;\n}\n\nexport interface NamiruChatConfig {\n agentId: string;\n mode?: \"button\" | \"inline\";\n position?: \"bottom-right\" | \"bottom-left\";\n width?: string;\n height?: string;\n container?: HTMLElement;\n serverUrl?: string;\n wsUrl?: 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 interface NamiruChatInstance {\n destroy: () => void;\n updateConfig: (config: Partial<NamiruChatConfig>) => void;\n}\n\nexport interface NamiruChatProps {\n agentId: string;\n mode?: \"button\" | \"inline\";\n position?: \"bottom-right\" | \"bottom-left\";\n width?: string;\n height?: string;\n serverUrl?: string;\n onLeadCapture?: (lead: LeadCaptureData) => void;\n onFeedback?: (rating: \"up\" | \"down\") => void;\n onSessionStart?: (sessionId: string) => void;\n onSessionEnd?: (sessionId: string) => void;\n}\n\ndeclare global {\n interface Window {\n NamiruChat?: {\n init: (config: NamiruChatConfig) => NamiruChatInstance;\n };\n }\n}\n\nconst WIDGET_SCRIPT_URL = \"https://namiru.ai/widget.js\";\n\nfunction loadWidgetScript(): Promise<void> {\n return new Promise((resolve, reject) => {\n // Already loaded\n if (window.NamiruChat) {\n resolve();\n return;\n }\n\n // Check if script tag already exists\n const existing = document.querySelector(`script[src=\"${WIDGET_SCRIPT_URL}\"]`);\n if (existing) {\n existing.addEventListener(\"load\", () => resolve());\n existing.addEventListener(\"error\", () => reject(new Error(\"Failed to load Namiru widget script\")));\n return;\n }\n\n const script = document.createElement(\"script\");\n script.src = WIDGET_SCRIPT_URL;\n script.async = true;\n script.onload = () => resolve();\n script.onerror = () => reject(new Error(\"Failed to load Namiru widget script\"));\n document.head.appendChild(script);\n });\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 await loadWidgetScript();\n\n if (destroyed || !containerRef.current || !window.NamiruChat) 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 serverUrl: props.serverUrl,\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 = window.NamiruChat.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"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAkC,iBAwIzBC,EAAA,6BAtFHC,EAAoB,8BAE1B,SAASC,GAAkC,C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M,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
- "names": ["src_exports", "__export", "NamiruChat", "__toCommonJS", "import_react", "import_jsx_runtime", "WIDGET_SCRIPT_URL", "loadWidgetScript", "resolve", "reject", "existing", "script", "props", "containerRef", "instanceRef", "prevAgentIdRef", "destroyed", "initialize", "config"]
4
+ "sourcesContent": ["import { useRef, useEffect } from \"react\";\n\nexport interface NamiruChatProps {\n agentId: string;\n mode?: \"button\" | \"inline\";\n position?: \"bottom-right\" | \"bottom-left\";\n width?: string;\n height?: string;\n}\n\ndeclare global {\n interface Window {\n NamiruChat?: {\n init: (config: Record<string, unknown>) => { destroy: () => void };\n };\n }\n}\n\nconst WIDGET_SCRIPT_URL = \"https://namiru.ai/widget.js\";\n\nfunction loadWidgetScript(): Promise<void> {\n return new Promise((resolve, reject) => {\n if (window.NamiruChat) { resolve(); return; }\n const existing = document.querySelector(`script[src=\"${WIDGET_SCRIPT_URL}\"]`);\n if (existing) {\n existing.addEventListener(\"load\", () => resolve());\n existing.addEventListener(\"error\", () => reject(new Error(\"Failed to load Namiru widget script\")));\n return;\n }\n const script = document.createElement(\"script\");\n script.src = WIDGET_SCRIPT_URL;\n script.async = true;\n script.onload = () => resolve();\n script.onerror = () => reject(new Error(\"Failed to load Namiru widget script\"));\n document.head.appendChild(script);\n });\n}\n\nexport function NamiruChat(props: NamiruChatProps) {\n const containerRef = useRef<HTMLDivElement>(null);\n const instanceRef = useRef<{ destroy: () => void } | null>(null);\n\n useEffect(() => {\n let destroyed = false;\n\n async function initialize() {\n await loadWidgetScript();\n if (destroyed || !containerRef.current || !window.NamiruChat) return;\n\n instanceRef.current = window.NamiruChat.init({\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 });\n }\n\n initialize();\n\n return () => {\n destroyed = true;\n instanceRef.current?.destroy();\n instanceRef.current = null;\n };\n }, [props.agentId]);\n\n return <div ref={containerRef} style={props.mode === 'inline' ? { width: props.width, height: props.height } : undefined} />;\n}\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAkC,iBAoEzBC,EAAA,6BAlDHC,EAAoB,8BAE1B,SAASC,GAAkC,CACzC,OAAO,IAAI,QAAQ,CAACC,EAASC,IAAW,CACtC,GAAI,OAAO,WAAY,CAAED,EAAQ,EAAG,MAAQ,CAC5C,IAAME,EAAW,SAAS,cAAc,eAAeJ,CAAiB,IAAI,EAC5E,GAAII,EAAU,CACZA,EAAS,iBAAiB,OAAQ,IAAMF,EAAQ,CAAC,EACjDE,EAAS,iBAAiB,QAAS,IAAMD,EAAO,IAAI,MAAM,qCAAqC,CAAC,CAAC,EACjG,MACF,CACA,IAAME,EAAS,SAAS,cAAc,QAAQ,EAC9CA,EAAO,IAAML,EACbK,EAAO,MAAQ,GACfA,EAAO,OAAS,IAAMH,EAAQ,EAC9BG,EAAO,QAAU,IAAMF,EAAO,IAAI,MAAM,qCAAqC,CAAC,EAC9E,SAAS,KAAK,YAAYE,CAAM,CAClC,CAAC,CACH,CAEO,SAAST,EAAWU,EAAwB,CACjD,IAAMC,KAAe,UAAuB,IAAI,EAC1CC,KAAc,UAAuC,IAAI,EAE/D,sBAAU,IAAM,CACd,IAAIC,EAAY,GAEhB,eAAeC,GAAa,CAC1B,MAAMT,EAAiB,EACnB,EAAAQ,GAAa,CAACF,EAAa,SAAW,CAAC,OAAO,cAElDC,EAAY,QAAU,OAAO,WAAW,KAAK,CAC3C,QAASF,EAAM,QACf,KAAMA,EAAM,KACZ,SAAUA,EAAM,SAChB,MAAOA,EAAM,MACb,OAAQA,EAAM,OACd,UAAWA,EAAM,OAAS,SAAWC,EAAa,QAAU,MAC9D,CAAC,EACH,CAEA,OAAAG,EAAW,EAEJ,IAAM,CACXD,EAAY,GACZD,EAAY,SAAS,QAAQ,EAC7BA,EAAY,QAAU,IACxB,CACF,EAAG,CAACF,EAAM,OAAO,CAAC,KAEX,OAAC,OAAI,IAAKC,EAAc,MAAOD,EAAM,OAAS,SAAW,CAAE,MAAOA,EAAM,MAAO,OAAQA,EAAM,MAAO,EAAI,OAAW,CAC5H",
6
+ "names": ["src_exports", "__export", "NamiruChat", "__toCommonJS", "import_react", "import_jsx_runtime", "WIDGET_SCRIPT_URL", "loadWidgetScript", "resolve", "reject", "existing", "script", "props", "containerRef", "instanceRef", "destroyed", "initialize"]
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@namiruai/react",
3
- "version": "1.12.0",
3
+ "version": "1.13.0",
4
4
  "description": "React wrapper for Namiru AI chat widget",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",