@bitpalm/ai-agents 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/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +22 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/react.cjs +2 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +35 -0
- package/dist/react.d.ts +35 -0
- package/dist/react.js +2 -0
- package/dist/react.js.map +1 -0
- package/package.json +49 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var S=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var R=(o,i)=>{for(var c in i)S(o,c,{get:i[c],enumerable:!0})},U=(o,i,c,u)=>{if(i&&typeof i=="object"||typeof i=="function")for(let l of z(i))!O.call(o,l)&&l!==c&&S(o,l,{get:()=>i[l],enumerable:!(u=P(i,l))||u.enumerable});return o};var D=o=>U(S({},"__esModule",{value:!0}),o);var J={};R(J,{createWidget:()=>b});module.exports=D(J);var N="https://agents.bitpalm.ae",r="_bp_";function j(){if(typeof document<"u"){let o=document.documentElement.lang;if(o)return o.slice(0,2).toLowerCase()}return"en"}function b(o){let{slug:i,locale:c=j(),baseUrl:u=N,zIndex:l=9999}=o,n=document,s=n.createElement("iframe"),E=`${u}/t/${i}/widget`;s.src=`${E}${E.includes("?")?"&":"?"}locale=${c}`,s.allow="clipboard-write",s.setAttribute("allowtransparency","true"),s.style.cssText=`position:fixed;bottom:0;right:0;width:0;height:0;border:none;z-index:${l};background:transparent;color-scheme:normal;transition:width .3s,height .3s;`,n.body.appendChild(s);let B=new URL(s.src).origin,e=n.createElement("div");if(e.setAttribute("role","button"),e.setAttribute("aria-label","Chat"),e.style.cssText=`position:fixed;bottom:24px;right:24px;width:56px;height:56px;border-radius:50%;display:none;align-items:center;justify-content:center;cursor:pointer;z-index:${l-1};background:#00ff41;box-shadow:0 0 15px rgba(0,255,65,0.31);transition:transform .2s;`,e.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M7.9 20A9 9 0 1 0 4 16.1L2 22Z"/></svg>',e.onmouseenter=()=>{e.style.transform="scale(1.1)"},e.onmouseleave=()=>{e.style.transform="scale(1)"},e.onclick=()=>W(),n.body.appendChild(e),!n.getElementById("_bp_fade")){let t=n.createElement("style");t.id="_bp_fade",t.textContent="@keyframes _bp_fade{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}",n.head.appendChild(t)}let d=null,g=()=>{d&&(d.remove(),d=null)},I=t=>{if(t.origin===B){if(t.data?.type==="bitpalm-widget-config"){t.data.primaryColor&&(e.style.background=t.data.primaryColor,e.style.boxShadow=t.data.chatShadow==="none"?"none":`0 0 15px ${t.data.primaryColor}50`);let p=t.data.chatButtonIconColor||"black";if(t.data.chatButtonIconSvg){e.innerHTML="";let a=n.createElement("span");a.style.cssText=`display:flex;align-items:center;justify-content:center;width:24px;height:24px;color:${p}`,a.innerHTML=t.data.chatButtonIconSvg,e.appendChild(a)}else{let a=e.querySelector("svg");a&&(a.style.stroke=p)}e.style.display="flex"}if(t.data?.type==="bitpalm-widget-resize"&&(s.style.width=`${t.data.width}px`,s.style.height=`${t.data.height}px`,e.style.display=t.data.width>0?"none":"flex"),t.data?.type==="bitpalm-trigger-show"){g(),d=n.createElement("div"),d.style.cssText=`position:fixed;bottom:90px;right:24px;max-width:240px;background:#fff;border-radius:16px;padding:12px 32px 12px 12px;box-shadow:0 2px 20px rgba(0,0,0,0.08);cursor:pointer;z-index:${l-1};font-family:system-ui,sans-serif;animation:_bp_fade .3s;`;let p=(t.data.message||"").replace(/</g,"<");d.innerHTML=`<p style="font-size:14px;color:#1f2937;margin:0;">${p}</p><div style="position:absolute;bottom:-8px;right:20px;width:0;height:0;border-left:8px solid transparent;border-right:8px solid transparent;border-top:8px solid #fff;"></div>`;let a=n.createElement("button");a.style.cssText="position:absolute;top:-8px;right:-8px;width:28px;height:28px;border-radius:50%;background:#fff;border:none;box-shadow:0 1px 4px rgba(0,0,0,0.1);cursor:pointer;display:flex;align-items:center;justify-content:center;font-size:14px;color:#9ca3af;",a.innerHTML="✕",a.onclick=H=>{H.stopPropagation(),g(),s.contentWindow?.postMessage({type:"bitpalm-trigger-dismiss"},"*")},d.onclick=()=>{g(),e.style.display="none",s.contentWindow?.postMessage({type:"bitpalm-trigger-engaged"},"*")},d.appendChild(a),n.body.appendChild(d)}t.data?.type==="bitpalm-trigger-hide"&&g()}};window.addEventListener("message",I);let h=parseInt(sessionStorage.getItem(`${r}pages`)||"0")+1;sessionStorage.setItem(`${r}pages`,String(h));let m=JSON.parse(sessionStorage.getItem(`${r}hist`)||"[]");m.push(location.href),m.length>20&&(m=m.slice(-20)),sessionStorage.setItem(`${r}hist`,JSON.stringify(m));let L=Date.now(),f=parseInt(sessionStorage.getItem(`${r}site_start`)||"0");f||(f=L,sessionStorage.setItem(`${r}site_start`,String(f))),s.addEventListener("load",()=>{let t=!!localStorage.getItem(`${r}visited`);s.contentWindow?.postMessage({type:"bitpalm-parent-context",url:location.href,title:n.title,returning:t,pageCount:h,pageHistory:m,loadedAt:L,siteStart:f,locale:c},"*"),t||localStorage.setItem(`${r}visited`,"1")});let T=history.pushState.bind(history),M=history.replaceState.bind(history),y=()=>{h++,sessionStorage.setItem(`${r}pages`,String(h));let t=JSON.parse(sessionStorage.getItem(`${r}hist`)||"[]");t.push(location.href),t.length>20&&t.splice(0,t.length-20),sessionStorage.setItem(`${r}hist`,JSON.stringify(t)),s.contentWindow?.postMessage({type:"bitpalm-page-change",url:location.href,title:n.title,pageCount:h,pageHistory:t,loadedAt:Date.now()},"*")};history.pushState=function(...t){T(...t),y()},history.replaceState=function(...t){M(...t),y()},window.addEventListener("popstate",y);let $=-1,x,k=()=>{clearTimeout(x),x=setTimeout(()=>{let t=Math.max(n.documentElement.scrollHeight,n.body.scrollHeight)-window.innerHeight,p=t>0?Math.round(window.scrollY/t*100):100;p!==$&&($=p,s.contentWindow?.postMessage({type:"bitpalm-scroll-depth",percent:p},"*"))},500)};window.addEventListener("scroll",k,{passive:!0});let _=t=>{t.clientY<=0&&s.contentWindow?.postMessage({type:"bitpalm-exit-intent"},"*")};n.addEventListener("mouseout",_);let w,A=!1,v=()=>{clearTimeout(w),!A&&(w=setTimeout(()=>{A=!0,s.contentWindow?.postMessage({type:"bitpalm-inactivity"},"*")},15e3))},C=["mousemove","keydown","scroll","touchstart"];C.forEach(t=>n.addEventListener(t,v,{passive:!0})),v();let W=()=>{e.style.display="none",g(),s.contentWindow?.postMessage({type:"bitpalm-open"},"*")};return{open:W,close:()=>{s.contentWindow?.postMessage({type:"bitpalm-close"},"*")},destroy:()=>{window.removeEventListener("message",I),window.removeEventListener("scroll",k),window.removeEventListener("popstate",y),n.removeEventListener("mouseout",_),C.forEach(t=>n.removeEventListener(t,v)),clearTimeout(x),clearTimeout(w),history.pushState=T,history.replaceState=M,g(),e.remove(),s.remove()}}}if(typeof document<"u"){let o=document.currentScript;if(o?.dataset.slug){let i=()=>{b({slug:o.dataset.slug,locale:o.dataset.locale,baseUrl:o.dataset.baseUrl,zIndex:o.dataset.zIndex?Number(o.dataset.zIndex):void 0})};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",i):i()}}0&&(module.exports={createWidget});
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/widget.ts"],"sourcesContent":["export { createWidget } from \"./widget\";\nexport type { BitPalmAgentOptions, BitPalmAgentInstance } from \"./types\";\n\nimport { createWidget } from \"./widget\";\n\n/**\n * Auto-init from script tag:\n * <script src=\"https://cdn.bitpalm.ae/widget.js\" data-slug=\"my-agent\"></script>\n */\nif (typeof document !== \"undefined\") {\n const script = document.currentScript as HTMLScriptElement | null;\n if (script?.dataset.slug) {\n const init = () => {\n createWidget({\n slug: script!.dataset.slug!,\n locale: script!.dataset.locale,\n baseUrl: script!.dataset.baseUrl,\n zIndex: script!.dataset.zIndex ? Number(script!.dataset.zIndex) : undefined,\n });\n };\n\n if (document.readyState === \"loading\") {\n document.addEventListener(\"DOMContentLoaded\", init);\n } else {\n init();\n }\n }\n}\n","import type { BitPalmAgentOptions, BitPalmAgentInstance } from \"./types\";\n\nconst DEFAULT_BASE_URL = \"https://agents.bitpalm.ae\";\nconst STORAGE_PREFIX = \"_bp_\";\n\nfunction detectLocale(): string {\n if (typeof document !== \"undefined\") {\n const lang = document.documentElement.lang;\n if (lang) return lang.slice(0, 2).toLowerCase();\n }\n return \"en\";\n}\n\nexport function createWidget(options: BitPalmAgentOptions): BitPalmAgentInstance {\n const {\n slug,\n locale = detectLocale(),\n baseUrl = DEFAULT_BASE_URL,\n zIndex = 9999,\n } = options;\n\n const d = document;\n\n // --- Iframe ---\n const iframe = d.createElement(\"iframe\");\n const widgetUrl = `${baseUrl}/t/${slug}/widget`;\n iframe.src = `${widgetUrl}${widgetUrl.includes(\"?\") ? \"&\" : \"?\"}locale=${locale}`;\n iframe.allow = \"clipboard-write\";\n iframe.setAttribute(\"allowtransparency\", \"true\");\n iframe.style.cssText = `position:fixed;bottom:0;right:0;width:0;height:0;border:none;z-index:${zIndex};background:transparent;color-scheme:normal;transition:width .3s,height .3s;`;\n d.body.appendChild(iframe);\n\n const origin = new URL(iframe.src).origin;\n\n // --- Native launcher button ---\n const btn = d.createElement(\"div\");\n btn.setAttribute(\"role\", \"button\");\n btn.setAttribute(\"aria-label\", \"Chat\");\n btn.style.cssText = `position:fixed;bottom:24px;right:24px;width:56px;height:56px;border-radius:50%;display:none;align-items:center;justify-content:center;cursor:pointer;z-index:${zIndex - 1};background:#00ff41;box-shadow:0 0 15px rgba(0,255,65,0.31);transition:transform .2s;`;\n btn.innerHTML = '<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"black\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"M7.9 20A9 9 0 1 0 4 16.1L2 22Z\"/></svg>';\n btn.onmouseenter = () => { btn.style.transform = \"scale(1.1)\"; };\n btn.onmouseleave = () => { btn.style.transform = \"scale(1)\"; };\n btn.onclick = () => openWidget();\n d.body.appendChild(btn);\n\n // --- Fade animation for trigger bubbles ---\n if (!d.getElementById(\"_bp_fade\")) {\n const s = d.createElement(\"style\");\n s.id = \"_bp_fade\";\n s.textContent = \"@keyframes _bp_fade{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}\";\n d.head.appendChild(s);\n }\n\n // --- Trigger bubble ---\n let bubble: HTMLDivElement | null = null;\n const removeBubble = () => {\n if (bubble) { bubble.remove(); bubble = null; }\n };\n\n // --- postMessage handler ---\n const handleMessage = (e: MessageEvent) => {\n if (e.origin !== origin) return;\n\n // Widget config (colors, icon)\n if (e.data?.type === \"bitpalm-widget-config\") {\n if (e.data.primaryColor) {\n btn.style.background = e.data.primaryColor;\n btn.style.boxShadow = e.data.chatShadow === \"none\" ? \"none\" : `0 0 15px ${e.data.primaryColor}50`;\n }\n const ic = e.data.chatButtonIconColor || \"black\";\n if (e.data.chatButtonIconSvg) {\n btn.innerHTML = \"\";\n const sp = d.createElement(\"span\");\n sp.style.cssText = `display:flex;align-items:center;justify-content:center;width:24px;height:24px;color:${ic}`;\n sp.innerHTML = e.data.chatButtonIconSvg;\n btn.appendChild(sp);\n } else {\n const sv = btn.querySelector(\"svg\");\n if (sv) (sv as SVGElement).style.stroke = ic;\n }\n btn.style.display = \"flex\";\n }\n\n // Resize\n if (e.data?.type === \"bitpalm-widget-resize\") {\n iframe.style.width = `${e.data.width}px`;\n iframe.style.height = `${e.data.height}px`;\n btn.style.display = e.data.width > 0 ? \"none\" : \"flex\";\n }\n\n // Trigger bubble show\n if (e.data?.type === \"bitpalm-trigger-show\") {\n removeBubble();\n bubble = d.createElement(\"div\");\n bubble.style.cssText = `position:fixed;bottom:90px;right:24px;max-width:240px;background:#fff;border-radius:16px;padding:12px 32px 12px 12px;box-shadow:0 2px 20px rgba(0,0,0,0.08);cursor:pointer;z-index:${zIndex - 1};font-family:system-ui,sans-serif;animation:_bp_fade .3s;`;\n const msg = (e.data.message || \"\").replace(/</g, \"<\");\n bubble.innerHTML = `<p style=\"font-size:14px;color:#1f2937;margin:0;\">${msg}</p><div style=\"position:absolute;bottom:-8px;right:20px;width:0;height:0;border-left:8px solid transparent;border-right:8px solid transparent;border-top:8px solid #fff;\"></div>`;\n const close = d.createElement(\"button\");\n close.style.cssText = \"position:absolute;top:-8px;right:-8px;width:28px;height:28px;border-radius:50%;background:#fff;border:none;box-shadow:0 1px 4px rgba(0,0,0,0.1);cursor:pointer;display:flex;align-items:center;justify-content:center;font-size:14px;color:#9ca3af;\";\n close.innerHTML = \"✕\";\n close.onclick = (ev) => { ev.stopPropagation(); removeBubble(); iframe.contentWindow?.postMessage({ type: \"bitpalm-trigger-dismiss\" }, \"*\"); };\n bubble.onclick = () => { removeBubble(); btn.style.display = \"none\"; iframe.contentWindow?.postMessage({ type: \"bitpalm-trigger-engaged\" }, \"*\"); };\n bubble.appendChild(close);\n d.body.appendChild(bubble);\n }\n\n // Trigger bubble hide\n if (e.data?.type === \"bitpalm-trigger-hide\") { removeBubble(); }\n };\n window.addEventListener(\"message\", handleMessage);\n\n // --- Visitor Intelligence: page counter + history ---\n let pageCount = parseInt(sessionStorage.getItem(`${STORAGE_PREFIX}pages`) || \"0\") + 1;\n sessionStorage.setItem(`${STORAGE_PREFIX}pages`, String(pageCount));\n\n let hist: string[] = JSON.parse(sessionStorage.getItem(`${STORAGE_PREFIX}hist`) || \"[]\");\n hist.push(location.href);\n if (hist.length > 20) hist = hist.slice(-20);\n sessionStorage.setItem(`${STORAGE_PREFIX}hist`, JSON.stringify(hist));\n\n const loadedAt = Date.now();\n let siteStart = parseInt(sessionStorage.getItem(`${STORAGE_PREFIX}site_start`) || \"0\");\n if (!siteStart) {\n siteStart = loadedAt;\n sessionStorage.setItem(`${STORAGE_PREFIX}site_start`, String(siteStart));\n }\n\n // --- Send parent context on iframe load ---\n iframe.addEventListener(\"load\", () => {\n const returning = !!localStorage.getItem(`${STORAGE_PREFIX}visited`);\n iframe.contentWindow?.postMessage({\n type: \"bitpalm-parent-context\",\n url: location.href,\n title: d.title,\n returning,\n pageCount,\n pageHistory: hist,\n loadedAt,\n siteStart,\n locale,\n }, \"*\");\n if (!returning) localStorage.setItem(`${STORAGE_PREFIX}visited`, \"1\");\n });\n\n // --- SPA navigation detection ---\n const origPush = history.pushState.bind(history);\n const origReplace = history.replaceState.bind(history);\n\n const onNav = () => {\n pageCount++;\n sessionStorage.setItem(`${STORAGE_PREFIX}pages`, String(pageCount));\n const h: string[] = JSON.parse(sessionStorage.getItem(`${STORAGE_PREFIX}hist`) || \"[]\");\n h.push(location.href);\n if (h.length > 20) h.splice(0, h.length - 20);\n sessionStorage.setItem(`${STORAGE_PREFIX}hist`, JSON.stringify(h));\n iframe.contentWindow?.postMessage({\n type: \"bitpalm-page-change\",\n url: location.href,\n title: d.title,\n pageCount,\n pageHistory: h,\n loadedAt: Date.now(),\n }, \"*\");\n };\n\n history.pushState = function (...args: Parameters<typeof history.pushState>) {\n origPush(...args);\n onNav();\n };\n history.replaceState = function (...args: Parameters<typeof history.replaceState>) {\n origReplace(...args);\n onNav();\n };\n window.addEventListener(\"popstate\", onNav);\n\n // --- Scroll depth tracking ---\n let lastScrollDepth = -1;\n let scrollTimeout: ReturnType<typeof setTimeout>;\n const handleScroll = () => {\n clearTimeout(scrollTimeout);\n scrollTimeout = setTimeout(() => {\n const total = Math.max(d.documentElement.scrollHeight, d.body.scrollHeight) - window.innerHeight;\n const pct = total > 0 ? Math.round(window.scrollY / total * 100) : 100;\n if (pct !== lastScrollDepth) {\n lastScrollDepth = pct;\n iframe.contentWindow?.postMessage({ type: \"bitpalm-scroll-depth\", percent: pct }, \"*\");\n }\n }, 500);\n };\n window.addEventListener(\"scroll\", handleScroll, { passive: true });\n\n // --- Exit intent ---\n const handleMouseOut = (e: MouseEvent) => {\n if (e.clientY <= 0) {\n iframe.contentWindow?.postMessage({ type: \"bitpalm-exit-intent\" }, \"*\");\n }\n };\n d.addEventListener(\"mouseout\", handleMouseOut);\n\n // --- Inactivity detection (15s) ---\n let idleTimer: ReturnType<typeof setTimeout>;\n let idleFired = false;\n const resetIdle = () => {\n clearTimeout(idleTimer);\n if (idleFired) return;\n idleTimer = setTimeout(() => {\n idleFired = true;\n iframe.contentWindow?.postMessage({ type: \"bitpalm-inactivity\" }, \"*\");\n }, 15_000);\n };\n const idleEvents = [\"mousemove\", \"keydown\", \"scroll\", \"touchstart\"] as const;\n idleEvents.forEach((ev) => d.addEventListener(ev, resetIdle, { passive: true }));\n resetIdle();\n\n // --- Public API ---\n const openWidget = () => {\n btn.style.display = \"none\";\n removeBubble();\n iframe.contentWindow?.postMessage({ type: \"bitpalm-open\" }, \"*\");\n };\n\n const closeWidget = () => {\n iframe.contentWindow?.postMessage({ type: \"bitpalm-close\" }, \"*\");\n };\n\n const destroy = () => {\n window.removeEventListener(\"message\", handleMessage);\n window.removeEventListener(\"scroll\", handleScroll);\n window.removeEventListener(\"popstate\", onNav);\n d.removeEventListener(\"mouseout\", handleMouseOut);\n idleEvents.forEach((ev) => d.removeEventListener(ev, resetIdle));\n clearTimeout(scrollTimeout);\n clearTimeout(idleTimer);\n history.pushState = origPush;\n history.replaceState = origReplace;\n removeBubble();\n btn.remove();\n iframe.remove();\n };\n\n return { open: openWidget, close: closeWidget, destroy };\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kBAAAE,IAAA,eAAAC,EAAAH,GCEA,IAAMI,EAAmB,4BACnBC,EAAiB,OAEvB,SAASC,GAAuB,CAC9B,GAAI,O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Q,QAAQ,MAAM,EAAI,MACpE,CAAC,CACH,EAEI,SAAS,aAAe,UAC1B,SAAS,iBAAiB,mBAAoBC,CAAI,EAElDA,EAAK,CAET,CACF","names":["src_exports","__export","createWidget","__toCommonJS","DEFAULT_BASE_URL","STORAGE_PREFIX","detectLocale","lang","createWidget","options","slug","locale","baseUrl","zIndex","d","iframe","widgetUrl","origin","btn","openWidget","s","bubble","removeBubble","handleMessage","e","ic","sp","sv","msg","close","ev","pageCount","hist","loadedAt","siteStart","returning","origPush","origReplace","onNav","h","args","lastScrollDepth","scrollTimeout","handleScroll","total","pct","handleMouseOut","idleTimer","idleFired","resetIdle","idleEvents","script","init","createWidget"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
interface BitPalmAgentOptions {
|
|
2
|
+
/** Your agent slug from the BitPalm dashboard. */
|
|
3
|
+
slug: string;
|
|
4
|
+
/** Locale for the widget UI (e.g. "en", "de", "ar"). Auto-detected if omitted. */
|
|
5
|
+
locale?: string;
|
|
6
|
+
/** Base URL of the agent platform. Defaults to "https://agents.bitpalm.ae". */
|
|
7
|
+
baseUrl?: string;
|
|
8
|
+
/** z-index for the widget elements. Defaults to 9999. */
|
|
9
|
+
zIndex?: number;
|
|
10
|
+
}
|
|
11
|
+
interface BitPalmAgentInstance {
|
|
12
|
+
/** Open the chat widget programmatically. */
|
|
13
|
+
open: () => void;
|
|
14
|
+
/** Close the chat widget programmatically. */
|
|
15
|
+
close: () => void;
|
|
16
|
+
/** Remove the widget and clean up all event listeners. */
|
|
17
|
+
destroy: () => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
declare function createWidget(options: BitPalmAgentOptions): BitPalmAgentInstance;
|
|
21
|
+
|
|
22
|
+
export { type BitPalmAgentInstance, type BitPalmAgentOptions, createWidget };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
interface BitPalmAgentOptions {
|
|
2
|
+
/** Your agent slug from the BitPalm dashboard. */
|
|
3
|
+
slug: string;
|
|
4
|
+
/** Locale for the widget UI (e.g. "en", "de", "ar"). Auto-detected if omitted. */
|
|
5
|
+
locale?: string;
|
|
6
|
+
/** Base URL of the agent platform. Defaults to "https://agents.bitpalm.ae". */
|
|
7
|
+
baseUrl?: string;
|
|
8
|
+
/** z-index for the widget elements. Defaults to 9999. */
|
|
9
|
+
zIndex?: number;
|
|
10
|
+
}
|
|
11
|
+
interface BitPalmAgentInstance {
|
|
12
|
+
/** Open the chat widget programmatically. */
|
|
13
|
+
open: () => void;
|
|
14
|
+
/** Close the chat widget programmatically. */
|
|
15
|
+
close: () => void;
|
|
16
|
+
/** Remove the widget and clean up all event listeners. */
|
|
17
|
+
destroy: () => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
declare function createWidget(options: BitPalmAgentOptions): BitPalmAgentInstance;
|
|
21
|
+
|
|
22
|
+
export { type BitPalmAgentInstance, type BitPalmAgentOptions, createWidget };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var H="https://agents.bitpalm.ae",a="_bp_";function P(){if(typeof document<"u"){let s=document.documentElement.lang;if(s)return s.slice(0,2).toLowerCase()}return"en"}function x(s){let{slug:g,locale:w=P(),baseUrl:C=H,zIndex:u=9999}=s,o=document,n=o.createElement("iframe"),v=`${C}/t/${g}/widget`;n.src=`${v}${v.includes("?")?"&":"?"}locale=${w}`,n.allow="clipboard-write",n.setAttribute("allowtransparency","true"),n.style.cssText=`position:fixed;bottom:0;right:0;width:0;height:0;border:none;z-index:${u};background:transparent;color-scheme:normal;transition:width .3s,height .3s;`,o.body.appendChild(n);let W=new URL(n.src).origin,e=o.createElement("div");if(e.setAttribute("role","button"),e.setAttribute("aria-label","Chat"),e.style.cssText=`position:fixed;bottom:24px;right:24px;width:56px;height:56px;border-radius:50%;display:none;align-items:center;justify-content:center;cursor:pointer;z-index:${u-1};background:#00ff41;box-shadow:0 0 15px rgba(0,255,65,0.31);transition:transform .2s;`,e.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M7.9 20A9 9 0 1 0 4 16.1L2 22Z"/></svg>',e.onmouseenter=()=>{e.style.transform="scale(1.1)"},e.onmouseleave=()=>{e.style.transform="scale(1)"},e.onclick=()=>A(),o.body.appendChild(e),!o.getElementById("_bp_fade")){let t=o.createElement("style");t.id="_bp_fade",t.textContent="@keyframes _bp_fade{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}",o.head.appendChild(t)}let r=null,d=()=>{r&&(r.remove(),r=null)},S=t=>{if(t.origin===W){if(t.data?.type==="bitpalm-widget-config"){t.data.primaryColor&&(e.style.background=t.data.primaryColor,e.style.boxShadow=t.data.chatShadow==="none"?"none":`0 0 15px ${t.data.primaryColor}50`);let l=t.data.chatButtonIconColor||"black";if(t.data.chatButtonIconSvg){e.innerHTML="";let i=o.createElement("span");i.style.cssText=`display:flex;align-items:center;justify-content:center;width:24px;height:24px;color:${l}`,i.innerHTML=t.data.chatButtonIconSvg,e.appendChild(i)}else{let i=e.querySelector("svg");i&&(i.style.stroke=l)}e.style.display="flex"}if(t.data?.type==="bitpalm-widget-resize"&&(n.style.width=`${t.data.width}px`,n.style.height=`${t.data.height}px`,e.style.display=t.data.width>0?"none":"flex"),t.data?.type==="bitpalm-trigger-show"){d(),r=o.createElement("div"),r.style.cssText=`position:fixed;bottom:90px;right:24px;max-width:240px;background:#fff;border-radius:16px;padding:12px 32px 12px 12px;box-shadow:0 2px 20px rgba(0,0,0,0.08);cursor:pointer;z-index:${u-1};font-family:system-ui,sans-serif;animation:_bp_fade .3s;`;let l=(t.data.message||"").replace(/</g,"<");r.innerHTML=`<p style="font-size:14px;color:#1f2937;margin:0;">${l}</p><div style="position:absolute;bottom:-8px;right:20px;width:0;height:0;border-left:8px solid transparent;border-right:8px solid transparent;border-top:8px solid #fff;"></div>`;let i=o.createElement("button");i.style.cssText="position:absolute;top:-8px;right:-8px;width:28px;height:28px;border-radius:50%;background:#fff;border:none;box-shadow:0 1px 4px rgba(0,0,0,0.1);cursor:pointer;display:flex;align-items:center;justify-content:center;font-size:14px;color:#9ca3af;",i.innerHTML="✕",i.onclick=B=>{B.stopPropagation(),d(),n.contentWindow?.postMessage({type:"bitpalm-trigger-dismiss"},"*")},r.onclick=()=>{d(),e.style.display="none",n.contentWindow?.postMessage({type:"bitpalm-trigger-engaged"},"*")},r.appendChild(i),o.body.appendChild(r)}t.data?.type==="bitpalm-trigger-hide"&&d()}};window.addEventListener("message",S);let c=parseInt(sessionStorage.getItem(`${a}pages`)||"0")+1;sessionStorage.setItem(`${a}pages`,String(c));let p=JSON.parse(sessionStorage.getItem(`${a}hist`)||"[]");p.push(location.href),p.length>20&&(p=p.slice(-20)),sessionStorage.setItem(`${a}hist`,JSON.stringify(p));let E=Date.now(),m=parseInt(sessionStorage.getItem(`${a}site_start`)||"0");m||(m=E,sessionStorage.setItem(`${a}site_start`,String(m))),n.addEventListener("load",()=>{let t=!!localStorage.getItem(`${a}visited`);n.contentWindow?.postMessage({type:"bitpalm-parent-context",url:location.href,title:o.title,returning:t,pageCount:c,pageHistory:p,loadedAt:E,siteStart:m,locale:w},"*"),t||localStorage.setItem(`${a}visited`,"1")});let I=history.pushState.bind(history),L=history.replaceState.bind(history),h=()=>{c++,sessionStorage.setItem(`${a}pages`,String(c));let t=JSON.parse(sessionStorage.getItem(`${a}hist`)||"[]");t.push(location.href),t.length>20&&t.splice(0,t.length-20),sessionStorage.setItem(`${a}hist`,JSON.stringify(t)),n.contentWindow?.postMessage({type:"bitpalm-page-change",url:location.href,title:o.title,pageCount:c,pageHistory:t,loadedAt:Date.now()},"*")};history.pushState=function(...t){I(...t),h()},history.replaceState=function(...t){L(...t),h()},window.addEventListener("popstate",h);let T=-1,f,M=()=>{clearTimeout(f),f=setTimeout(()=>{let t=Math.max(o.documentElement.scrollHeight,o.body.scrollHeight)-window.innerHeight,l=t>0?Math.round(window.scrollY/t*100):100;l!==T&&(T=l,n.contentWindow?.postMessage({type:"bitpalm-scroll-depth",percent:l},"*"))},500)};window.addEventListener("scroll",M,{passive:!0});let $=t=>{t.clientY<=0&&n.contentWindow?.postMessage({type:"bitpalm-exit-intent"},"*")};o.addEventListener("mouseout",$);let y,k=!1,b=()=>{clearTimeout(y),!k&&(y=setTimeout(()=>{k=!0,n.contentWindow?.postMessage({type:"bitpalm-inactivity"},"*")},15e3))},_=["mousemove","keydown","scroll","touchstart"];_.forEach(t=>o.addEventListener(t,b,{passive:!0})),b();let A=()=>{e.style.display="none",d(),n.contentWindow?.postMessage({type:"bitpalm-open"},"*")};return{open:A,close:()=>{n.contentWindow?.postMessage({type:"bitpalm-close"},"*")},destroy:()=>{window.removeEventListener("message",S),window.removeEventListener("scroll",M),window.removeEventListener("popstate",h),o.removeEventListener("mouseout",$),_.forEach(t=>o.removeEventListener(t,b)),clearTimeout(f),clearTimeout(y),history.pushState=I,history.replaceState=L,d(),e.remove(),n.remove()}}}if(typeof document<"u"){let s=document.currentScript;if(s?.dataset.slug){let g=()=>{x({slug:s.dataset.slug,locale:s.dataset.locale,baseUrl:s.dataset.baseUrl,zIndex:s.dataset.zIndex?Number(s.dataset.zIndex):void 0})};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",g):g()}}export{x as createWidget};
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/widget.ts","../src/index.ts"],"sourcesContent":["import type { BitPalmAgentOptions, BitPalmAgentInstance } from \"./types\";\n\nconst DEFAULT_BASE_URL = \"https://agents.bitpalm.ae\";\nconst STORAGE_PREFIX = \"_bp_\";\n\nfunction detectLocale(): string {\n if (typeof document !== \"undefined\") {\n const lang = document.documentElement.lang;\n if (lang) return lang.slice(0, 2).toLowerCase();\n }\n return \"en\";\n}\n\nexport function createWidget(options: BitPalmAgentOptions): BitPalmAgentInstance {\n const {\n slug,\n locale = detectLocale(),\n baseUrl = DEFAULT_BASE_URL,\n zIndex = 9999,\n } = options;\n\n const d = document;\n\n // --- Iframe ---\n const iframe = d.createElement(\"iframe\");\n const widgetUrl = `${baseUrl}/t/${slug}/widget`;\n iframe.src = `${widgetUrl}${widgetUrl.includes(\"?\") ? \"&\" : \"?\"}locale=${locale}`;\n iframe.allow = \"clipboard-write\";\n iframe.setAttribute(\"allowtransparency\", \"true\");\n iframe.style.cssText = `position:fixed;bottom:0;right:0;width:0;height:0;border:none;z-index:${zIndex};background:transparent;color-scheme:normal;transition:width .3s,height .3s;`;\n d.body.appendChild(iframe);\n\n const origin = new URL(iframe.src).origin;\n\n // --- Native launcher button ---\n const btn = d.createElement(\"div\");\n btn.setAttribute(\"role\", \"button\");\n btn.setAttribute(\"aria-label\", \"Chat\");\n btn.style.cssText = `position:fixed;bottom:24px;right:24px;width:56px;height:56px;border-radius:50%;display:none;align-items:center;justify-content:center;cursor:pointer;z-index:${zIndex - 1};background:#00ff41;box-shadow:0 0 15px rgba(0,255,65,0.31);transition:transform .2s;`;\n btn.innerHTML = '<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"black\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"M7.9 20A9 9 0 1 0 4 16.1L2 22Z\"/></svg>';\n btn.onmouseenter = () => { btn.style.transform = \"scale(1.1)\"; };\n btn.onmouseleave = () => { btn.style.transform = \"scale(1)\"; };\n btn.onclick = () => openWidget();\n d.body.appendChild(btn);\n\n // --- Fade animation for trigger bubbles ---\n if (!d.getElementById(\"_bp_fade\")) {\n const s = d.createElement(\"style\");\n s.id = \"_bp_fade\";\n s.textContent = \"@keyframes _bp_fade{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}\";\n d.head.appendChild(s);\n }\n\n // --- Trigger bubble ---\n let bubble: HTMLDivElement | null = null;\n const removeBubble = () => {\n if (bubble) { bubble.remove(); bubble = null; }\n };\n\n // --- postMessage handler ---\n const handleMessage = (e: MessageEvent) => {\n if (e.origin !== origin) return;\n\n // Widget config (colors, icon)\n if (e.data?.type === \"bitpalm-widget-config\") {\n if (e.data.primaryColor) {\n btn.style.background = e.data.primaryColor;\n btn.style.boxShadow = e.data.chatShadow === \"none\" ? \"none\" : `0 0 15px ${e.data.primaryColor}50`;\n }\n const ic = e.data.chatButtonIconColor || \"black\";\n if (e.data.chatButtonIconSvg) {\n btn.innerHTML = \"\";\n const sp = d.createElement(\"span\");\n sp.style.cssText = `display:flex;align-items:center;justify-content:center;width:24px;height:24px;color:${ic}`;\n sp.innerHTML = e.data.chatButtonIconSvg;\n btn.appendChild(sp);\n } else {\n const sv = btn.querySelector(\"svg\");\n if (sv) (sv as SVGElement).style.stroke = ic;\n }\n btn.style.display = \"flex\";\n }\n\n // Resize\n if (e.data?.type === \"bitpalm-widget-resize\") {\n iframe.style.width = `${e.data.width}px`;\n iframe.style.height = `${e.data.height}px`;\n btn.style.display = e.data.width > 0 ? \"none\" : \"flex\";\n }\n\n // Trigger bubble show\n if (e.data?.type === \"bitpalm-trigger-show\") {\n removeBubble();\n bubble = d.createElement(\"div\");\n bubble.style.cssText = `position:fixed;bottom:90px;right:24px;max-width:240px;background:#fff;border-radius:16px;padding:12px 32px 12px 12px;box-shadow:0 2px 20px rgba(0,0,0,0.08);cursor:pointer;z-index:${zIndex - 1};font-family:system-ui,sans-serif;animation:_bp_fade .3s;`;\n const msg = (e.data.message || \"\").replace(/</g, \"<\");\n bubble.innerHTML = `<p style=\"font-size:14px;color:#1f2937;margin:0;\">${msg}</p><div style=\"position:absolute;bottom:-8px;right:20px;width:0;height:0;border-left:8px solid transparent;border-right:8px solid transparent;border-top:8px solid #fff;\"></div>`;\n const close = d.createElement(\"button\");\n close.style.cssText = \"position:absolute;top:-8px;right:-8px;width:28px;height:28px;border-radius:50%;background:#fff;border:none;box-shadow:0 1px 4px rgba(0,0,0,0.1);cursor:pointer;display:flex;align-items:center;justify-content:center;font-size:14px;color:#9ca3af;\";\n close.innerHTML = \"✕\";\n close.onclick = (ev) => { ev.stopPropagation(); removeBubble(); iframe.contentWindow?.postMessage({ type: \"bitpalm-trigger-dismiss\" }, \"*\"); };\n bubble.onclick = () => { removeBubble(); btn.style.display = \"none\"; iframe.contentWindow?.postMessage({ type: \"bitpalm-trigger-engaged\" }, \"*\"); };\n bubble.appendChild(close);\n d.body.appendChild(bubble);\n }\n\n // Trigger bubble hide\n if (e.data?.type === \"bitpalm-trigger-hide\") { removeBubble(); }\n };\n window.addEventListener(\"message\", handleMessage);\n\n // --- Visitor Intelligence: page counter + history ---\n let pageCount = parseInt(sessionStorage.getItem(`${STORAGE_PREFIX}pages`) || \"0\") + 1;\n sessionStorage.setItem(`${STORAGE_PREFIX}pages`, String(pageCount));\n\n let hist: string[] = JSON.parse(sessionStorage.getItem(`${STORAGE_PREFIX}hist`) || \"[]\");\n hist.push(location.href);\n if (hist.length > 20) hist = hist.slice(-20);\n sessionStorage.setItem(`${STORAGE_PREFIX}hist`, JSON.stringify(hist));\n\n const loadedAt = Date.now();\n let siteStart = parseInt(sessionStorage.getItem(`${STORAGE_PREFIX}site_start`) || \"0\");\n if (!siteStart) {\n siteStart = loadedAt;\n sessionStorage.setItem(`${STORAGE_PREFIX}site_start`, String(siteStart));\n }\n\n // --- Send parent context on iframe load ---\n iframe.addEventListener(\"load\", () => {\n const returning = !!localStorage.getItem(`${STORAGE_PREFIX}visited`);\n iframe.contentWindow?.postMessage({\n type: \"bitpalm-parent-context\",\n url: location.href,\n title: d.title,\n returning,\n pageCount,\n pageHistory: hist,\n loadedAt,\n siteStart,\n locale,\n }, \"*\");\n if (!returning) localStorage.setItem(`${STORAGE_PREFIX}visited`, \"1\");\n });\n\n // --- SPA navigation detection ---\n const origPush = history.pushState.bind(history);\n const origReplace = history.replaceState.bind(history);\n\n const onNav = () => {\n pageCount++;\n sessionStorage.setItem(`${STORAGE_PREFIX}pages`, String(pageCount));\n const h: string[] = JSON.parse(sessionStorage.getItem(`${STORAGE_PREFIX}hist`) || \"[]\");\n h.push(location.href);\n if (h.length > 20) h.splice(0, h.length - 20);\n sessionStorage.setItem(`${STORAGE_PREFIX}hist`, JSON.stringify(h));\n iframe.contentWindow?.postMessage({\n type: \"bitpalm-page-change\",\n url: location.href,\n title: d.title,\n pageCount,\n pageHistory: h,\n loadedAt: Date.now(),\n }, \"*\");\n };\n\n history.pushState = function (...args: Parameters<typeof history.pushState>) {\n origPush(...args);\n onNav();\n };\n history.replaceState = function (...args: Parameters<typeof history.replaceState>) {\n origReplace(...args);\n onNav();\n };\n window.addEventListener(\"popstate\", onNav);\n\n // --- Scroll depth tracking ---\n let lastScrollDepth = -1;\n let scrollTimeout: ReturnType<typeof setTimeout>;\n const handleScroll = () => {\n clearTimeout(scrollTimeout);\n scrollTimeout = setTimeout(() => {\n const total = Math.max(d.documentElement.scrollHeight, d.body.scrollHeight) - window.innerHeight;\n const pct = total > 0 ? Math.round(window.scrollY / total * 100) : 100;\n if (pct !== lastScrollDepth) {\n lastScrollDepth = pct;\n iframe.contentWindow?.postMessage({ type: \"bitpalm-scroll-depth\", percent: pct }, \"*\");\n }\n }, 500);\n };\n window.addEventListener(\"scroll\", handleScroll, { passive: true });\n\n // --- Exit intent ---\n const handleMouseOut = (e: MouseEvent) => {\n if (e.clientY <= 0) {\n iframe.contentWindow?.postMessage({ type: \"bitpalm-exit-intent\" }, \"*\");\n }\n };\n d.addEventListener(\"mouseout\", handleMouseOut);\n\n // --- Inactivity detection (15s) ---\n let idleTimer: ReturnType<typeof setTimeout>;\n let idleFired = false;\n const resetIdle = () => {\n clearTimeout(idleTimer);\n if (idleFired) return;\n idleTimer = setTimeout(() => {\n idleFired = true;\n iframe.contentWindow?.postMessage({ type: \"bitpalm-inactivity\" }, \"*\");\n }, 15_000);\n };\n const idleEvents = [\"mousemove\", \"keydown\", \"scroll\", \"touchstart\"] as const;\n idleEvents.forEach((ev) => d.addEventListener(ev, resetIdle, { passive: true }));\n resetIdle();\n\n // --- Public API ---\n const openWidget = () => {\n btn.style.display = \"none\";\n removeBubble();\n iframe.contentWindow?.postMessage({ type: \"bitpalm-open\" }, \"*\");\n };\n\n const closeWidget = () => {\n iframe.contentWindow?.postMessage({ type: \"bitpalm-close\" }, \"*\");\n };\n\n const destroy = () => {\n window.removeEventListener(\"message\", handleMessage);\n window.removeEventListener(\"scroll\", handleScroll);\n window.removeEventListener(\"popstate\", onNav);\n d.removeEventListener(\"mouseout\", handleMouseOut);\n idleEvents.forEach((ev) => d.removeEventListener(ev, resetIdle));\n clearTimeout(scrollTimeout);\n clearTimeout(idleTimer);\n history.pushState = origPush;\n history.replaceState = origReplace;\n removeBubble();\n btn.remove();\n iframe.remove();\n };\n\n return { open: openWidget, close: closeWidget, destroy };\n}\n","export { createWidget } from \"./widget\";\nexport type { BitPalmAgentOptions, BitPalmAgentInstance } from \"./types\";\n\nimport { createWidget } from \"./widget\";\n\n/**\n * Auto-init from script tag:\n * <script src=\"https://cdn.bitpalm.ae/widget.js\" data-slug=\"my-agent\"></script>\n */\nif (typeof document !== \"undefined\") {\n const script = document.currentScript as HTMLScriptElement | null;\n if (script?.dataset.slug) {\n const init = () => {\n createWidget({\n slug: script!.dataset.slug!,\n locale: script!.dataset.locale,\n baseUrl: script!.dataset.baseUrl,\n zIndex: script!.dataset.zIndex ? Number(script!.dataset.zIndex) : undefined,\n });\n };\n\n if (document.readyState === \"loading\") {\n document.addEventListener(\"DOMContentLoaded\", init);\n } else {\n init();\n }\n }\n}\n"],"mappings":"AAEA,IAAMA,EAAmB,4BACnBC,EAAiB,OAEvB,SAASC,GAAuB,CAC9B,GAAI,OAAO,SAAa,IAAa,CACnC,IAAMC,EAAO,SAAS,gBAAgB,KACtC,GAAIA,EAAM,OAAOA,EAAK,MAAM,EAAG,CAAC,EAAE,YAAY,CAChD,CACA,MAAO,IACT,CAEO,SAASC,EAAaC,EAAoD,CAC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Widget","options","slug","locale","baseUrl","zIndex","d","iframe","widgetUrl","origin","btn","openWidget","s","bubble","removeBubble","handleMessage","e","ic","sp","sv","msg","close","ev","pageCount","hist","loadedAt","siteStart","returning","origPush","origReplace","onNav","h","args","lastScrollDepth","scrollTimeout","handleScroll","total","pct","handleMouseOut","idleTimer","idleFired","resetIdle","idleEvents","script","init","createWidget"]}
|
package/dist/react.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var S=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var z=Object.prototype.hasOwnProperty;var D=(i,s)=>{for(var r in s)S(i,r,{get:s[r],enumerable:!0})},N=(i,s,r,f)=>{if(s&&typeof s=="object"||typeof s=="function")for(let p of R(s))!z.call(i,p)&&p!==r&&S(i,p,{get:()=>s[p],enumerable:!(f=O(s,p))||f.enumerable});return i};var U=i=>N(S({},"__esModule",{value:!0}),i);var F={};D(F,{BitPalmAgent:()=>Y});module.exports=U(F);var h=require("react");var j="https://agents.bitpalm.ae",l="_bp_";function J(){if(typeof document<"u"){let i=document.documentElement.lang;if(i)return i.slice(0,2).toLowerCase()}return"en"}function C(i){let{slug:s,locale:r=J(),baseUrl:f=j,zIndex:p=9999}=i,n=document,o=n.createElement("iframe"),E=`${f}/t/${s}/widget`;o.src=`${E}${E.includes("?")?"&":"?"}locale=${r}`,o.allow="clipboard-write",o.setAttribute("allowtransparency","true"),o.style.cssText=`position:fixed;bottom:0;right:0;width:0;height:0;border:none;z-index:${p};background:transparent;color-scheme:normal;transition:width .3s,height .3s;`,n.body.appendChild(o);let W=new URL(o.src).origin,e=n.createElement("div");if(e.setAttribute("role","button"),e.setAttribute("aria-label","Chat"),e.style.cssText=`position:fixed;bottom:24px;right:24px;width:56px;height:56px;border-radius:50%;display:none;align-items:center;justify-content:center;cursor:pointer;z-index:${p-1};background:#00ff41;box-shadow:0 0 15px rgba(0,255,65,0.31);transition:transform .2s;`,e.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M7.9 20A9 9 0 1 0 4 16.1L2 22Z"/></svg>',e.onmouseenter=()=>{e.style.transform="scale(1.1)"},e.onmouseleave=()=>{e.style.transform="scale(1)"},e.onclick=()=>_(),n.body.appendChild(e),!n.getElementById("_bp_fade")){let t=n.createElement("style");t.id="_bp_fade",t.textContent="@keyframes _bp_fade{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}",n.head.appendChild(t)}let c=null,g=()=>{c&&(c.remove(),c=null)},I=t=>{if(t.origin===W){if(t.data?.type==="bitpalm-widget-config"){t.data.primaryColor&&(e.style.background=t.data.primaryColor,e.style.boxShadow=t.data.chatShadow==="none"?"none":`0 0 15px ${t.data.primaryColor}50`);let d=t.data.chatButtonIconColor||"black";if(t.data.chatButtonIconSvg){e.innerHTML="";let a=n.createElement("span");a.style.cssText=`display:flex;align-items:center;justify-content:center;width:24px;height:24px;color:${d}`,a.innerHTML=t.data.chatButtonIconSvg,e.appendChild(a)}else{let a=e.querySelector("svg");a&&(a.style.stroke=d)}e.style.display="flex"}if(t.data?.type==="bitpalm-widget-resize"&&(o.style.width=`${t.data.width}px`,o.style.height=`${t.data.height}px`,e.style.display=t.data.width>0?"none":"flex"),t.data?.type==="bitpalm-trigger-show"){g(),c=n.createElement("div"),c.style.cssText=`position:fixed;bottom:90px;right:24px;max-width:240px;background:#fff;border-radius:16px;padding:12px 32px 12px 12px;box-shadow:0 2px 20px rgba(0,0,0,0.08);cursor:pointer;z-index:${p-1};font-family:system-ui,sans-serif;animation:_bp_fade .3s;`;let d=(t.data.message||"").replace(/</g,"<");c.innerHTML=`<p style="font-size:14px;color:#1f2937;margin:0;">${d}</p><div style="position:absolute;bottom:-8px;right:20px;width:0;height:0;border-left:8px solid transparent;border-right:8px solid transparent;border-top:8px solid #fff;"></div>`;let a=n.createElement("button");a.style.cssText="position:absolute;top:-8px;right:-8px;width:28px;height:28px;border-radius:50%;background:#fff;border:none;box-shadow:0 1px 4px rgba(0,0,0,0.1);cursor:pointer;display:flex;align-items:center;justify-content:center;font-size:14px;color:#9ca3af;",a.innerHTML="✕",a.onclick=H=>{H.stopPropagation(),g(),o.contentWindow?.postMessage({type:"bitpalm-trigger-dismiss"},"*")},c.onclick=()=>{g(),e.style.display="none",o.contentWindow?.postMessage({type:"bitpalm-trigger-engaged"},"*")},c.appendChild(a),n.body.appendChild(c)}t.data?.type==="bitpalm-trigger-hide"&&g()}};window.addEventListener("message",I);let u=parseInt(sessionStorage.getItem(`${l}pages`)||"0")+1;sessionStorage.setItem(`${l}pages`,String(u));let m=JSON.parse(sessionStorage.getItem(`${l}hist`)||"[]");m.push(location.href),m.length>20&&(m=m.slice(-20)),sessionStorage.setItem(`${l}hist`,JSON.stringify(m));let T=Date.now(),y=parseInt(sessionStorage.getItem(`${l}site_start`)||"0");y||(y=T,sessionStorage.setItem(`${l}site_start`,String(y))),o.addEventListener("load",()=>{let t=!!localStorage.getItem(`${l}visited`);o.contentWindow?.postMessage({type:"bitpalm-parent-context",url:location.href,title:n.title,returning:t,pageCount:u,pageHistory:m,loadedAt:T,siteStart:y,locale:r},"*"),t||localStorage.setItem(`${l}visited`,"1")});let $=history.pushState.bind(history),L=history.replaceState.bind(history),b=()=>{u++,sessionStorage.setItem(`${l}pages`,String(u));let t=JSON.parse(sessionStorage.getItem(`${l}hist`)||"[]");t.push(location.href),t.length>20&&t.splice(0,t.length-20),sessionStorage.setItem(`${l}hist`,JSON.stringify(t)),o.contentWindow?.postMessage({type:"bitpalm-page-change",url:location.href,title:n.title,pageCount:u,pageHistory:t,loadedAt:Date.now()},"*")};history.pushState=function(...t){$(...t),b()},history.replaceState=function(...t){L(...t),b()},window.addEventListener("popstate",b);let A=-1,x,M=()=>{clearTimeout(x),x=setTimeout(()=>{let t=Math.max(n.documentElement.scrollHeight,n.body.scrollHeight)-window.innerHeight,d=t>0?Math.round(window.scrollY/t*100):100;d!==A&&(A=d,o.contentWindow?.postMessage({type:"bitpalm-scroll-depth",percent:d},"*"))},500)};window.addEventListener("scroll",M,{passive:!0});let B=t=>{t.clientY<=0&&o.contentWindow?.postMessage({type:"bitpalm-exit-intent"},"*")};n.addEventListener("mouseout",B);let w,P=!1,v=()=>{clearTimeout(w),!P&&(w=setTimeout(()=>{P=!0,o.contentWindow?.postMessage({type:"bitpalm-inactivity"},"*")},15e3))},k=["mousemove","keydown","scroll","touchstart"];k.forEach(t=>n.addEventListener(t,v,{passive:!0})),v();let _=()=>{e.style.display="none",g(),o.contentWindow?.postMessage({type:"bitpalm-open"},"*")};return{open:_,close:()=>{o.contentWindow?.postMessage({type:"bitpalm-close"},"*")},destroy:()=>{window.removeEventListener("message",I),window.removeEventListener("scroll",M),window.removeEventListener("popstate",b),n.removeEventListener("mouseout",B),k.forEach(t=>n.removeEventListener(t,v)),clearTimeout(x),clearTimeout(w),history.pushState=$,history.replaceState=L,g(),e.remove(),o.remove()}}}function Y(i){let s=(0,h.useRef)(null),r=(0,h.useRef)(!1);return(0,h.useEffect)(()=>{if(!r.current)return r.current=!0,s.current=C(i),()=>{s.current?.destroy(),s.current=null,r.current=!1}},[]),null}0&&(module.exports={BitPalmAgent});
|
|
2
|
+
//# sourceMappingURL=react.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/react.ts","../src/widget.ts"],"sourcesContent":["import { useEffect, useRef } from \"react\";\nimport { createWidget } from \"./widget\";\nimport type { BitPalmAgentOptions, BitPalmAgentInstance } from \"./types\";\n\nexport type { BitPalmAgentOptions, BitPalmAgentInstance } from \"./types\";\n\nexport type BitPalmAgentProps = BitPalmAgentOptions;\n\n/**\n * React component that mounts the BitPalm AI agent widget.\n *\n * @example\n * ```tsx\n * import { BitPalmAgent } from '@bitpalm/ai-agents/react';\n *\n * export default function App() {\n * return <BitPalmAgent slug=\"my-agent\" />;\n * }\n * ```\n */\nexport function BitPalmAgent(props: BitPalmAgentProps): null {\n const instanceRef = useRef<BitPalmAgentInstance | null>(null);\n const mountedRef = useRef(false);\n\n useEffect(() => {\n if (mountedRef.current) return;\n mountedRef.current = true;\n\n instanceRef.current = createWidget(props);\n\n return () => {\n instanceRef.current?.destroy();\n instanceRef.current = null;\n mountedRef.current = false;\n };\n }, []); // eslint-disable-line react-hooks/exhaustive-deps\n\n return null;\n}\n","import type { BitPalmAgentOptions, BitPalmAgentInstance } from \"./types\";\n\nconst DEFAULT_BASE_URL = \"https://agents.bitpalm.ae\";\nconst STORAGE_PREFIX = \"_bp_\";\n\nfunction detectLocale(): string {\n if (typeof document !== \"undefined\") {\n const lang = document.documentElement.lang;\n if (lang) return lang.slice(0, 2).toLowerCase();\n }\n return \"en\";\n}\n\nexport function createWidget(options: BitPalmAgentOptions): BitPalmAgentInstance {\n const {\n slug,\n locale = detectLocale(),\n baseUrl = DEFAULT_BASE_URL,\n zIndex = 9999,\n } = options;\n\n const d = document;\n\n // --- Iframe ---\n const iframe = d.createElement(\"iframe\");\n const widgetUrl = `${baseUrl}/t/${slug}/widget`;\n iframe.src = `${widgetUrl}${widgetUrl.includes(\"?\") ? \"&\" : \"?\"}locale=${locale}`;\n iframe.allow = \"clipboard-write\";\n iframe.setAttribute(\"allowtransparency\", \"true\");\n iframe.style.cssText = `position:fixed;bottom:0;right:0;width:0;height:0;border:none;z-index:${zIndex};background:transparent;color-scheme:normal;transition:width .3s,height .3s;`;\n d.body.appendChild(iframe);\n\n const origin = new URL(iframe.src).origin;\n\n // --- Native launcher button ---\n const btn = d.createElement(\"div\");\n btn.setAttribute(\"role\", \"button\");\n btn.setAttribute(\"aria-label\", \"Chat\");\n btn.style.cssText = `position:fixed;bottom:24px;right:24px;width:56px;height:56px;border-radius:50%;display:none;align-items:center;justify-content:center;cursor:pointer;z-index:${zIndex - 1};background:#00ff41;box-shadow:0 0 15px rgba(0,255,65,0.31);transition:transform .2s;`;\n btn.innerHTML = '<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"black\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"M7.9 20A9 9 0 1 0 4 16.1L2 22Z\"/></svg>';\n btn.onmouseenter = () => { btn.style.transform = \"scale(1.1)\"; };\n btn.onmouseleave = () => { btn.style.transform = \"scale(1)\"; };\n btn.onclick = () => openWidget();\n d.body.appendChild(btn);\n\n // --- Fade animation for trigger bubbles ---\n if (!d.getElementById(\"_bp_fade\")) {\n const s = d.createElement(\"style\");\n s.id = \"_bp_fade\";\n s.textContent = \"@keyframes _bp_fade{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}\";\n d.head.appendChild(s);\n }\n\n // --- Trigger bubble ---\n let bubble: HTMLDivElement | null = null;\n const removeBubble = () => {\n if (bubble) { bubble.remove(); bubble = null; }\n };\n\n // --- postMessage handler ---\n const handleMessage = (e: MessageEvent) => {\n if (e.origin !== origin) return;\n\n // Widget config (colors, icon)\n if (e.data?.type === \"bitpalm-widget-config\") {\n if (e.data.primaryColor) {\n btn.style.background = e.data.primaryColor;\n btn.style.boxShadow = e.data.chatShadow === \"none\" ? \"none\" : `0 0 15px ${e.data.primaryColor}50`;\n }\n const ic = e.data.chatButtonIconColor || \"black\";\n if (e.data.chatButtonIconSvg) {\n btn.innerHTML = \"\";\n const sp = d.createElement(\"span\");\n sp.style.cssText = `display:flex;align-items:center;justify-content:center;width:24px;height:24px;color:${ic}`;\n sp.innerHTML = e.data.chatButtonIconSvg;\n btn.appendChild(sp);\n } else {\n const sv = btn.querySelector(\"svg\");\n if (sv) (sv as SVGElement).style.stroke = ic;\n }\n btn.style.display = \"flex\";\n }\n\n // Resize\n if (e.data?.type === \"bitpalm-widget-resize\") {\n iframe.style.width = `${e.data.width}px`;\n iframe.style.height = `${e.data.height}px`;\n btn.style.display = e.data.width > 0 ? \"none\" : \"flex\";\n }\n\n // Trigger bubble show\n if (e.data?.type === \"bitpalm-trigger-show\") {\n removeBubble();\n bubble = d.createElement(\"div\");\n bubble.style.cssText = `position:fixed;bottom:90px;right:24px;max-width:240px;background:#fff;border-radius:16px;padding:12px 32px 12px 12px;box-shadow:0 2px 20px rgba(0,0,0,0.08);cursor:pointer;z-index:${zIndex - 1};font-family:system-ui,sans-serif;animation:_bp_fade .3s;`;\n const msg = (e.data.message || \"\").replace(/</g, \"<\");\n bubble.innerHTML = `<p style=\"font-size:14px;color:#1f2937;margin:0;\">${msg}</p><div style=\"position:absolute;bottom:-8px;right:20px;width:0;height:0;border-left:8px solid transparent;border-right:8px solid transparent;border-top:8px solid #fff;\"></div>`;\n const close = d.createElement(\"button\");\n close.style.cssText = \"position:absolute;top:-8px;right:-8px;width:28px;height:28px;border-radius:50%;background:#fff;border:none;box-shadow:0 1px 4px rgba(0,0,0,0.1);cursor:pointer;display:flex;align-items:center;justify-content:center;font-size:14px;color:#9ca3af;\";\n close.innerHTML = \"✕\";\n close.onclick = (ev) => { ev.stopPropagation(); removeBubble(); iframe.contentWindow?.postMessage({ type: \"bitpalm-trigger-dismiss\" }, \"*\"); };\n bubble.onclick = () => { removeBubble(); btn.style.display = \"none\"; iframe.contentWindow?.postMessage({ type: \"bitpalm-trigger-engaged\" }, \"*\"); };\n bubble.appendChild(close);\n d.body.appendChild(bubble);\n }\n\n // Trigger bubble hide\n if (e.data?.type === \"bitpalm-trigger-hide\") { removeBubble(); }\n };\n window.addEventListener(\"message\", handleMessage);\n\n // --- Visitor Intelligence: page counter + history ---\n let pageCount = parseInt(sessionStorage.getItem(`${STORAGE_PREFIX}pages`) || \"0\") + 1;\n sessionStorage.setItem(`${STORAGE_PREFIX}pages`, String(pageCount));\n\n let hist: string[] = JSON.parse(sessionStorage.getItem(`${STORAGE_PREFIX}hist`) || \"[]\");\n hist.push(location.href);\n if (hist.length > 20) hist = hist.slice(-20);\n sessionStorage.setItem(`${STORAGE_PREFIX}hist`, JSON.stringify(hist));\n\n const loadedAt = Date.now();\n let siteStart = parseInt(sessionStorage.getItem(`${STORAGE_PREFIX}site_start`) || \"0\");\n if (!siteStart) {\n siteStart = loadedAt;\n sessionStorage.setItem(`${STORAGE_PREFIX}site_start`, String(siteStart));\n }\n\n // --- Send parent context on iframe load ---\n iframe.addEventListener(\"load\", () => {\n const returning = !!localStorage.getItem(`${STORAGE_PREFIX}visited`);\n iframe.contentWindow?.postMessage({\n type: \"bitpalm-parent-context\",\n url: location.href,\n title: d.title,\n returning,\n pageCount,\n pageHistory: hist,\n loadedAt,\n siteStart,\n locale,\n }, \"*\");\n if (!returning) localStorage.setItem(`${STORAGE_PREFIX}visited`, \"1\");\n });\n\n // --- SPA navigation detection ---\n const origPush = history.pushState.bind(history);\n const origReplace = history.replaceState.bind(history);\n\n const onNav = () => {\n pageCount++;\n sessionStorage.setItem(`${STORAGE_PREFIX}pages`, String(pageCount));\n const h: string[] = JSON.parse(sessionStorage.getItem(`${STORAGE_PREFIX}hist`) || \"[]\");\n h.push(location.href);\n if (h.length > 20) h.splice(0, h.length - 20);\n sessionStorage.setItem(`${STORAGE_PREFIX}hist`, JSON.stringify(h));\n iframe.contentWindow?.postMessage({\n type: \"bitpalm-page-change\",\n url: location.href,\n title: d.title,\n pageCount,\n pageHistory: h,\n loadedAt: Date.now(),\n }, \"*\");\n };\n\n history.pushState = function (...args: Parameters<typeof history.pushState>) {\n origPush(...args);\n onNav();\n };\n history.replaceState = function (...args: Parameters<typeof history.replaceState>) {\n origReplace(...args);\n onNav();\n };\n window.addEventListener(\"popstate\", onNav);\n\n // --- Scroll depth tracking ---\n let lastScrollDepth = -1;\n let scrollTimeout: ReturnType<typeof setTimeout>;\n const handleScroll = () => {\n clearTimeout(scrollTimeout);\n scrollTimeout = setTimeout(() => {\n const total = Math.max(d.documentElement.scrollHeight, d.body.scrollHeight) - window.innerHeight;\n const pct = total > 0 ? Math.round(window.scrollY / total * 100) : 100;\n if (pct !== lastScrollDepth) {\n lastScrollDepth = pct;\n iframe.contentWindow?.postMessage({ type: \"bitpalm-scroll-depth\", percent: pct }, \"*\");\n }\n }, 500);\n };\n window.addEventListener(\"scroll\", handleScroll, { passive: true });\n\n // --- Exit intent ---\n const handleMouseOut = (e: MouseEvent) => {\n if (e.clientY <= 0) {\n iframe.contentWindow?.postMessage({ type: \"bitpalm-exit-intent\" }, \"*\");\n }\n };\n d.addEventListener(\"mouseout\", handleMouseOut);\n\n // --- Inactivity detection (15s) ---\n let idleTimer: ReturnType<typeof setTimeout>;\n let idleFired = false;\n const resetIdle = () => {\n clearTimeout(idleTimer);\n if (idleFired) return;\n idleTimer = setTimeout(() => {\n idleFired = true;\n iframe.contentWindow?.postMessage({ type: \"bitpalm-inactivity\" }, \"*\");\n }, 15_000);\n };\n const idleEvents = [\"mousemove\", \"keydown\", \"scroll\", \"touchstart\"] as const;\n idleEvents.forEach((ev) => d.addEventListener(ev, resetIdle, { passive: true }));\n resetIdle();\n\n // --- Public API ---\n const openWidget = () => {\n btn.style.display = \"none\";\n removeBubble();\n iframe.contentWindow?.postMessage({ type: \"bitpalm-open\" }, \"*\");\n };\n\n const closeWidget = () => {\n iframe.contentWindow?.postMessage({ type: \"bitpalm-close\" }, \"*\");\n };\n\n const destroy = () => {\n window.removeEventListener(\"message\", handleMessage);\n window.removeEventListener(\"scroll\", handleScroll);\n window.removeEventListener(\"popstate\", onNav);\n d.removeEventListener(\"mouseout\", handleMouseOut);\n idleEvents.forEach((ev) => d.removeEventListener(ev, resetIdle));\n clearTimeout(scrollTimeout);\n clearTimeout(idleTimer);\n history.pushState = origPush;\n history.replaceState = origReplace;\n removeBubble();\n btn.remove();\n iframe.remove();\n };\n\n return { open: openWidget, close: closeWidget, destroy };\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAkC,iBCElC,IAAMC,EAAmB,4BACnBC,EAAiB,OAEvB,SAASC,GAAuB,CAC9B,GAAI,OAAO,SAAa,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U,EACvB,CACF,EAAG,CAAC,CAAC,EAEE,IACT","names":["react_exports","__export","BitPalmAgent","__toCommonJS","import_react","DEFAULT_BASE_URL","STORAGE_PREFIX","detectLocale","lang","createWidget","options","slug","locale","baseUrl","zIndex","d","iframe","widgetUrl","origin","btn","openWidget","s","bubble","removeBubble","handleMessage","e","ic","sp","sv","msg","close","ev","pageCount","hist","loadedAt","siteStart","returning","origPush","origReplace","onNav","h","args","lastScrollDepth","scrollTimeout","handleScroll","total","pct","handleMouseOut","idleTimer","idleFired","resetIdle","idleEvents","BitPalmAgent","props","instanceRef","mountedRef","createWidget"]}
|
package/dist/react.d.cts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
interface BitPalmAgentOptions {
|
|
2
|
+
/** Your agent slug from the BitPalm dashboard. */
|
|
3
|
+
slug: string;
|
|
4
|
+
/** Locale for the widget UI (e.g. "en", "de", "ar"). Auto-detected if omitted. */
|
|
5
|
+
locale?: string;
|
|
6
|
+
/** Base URL of the agent platform. Defaults to "https://agents.bitpalm.ae". */
|
|
7
|
+
baseUrl?: string;
|
|
8
|
+
/** z-index for the widget elements. Defaults to 9999. */
|
|
9
|
+
zIndex?: number;
|
|
10
|
+
}
|
|
11
|
+
interface BitPalmAgentInstance {
|
|
12
|
+
/** Open the chat widget programmatically. */
|
|
13
|
+
open: () => void;
|
|
14
|
+
/** Close the chat widget programmatically. */
|
|
15
|
+
close: () => void;
|
|
16
|
+
/** Remove the widget and clean up all event listeners. */
|
|
17
|
+
destroy: () => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type BitPalmAgentProps = BitPalmAgentOptions;
|
|
21
|
+
/**
|
|
22
|
+
* React component that mounts the BitPalm AI agent widget.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```tsx
|
|
26
|
+
* import { BitPalmAgent } from '@bitpalm/ai-agents/react';
|
|
27
|
+
*
|
|
28
|
+
* export default function App() {
|
|
29
|
+
* return <BitPalmAgent slug="my-agent" />;
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
declare function BitPalmAgent(props: BitPalmAgentProps): null;
|
|
34
|
+
|
|
35
|
+
export { BitPalmAgent, type BitPalmAgentInstance, type BitPalmAgentOptions, type BitPalmAgentProps };
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
interface BitPalmAgentOptions {
|
|
2
|
+
/** Your agent slug from the BitPalm dashboard. */
|
|
3
|
+
slug: string;
|
|
4
|
+
/** Locale for the widget UI (e.g. "en", "de", "ar"). Auto-detected if omitted. */
|
|
5
|
+
locale?: string;
|
|
6
|
+
/** Base URL of the agent platform. Defaults to "https://agents.bitpalm.ae". */
|
|
7
|
+
baseUrl?: string;
|
|
8
|
+
/** z-index for the widget elements. Defaults to 9999. */
|
|
9
|
+
zIndex?: number;
|
|
10
|
+
}
|
|
11
|
+
interface BitPalmAgentInstance {
|
|
12
|
+
/** Open the chat widget programmatically. */
|
|
13
|
+
open: () => void;
|
|
14
|
+
/** Close the chat widget programmatically. */
|
|
15
|
+
close: () => void;
|
|
16
|
+
/** Remove the widget and clean up all event listeners. */
|
|
17
|
+
destroy: () => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type BitPalmAgentProps = BitPalmAgentOptions;
|
|
21
|
+
/**
|
|
22
|
+
* React component that mounts the BitPalm AI agent widget.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```tsx
|
|
26
|
+
* import { BitPalmAgent } from '@bitpalm/ai-agents/react';
|
|
27
|
+
*
|
|
28
|
+
* export default function App() {
|
|
29
|
+
* return <BitPalmAgent slug="my-agent" />;
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
declare function BitPalmAgent(props: BitPalmAgentProps): null;
|
|
34
|
+
|
|
35
|
+
export { BitPalmAgent, type BitPalmAgentInstance, type BitPalmAgentOptions, type BitPalmAgentProps };
|
package/dist/react.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{useEffect as R,useRef as k}from"react";var H="https://agents.bitpalm.ae",i="_bp_";function O(){if(typeof document<"u"){let l=document.documentElement.lang;if(l)return l.slice(0,2).toLowerCase()}return"en"}function P(l){let{slug:g,locale:p=O(),baseUrl:_=H,zIndex:f=9999}=l,n=document,o=n.createElement("iframe"),w=`${_}/t/${g}/widget`;o.src=`${w}${w.includes("?")?"&":"?"}locale=${p}`,o.allow="clipboard-write",o.setAttribute("allowtransparency","true"),o.style.cssText=`position:fixed;bottom:0;right:0;width:0;height:0;border:none;z-index:${f};background:transparent;color-scheme:normal;transition:width .3s,height .3s;`,n.body.appendChild(o);let C=new URL(o.src).origin,e=n.createElement("div");if(e.setAttribute("role","button"),e.setAttribute("aria-label","Chat"),e.style.cssText=`position:fixed;bottom:24px;right:24px;width:56px;height:56px;border-radius:50%;display:none;align-items:center;justify-content:center;cursor:pointer;z-index:${f-1};background:#00ff41;box-shadow:0 0 15px rgba(0,255,65,0.31);transition:transform .2s;`,e.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M7.9 20A9 9 0 1 0 4 16.1L2 22Z"/></svg>',e.onmouseenter=()=>{e.style.transform="scale(1.1)"},e.onmouseleave=()=>{e.style.transform="scale(1)"},e.onclick=()=>B(),n.body.appendChild(e),!n.getElementById("_bp_fade")){let t=n.createElement("style");t.id="_bp_fade",t.textContent="@keyframes _bp_fade{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}",n.head.appendChild(t)}let r=null,c=()=>{r&&(r.remove(),r=null)},v=t=>{if(t.origin===C){if(t.data?.type==="bitpalm-widget-config"){t.data.primaryColor&&(e.style.background=t.data.primaryColor,e.style.boxShadow=t.data.chatShadow==="none"?"none":`0 0 15px ${t.data.primaryColor}50`);let a=t.data.chatButtonIconColor||"black";if(t.data.chatButtonIconSvg){e.innerHTML="";let s=n.createElement("span");s.style.cssText=`display:flex;align-items:center;justify-content:center;width:24px;height:24px;color:${a}`,s.innerHTML=t.data.chatButtonIconSvg,e.appendChild(s)}else{let s=e.querySelector("svg");s&&(s.style.stroke=a)}e.style.display="flex"}if(t.data?.type==="bitpalm-widget-resize"&&(o.style.width=`${t.data.width}px`,o.style.height=`${t.data.height}px`,e.style.display=t.data.width>0?"none":"flex"),t.data?.type==="bitpalm-trigger-show"){c(),r=n.createElement("div"),r.style.cssText=`position:fixed;bottom:90px;right:24px;max-width:240px;background:#fff;border-radius:16px;padding:12px 32px 12px 12px;box-shadow:0 2px 20px rgba(0,0,0,0.08);cursor:pointer;z-index:${f-1};font-family:system-ui,sans-serif;animation:_bp_fade .3s;`;let a=(t.data.message||"").replace(/</g,"<");r.innerHTML=`<p style="font-size:14px;color:#1f2937;margin:0;">${a}</p><div style="position:absolute;bottom:-8px;right:20px;width:0;height:0;border-left:8px solid transparent;border-right:8px solid transparent;border-top:8px solid #fff;"></div>`;let s=n.createElement("button");s.style.cssText="position:absolute;top:-8px;right:-8px;width:28px;height:28px;border-radius:50%;background:#fff;border:none;box-shadow:0 1px 4px rgba(0,0,0,0.1);cursor:pointer;display:flex;align-items:center;justify-content:center;font-size:14px;color:#9ca3af;",s.innerHTML="✕",s.onclick=W=>{W.stopPropagation(),c(),o.contentWindow?.postMessage({type:"bitpalm-trigger-dismiss"},"*")},r.onclick=()=>{c(),e.style.display="none",o.contentWindow?.postMessage({type:"bitpalm-trigger-engaged"},"*")},r.appendChild(s),n.body.appendChild(r)}t.data?.type==="bitpalm-trigger-hide"&&c()}};window.addEventListener("message",v);let m=parseInt(sessionStorage.getItem(`${i}pages`)||"0")+1;sessionStorage.setItem(`${i}pages`,String(m));let d=JSON.parse(sessionStorage.getItem(`${i}hist`)||"[]");d.push(location.href),d.length>20&&(d=d.slice(-20)),sessionStorage.setItem(`${i}hist`,JSON.stringify(d));let S=Date.now(),u=parseInt(sessionStorage.getItem(`${i}site_start`)||"0");u||(u=S,sessionStorage.setItem(`${i}site_start`,String(u))),o.addEventListener("load",()=>{let t=!!localStorage.getItem(`${i}visited`);o.contentWindow?.postMessage({type:"bitpalm-parent-context",url:location.href,title:n.title,returning:t,pageCount:m,pageHistory:d,loadedAt:S,siteStart:u,locale:p},"*"),t||localStorage.setItem(`${i}visited`,"1")});let E=history.pushState.bind(history),I=history.replaceState.bind(history),h=()=>{m++,sessionStorage.setItem(`${i}pages`,String(m));let t=JSON.parse(sessionStorage.getItem(`${i}hist`)||"[]");t.push(location.href),t.length>20&&t.splice(0,t.length-20),sessionStorage.setItem(`${i}hist`,JSON.stringify(t)),o.contentWindow?.postMessage({type:"bitpalm-page-change",url:location.href,title:n.title,pageCount:m,pageHistory:t,loadedAt:Date.now()},"*")};history.pushState=function(...t){E(...t),h()},history.replaceState=function(...t){I(...t),h()},window.addEventListener("popstate",h);let T=-1,y,$=()=>{clearTimeout(y),y=setTimeout(()=>{let t=Math.max(n.documentElement.scrollHeight,n.body.scrollHeight)-window.innerHeight,a=t>0?Math.round(window.scrollY/t*100):100;a!==T&&(T=a,o.contentWindow?.postMessage({type:"bitpalm-scroll-depth",percent:a},"*"))},500)};window.addEventListener("scroll",$,{passive:!0});let L=t=>{t.clientY<=0&&o.contentWindow?.postMessage({type:"bitpalm-exit-intent"},"*")};n.addEventListener("mouseout",L);let b,A=!1,x=()=>{clearTimeout(b),!A&&(b=setTimeout(()=>{A=!0,o.contentWindow?.postMessage({type:"bitpalm-inactivity"},"*")},15e3))},M=["mousemove","keydown","scroll","touchstart"];M.forEach(t=>n.addEventListener(t,x,{passive:!0})),x();let B=()=>{e.style.display="none",c(),o.contentWindow?.postMessage({type:"bitpalm-open"},"*")};return{open:B,close:()=>{o.contentWindow?.postMessage({type:"bitpalm-close"},"*")},destroy:()=>{window.removeEventListener("message",v),window.removeEventListener("scroll",$),window.removeEventListener("popstate",h),n.removeEventListener("mouseout",L),M.forEach(t=>n.removeEventListener(t,x)),clearTimeout(y),clearTimeout(b),history.pushState=E,history.replaceState=I,c(),e.remove(),o.remove()}}}function J(l){let g=k(null),p=k(!1);return R(()=>{if(!p.current)return p.current=!0,g.current=P(l),()=>{g.current?.destroy(),g.current=null,p.current=!1}},[]),null}export{J as BitPalmAgent};
|
|
2
|
+
//# sourceMappingURL=react.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/react.ts","../src/widget.ts"],"sourcesContent":["import { useEffect, useRef } from \"react\";\nimport { createWidget } from \"./widget\";\nimport type { BitPalmAgentOptions, BitPalmAgentInstance } from \"./types\";\n\nexport type { BitPalmAgentOptions, BitPalmAgentInstance } from \"./types\";\n\nexport type BitPalmAgentProps = BitPalmAgentOptions;\n\n/**\n * React component that mounts the BitPalm AI agent widget.\n *\n * @example\n * ```tsx\n * import { BitPalmAgent } from '@bitpalm/ai-agents/react';\n *\n * export default function App() {\n * return <BitPalmAgent slug=\"my-agent\" />;\n * }\n * ```\n */\nexport function BitPalmAgent(props: BitPalmAgentProps): null {\n const instanceRef = useRef<BitPalmAgentInstance | null>(null);\n const mountedRef = useRef(false);\n\n useEffect(() => {\n if (mountedRef.current) return;\n mountedRef.current = true;\n\n instanceRef.current = createWidget(props);\n\n return () => {\n instanceRef.current?.destroy();\n instanceRef.current = null;\n mountedRef.current = false;\n };\n }, []); // eslint-disable-line react-hooks/exhaustive-deps\n\n return null;\n}\n","import type { BitPalmAgentOptions, BitPalmAgentInstance } from \"./types\";\n\nconst DEFAULT_BASE_URL = \"https://agents.bitpalm.ae\";\nconst STORAGE_PREFIX = \"_bp_\";\n\nfunction detectLocale(): string {\n if (typeof document !== \"undefined\") {\n const lang = document.documentElement.lang;\n if (lang) return lang.slice(0, 2).toLowerCase();\n }\n return \"en\";\n}\n\nexport function createWidget(options: BitPalmAgentOptions): BitPalmAgentInstance {\n const {\n slug,\n locale = detectLocale(),\n baseUrl = DEFAULT_BASE_URL,\n zIndex = 9999,\n } = options;\n\n const d = document;\n\n // --- Iframe ---\n const iframe = d.createElement(\"iframe\");\n const widgetUrl = `${baseUrl}/t/${slug}/widget`;\n iframe.src = `${widgetUrl}${widgetUrl.includes(\"?\") ? \"&\" : \"?\"}locale=${locale}`;\n iframe.allow = \"clipboard-write\";\n iframe.setAttribute(\"allowtransparency\", \"true\");\n iframe.style.cssText = `position:fixed;bottom:0;right:0;width:0;height:0;border:none;z-index:${zIndex};background:transparent;color-scheme:normal;transition:width .3s,height .3s;`;\n d.body.appendChild(iframe);\n\n const origin = new URL(iframe.src).origin;\n\n // --- Native launcher button ---\n const btn = d.createElement(\"div\");\n btn.setAttribute(\"role\", \"button\");\n btn.setAttribute(\"aria-label\", \"Chat\");\n btn.style.cssText = `position:fixed;bottom:24px;right:24px;width:56px;height:56px;border-radius:50%;display:none;align-items:center;justify-content:center;cursor:pointer;z-index:${zIndex - 1};background:#00ff41;box-shadow:0 0 15px rgba(0,255,65,0.31);transition:transform .2s;`;\n btn.innerHTML = '<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"black\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"M7.9 20A9 9 0 1 0 4 16.1L2 22Z\"/></svg>';\n btn.onmouseenter = () => { btn.style.transform = \"scale(1.1)\"; };\n btn.onmouseleave = () => { btn.style.transform = \"scale(1)\"; };\n btn.onclick = () => openWidget();\n d.body.appendChild(btn);\n\n // --- Fade animation for trigger bubbles ---\n if (!d.getElementById(\"_bp_fade\")) {\n const s = d.createElement(\"style\");\n s.id = \"_bp_fade\";\n s.textContent = \"@keyframes _bp_fade{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}\";\n d.head.appendChild(s);\n }\n\n // --- Trigger bubble ---\n let bubble: HTMLDivElement | null = null;\n const removeBubble = () => {\n if (bubble) { bubble.remove(); bubble = null; }\n };\n\n // --- postMessage handler ---\n const handleMessage = (e: MessageEvent) => {\n if (e.origin !== origin) return;\n\n // Widget config (colors, icon)\n if (e.data?.type === \"bitpalm-widget-config\") {\n if (e.data.primaryColor) {\n btn.style.background = e.data.primaryColor;\n btn.style.boxShadow = e.data.chatShadow === \"none\" ? \"none\" : `0 0 15px ${e.data.primaryColor}50`;\n }\n const ic = e.data.chatButtonIconColor || \"black\";\n if (e.data.chatButtonIconSvg) {\n btn.innerHTML = \"\";\n const sp = d.createElement(\"span\");\n sp.style.cssText = `display:flex;align-items:center;justify-content:center;width:24px;height:24px;color:${ic}`;\n sp.innerHTML = e.data.chatButtonIconSvg;\n btn.appendChild(sp);\n } else {\n const sv = btn.querySelector(\"svg\");\n if (sv) (sv as SVGElement).style.stroke = ic;\n }\n btn.style.display = \"flex\";\n }\n\n // Resize\n if (e.data?.type === \"bitpalm-widget-resize\") {\n iframe.style.width = `${e.data.width}px`;\n iframe.style.height = `${e.data.height}px`;\n btn.style.display = e.data.width > 0 ? \"none\" : \"flex\";\n }\n\n // Trigger bubble show\n if (e.data?.type === \"bitpalm-trigger-show\") {\n removeBubble();\n bubble = d.createElement(\"div\");\n bubble.style.cssText = `position:fixed;bottom:90px;right:24px;max-width:240px;background:#fff;border-radius:16px;padding:12px 32px 12px 12px;box-shadow:0 2px 20px rgba(0,0,0,0.08);cursor:pointer;z-index:${zIndex - 1};font-family:system-ui,sans-serif;animation:_bp_fade .3s;`;\n const msg = (e.data.message || \"\").replace(/</g, \"<\");\n bubble.innerHTML = `<p style=\"font-size:14px;color:#1f2937;margin:0;\">${msg}</p><div style=\"position:absolute;bottom:-8px;right:20px;width:0;height:0;border-left:8px solid transparent;border-right:8px solid transparent;border-top:8px solid #fff;\"></div>`;\n const close = d.createElement(\"button\");\n close.style.cssText = \"position:absolute;top:-8px;right:-8px;width:28px;height:28px;border-radius:50%;background:#fff;border:none;box-shadow:0 1px 4px rgba(0,0,0,0.1);cursor:pointer;display:flex;align-items:center;justify-content:center;font-size:14px;color:#9ca3af;\";\n close.innerHTML = \"✕\";\n close.onclick = (ev) => { ev.stopPropagation(); removeBubble(); iframe.contentWindow?.postMessage({ type: \"bitpalm-trigger-dismiss\" }, \"*\"); };\n bubble.onclick = () => { removeBubble(); btn.style.display = \"none\"; iframe.contentWindow?.postMessage({ type: \"bitpalm-trigger-engaged\" }, \"*\"); };\n bubble.appendChild(close);\n d.body.appendChild(bubble);\n }\n\n // Trigger bubble hide\n if (e.data?.type === \"bitpalm-trigger-hide\") { removeBubble(); }\n };\n window.addEventListener(\"message\", handleMessage);\n\n // --- Visitor Intelligence: page counter + history ---\n let pageCount = parseInt(sessionStorage.getItem(`${STORAGE_PREFIX}pages`) || \"0\") + 1;\n sessionStorage.setItem(`${STORAGE_PREFIX}pages`, String(pageCount));\n\n let hist: string[] = JSON.parse(sessionStorage.getItem(`${STORAGE_PREFIX}hist`) || \"[]\");\n hist.push(location.href);\n if (hist.length > 20) hist = hist.slice(-20);\n sessionStorage.setItem(`${STORAGE_PREFIX}hist`, JSON.stringify(hist));\n\n const loadedAt = Date.now();\n let siteStart = parseInt(sessionStorage.getItem(`${STORAGE_PREFIX}site_start`) || \"0\");\n if (!siteStart) {\n siteStart = loadedAt;\n sessionStorage.setItem(`${STORAGE_PREFIX}site_start`, String(siteStart));\n }\n\n // --- Send parent context on iframe load ---\n iframe.addEventListener(\"load\", () => {\n const returning = !!localStorage.getItem(`${STORAGE_PREFIX}visited`);\n iframe.contentWindow?.postMessage({\n type: \"bitpalm-parent-context\",\n url: location.href,\n title: d.title,\n returning,\n pageCount,\n pageHistory: hist,\n loadedAt,\n siteStart,\n locale,\n }, \"*\");\n if (!returning) localStorage.setItem(`${STORAGE_PREFIX}visited`, \"1\");\n });\n\n // --- SPA navigation detection ---\n const origPush = history.pushState.bind(history);\n const origReplace = history.replaceState.bind(history);\n\n const onNav = () => {\n pageCount++;\n sessionStorage.setItem(`${STORAGE_PREFIX}pages`, String(pageCount));\n const h: string[] = JSON.parse(sessionStorage.getItem(`${STORAGE_PREFIX}hist`) || \"[]\");\n h.push(location.href);\n if (h.length > 20) h.splice(0, h.length - 20);\n sessionStorage.setItem(`${STORAGE_PREFIX}hist`, JSON.stringify(h));\n iframe.contentWindow?.postMessage({\n type: \"bitpalm-page-change\",\n url: location.href,\n title: d.title,\n pageCount,\n pageHistory: h,\n loadedAt: Date.now(),\n }, \"*\");\n };\n\n history.pushState = function (...args: Parameters<typeof history.pushState>) {\n origPush(...args);\n onNav();\n };\n history.replaceState = function (...args: Parameters<typeof history.replaceState>) {\n origReplace(...args);\n onNav();\n };\n window.addEventListener(\"popstate\", onNav);\n\n // --- Scroll depth tracking ---\n let lastScrollDepth = -1;\n let scrollTimeout: ReturnType<typeof setTimeout>;\n const handleScroll = () => {\n clearTimeout(scrollTimeout);\n scrollTimeout = setTimeout(() => {\n const total = Math.max(d.documentElement.scrollHeight, d.body.scrollHeight) - window.innerHeight;\n const pct = total > 0 ? Math.round(window.scrollY / total * 100) : 100;\n if (pct !== lastScrollDepth) {\n lastScrollDepth = pct;\n iframe.contentWindow?.postMessage({ type: \"bitpalm-scroll-depth\", percent: pct }, \"*\");\n }\n }, 500);\n };\n window.addEventListener(\"scroll\", handleScroll, { passive: true });\n\n // --- Exit intent ---\n const handleMouseOut = (e: MouseEvent) => {\n if (e.clientY <= 0) {\n iframe.contentWindow?.postMessage({ type: \"bitpalm-exit-intent\" }, \"*\");\n }\n };\n d.addEventListener(\"mouseout\", handleMouseOut);\n\n // --- Inactivity detection (15s) ---\n let idleTimer: ReturnType<typeof setTimeout>;\n let idleFired = false;\n const resetIdle = () => {\n clearTimeout(idleTimer);\n if (idleFired) return;\n idleTimer = setTimeout(() => {\n idleFired = true;\n iframe.contentWindow?.postMessage({ type: \"bitpalm-inactivity\" }, \"*\");\n }, 15_000);\n };\n const idleEvents = [\"mousemove\", \"keydown\", \"scroll\", \"touchstart\"] as const;\n idleEvents.forEach((ev) => d.addEventListener(ev, resetIdle, { passive: true }));\n resetIdle();\n\n // --- Public API ---\n const openWidget = () => {\n btn.style.display = \"none\";\n removeBubble();\n iframe.contentWindow?.postMessage({ type: \"bitpalm-open\" }, \"*\");\n };\n\n const closeWidget = () => {\n iframe.contentWindow?.postMessage({ type: \"bitpalm-close\" }, \"*\");\n };\n\n const destroy = () => {\n window.removeEventListener(\"message\", handleMessage);\n window.removeEventListener(\"scroll\", handleScroll);\n window.removeEventListener(\"popstate\", onNav);\n d.removeEventListener(\"mouseout\", handleMouseOut);\n idleEvents.forEach((ev) => d.removeEventListener(ev, resetIdle));\n clearTimeout(scrollTimeout);\n clearTimeout(idleTimer);\n history.pushState = origPush;\n history.replaceState = origReplace;\n removeBubble();\n btn.remove();\n iframe.remove();\n };\n\n return { open: openWidget, close: closeWidget, destroy };\n}\n"],"mappings":"AAAA,OAAS,aAAAA,EAAW,UAAAC,MAAc,QCElC,IAAMC,EAAmB,4BACnBC,EAAiB,OAEvB,SAASC,GAAuB,CAC9B,GAAI,OAAO,SAAa,IAAa,CACnC,IAAMC,EAAO,SAAS,gBAAgB,KACtC,GAAIA,EAAM,OAAOA,EAAK,MAAM,EAAG,CAAC,EAAE,YAAY,CAChD,CACA,MAAO,IACT,CAEO,SAASC,EAAaC,EAAoD,CAC/E,GAAM,CACJ,KAAAC,EACA,OAAAC,EAASL,EAAa,EACtB,QAAAM,EAAUR,EACV,OAAAS,EAAS,IACX,EAAIJ,EAEEK,EAAI,SAGJC,EAASD,EAAE,cAAc,QAAQ,EACjCE,EAAY,GAAGJ,CAAO,MAAMF,CAAI,UACtCK,EAAO,IAAM,GAAGC,CAAS,GAAGA,EAAU,SAAS,GAAG,EAAI,IAAM,GAAG,UAAUL,CAAM,GAC/EI,EAAO,MAAQ,kBACfA,EAAO,aAAa,oBAAqB,MAAM,EAC/CA,EAAO,MAAM,QAAU,wEAAwEF,CAAM,+EACrGC,EAAE,KAAK,YAAYC,CAAM,EAEzB,IAAME,EAAS,IAAI,IAAIF,EAAO,GAAG,EAAE,OAG7BG,EAAMJ,EAAE,cAAc,KAAK,EAWjC,GAV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BAAoB,SAAUoB,CAAY,EACjD,OAAO,oBAAoB,WAAYL,CAAK,EAC5CxB,EAAE,oBAAoB,WAAYgC,CAAc,EAChDI,EAAW,QAASpB,GAAOhB,EAAE,oBAAoBgB,EAAImB,CAAS,CAAC,EAC/D,aAAaP,CAAa,EAC1B,aAAaK,CAAS,EACtB,QAAQ,UAAYX,EACpB,QAAQ,aAAeC,EACvBf,EAAa,EACbJ,EAAI,OAAO,EACXH,EAAO,OAAO,CAChB,CAEuD,CACzD,CD7NO,SAASoC,EAAaC,EAAgC,CAC3D,IAAMC,EAAcC,EAAoC,IAAI,EACtDC,EAAaD,EAAO,EAAK,EAE/B,OAAAE,EAAU,IAAM,CACd,GAAI,CAAAD,EAAW,QACf,OAAAA,EAAW,QAAU,GAErBF,EAAY,QAAUI,EAAaL,CAAK,EAEjC,IAAM,CACXC,EAAY,SAAS,QAAQ,EAC7BA,EAAY,QAAU,KACtBE,EAAW,QAAU,EACvB,CACF,EAAG,CAAC,CAAC,EAEE,IACT","names":["useEffect","useRef","DEFAULT_BASE_URL","STORAGE_PREFIX","detectLocale","lang","createWidget","options","slug","locale","baseUrl","zIndex","d","iframe","widgetUrl","origin","btn","openWidget","s","bubble","removeBubble","handleMessage","e","ic","sp","sv","msg","close","ev","pageCount","hist","loadedAt","siteStart","returning","origPush","origReplace","onNav","h","args","lastScrollDepth","scrollTimeout","handleScroll","total","pct","handleMouseOut","idleTimer","idleFired","resetIdle","idleEvents","BitPalmAgent","props","instanceRef","useRef","mountedRef","useEffect","createWidget"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bitpalm/ai-agents",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Drop-in AI chat agent widget for any website. Includes visitor intelligence, SPA navigation tracking, trigger bubbles, and more.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "BitPalm <business@bitpalm.ae>",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/BitPalm-LLC/ai-agents-sdk"
|
|
10
|
+
},
|
|
11
|
+
"keywords": ["ai", "chatbot", "widget", "bitpalm", "agents", "chat"],
|
|
12
|
+
"type": "module",
|
|
13
|
+
"main": "./dist/index.cjs",
|
|
14
|
+
"module": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"import": "./dist/index.js",
|
|
20
|
+
"require": "./dist/index.cjs"
|
|
21
|
+
},
|
|
22
|
+
"./react": {
|
|
23
|
+
"types": "./dist/react.d.ts",
|
|
24
|
+
"import": "./dist/react.js",
|
|
25
|
+
"require": "./dist/react.cjs"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"files": ["dist"],
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsup",
|
|
31
|
+
"dev": "tsup --watch",
|
|
32
|
+
"typecheck": "tsc --noEmit",
|
|
33
|
+
"prepublishOnly": "pnpm build"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"react": ">=17.0.0"
|
|
37
|
+
},
|
|
38
|
+
"peerDependenciesMeta": {
|
|
39
|
+
"react": {
|
|
40
|
+
"optional": true
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"react": "^19.0.0",
|
|
45
|
+
"@types/react": "^19.0.0",
|
|
46
|
+
"tsup": "^8.4.0",
|
|
47
|
+
"typescript": "^5.7.0"
|
|
48
|
+
}
|
|
49
|
+
}
|