@aitronos/freddy-plugins 0.4.26 → 0.4.28
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 +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/web-components.iife.js +1 -1
- package/dist/web-components.iife.js.map +1 -1
- package/dist/web-components.js +1 -1
- package/dist/web-components.js.map +1 -1
- package/package.json +2 -2
- package/CHANGELOG.md +0 -208
|
@@ -40,7 +40,7 @@ const buttonText = ref('Click me')
|
|
|
40
40
|
|
|
41
41
|
const handleClick = () => {
|
|
42
42
|
}
|
|
43
|
-
<\/script>`,IT=x(t.defineComponent({__name:"ChatInterface",props:{placeholder:{default:"Type your message...",type:String},messages:{default:void 0,type:Array},size:{default:"md",type:String},apiKey:{default:void 0,type:String},apiBaseUrl:{default:"/freddy-api",type:String},organizationId:{default:void 0,type:String},fileSearch:{type:Boolean,default:!1},webSearch:{type:Boolean,default:!1},debugMode:{type:Boolean,default:!1},welcomeTitle:{default:"Start a conversation",type:String},welcomeText:{default:"Type a message below to begin chatting with your AI assistant.",type:String},welcomeIcon:{default:"💬",type:String}},emits:["send","sendWithContext"],setup(r,{emit:e}){const n=r,o=e,a=t.ref(""),i=t.ref(null),l=t.ref(null),s=t.ref(!1),c=t.computed(()=>n.welcomeIcon?n.welcomeIcon.startsWith("http")||n.welcomeIcon.startsWith("/")||n.welcomeIcon.includes(".")||n.welcomeIcon.startsWith("data:"):!1),d=t.computed(()=>n.welcomeIcon?n.welcomeIcon.startsWith("Icon"):!1),u=()=>{s.value=!0},p=()=>[{id:"assistant-1",name:"General Assistant",description:"A helpful general-purpose assistant",default:!0},{id:"assistant-2",name:"Code Assistant",description:"Specialized in programming and development"},{id:"assistant-3",name:"Writing Assistant",description:"Focused on writing and content creation"}],m=()=>[{id:"gpt-4",name:"GPT-4",description:"Most capable model",owned_by:"openai"},{id:"gpt-4-turbo",name:"GPT-4 Turbo",description:"Faster and more efficient",owned_by:"openai"},{id:"gpt-3.5-turbo",name:"GPT-3.5 Turbo",description:"Fast and cost-effective",owned_by:"openai"}],g=t.ref([]),_=t.ref([]),b=t.ref(!1),f=t.ref(!1),T=t.ref(null),E=t.ref(null),S=t.computed(()=>n.debugMode),C=t.ref("None"),R=t.ref(!1),h=t.ref({requestSent:0,apiResponseReceived:0,firstStreamObject:0,ourStreamStart:0,apiStreamEnd:0,ourStreamEnd:0}),v=t.ref(new Os({apiKey:n.apiKey,baseUrl:n.apiBaseUrl}));t.watch([()=>n.apiKey,()=>n.apiBaseUrl],([M,L])=>{v.value=new Os({apiKey:M,baseUrl:L})},{immediate:!1});const A=async()=>{var M,L;if(!n.apiKey){g.value=p(),b.value=!1;return}b.value=!0,T.value=null;try{const U={"api-key":n.apiKey,"Content-Type":"application/json",accept:"application/json"},V=`${n.apiBaseUrl}/v1/organizations/${n.organizationId}/assistants`,_e=new AbortController,fe=setTimeout(()=>_e.abort(),1e4),ie=await fetch(V,{method:"GET",headers:U,mode:"cors",signal:_e.signal});if(clearTimeout(fe),!ie.ok)throw new Error(`Failed to fetch assistants: ${ie.status} ${ie.statusText}`);const oe=await ie.json(),re=Array.isArray(oe)?oe:oe.data||[];g.value=re.map(q=>({id:q.id.toString(),name:q.name||`Assistant ${q.id}`,description:q.description||"",default:q.isDefault||!1})),g.value.length>0&&!g.value.some(q=>q.default)&&(g.value[0].default=!0)}catch(U){const V=U instanceof Error?U.message:"Failed to fetch assistants";T.value=V,U.name!=="AbortError"&&(V.includes("CORS")||V.includes("Access-Control-Allow-Origin")?(M=l.value)==null||M.showErrorBanner("CORS Error: Cannot connect to Freddy API from localhost. Try using the production build or configure CORS."):(L=l.value)==null||L.showErrorBanner(`API Error: ${V}`)),g.value=[]}finally{b.value=!1}},N=async()=>{var M,L;if(!n.apiKey){_.value=m(),f.value=!1;return}f.value=!0,T.value=null;try{const U={"api-key":n.apiKey,"Content-Type":"application/json",accept:"application/json"},V=`${n.apiBaseUrl}/v1/organizations/${n.organizationId}/models`,_e=new AbortController,fe=setTimeout(()=>_e.abort(),1e4),ie=await fetch(V,{method:"GET",headers:U,mode:"cors",signal:_e.signal});if(clearTimeout(fe),!ie.ok)throw new Error(`Failed to fetch models: ${ie.status} ${ie.statusText}`);const oe=await ie.json(),q=(Array.isArray(oe)?oe:oe.data||[]).map(G=>({id:G.id.toString(),name:G.title||G.name||`Model ${G.id}`,description:G.description||"",owned_by:G.owned_by||"freddy",default:!1}));q.length>0&&(q[0].default=!0),_.value=q}catch(U){const V=U instanceof Error?U.message:"Failed to fetch models";T.value=V,U.name!=="AbortError"&&(V.includes("CORS")||V.includes("Access-Control-Allow-Origin")?(M=l.value)==null||M.showErrorBanner("CORS Error: Cannot connect to Freddy API from localhost. Try using the production build or configure CORS."):(L=l.value)==null||L.showErrorBanner(`API Error: ${V}`)),_.value=[]}finally{f.value=!1}},w=async()=>{if(!n.apiKey)return Promise.resolve();try{const M=new AbortController,L=setTimeout(()=>M.abort(),5e3),U=await fetch(`${n.apiBaseUrl}/v1/organizations/${n.organizationId}/models`,{method:"GET",headers:{"api-key":n.apiKey,"Content-Type":"application/json",accept:"application/json"},mode:"cors",signal:M.signal});if(clearTimeout(L),!U.ok){const V=await U.text()}return U.ok}catch{return!1}},O=async(M,L)=>{var fe,ie,oe,re;if(!n.apiKey||!n.organizationId||!(g.value.find(q=>q.default)||g.value[0]))return;const V=Date.now().toString()+"_assistant",_e={id:V,content:"Thinking...",sender:"assistant",timestamp:new Date,type:"text"};D.value.push(_e),C.value=`➕ ADDED assistant message with ID: ${V} at index: ${D.value.length-1}`,i.value&&Nt(i.value);try{const q={organization_id:n.organizationId,assistant_id:"221",thread_id:(fe=E.value)==null?void 0:fe.toString(),inputs:[{role:"user",texts:[{text:M}],files:[]}],model:"ftg-2.0
|
|
43
|
+
<\/script>`,IT=x(t.defineComponent({__name:"ChatInterface",props:{placeholder:{default:"Type your message...",type:String},messages:{default:void 0,type:Array},size:{default:"md",type:String},apiKey:{default:void 0,type:String},apiBaseUrl:{default:"/freddy-api",type:String},organizationId:{default:void 0,type:String},fileSearch:{type:Boolean,default:!1},webSearch:{type:Boolean,default:!1},debugMode:{type:Boolean,default:!1},welcomeTitle:{default:"Start a conversation",type:String},welcomeText:{default:"Type a message below to begin chatting with your AI assistant.",type:String},welcomeIcon:{default:"💬",type:String}},emits:["send","sendWithContext"],setup(r,{emit:e}){const n=r,o=e,a=t.ref(""),i=t.ref(null),l=t.ref(null),s=t.ref(!1),c=t.computed(()=>n.welcomeIcon?n.welcomeIcon.startsWith("http")||n.welcomeIcon.startsWith("/")||n.welcomeIcon.includes(".")||n.welcomeIcon.startsWith("data:"):!1),d=t.computed(()=>n.welcomeIcon?n.welcomeIcon.startsWith("Icon"):!1),u=()=>{s.value=!0},p=()=>[{id:"assistant-1",name:"General Assistant",description:"A helpful general-purpose assistant",default:!0},{id:"assistant-2",name:"Code Assistant",description:"Specialized in programming and development"},{id:"assistant-3",name:"Writing Assistant",description:"Focused on writing and content creation"}],m=()=>[{id:"gpt-4",name:"GPT-4",description:"Most capable model",owned_by:"openai"},{id:"gpt-4-turbo",name:"GPT-4 Turbo",description:"Faster and more efficient",owned_by:"openai"},{id:"gpt-3.5-turbo",name:"GPT-3.5 Turbo",description:"Fast and cost-effective",owned_by:"openai"}],g=t.ref([]),_=t.ref([]),b=t.ref(!1),f=t.ref(!1),T=t.ref(null),E=t.ref(null),S=t.computed(()=>n.debugMode),C=t.ref("None"),R=t.ref(!1),h=t.ref({requestSent:0,apiResponseReceived:0,firstStreamObject:0,ourStreamStart:0,apiStreamEnd:0,ourStreamEnd:0}),v=t.ref(new Os({apiKey:n.apiKey,baseUrl:n.apiBaseUrl}));t.watch([()=>n.apiKey,()=>n.apiBaseUrl],([M,L])=>{v.value=new Os({apiKey:M,baseUrl:L})},{immediate:!1});const A=async()=>{var M,L;if(!n.apiKey){g.value=p(),b.value=!1;return}b.value=!0,T.value=null;try{const U={"api-key":n.apiKey,"Content-Type":"application/json",accept:"application/json"},V=`${n.apiBaseUrl}/v1/organizations/${n.organizationId}/assistants`,_e=new AbortController,fe=setTimeout(()=>_e.abort(),1e4),ie=await fetch(V,{method:"GET",headers:U,mode:"cors",signal:_e.signal});if(clearTimeout(fe),!ie.ok)throw new Error(`Failed to fetch assistants: ${ie.status} ${ie.statusText}`);const oe=await ie.json(),re=Array.isArray(oe)?oe:oe.data||[];g.value=re.map(q=>({id:q.id.toString(),name:q.name||`Assistant ${q.id}`,description:q.description||"",default:q.isDefault||!1})),g.value.length>0&&!g.value.some(q=>q.default)&&(g.value[0].default=!0)}catch(U){const V=U instanceof Error?U.message:"Failed to fetch assistants";T.value=V,U.name!=="AbortError"&&(V.includes("CORS")||V.includes("Access-Control-Allow-Origin")?(M=l.value)==null||M.showErrorBanner("CORS Error: Cannot connect to Freddy API from localhost. Try using the production build or configure CORS."):(L=l.value)==null||L.showErrorBanner(`API Error: ${V}`)),g.value=[]}finally{b.value=!1}},N=async()=>{var M,L;if(!n.apiKey){_.value=m(),f.value=!1;return}f.value=!0,T.value=null;try{const U={"api-key":n.apiKey,"Content-Type":"application/json",accept:"application/json"},V=`${n.apiBaseUrl}/v1/organizations/${n.organizationId}/models`,_e=new AbortController,fe=setTimeout(()=>_e.abort(),1e4),ie=await fetch(V,{method:"GET",headers:U,mode:"cors",signal:_e.signal});if(clearTimeout(fe),!ie.ok)throw new Error(`Failed to fetch models: ${ie.status} ${ie.statusText}`);const oe=await ie.json(),q=(Array.isArray(oe)?oe:oe.data||[]).map(G=>({id:G.id.toString(),name:G.title||G.name||`Model ${G.id}`,description:G.description||"",owned_by:G.owned_by||"freddy",default:!1}));q.length>0&&(q[0].default=!0),_.value=q}catch(U){const V=U instanceof Error?U.message:"Failed to fetch models";T.value=V,U.name!=="AbortError"&&(V.includes("CORS")||V.includes("Access-Control-Allow-Origin")?(M=l.value)==null||M.showErrorBanner("CORS Error: Cannot connect to Freddy API from localhost. Try using the production build or configure CORS."):(L=l.value)==null||L.showErrorBanner(`API Error: ${V}`)),_.value=[]}finally{f.value=!1}},w=async()=>{if(!n.apiKey)return Promise.resolve();try{const M=new AbortController,L=setTimeout(()=>M.abort(),5e3),U=await fetch(`${n.apiBaseUrl}/v1/organizations/${n.organizationId}/models`,{method:"GET",headers:{"api-key":n.apiKey,"Content-Type":"application/json",accept:"application/json"},mode:"cors",signal:M.signal});if(clearTimeout(L),!U.ok){const V=await U.text()}return U.ok}catch{return!1}},O=async(M,L)=>{var fe,ie,oe,re;if(!n.apiKey||!n.organizationId||!(g.value.find(q=>q.default)||g.value[0]))return;const V=Date.now().toString()+"_assistant",_e={id:V,content:"Thinking...",sender:"assistant",timestamp:new Date,type:"text"};D.value.push(_e),C.value=`➕ ADDED assistant message with ID: ${V} at index: ${D.value.length-1}`,i.value&&Nt(i.value);try{const q={organization_id:n.organizationId,assistant_id:"221",thread_id:(fe=E.value)==null?void 0:fe.toString(),inputs:[{role:"user",texts:[{text:M}],files:[]}],model:"ftg-2.0",tools:{web_search:{is_enabled:typeof n.webSearch=="string"?n.webSearch==="true":n.webSearch},file_search:{is_enabled:typeof n.fileSearch=="string"?n.fileSearch==="true":n.fileSearch}},tool_choice:"auto"};E.value;const G=D.value.findIndex(ne=>ne.id===V);let le="";C.value=`🔍 INDEX LOOKUP: ${V} -> ${G} (total: ${D.value.length})`,R.value=!0,C.value="Starting stream...",h.value={requestSent:0,apiResponseReceived:0,firstStreamObject:0,ourStreamStart:0,apiStreamEnd:0,ourStreamEnd:0};try{h.value.requestSent=Date.now(),C.value=`📤 Request sent at ${h.value.requestSent}`,C.value="🚀 Calling API...";const ne=await fetch(`${n.apiBaseUrl}/v1/model/response`,{method:"POST",headers:{"api-key":n.apiKey,"Content-Type":"application/json",Accept:"text/event-stream"},body:JSON.stringify(q)}),Se=ne.headers.get("content-type");C.value="📡 Starting real-time streaming...",h.value.apiResponseReceived=Date.now(),h.value.firstStreamObject=Date.now(),h.value.ourStreamStart=Date.now();let me="",Ae=0,we="";try{const Q=(ie=ne.body)==null?void 0:ie.getReader(),Me=new TextDecoder;if(Q){for(;;){const{done:ft,value:wt}=await Q.read();if(ft)break;const Et=Me.decode(wt,{stream:!0});we+=Et,C.value=`📥 CHUNK RECEIVED: ${Et.length} bytes (buffer: ${we.length})`;let je=0,St=[],rt=0,Pe=!1;for(let ce=0;ce<we.length;ce++){const Ne=we[ce];if(Ne==='"'&&(ce===0||we[ce-1]!=="\\"||ce>1&&we[ce-2]==="\\")&&(Pe=!Pe),!Pe&&(Ne==="{"?rt++:Ne==="}"&&rt--,rt===0)){const nt=we.slice(je,ce+1);je=ce+1;try{const ot=JSON.parse(nt);St.push(ot)}catch(ot){C.value=`⚠️ JSON PARSE ERROR: ${ot.message}`}}}we=we.slice(je),St.forEach(ce=>{C.value=`📥 REAL-TIME EVENT: ${ce.event} | Response: ${ce.response?ce.response.substring(0,30)+"...":"null"}`,ce.event==="response.output_text.delta"&&ce.response?(Ae++,me+=ce.response,G!==-1&&G<D.value.length&&(D.value[G]={...D.value[G],content:me},C.value=`⚡ REAL-TIME ${Ae}: "${ce.response}" (total: ${me.length} chars)`),i.value&&Nt(i.value)):ce.event==="response.completed"&&(ce.threadId&&(E.value=ce.threadId),ce.response&&G!==-1&&G<D.value.length&&(D.value[G]={...D.value[G],content:ce.response}),C.value=`🏁 REAL-TIME COMPLETE: Thread ${ce.threadId} - ${Ae} deltas processed`,R.value=!1,h.value.apiStreamEnd=Date.now(),h.value.ourStreamEnd=Date.now())})}Q.releaseLock()}}catch(Q){C.value=`❌ STREAMING ERROR: ${Q.message}`}h.value.apiStreamEnd=Date.now(),h.value.ourStreamEnd=Date.now(),R.value=!1;return}catch(ne){throw C.value=`Service failed: ${(ne==null?void 0:ne.message)??"Unknown"} (Status: ${(ne==null?void 0:ne.status)??"N/A"})`,R.value=!1,ne}}catch(q){R.value=!1;const G=D.value.findIndex(le=>le.id===V);G!==-1&&(D.value[G]={...D.value[G],content:"Sorry, I encountered an error while processing your message. Please try again."}),(re=l.value)==null||re.showErrorBanner(`Failed to send message: ${q instanceof Error?q.message:"Unknown error"}`)}},z=new Ge({html:!0,linkify:!1,typographer:!0,breaks:!0,highlight:(M,L)=>{let U=M;if(L&&ip.getLanguage(L))try{U=ip.highlight(M,{language:L}).value}catch{}else U=z.utils.escapeHtml(M);const V=`code-${Math.random().toString(36).substr(2,9)}`;return`<div class="flex overflow-x-auto flex-col rounded-xl w-fit min-w-[50%] max-w-[100%]">
|
|
44
44
|
<div class="flex justify-between items-center p-2.5 bg-slate-900">
|
|
45
45
|
<div class="text-sm text-gray-300">${L||"plaintext"}</div>
|
|
46
46
|
<div class="flex gap-2 items-center cursor-pointer">
|