feazy-neo-chat-component 0.1.70 → 0.1.73

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.
@@ -241,4 +241,4 @@ ${i}
241
241
  ${s}
242
242
  }`),l.join(`
243
243
 
244
- `)}loadRemoteConfig(r,n){if(!r||!n)return;const o=n.replace(/\/+$/,""),a=`${o}|${r}`;if(this.remoteConfigKey===a&&(this.remoteConfigStatus==="loading"||this.remoteConfigStatus==="loaded"))return;this.remoteConfigKey=a,this.remoteConfigStatus="loading";const i=`${o}/v1/chat-settings/widget-config/${encodeURIComponent(r)}`;fetch(i,{method:"GET"}).then(async s=>{if(!s.ok){console.warn("Failed to load remote chat widget config:",s.status,s.statusText),this.remoteConfigStatus="error";return}const l=await s.json();this.remoteConfig=this.normalizeRemoteConfig(l),this.remoteConfigStatus="loaded",this.render()}).catch(s=>{console.error("Error loading remote chat widget config:",s),this.remoteConfigStatus="error"})}normalizeRemoteConfig(r){var c,u,d;if(!r||typeof r!="object")return{};const n=r,o={...n},a=m=>{if(typeof m!="string")return;const p=m.trim();return p||void 0},i=m=>{if(typeof m=="number")return Number.isFinite(m)?m:void 0;if(typeof m=="string"){const p=Number(m);return Number.isFinite(p)?p:void 0}},s=m=>{if(typeof m=="boolean")return m;if(m==="true")return!0;if(m==="false")return!1},l=m=>{if(!m||typeof m!="object")return;const p=m,h={stability:i(p.stability),similarity_boost:i(p.similarity_boost??p.similarityBoost),style:i(p.style),use_speaker_boost:s(p.use_speaker_boost??p.useSpeakerBoost),speed:i(p.speed)};if(!(h.stability===void 0&&h.similarity_boost===void 0&&h.style===void 0&&h.use_speaker_boost===void 0&&h.speed===void 0))return h};if(n.api&&typeof n.api=="object"){const m=n.api;typeof m.baseUrl=="string"&&m.baseUrl&&(o.baseUrl=m.baseUrl),typeof m.tenant=="string"&&m.tenant&&(o.tenant=m.tenant)}if(n.colors&&typeof n.colors=="object"){const m=n.colors;if(this.normalizeColorMap(m.common)||this.normalizeColorMap(m.light)||this.normalizeColorMap(m.dark)){const h=this.normalizeColorMap(m.common),g=this.normalizeColorMap(m.light),w=this.normalizeColorMap(m.dark),b={};h&&(b.common=h),g&&(b.light=g),w&&(b.dark=w),o.colors=b}else{const h=this.normalizeColorMap(m);h?o.colors=h:delete o.colors}}{const m=a(n.bubbleIconUrl)??a(n.bubble_icon_url)??a(n.launcherIconUrl)??a(n.launcher_icon_url);m?o.bubbleIconUrl=m:(delete o.bubbleIconUrl,delete o.bubble_icon_url,delete o.launcherIconUrl,delete o.launcher_icon_url)}{const m=n.tts&&typeof n.tts=="object"?n.tts:void 0,p=a(m==null?void 0:m.modelId)??a(m==null?void 0:m.model_id)??a(n.ttsModelId)??a(n.tts_model_id),h=a(m==null?void 0:m.voiceId)??a(m==null?void 0:m.voice_id)??a(n.ttsVoiceId)??a(n.tts_voice_id),g=l((m==null?void 0:m.voiceSettings)??(m==null?void 0:m.voice_settings))??l(n.ttsVoiceSettings)??l(n.tts_voice_settings);if(p||h||g){const w=o.tts&&typeof o.tts=="object"?o.tts:void 0;o.tts={...w||{},...p?{modelId:p}:null,...h?{voiceId:h}:null,...g?{voiceSettings:g}:null}}delete o.ttsModelId,delete o.tts_model_id,delete o.ttsVoiceId,delete o.tts_voice_id,delete o.ttsVoiceSettings,delete o.tts_voice_settings,m&&((c=o.tts)==null||delete c.model_id,(u=o.tts)==null||delete u.voice_id,(d=o.tts)==null||delete d.voice_settings)}return o}render(){if(!this.container)return;const r=this.getAttribute("prompt-id")||void 0,n=this.getAttribute("api-key")||void 0,o=this.getAttribute("base-url")||void 0,a=this.getAttribute("tenant")||void 0,i=this.getAttribute("theme"),s=i==="light"||i==="dark"?i:void 0,l=this.getAttribute("high-contrast")==="true",c=this.hasAttribute("bubbleless"),u=c?this.getAttribute("bubbleless"):null,d=c?u===null||u===""||u==="true":void 0,m=this.hasAttribute("remote-config"),p=m?this.getAttribute("remote-config"):null,h=m?p===null||p===""||p==="true":!1,g=this.getAttribute("config");let w;if(g)try{w=JSON.parse(g)}catch(z){console.warn("Failed to parse chat-component config attribute:",z)}h?this.loadRemoteConfig(r,o):(this.remoteConfigStatus="idle",this.remoteConfig=null,this.remoteConfigKey=void 0);const b={...w,promptId:(w==null?void 0:w.promptId)??r,apiKey:(w==null?void 0:w.apiKey)??n,baseUrl:(w==null?void 0:w.baseUrl)??o,tenant:(w==null?void 0:w.tenant)??a,theme:(w==null?void 0:w.theme)??s,highContrast:(w==null?void 0:w.highContrast)??l};let A;if(h&&this.remoteConfig){const z=Yn(this.remoteConfig);A=Tm(z,b)}else A=Yn(b);const S=this.normalizeColorsConfig(A.colors);S&&(A={...A,colors:S});const C=this.getThemeAwareColors(A.colors);if(this.appliedColorVars.forEach(z=>this.container.style.removeProperty(z)),this.appliedColorVars=[],C.dark)for(const[z,P]of Object.entries(C.dark)){const W=z.startsWith("--")?z:`--${z}`,q=this.applyDefaultGlowAlpha(W,P,.3);this.container.style.setProperty(W,q),this.appliedColorVars.push(W)}this.colorOverrideStyle&&(this.colorOverrideStyle.textContent=this.buildColorOverrideCss(C));const M=h&&this.remoteConfigStatus!=="loaded"?!0:d;this.root||(this.root=Fa(this.container)),this.root.render(f.jsx(V.StrictMode,{children:f.jsx($z,{config:A,bubbleless:M,registerOpenHandler:z=>{this.openChatHandler=z}})}))}openChat(){this.openChatHandler&&this.openChatHandler()}}customElements.get("chat-component")||customElements.define("chat-component",nC)})(React,ReactDOM);
244
+ `)}loadRemoteConfig(r,n){if(!r||!n)return;const o=n.replace(/\/+$/,""),a=`${o}|${r}`;if(this.remoteConfigKey===a&&(this.remoteConfigStatus==="loading"||this.remoteConfigStatus==="loaded"))return;this.remoteConfigKey=a,this.remoteConfigStatus="loading";const i=`${o}/v1/chat-settings/widget-config/${encodeURIComponent(r)}`;fetch(i,{method:"GET"}).then(async s=>{if(!s.ok){console.warn("Failed to load remote chat widget config:",s.status,s.statusText),this.remoteConfigStatus="error";return}const l=await s.json();this.remoteConfig=this.normalizeRemoteConfig(l),this.remoteConfigStatus="loaded",this.render()}).catch(s=>{console.error("Error loading remote chat widget config:",s),this.remoteConfigStatus="error"})}normalizeRemoteConfig(r){var c,u,d;if(!r||typeof r!="object")return{};const n=r,o={...n},a=m=>{if(typeof m!="string")return;const p=m.trim();return p||void 0},i=m=>{if(typeof m=="number")return Number.isFinite(m)?m:void 0;if(typeof m=="string"){const p=Number(m);return Number.isFinite(p)?p:void 0}},s=m=>{if(typeof m=="boolean")return m;if(m==="true")return!0;if(m==="false")return!1},l=m=>{if(!m||typeof m!="object")return;const p=m,h={stability:i(p.stability),similarity_boost:i(p.similarity_boost??p.similarityBoost),style:i(p.style),use_speaker_boost:s(p.use_speaker_boost??p.useSpeakerBoost),speed:i(p.speed)};if(!(h.stability===void 0&&h.similarity_boost===void 0&&h.style===void 0&&h.use_speaker_boost===void 0&&h.speed===void 0))return h};if(n.api&&typeof n.api=="object"){const m=n.api;typeof m.baseUrl=="string"&&m.baseUrl&&(o.baseUrl=m.baseUrl),typeof m.tenant=="string"&&m.tenant&&(o.tenant=m.tenant)}if(n.colors&&typeof n.colors=="object"){const m=n.colors;if(this.normalizeColorMap(m.common)||this.normalizeColorMap(m.light)||this.normalizeColorMap(m.dark)){const h=this.normalizeColorMap(m.common),g=this.normalizeColorMap(m.light),w=this.normalizeColorMap(m.dark),b={};h&&(b.common=h),g&&(b.light=g),w&&(b.dark=w),o.colors=b}else{const h=this.normalizeColorMap(m);h?o.colors=h:delete o.colors}}{const m=a(n.bubbleIconUrl)??a(n.bubble_icon_url)??a(n.launcherIconUrl)??a(n.launcher_icon_url);m?o.bubbleIconUrl=m:(delete o.bubbleIconUrl,delete o.bubble_icon_url,delete o.launcherIconUrl,delete o.launcher_icon_url)}{const m=n.tts&&typeof n.tts=="object"?n.tts:void 0,p=a(m==null?void 0:m.modelId)??a(m==null?void 0:m.model_id)??a(n.ttsModelId)??a(n.tts_model_id),h=a(m==null?void 0:m.voiceId)??a(m==null?void 0:m.voice_id)??a(n.ttsVoiceId)??a(n.tts_voice_id),g=l((m==null?void 0:m.voiceSettings)??(m==null?void 0:m.voice_settings))??l(n.ttsVoiceSettings)??l(n.tts_voice_settings);if(p||h||g){const w=o.tts&&typeof o.tts=="object"?o.tts:void 0;o.tts={...w||{},...p?{modelId:p}:null,...h?{voiceId:h}:null,...g?{voiceSettings:g}:null}}delete o.ttsModelId,delete o.tts_model_id,delete o.ttsVoiceId,delete o.tts_voice_id,delete o.ttsVoiceSettings,delete o.tts_voice_settings,m&&((c=o.tts)==null||delete c.model_id,(u=o.tts)==null||delete u.voice_id,(d=o.tts)==null||delete d.voice_settings)}return o}render(){if(!this.container)return;const r=this.getAttribute("prompt-id")||void 0,n=this.getAttribute("api-key")||void 0,o=this.getAttribute("base-url")||void 0,a=this.getAttribute("tenant")||void 0,i=this.getAttribute("theme"),s=i==="light"||i==="dark"?i:void 0,l=this.getAttribute("high-contrast")==="true",c=this.hasAttribute("bubbleless"),u=c?this.getAttribute("bubbleless"):null,d=c?u===null||u===""||u==="true":void 0,m=this.hasAttribute("remote-config"),p=m?this.getAttribute("remote-config"):null,h=m?p===null||p===""||p==="true":!1,g=this.getAttribute("config");let w;if(g)try{w=JSON.parse(g)}catch(z){console.warn("Failed to parse chat-component config attribute:",z)}h?this.loadRemoteConfig(r,o):(this.remoteConfigStatus="idle",this.remoteConfig=null,this.remoteConfigKey=void 0);const b={...w,promptId:(w==null?void 0:w.promptId)??r,apiKey:(w==null?void 0:w.apiKey)??n,baseUrl:(w==null?void 0:w.baseUrl)??o,tenant:(w==null?void 0:w.tenant)??a,theme:(w==null?void 0:w.theme)??s,highContrast:(w==null?void 0:w.highContrast)??l};let A;if(h&&this.remoteConfig){const z=Yn(this.remoteConfig);A=Tm(z,b)}else A=Yn(b);const S=this.normalizeColorsConfig(A.colors);S&&(A={...A,colors:S}),A.widgetRootDisplay==="inline"?this.container.style.display="inline":this.container.style.removeProperty("display");const C=this.getThemeAwareColors(A.colors);if(this.appliedColorVars.forEach(z=>this.container.style.removeProperty(z)),this.appliedColorVars=[],C.dark)for(const[z,P]of Object.entries(C.dark)){const W=z.startsWith("--")?z:`--${z}`,q=this.applyDefaultGlowAlpha(W,P,.3);this.container.style.setProperty(W,q),this.appliedColorVars.push(W)}this.colorOverrideStyle&&(this.colorOverrideStyle.textContent=this.buildColorOverrideCss(C));const M=h&&this.remoteConfigStatus!=="loaded"?!0:d;this.root||(this.root=Fa(this.container)),this.root.render(f.jsx(V.StrictMode,{children:f.jsx($z,{config:A,bubbleless:M,registerOpenHandler:z=>{this.openChatHandler=z}})}))}openChat(){this.openChatHandler&&this.openChatHandler()}}customElements.get("chat-component")||customElements.define("chat-component",nC)})(React,ReactDOM);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "feazy-neo-chat-component",
3
- "version": "0.1.70",
3
+ "version": "0.1.73",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "dist/chat-component.cjs.js",