(function(N,R){typeof exports=="object"&&typeof module<"u"?R(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],R):(N=typeof globalThis<"u"?globalThis:N||self,R(N.ViteButton={},N.React))})(this,function(N,R){"use strict";var q={exports:{}},V={};/** * @license React * react-jsx-runtime.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var oe;function De(){if(oe)return V;oe=1;var A=R,T=Symbol.for("react.element"),O=Symbol.for("react.fragment"),u=Object.prototype.hasOwnProperty,E=A.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,j={key:!0,ref:!0,__self:!0,__source:!0};function S(b,d,v){var m,h={},x=null,p=null;v!==void 0&&(x=""+v),d.key!==void 0&&(x=""+d.key),d.ref!==void 0&&(p=d.ref);for(m in d)u.call(d,m)&&!j.hasOwnProperty(m)&&(h[m]=d[m]);if(b&&b.defaultProps)for(m in d=b.defaultProps,d)h[m]===void 0&&(h[m]=d[m]);return{$$typeof:T,type:b,key:x,ref:p,props:h,_owner:E.current}}return V.Fragment=O,V.jsx=S,V.jsxs=S,V}var L={};/** * @license React * react-jsx-runtime.development.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var se;function Ne(){return se||(se=1,process.env.NODE_ENV!=="production"&&function(){var A=R,T=Symbol.for("react.element"),O=Symbol.for("react.portal"),u=Symbol.for("react.fragment"),E=Symbol.for("react.strict_mode"),j=Symbol.for("react.profiler"),S=Symbol.for("react.provider"),b=Symbol.for("react.context"),d=Symbol.for("react.forward_ref"),v=Symbol.for("react.suspense"),m=Symbol.for("react.suspense_list"),h=Symbol.for("react.memo"),x=Symbol.for("react.lazy"),p=Symbol.for("react.offscreen"),w=Symbol.iterator,P="@@iterator";function H(e){if(e===null||typeof e!="object")return null;var r=w&&e[w]||e[P];return typeof r=="function"?r:null}var D=A.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function g(e){{for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n=1&&f>=0&&a[c]!==y[f];)f--;for(;c>=1&&f>=0;c--,f--)if(a[c]!==y[f]){if(c!==1||f!==1)do if(c--,f--,f<0||a[c]!==y[f]){var _=` `+a[c].replace(" at new "," at ");return e.displayName&&_.includes("")&&(_=_.replace("",e.displayName)),typeof e=="function"&&G.set(e,_),_}while(c>=1&&f>=0);break}}}finally{ee=!1,Z.current=s,$e(),Error.prepareStackTrace=o}var Y=e?e.displayName||e.name:"",Oe=Y?U(Y):"";return typeof e=="function"&&G.set(e,Oe),Oe}function Ge(e,r,t){return ye(e,!1)}function Be(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function B(e,r,t){if(e==null)return"";if(typeof e=="function")return ye(e,Be(e));if(typeof e=="string")return U(e);switch(e){case v:return U("Suspense");case m:return U("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case d:return Ge(e.render);case h:return B(e.type,r,t);case x:{var n=e,o=n._payload,s=n._init;try{return B(s(o),r,t)}catch{}}}return""}var J=Object.prototype.hasOwnProperty,be={},Ee=D.ReactDebugCurrentFrame;function z(e){if(e){var r=e._owner,t=B(e.type,e._source,r?r.type:null);Ee.setExtraStackFrame(t)}else Ee.setExtraStackFrame(null)}function Je(e,r,t,n,o){{var s=Function.call.bind(J);for(var i in e)if(s(e,i)){var a=void 0;try{if(typeof e[i]!="function"){var y=Error((n||"React class")+": "+t+" type `"+i+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[i]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw y.name="Invariant Violation",y}a=e[i](r,i,n,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(c){a=c}a&&!(a instanceof Error)&&(z(o),g("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",n||"React class",t,i,typeof a),z(null)),a instanceof Error&&!(a.message in be)&&(be[a.message]=!0,z(o),g("Failed %s type: %s",t,a.message),z(null))}}}var ze=Array.isArray;function re(e){return ze(e)}function qe(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,t=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t}}function He(e){try{return xe(e),!1}catch{return!0}}function xe(e){return""+e}function _e(e){if(He(e))return g("The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",qe(e)),xe(e)}var $=D.ReactCurrentOwner,Ke={key:!0,ref:!0,__self:!0,__source:!0},Re,we,te;te={};function Xe(e){if(J.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function Ze(e){if(J.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function Qe(e,r){if(typeof e.ref=="string"&&$.current&&r&&$.current.stateNode!==r){var t=k($.current.type);te[t]||(g('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',k($.current.type),e.ref),te[t]=!0)}}function er(e,r){{var t=function(){Re||(Re=!0,g("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}}function rr(e,r){{var t=function(){we||(we=!0,g("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"ref",{get:t,configurable:!0})}}var tr=function(e,r,t,n,o,s,i){var a={$$typeof:T,type:e,key:r,ref:t,props:i,_owner:s};return a._store={},Object.defineProperty(a._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(a,"_self",{configurable:!1,enumerable:!1,writable:!1,value:n}),Object.defineProperty(a,"_source",{configurable:!1,enumerable:!1,writable:!1,value:o}),Object.freeze&&(Object.freeze(a.props),Object.freeze(a)),a};function nr(e,r,t,n,o){{var s,i={},a=null,y=null;t!==void 0&&(_e(t),a=""+t),Ze(r)&&(_e(r.key),a=""+r.key),Xe(r)&&(y=r.ref,Qe(r,o));for(s in r)J.call(r,s)&&!Ke.hasOwnProperty(s)&&(i[s]=r[s]);if(e&&e.defaultProps){var c=e.defaultProps;for(s in c)i[s]===void 0&&(i[s]=c[s])}if(a||y){var f=typeof e=="function"?e.displayName||e.name||"Unknown":e;a&&er(i,f),y&&rr(i,f)}return tr(e,a,y,o,n,$.current,i)}}var ne=D.ReactCurrentOwner,Te=D.ReactDebugCurrentFrame;function W(e){if(e){var r=e._owner,t=B(e.type,e._source,r?r.type:null);Te.setExtraStackFrame(t)}else Te.setExtraStackFrame(null)}var ae;ae=!1;function ie(e){return typeof e=="object"&&e!==null&&e.$$typeof===T}function Se(){{if(ne.current){var e=k(ne.current.type);if(e)return` Check the render method of \``+e+"`."}return""}}function ar(e){{if(e!==void 0){var r=e.fileName.replace(/^.*[\\\/]/,""),t=e.lineNumber;return` Check your code at `+r+":"+t+"."}return""}}var je={};function ir(e){{var r=Se();if(!r){var t=typeof e=="string"?e:e.displayName||e.name;t&&(r=` Check the top-level render call using <`+t+">.")}return r}}function Pe(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=ir(r);if(je[t])return;je[t]=!0;var n="";e&&e._owner&&e._owner!==ne.current&&(n=" It was passed a child from "+k(e._owner.type)+"."),W(e),g('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',t,n),W(null)}}function ke(e,r){{if(typeof e!="object")return;if(re(e))for(var t=0;t",a=" Did you accidentally export a JSX literal instead of a component?"):c=typeof e,g("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",c,a)}var f=nr(e,r,t,o,s);if(f==null)return f;if(i){var _=r.children;if(_!==void 0)if(n)if(re(_)){for(var Y=0;Y<_.length;Y++)ke(_[Y],e);Object.freeze&&Object.freeze(_)}else g("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else ke(_,e)}return e===u?sr(f):or(f),f}}function lr(e,r,t){return Ce(e,r,t,!0)}function ur(e,r,t){return Ce(e,r,t,!1)}var cr=ur,fr=lr;L.Fragment=u,L.jsx=cr,L.jsxs=fr}()),L}process.env.NODE_ENV==="production"?q.exports=De():q.exports=Ne();var l=q.exports;function Ae({question:A="",apiKey:T="",selectedDocs:O="",history:u=[],conversationId:E=null,apiHost:j="",onEvent:S=()=>{console.log("Event triggered, but no handler provided.")}}){let b="default";return O&&(b=O),new Promise((d,v)=>{const m={question:A,api_key:T,embeddings_key:T,active_docs:b,history:JSON.stringify(u),conversation_id:E,model:"default"};fetch(j+"/stream",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(m)}).then(h=>{if(!h.body)throw Error("No response body");const x=h.body.getReader(),p=new TextDecoder("utf-8");let w=0;const P=({done:H,value:D})=>{if(H){console.log(w),d();return}w+=1;const K=p.decode(D).split(` `);for(let F of K){if(F.trim()=="")continue;F.startsWith("data:")&&(F=F.substring(5));const X=new MessageEvent("message",{data:F});S(X)}x.read().then(P).catch(v)};x.read().then(P).catch(v)}).catch(h=>{console.error("Connection failed:",h),v(h)})})}const Fe=({apiHost:A="https://gptcloud.arc53.com",selectDocs:T="default",apiKey:O="docsgpt-public"})=>{const[u,E]=R.useState(()=>typeof window<"u"&&localStorage.getItem("docsGPTChatState")||"init"),[j,S]=R.useState(""),b=R.useRef(null);R.useEffect(()=>{if(b.current){const v=b.current;v.scrollTop=v.scrollHeight}},[j]),R.useEffect(()=>{localStorage.setItem("docsGPTChatState",u)},[u]);const d=v=>{S(""),v.preventDefault(),E("processing"),setTimeout(()=>{E("answer")},800);const h=v.currentTarget[0].value;Ae({question:h,apiKey:O,selectedDocs:T,history:[],conversationId:null,apiHost:A,onEvent:x=>{const p=JSON.parse(x.data);if(p.type==="end")E("answer");else if(p.type==="source"){let w;if(p.metadata&&p.metadata.title){const P=p.metadata.title.split("/");w={title:P[P.length-1],text:p.doc}}else w={title:p.doc,text:p.doc};console.log(w)}else if(p.type==="id")console.log(p.id);else{const w=p.answer;S(P=>P+w)}}})};return l.jsx(l.Fragment,{children:l.jsxs("div",{className:"dark widget-container",children:[l.jsx("div",{onClick:()=>E("init"),className:`${u!=="minimized"?"hidden":""} cursor-pointer`,children:l.jsx("div",{className:"mr-2 mb-2 w-20 h-20 rounded-full overflow-hidden dark:divide-gray-700 border dark:border-gray-700 bg-gradient-to-br from-gray-100/80 via-white to-white dark:from-gray-900/80 dark:via-gray-900 dark:to-gray-900 font-sans shadow backdrop-blur-sm flex items-center justify-center",children:l.jsx("img",{src:"https://d3dg1063dc54p9.cloudfront.net/cute-docsgpt.png",alt:"DocsGPT",className:"cursor-pointer hover:opacity-50 h-14"})})}),l.jsxs("div",{className:` ${u!=="minimized"?"":"hidden"} divide-y dark:divide-gray-700 rounded-md border dark:border-gray-700 bg-gradient-to-br from-gray-100/80 via-white to-white dark:from-gray-900/80 dark:via-gray-900 dark:to-gray-900 font-sans shadow backdrop-blur-sm`,style:{width:"18rem",transform:"translateY(0%) translateZ(0px)"},children:[l.jsxs("div",{children:[l.jsx("img",{src:"https://d3dg1063dc54p9.cloudfront.net/exit.svg",alt:"Exit",className:"cursor-pointer hover:opacity-50 h-2 absolute top-0 right-0 m-2 white-filter",onClick:v=>{v.stopPropagation(),E("minimized")}}),l.jsxs("div",{className:"flex items-center gap-2 p-3",children:[l.jsxs("div",{className:`${u==="init"||u==="processing"||u==="typing"?"":"hidden"} flex-1`,children:[l.jsx("h3",{className:"text-sm font-bold text-gray-700 dark:text-gray-200",children:"Need help with documentation?"}),l.jsx("p",{className:"mt-1 text-xs text-gray-400 dark:text-gray-500",children:"DocsGPT AI assistant will help you with docs"})]}),l.jsx("div",{id:"docsgpt-answer",ref:b,className:`${u!=="answer"?"hidden":""}`,children:l.jsx("p",{className:"mt-1 text-sm text-gray-600 dark:text-white text-left",children:j})})]})]}),l.jsxs("div",{className:"w-full",children:[l.jsx("button",{onClick:()=>E("typing"),className:`flex w-full justify-center px-5 py-3 text-sm text-gray-800 font-bold dark:text-white transition duration-300 hover:bg-gray-100 rounded-b dark:hover:bg-gray-800/70 ${u!=="init"?"hidden":""}`,children:"Ask DocsGPT"}),(u==="typing"||u==="answer")&&l.jsxs("form",{onSubmit:d,className:"relative w-full m-0",style:{opacity:1},children:[l.jsx("input",{type:"text",className:"w-full bg-transparent px-5 py-3 pr-8 text-sm text-gray-700 dark:text-white focus:outline-none",placeholder:"What do you want to do?"}),l.jsx("button",{className:"absolute text-gray-400 dark:text-gray-500 text-sm inset-y-0 right-2 -mx-2 px-2",type:"submit",children:"Submit"})]}),l.jsxs("p",{className:`${u!=="processing"?"hidden":""} flex w-full justify-center px-5 py-3 text-sm text-gray-800 font-bold dark:text-white transition duration-300 rounded-b`,children:["Processing",l.jsx("span",{className:"dot-animation",children:"."}),l.jsx("span",{className:"dot-animation delay-200",children:"."}),l.jsx("span",{className:"dot-animation delay-400",children:"."})]})]})]})]})})};N.DocsGPTWidget=Fe,Object.defineProperty(N,Symbol.toStringTag,{value:"Module"})}); //# sourceMappingURL=index.umd.js.map