Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@nlux/react

Package Overview
Dependencies
Maintainers
1
Versions
142
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nlux/react - npm Package Compare versions

Comparing version 0.10.3 to 0.10.4

2

cjs/nlux-react.js

@@ -1,1 +0,1 @@

"use strict";var e=require("@nlux/core"),t=require("react"),r=require("react-dom");const n=e=>new Promise((t=>{const n=document.createElement("div");r.render(e,n,(()=>{if(1!==n.children.length||!n.firstElementChild)throw new Error("Expected exactly one child");t(n.firstElementChild)}))})),o=async e=>{const[t,r]=await Promise.all([(async()=>{if(!e.bot)return;const t="string"==typeof e.bot.picture?e.bot.picture:await n(e.bot.picture);return{name:e.bot.name,tagline:e.bot.tagline,picture:t}})(),(async()=>{if(!e.user)return;const t="string"==typeof e.user.picture?e.user.picture:await n(e.user.picture);return{name:e.user.name,picture:t}})()]);return{bot:t,user:r}},i=(e,t)=>{if(void 0===e&&void 0===t)return;if(void 0!==e&&void 0===t){const t={},r=Object.keys(e);for(const e of r)t[e]=void 0;return t}if(void 0===e&&void 0!==t)return t;if(!t||!e)return;let r=!1;const n={},o=Object.keys(t);for(const i of o)e[i]!==t[i]&&(n[i]=t[i],r=!0);return r?n:void 0},a=async(t,r)=>{const n=i(t.events,r.events),a=i(t.layoutOptions,r.layoutOptions),s=i(t.conversationOptions,r.conversationOptions),u=i(t.promptBoxOptions,r.promptBoxOptions),c=await(async(e,t)=>{const r={};if((void 0!==e||void 0!==t)&&(e?.bot!==t?.bot&&(r.bot=void 0===t?.bot?void 0:(await o({bot:t.bot})).bot),e?.user!==t?.user&&(r.user=void 0===t?.user?void 0:(await o({user:t.user})).user),0!==Object.keys(r).length))return r})(t.personaOptions,r.personaOptions),p={};void 0!==n&&(p.events=n??{}),void 0!==a&&(p.layoutOptions=a??{}),void 0!==s&&(p.conversationOptions=s??{}),void 0!==u&&(p.promptBoxOptions=u??{}),void 0!==c&&(p.personaOptions=c??{});const d=t.adapter!==r.adapter?r.adapter:void 0;if(void 0!==d){const t=(t=>{let r="unknown";const n=t;if("function"==typeof n?.create)r="builder";else if("function"==typeof n?.fetchText||"function"==typeof n?.streamText)return r="instance",t;if("unknown"!==r){if("builder"===r){const t=n.create();return"function"==typeof t?.fetchText||"function"==typeof t?.streamText?t:void e.warn("The adapter builder did not return a valid adapter.")}return t}e.warn("Unable to determine the type of the adapter.")})(d);t?p.adapter=t:e.warn({message:"Invalid new adapter property provided! The adapter must be an instance of Adapter or AdapterBuilder.",type:"invalid-adapter"})}t.className!==r.className&&(p.className=r.className),t.syntaxHighlighter!==r.syntaxHighlighter&&(p.syntaxHighlighter=r.syntaxHighlighter);if(Object.keys(p).length>0)return p};Object.defineProperty(exports,"NluxConfigError",{enumerable:!0,get:function(){return e.NluxConfigError}}),Object.defineProperty(exports,"NluxError",{enumerable:!0,get:function(){return e.NluxError}}),Object.defineProperty(exports,"NluxRenderingError",{enumerable:!0,get:function(){return e.NluxRenderingError}}),Object.defineProperty(exports,"NluxUsageError",{enumerable:!0,get:function(){return e.NluxUsageError}}),Object.defineProperty(exports,"NluxValidationError",{enumerable:!0,get:function(){return e.NluxValidationError}}),Object.defineProperty(exports,"debug",{enumerable:!0,get:function(){return e.debug}}),exports.AiChat=r=>{const n=t.useRef(null),[i,s]=t.useState(null),u=t.useRef(null);return t.useEffect((()=>{if(!n.current)throw new Error("Root element is not defined");let t=!0;const{adapter:i,className:a,syntaxHighlighter:s,layoutOptions:c,conversationOptions:p,promptBoxOptions:d,personaOptions:l,events:f}=r;let h=e.createAiChat().withAdapter(i);if(c&&(h=h.withLayoutOptions(c)),d&&(h=h.withPromptBoxOptions(d)),p&&(h=h.withConversationOptions(p)),a&&(h=h.withClassName(a)),s&&(h=h.withSyntaxHighlighter(s)),f){const e=Object.keys(f);for(const t of e){const e=f[t];e&&h.on(t,e)}}return l?o(l).then((r=>{h=h.withPersonaOptions(r),t&&(n.current?(h.mount(n.current),u.current=h):e.warn("Root element is not defined! AiChat cannot be mounted."))})):(h.mount(n.current),u.current=h),()=>{t=!1,h?.unmount()}}),[]),t.useEffect((()=>{let t=!1;if(i)return u.current&&a(i,r).then((n=>{!t&&n&&(u.current?(u.current.updateProps(n),s(r)):e.warn("AiChat is not defined! Cannot update."))})),()=>{t=!0};s(r)}),[r,i]),t.createElement("div",{ref:n})};
"use strict";var e=require("@nlux/core"),t=require("react"),r=require("react-dom");const n=e=>new Promise((t=>{const n=document.createElement("div");r.render(e,n,(()=>{if(1!==n.children.length||!n.firstElementChild)throw new Error("Expected exactly one child");t(n.firstElementChild)}))})),o=async e=>{const[t,r]=await Promise.all([(async()=>{if(!e.bot)return;const t="string"==typeof e.bot.picture?e.bot.picture:await n(e.bot.picture);return{name:e.bot.name,tagline:e.bot.tagline,picture:t}})(),(async()=>{if(!e.user)return;const t="string"==typeof e.user.picture?e.user.picture:await n(e.user.picture);return{name:e.user.name,picture:t}})()]);return{bot:t,user:r}},i=(e,t)=>{if(void 0===e&&void 0===t)return;if(void 0!==e&&void 0===t){const t={},r=Object.keys(e);for(const e of r)t[e]=void 0;return t}if(void 0===e&&void 0!==t)return t;if(!t||!e)return;let r=!1;const n={},o=Object.keys(t);for(const i of o)e[i]!==t[i]&&(n[i]=t[i],r=!0);return r?n:void 0},s=async(t,r)=>{const n=i(t.events,r.events),s=i(t.layoutOptions,r.layoutOptions),a=i(t.conversationOptions,r.conversationOptions),u=i(t.promptBoxOptions,r.promptBoxOptions),c=await(async(e,t)=>{const r={};if((void 0!==e||void 0!==t)&&(e?.bot!==t?.bot&&(r.bot=void 0===t?.bot?void 0:(await o({bot:t.bot})).bot),e?.user!==t?.user&&(r.user=void 0===t?.user?void 0:(await o({user:t.user})).user),0!==Object.keys(r).length))return r})(t.personaOptions,r.personaOptions),p={};void 0!==n&&(p.events=n??{}),void 0!==s&&(p.layoutOptions=s??{}),void 0!==a&&(p.conversationOptions=a??{}),void 0!==u&&(p.promptBoxOptions=u??{}),void 0!==c&&(p.personaOptions=c??{});const d=t.adapter!==r.adapter?r.adapter:void 0;if(void 0!==d){const t=(t=>{let r="unknown";const n=t;if("function"==typeof n?.create)r="builder";else if("function"==typeof n?.fetchText||"function"==typeof n?.streamText)return r="instance",t;if("unknown"!==r){if("builder"===r){const t=n.create();return"function"==typeof t?.fetchText||"function"==typeof t?.streamText?t:void e.warn("The adapter builder did not return a valid adapter.")}return t}e.warn("Unable to determine the type of the adapter.")})(d);t?p.adapter=t:e.warn({message:"Invalid new adapter property provided! The adapter must be an instance of Adapter or AdapterBuilder.",type:"invalid-adapter"})}t.className!==r.className&&(p.className=r.className),t.syntaxHighlighter!==r.syntaxHighlighter&&(p.syntaxHighlighter=r.syntaxHighlighter);if(Object.keys(p).length>0)return p};Object.defineProperty(exports,"NluxConfigError",{enumerable:!0,get:function(){return e.NluxConfigError}}),Object.defineProperty(exports,"NluxError",{enumerable:!0,get:function(){return e.NluxError}}),Object.defineProperty(exports,"NluxRenderingError",{enumerable:!0,get:function(){return e.NluxRenderingError}}),Object.defineProperty(exports,"NluxUsageError",{enumerable:!0,get:function(){return e.NluxUsageError}}),Object.defineProperty(exports,"NluxValidationError",{enumerable:!0,get:function(){return e.NluxValidationError}}),Object.defineProperty(exports,"debug",{enumerable:!0,get:function(){return e.debug}}),exports.AiChat=r=>{const n=t.useRef(null),[i,a]=t.useState(null),u=t.useRef(null);return t.useEffect((()=>{if(!n.current)throw new Error("Root element is not defined");let t=!0;const{adapter:i,className:s,syntaxHighlighter:a,layoutOptions:c,conversationOptions:p,promptBoxOptions:d,personaOptions:l,events:f,conversationHistory:h}=r;let m=e.createAiChat().withAdapter(i);if(c&&(m=m.withLayoutOptions(c)),d&&(m=m.withPromptBoxOptions(d)),p&&(m=m.withConversationOptions(p)),s&&(m=m.withClassName(s)),a&&(m=m.withSyntaxHighlighter(a)),h&&(m=m.withConversationHistory(h)),f){const e=Object.keys(f);for(const t of e){const e=f[t];e&&m.on(t,e)}}return l?o(l).then((r=>{m=m.withPersonaOptions(r),t&&(n.current?(m.mount(n.current),u.current=m):e.warn("Root element is not defined! AiChat cannot be mounted."))})):(m.mount(n.current),u.current=m),()=>{t=!1,m?.unmount()}}),[]),t.useEffect((()=>{let t=!1;if(i)return u.current&&s(i,r).then((n=>{!t&&n&&(u.current?(u.current.updateProps(n),a(r)):e.warn("AiChat is not defined! Cannot update."))})),()=>{t=!0};a(r)}),[r,i]),t.createElement("div",{ref:n})};

@@ -1,1 +0,1 @@

import{warn as t,createAiChat as e}from"@nlux/core";export{NluxConfigError,NluxError,NluxRenderingError,NluxUsageError,NluxValidationError,debug}from"@nlux/core";import r,{useRef as n,useState as o,useEffect as i}from"react";import{render as s}from"react-dom";const a=t=>new Promise((e=>{const r=document.createElement("div");s(t,r,(()=>{if(1!==r.children.length||!r.firstElementChild)throw new Error("Expected exactly one child");e(r.firstElementChild)}))})),u=async t=>{const[e,r]=await Promise.all([(async()=>{if(!t.bot)return;const e="string"==typeof t.bot.picture?t.bot.picture:await a(t.bot.picture);return{name:t.bot.name,tagline:t.bot.tagline,picture:e}})(),(async()=>{if(!t.user)return;const e="string"==typeof t.user.picture?t.user.picture:await a(t.user.picture);return{name:t.user.name,picture:e}})()]);return{bot:e,user:r}},c=(t,e)=>{if(void 0===t&&void 0===e)return;if(void 0!==t&&void 0===e){const e={},r=Object.keys(t);for(const t of r)e[t]=void 0;return e}if(void 0===t&&void 0!==e)return e;if(!e||!t)return;let r=!1;const n={},o=Object.keys(e);for(const i of o)t[i]!==e[i]&&(n[i]=e[i],r=!0);return r?n:void 0},p=async(e,r)=>{const n=c(e.events,r.events),o=c(e.layoutOptions,r.layoutOptions),i=c(e.conversationOptions,r.conversationOptions),s=c(e.promptBoxOptions,r.promptBoxOptions),a=await(async(t,e)=>{const r={};if((void 0!==t||void 0!==e)&&(t?.bot!==e?.bot&&(r.bot=void 0===e?.bot?void 0:(await u({bot:e.bot})).bot),t?.user!==e?.user&&(r.user=void 0===e?.user?void 0:(await u({user:e.user})).user),0!==Object.keys(r).length))return r})(e.personaOptions,r.personaOptions),p={};void 0!==n&&(p.events=n??{}),void 0!==o&&(p.layoutOptions=o??{}),void 0!==i&&(p.conversationOptions=i??{}),void 0!==s&&(p.promptBoxOptions=s??{}),void 0!==a&&(p.personaOptions=a??{});const d=e.adapter!==r.adapter?r.adapter:void 0;if(void 0!==d){const e=(e=>{let r="unknown";const n=e;if("function"==typeof n?.create)r="builder";else if("function"==typeof n?.fetchText||"function"==typeof n?.streamText)return r="instance",e;if("unknown"!==r){if("builder"===r){const e=n.create();return"function"==typeof e?.fetchText||"function"==typeof e?.streamText?e:void t("The adapter builder did not return a valid adapter.")}return e}t("Unable to determine the type of the adapter.")})(d);e?p.adapter=e:t({message:"Invalid new adapter property provided! The adapter must be an instance of Adapter or AdapterBuilder.",type:"invalid-adapter"})}e.className!==r.className&&(p.className=r.className),e.syntaxHighlighter!==r.syntaxHighlighter&&(p.syntaxHighlighter=r.syntaxHighlighter);if(Object.keys(p).length>0)return p},d=s=>{const a=n(null),[c,d]=o(null),l=n(null);return i((()=>{if(!a.current)throw new Error("Root element is not defined");let r=!0;const{adapter:n,className:o,syntaxHighlighter:i,layoutOptions:c,conversationOptions:p,promptBoxOptions:d,personaOptions:f,events:m}=s;let h=e().withAdapter(n);if(c&&(h=h.withLayoutOptions(c)),d&&(h=h.withPromptBoxOptions(d)),p&&(h=h.withConversationOptions(p)),o&&(h=h.withClassName(o)),i&&(h=h.withSyntaxHighlighter(i)),m){const t=Object.keys(m);for(const e of t){const t=m[e];t&&h.on(e,t)}}return f?u(f).then((e=>{h=h.withPersonaOptions(e),r&&(a.current?(h.mount(a.current),l.current=h):t("Root element is not defined! AiChat cannot be mounted."))})):(h.mount(a.current),l.current=h),()=>{r=!1,h?.unmount()}}),[]),i((()=>{let e=!1;if(c)return l.current&&p(c,s).then((r=>{!e&&r&&(l.current?(l.current.updateProps(r),d(s)):t("AiChat is not defined! Cannot update."))})),()=>{e=!0};d(s)}),[s,c]),r.createElement("div",{ref:a})};export{d as AiChat};
import{warn as t,createAiChat as e}from"@nlux/core";export{NluxConfigError,NluxError,NluxRenderingError,NluxUsageError,NluxValidationError,debug}from"@nlux/core";import o,{useRef as r,useState as n,useEffect as i}from"react";import{render as s}from"react-dom";const a=t=>new Promise((e=>{const o=document.createElement("div");s(t,o,(()=>{if(1!==o.children.length||!o.firstElementChild)throw new Error("Expected exactly one child");e(o.firstElementChild)}))})),u=async t=>{const[e,o]=await Promise.all([(async()=>{if(!t.bot)return;const e="string"==typeof t.bot.picture?t.bot.picture:await a(t.bot.picture);return{name:t.bot.name,tagline:t.bot.tagline,picture:e}})(),(async()=>{if(!t.user)return;const e="string"==typeof t.user.picture?t.user.picture:await a(t.user.picture);return{name:t.user.name,picture:e}})()]);return{bot:e,user:o}},c=(t,e)=>{if(void 0===t&&void 0===e)return;if(void 0!==t&&void 0===e){const e={},o=Object.keys(t);for(const t of o)e[t]=void 0;return e}if(void 0===t&&void 0!==e)return e;if(!e||!t)return;let o=!1;const r={},n=Object.keys(e);for(const i of n)t[i]!==e[i]&&(r[i]=e[i],o=!0);return o?r:void 0},p=async(e,o)=>{const r=c(e.events,o.events),n=c(e.layoutOptions,o.layoutOptions),i=c(e.conversationOptions,o.conversationOptions),s=c(e.promptBoxOptions,o.promptBoxOptions),a=await(async(t,e)=>{const o={};if((void 0!==t||void 0!==e)&&(t?.bot!==e?.bot&&(o.bot=void 0===e?.bot?void 0:(await u({bot:e.bot})).bot),t?.user!==e?.user&&(o.user=void 0===e?.user?void 0:(await u({user:e.user})).user),0!==Object.keys(o).length))return o})(e.personaOptions,o.personaOptions),p={};void 0!==r&&(p.events=r??{}),void 0!==n&&(p.layoutOptions=n??{}),void 0!==i&&(p.conversationOptions=i??{}),void 0!==s&&(p.promptBoxOptions=s??{}),void 0!==a&&(p.personaOptions=a??{});const d=e.adapter!==o.adapter?o.adapter:void 0;if(void 0!==d){const e=(e=>{let o="unknown";const r=e;if("function"==typeof r?.create)o="builder";else if("function"==typeof r?.fetchText||"function"==typeof r?.streamText)return o="instance",e;if("unknown"!==o){if("builder"===o){const e=r.create();return"function"==typeof e?.fetchText||"function"==typeof e?.streamText?e:void t("The adapter builder did not return a valid adapter.")}return e}t("Unable to determine the type of the adapter.")})(d);e?p.adapter=e:t({message:"Invalid new adapter property provided! The adapter must be an instance of Adapter or AdapterBuilder.",type:"invalid-adapter"})}e.className!==o.className&&(p.className=o.className),e.syntaxHighlighter!==o.syntaxHighlighter&&(p.syntaxHighlighter=o.syntaxHighlighter);if(Object.keys(p).length>0)return p},d=s=>{const a=r(null),[c,d]=n(null),l=r(null);return i((()=>{if(!a.current)throw new Error("Root element is not defined");let o=!0;const{adapter:r,className:n,syntaxHighlighter:i,layoutOptions:c,conversationOptions:p,promptBoxOptions:d,personaOptions:f,events:m,conversationHistory:h}=s;let v=e().withAdapter(r);if(c&&(v=v.withLayoutOptions(c)),d&&(v=v.withPromptBoxOptions(d)),p&&(v=v.withConversationOptions(p)),n&&(v=v.withClassName(n)),i&&(v=v.withSyntaxHighlighter(i)),h&&(v=v.withConversationHistory(h)),m){const t=Object.keys(m);for(const e of t){const t=m[e];t&&v.on(e,t)}}return f?u(f).then((e=>{v=v.withPersonaOptions(e),o&&(a.current?(v.mount(a.current),l.current=v):t("Root element is not defined! AiChat cannot be mounted."))})):(v.mount(a.current),l.current=v),()=>{o=!1,v?.unmount()}}),[]),i((()=>{let e=!1;if(c)return l.current&&p(c,s).then((o=>{!e&&o&&(l.current?(l.current.updateProps(o),d(s)):t("AiChat is not defined! Cannot update."))})),()=>{e=!0};d(s)}),[s,c]),o.createElement("div",{ref:a})};export{d as AiChat};

@@ -1,2 +0,2 @@

import { Adapter, AdapterBuilder, EventsMap, HighlighterExtension, ConversationOptions, LayoutOptions, PromptBoxOptions } from '@nlux/core';
import { Adapter, AdapterBuilder, EventsMap, ConversationItem, HighlighterExtension, ConversationOptions, LayoutOptions, PromptBoxOptions } from '@nlux/core';
export { Adapter, AdapterBuilder, ConversationOptions, DataTransferMode, ErrorCallback, ErrorEventDetails, EventCallback, EventName, EventsMap, ExceptionId, HighlighterExtension, LayoutOptions, MessageReceivedCallback, MessageSentCallback, NluxConfigError, NluxError, NluxRenderingError, NluxUsageError, NluxValidationError, PromptBoxOptions, StandardAdapter, StreamingAdapterObserver, debug } from '@nlux/core';

@@ -38,2 +38,8 @@ import React, { JSX } from 'react';

/**
* The initial conversation history to display.
* This property is not reactive, which means that its value is only read once when the
* component is mounted and any subsequent changes to it will be ignored.
*/
conversationHistory?: ConversationItem[];
/**
* The syntax highlighter to use for any source code generated by the LLM

@@ -40,0 +46,0 @@ * and displayed in the conversation.

{
"name": "@nlux/react",
"version": "0.10.3",
"version": "0.10.4",
"description": "NLUX React is a library for building conversational AI interfaces, with support for OpenAI, HuggingFace, and more.",

@@ -57,3 +57,3 @@ "keywords": [

"dependencies": {
"@nlux/core": "0.10.3"
"@nlux/core": "0.10.4"
},

@@ -60,0 +60,0 @@ "peerDependencies": {

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@nlux/core"),require("react"),require("react-dom")):"function"==typeof define&&define.amd?define(["exports","@nlux/core","react","react-dom"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["@nlux/react"]={},e.core,e.React,e.reactDom)}(this,(function(e,t,r,n){"use strict";const o=e=>new Promise((t=>{const r=document.createElement("div");n.render(e,r,(()=>{if(1!==r.children.length||!r.firstElementChild)throw new Error("Expected exactly one child");t(r.firstElementChild)}))})),i=async e=>{const[t,r]=await Promise.all([(async()=>{if(!e.bot)return;const t="string"==typeof e.bot.picture?e.bot.picture:await o(e.bot.picture);return{name:e.bot.name,tagline:e.bot.tagline,picture:t}})(),(async()=>{if(!e.user)return;const t="string"==typeof e.user.picture?e.user.picture:await o(e.user.picture);return{name:e.user.name,picture:t}})()]);return{bot:t,user:r}},a=(e,t)=>{if(void 0===e&&void 0===t)return;if(void 0!==e&&void 0===t){const t={},r=Object.keys(e);for(const e of r)t[e]=void 0;return t}if(void 0===e&&void 0!==t)return t;if(!t||!e)return;let r=!1;const n={},o=Object.keys(t);for(const i of o)e[i]!==t[i]&&(n[i]=t[i],r=!0);return r?n:void 0},s=async(e,r)=>{const n=a(e.events,r.events),o=a(e.layoutOptions,r.layoutOptions),s=a(e.conversationOptions,r.conversationOptions),u=a(e.promptBoxOptions,r.promptBoxOptions),c=await(async(e,t)=>{const r={};if((void 0!==e||void 0!==t)&&(e?.bot!==t?.bot&&(r.bot=void 0===t?.bot?void 0:(await i({bot:t.bot})).bot),e?.user!==t?.user&&(r.user=void 0===t?.user?void 0:(await i({user:t.user})).user),0!==Object.keys(r).length))return r})(e.personaOptions,r.personaOptions),d={};void 0!==n&&(d.events=n??{}),void 0!==o&&(d.layoutOptions=o??{}),void 0!==s&&(d.conversationOptions=s??{}),void 0!==u&&(d.promptBoxOptions=u??{}),void 0!==c&&(d.personaOptions=c??{});const p=e.adapter!==r.adapter?r.adapter:void 0;if(void 0!==p){const e=(e=>{let r="unknown";const n=e;if("function"==typeof n?.create)r="builder";else if("function"==typeof n?.fetchText||"function"==typeof n?.streamText)return r="instance",e;if("unknown"!==r){if("builder"===r){const e=n.create();return"function"==typeof e?.fetchText||"function"==typeof e?.streamText?e:void t.warn("The adapter builder did not return a valid adapter.")}return e}t.warn("Unable to determine the type of the adapter.")})(p);e?d.adapter=e:t.warn({message:"Invalid new adapter property provided! The adapter must be an instance of Adapter or AdapterBuilder.",type:"invalid-adapter"})}e.className!==r.className&&(d.className=r.className),e.syntaxHighlighter!==r.syntaxHighlighter&&(d.syntaxHighlighter=r.syntaxHighlighter);if(Object.keys(d).length>0)return d};Object.defineProperty(e,"NluxConfigError",{enumerable:!0,get:function(){return t.NluxConfigError}}),Object.defineProperty(e,"NluxError",{enumerable:!0,get:function(){return t.NluxError}}),Object.defineProperty(e,"NluxRenderingError",{enumerable:!0,get:function(){return t.NluxRenderingError}}),Object.defineProperty(e,"NluxUsageError",{enumerable:!0,get:function(){return t.NluxUsageError}}),Object.defineProperty(e,"NluxValidationError",{enumerable:!0,get:function(){return t.NluxValidationError}}),Object.defineProperty(e,"debug",{enumerable:!0,get:function(){return t.debug}}),e.AiChat=e=>{const n=r.useRef(null),[o,a]=r.useState(null),u=r.useRef(null);return r.useEffect((()=>{if(!n.current)throw new Error("Root element is not defined");let r=!0;const{adapter:o,className:a,syntaxHighlighter:s,layoutOptions:c,conversationOptions:d,promptBoxOptions:p,personaOptions:l,events:f}=e;let m=t.createAiChat().withAdapter(o);if(c&&(m=m.withLayoutOptions(c)),p&&(m=m.withPromptBoxOptions(p)),d&&(m=m.withConversationOptions(d)),a&&(m=m.withClassName(a)),s&&(m=m.withSyntaxHighlighter(s)),f){const e=Object.keys(f);for(const t of e){const e=f[t];e&&m.on(t,e)}}return l?i(l).then((e=>{m=m.withPersonaOptions(e),r&&(n.current?(m.mount(n.current),u.current=m):t.warn("Root element is not defined! AiChat cannot be mounted."))})):(m.mount(n.current),u.current=m),()=>{r=!1,m?.unmount()}}),[]),r.useEffect((()=>{let r=!1;if(o)return u.current&&s(o,e).then((n=>{!r&&n&&(u.current?(u.current.updateProps(n),a(e)):t.warn("AiChat is not defined! Cannot update."))})),()=>{r=!0};a(e)}),[e,o]),r.createElement("div",{ref:n})}}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@nlux/core"),require("react"),require("react-dom")):"function"==typeof define&&define.amd?define(["exports","@nlux/core","react","react-dom"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["@nlux/react"]={},e.core,e.React,e.reactDom)}(this,(function(e,t,r,n){"use strict";const o=e=>new Promise((t=>{const r=document.createElement("div");n.render(e,r,(()=>{if(1!==r.children.length||!r.firstElementChild)throw new Error("Expected exactly one child");t(r.firstElementChild)}))})),i=async e=>{const[t,r]=await Promise.all([(async()=>{if(!e.bot)return;const t="string"==typeof e.bot.picture?e.bot.picture:await o(e.bot.picture);return{name:e.bot.name,tagline:e.bot.tagline,picture:t}})(),(async()=>{if(!e.user)return;const t="string"==typeof e.user.picture?e.user.picture:await o(e.user.picture);return{name:e.user.name,picture:t}})()]);return{bot:t,user:r}},a=(e,t)=>{if(void 0===e&&void 0===t)return;if(void 0!==e&&void 0===t){const t={},r=Object.keys(e);for(const e of r)t[e]=void 0;return t}if(void 0===e&&void 0!==t)return t;if(!t||!e)return;let r=!1;const n={},o=Object.keys(t);for(const i of o)e[i]!==t[i]&&(n[i]=t[i],r=!0);return r?n:void 0},s=async(e,r)=>{const n=a(e.events,r.events),o=a(e.layoutOptions,r.layoutOptions),s=a(e.conversationOptions,r.conversationOptions),u=a(e.promptBoxOptions,r.promptBoxOptions),c=await(async(e,t)=>{const r={};if((void 0!==e||void 0!==t)&&(e?.bot!==t?.bot&&(r.bot=void 0===t?.bot?void 0:(await i({bot:t.bot})).bot),e?.user!==t?.user&&(r.user=void 0===t?.user?void 0:(await i({user:t.user})).user),0!==Object.keys(r).length))return r})(e.personaOptions,r.personaOptions),d={};void 0!==n&&(d.events=n??{}),void 0!==o&&(d.layoutOptions=o??{}),void 0!==s&&(d.conversationOptions=s??{}),void 0!==u&&(d.promptBoxOptions=u??{}),void 0!==c&&(d.personaOptions=c??{});const p=e.adapter!==r.adapter?r.adapter:void 0;if(void 0!==p){const e=(e=>{let r="unknown";const n=e;if("function"==typeof n?.create)r="builder";else if("function"==typeof n?.fetchText||"function"==typeof n?.streamText)return r="instance",e;if("unknown"!==r){if("builder"===r){const e=n.create();return"function"==typeof e?.fetchText||"function"==typeof e?.streamText?e:void t.warn("The adapter builder did not return a valid adapter.")}return e}t.warn("Unable to determine the type of the adapter.")})(p);e?d.adapter=e:t.warn({message:"Invalid new adapter property provided! The adapter must be an instance of Adapter or AdapterBuilder.",type:"invalid-adapter"})}e.className!==r.className&&(d.className=r.className),e.syntaxHighlighter!==r.syntaxHighlighter&&(d.syntaxHighlighter=r.syntaxHighlighter);if(Object.keys(d).length>0)return d};Object.defineProperty(e,"NluxConfigError",{enumerable:!0,get:function(){return t.NluxConfigError}}),Object.defineProperty(e,"NluxError",{enumerable:!0,get:function(){return t.NluxError}}),Object.defineProperty(e,"NluxRenderingError",{enumerable:!0,get:function(){return t.NluxRenderingError}}),Object.defineProperty(e,"NluxUsageError",{enumerable:!0,get:function(){return t.NluxUsageError}}),Object.defineProperty(e,"NluxValidationError",{enumerable:!0,get:function(){return t.NluxValidationError}}),Object.defineProperty(e,"debug",{enumerable:!0,get:function(){return t.debug}}),e.AiChat=e=>{const n=r.useRef(null),[o,a]=r.useState(null),u=r.useRef(null);return r.useEffect((()=>{if(!n.current)throw new Error("Root element is not defined");let r=!0;const{adapter:o,className:a,syntaxHighlighter:s,layoutOptions:c,conversationOptions:d,promptBoxOptions:p,personaOptions:l,events:f,conversationHistory:h}=e;let m=t.createAiChat().withAdapter(o);if(c&&(m=m.withLayoutOptions(c)),p&&(m=m.withPromptBoxOptions(p)),d&&(m=m.withConversationOptions(d)),a&&(m=m.withClassName(a)),s&&(m=m.withSyntaxHighlighter(s)),h&&(m=m.withConversationHistory(h)),f){const e=Object.keys(f);for(const t of e){const e=f[t];e&&m.on(t,e)}}return l?i(l).then((e=>{m=m.withPersonaOptions(e),r&&(n.current?(m.mount(n.current),u.current=m):t.warn("Root element is not defined! AiChat cannot be mounted."))})):(m.mount(n.current),u.current=m),()=>{r=!1,m?.unmount()}}),[]),r.useEffect((()=>{let r=!1;if(o)return u.current&&s(o,e).then((n=>{!r&&n&&(u.current?(u.current.updateProps(n),a(e)):t.warn("AiChat is not defined! Cannot update."))})),()=>{r=!0};a(e)}),[e,o]),r.createElement("div",{ref:n})}}));
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc