@aitronos/freddy-plugins 0.4.26 → 0.4.27

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 CHANGED
@@ -73,7 +73,7 @@ const buttonText = ref('Click me')
73
73
 
74
74
  const handleClick = () => {
75
75
  }
76
- <\/script>`,E9=t.defineComponent({__name:"ChatInterface",props:{placeholder:{default:"Type your message..."},messages:{default:void 0},size:{default:"md"},apiKey:{default:void 0},apiBaseUrl:{default:"/freddy-api"},organizationId:{default:void 0},fileSearch:{type:Boolean,default:!1},webSearch:{type:Boolean,default:!1},debugMode:{type:Boolean,default:!1},welcomeTitle:{default:"Start a conversation"},welcomeText:{default:"Type a message below to begin chatting with your AI assistant."},welcomeIcon:{default:"💬"}},emits:["send","sendWithContext"],setup(n,{emit:e}){const r=n,o=e,a=t.ref(""),i=t.ref(null),l=t.ref(null),s=t.ref(!1),c=t.computed(()=>r.welcomeIcon?r.welcomeIcon.startsWith("http")||r.welcomeIcon.startsWith("/")||r.welcomeIcon.includes(".")||r.welcomeIcon.startsWith("data:"):!1),u=t.computed(()=>r.welcomeIcon?r.welcomeIcon.startsWith("Icon"):!1),d=()=>{s.value=!0},_=()=>[{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([]),p=t.ref([]),f=t.ref(!1),E=t.ref(!1),T=t.ref(null),S=t.ref(null),b=t.computed(()=>r.debugMode),C=t.ref("None"),N=t.ref(!1),h=t.ref({requestSent:0,apiResponseReceived:0,firstStreamObject:0,ourStreamStart:0,apiStreamEnd:0,ourStreamEnd:0}),R=t.ref(new Hs({apiKey:r.apiKey,baseUrl:r.apiBaseUrl}));t.watch([()=>r.apiKey,()=>r.apiBaseUrl],([M,L])=>{R.value=new Hs({apiKey:M,baseUrl:L})},{immediate:!1});const v=async()=>{var M,L;if(!r.apiKey){g.value=_(),f.value=!1;return}f.value=!0,T.value=null;try{const U={"api-key":r.apiKey,"Content-Type":"application/json",accept:"application/json"},V=`${r.apiBaseUrl}/v1/organizations/${r.organizationId}/assistants`,de=new AbortController,ge=setTimeout(()=>de.abort(),1e4),ie=await fetch(V,{method:"GET",headers:U,mode:"cors",signal:de.signal});if(clearTimeout(ge),!ie.ok)throw new Error(`Failed to fetch assistants: ${ie.status} ${ie.statusText}`);const oe=await ie.json(),ne=Array.isArray(oe)?oe:oe.data||[];g.value=ne.map(z=>({id:z.id.toString(),name:z.name||`Assistant ${z.id}`,description:z.description||"",default:z.isDefault||!1})),g.value.length>0&&!g.value.some(z=>z.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{f.value=!1}},y=async()=>{var M,L;if(!r.apiKey){p.value=m(),E.value=!1;return}E.value=!0,T.value=null;try{const U={"api-key":r.apiKey,"Content-Type":"application/json",accept:"application/json"},V=`${r.apiBaseUrl}/v1/organizations/${r.organizationId}/models`,de=new AbortController,ge=setTimeout(()=>de.abort(),1e4),ie=await fetch(V,{method:"GET",headers:U,mode:"cors",signal:de.signal});if(clearTimeout(ge),!ie.ok)throw new Error(`Failed to fetch models: ${ie.status} ${ie.statusText}`);const oe=await ie.json(),z=(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}));z.length>0&&(z[0].default=!0),p.value=z}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}`)),p.value=[]}finally{E.value=!1}},w=async()=>{if(!r.apiKey)return Promise.resolve();try{const M=new AbortController,L=setTimeout(()=>M.abort(),5e3),U=await fetch(`${r.apiBaseUrl}/v1/organizations/${r.organizationId}/models`,{method:"GET",headers:{"api-key":r.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 ge,ie,oe,ne;if(!r.apiKey||!r.organizationId||!(g.value.find(z=>z.default)||g.value[0]))return;const V=Date.now().toString()+"_assistant",de={id:V,content:"Thinking...",sender:"assistant",timestamp:new Date,type:"text"};x.value.push(de),C.value=`➕ ADDED assistant message with ID: ${V} at index: ${x.value.length-1}`,i.value&&Rt(i.value);try{const z={organization_id:r.organizationId,assistant_id:"221",thread_id:(ge=S.value)==null?void 0:ge.toString(),inputs:[{role:"user",texts:[{text:M}],files:[]}],model:"ftg-2.0-mini",tools:{web_search:{is_enabled:typeof r.webSearch=="string"?r.webSearch==="true":r.webSearch},file_search:{is_enabled:typeof r.fileSearch=="string"?r.fileSearch==="true":r.fileSearch}},tool_choice:"auto"};S.value;const G=x.value.findIndex(re=>re.id===V);let se="";C.value=`🔍 INDEX LOOKUP: ${V} -> ${G} (total: ${x.value.length})`,N.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 re=await fetch(`${r.apiBaseUrl}/v1/model/response`,{method:"POST",headers:{"api-key":r.apiKey,"Content-Type":"application/json",Accept:"text/event-stream"},body:JSON.stringify(z)}),Se=re.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 _e="",ve=0,Ie="";try{const Q=(ie=re.body)==null?void 0:ie.getReader(),we=new TextDecoder;if(Q){for(;;){const{done:lt,value:ht}=await Q.read();if(lt)break;const ct=we.decode(ht,{stream:!0});Ie+=ct,C.value=`📥 CHUNK RECEIVED: ${ct.length} bytes (buffer: ${Ie.length})`;let We=0,St=[],Je=0,Me=!1;for(let le=0;le<Ie.length;le++){const ye=Ie[le];if(ye==='"'&&(le===0||Ie[le-1]!=="\\"||le>1&&Ie[le-2]==="\\")&&(Me=!Me),!Me&&(ye==="{"?Je++:ye==="}"&&Je--,Je===0)){const et=Ie.slice(We,le+1);We=le+1;try{const tt=JSON.parse(et);St.push(tt)}catch(tt){C.value=`⚠️ JSON PARSE ERROR: ${tt.message}`}}}Ie=Ie.slice(We),St.forEach(le=>{C.value=`📥 REAL-TIME EVENT: ${le.event} | Response: ${le.response?le.response.substring(0,30)+"...":"null"}`,le.event==="response.output_text.delta"&&le.response?(ve++,_e+=le.response,G!==-1&&G<x.value.length&&(x.value[G]={...x.value[G],content:_e},C.value=`⚡ REAL-TIME ${ve}: "${le.response}" (total: ${_e.length} chars)`),i.value&&Rt(i.value)):le.event==="response.completed"&&(le.threadId&&(S.value=le.threadId),le.response&&G!==-1&&G<x.value.length&&(x.value[G]={...x.value[G],content:le.response}),C.value=`🏁 REAL-TIME COMPLETE: Thread ${le.threadId} - ${ve} deltas processed`,N.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(),N.value=!1;return}catch(re){throw C.value=`Service failed: ${(re==null?void 0:re.message)??"Unknown"} (Status: ${(re==null?void 0:re.status)??"N/A"})`,N.value=!1,re}}catch(z){N.value=!1;const G=x.value.findIndex(se=>se.id===V);G!==-1&&(x.value[G]={...x.value[G],content:"Sorry, I encountered an error while processing your message. Please try again."}),(ne=l.value)==null||ne.showErrorBanner(`Failed to send message: ${z instanceof Error?z.message:"Unknown error"}`)}},H=new He({html:!0,linkify:!1,typographer:!0,breaks:!0,highlight:(M,L)=>{let U=M;if(L&&Gd.getLanguage(L))try{U=Gd.highlight(M,{language:L}).value}catch{}else U=H.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%]">
76
+ <\/script>`,E9=t.defineComponent({__name:"ChatInterface",props:{placeholder:{default:"Type your message..."},messages:{default:void 0},size:{default:"md"},apiKey:{default:void 0},apiBaseUrl:{default:"/freddy-api"},organizationId:{default:void 0},fileSearch:{type:Boolean,default:!1},webSearch:{type:Boolean,default:!1},debugMode:{type:Boolean,default:!1},welcomeTitle:{default:"Start a conversation"},welcomeText:{default:"Type a message below to begin chatting with your AI assistant."},welcomeIcon:{default:"💬"}},emits:["send","sendWithContext"],setup(n,{emit:e}){const r=n,o=e,a=t.ref(""),i=t.ref(null),l=t.ref(null),s=t.ref(!1),c=t.computed(()=>r.welcomeIcon?r.welcomeIcon.startsWith("http")||r.welcomeIcon.startsWith("/")||r.welcomeIcon.includes(".")||r.welcomeIcon.startsWith("data:"):!1),u=t.computed(()=>r.welcomeIcon?r.welcomeIcon.startsWith("Icon"):!1),d=()=>{s.value=!0},_=()=>[{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([]),p=t.ref([]),f=t.ref(!1),E=t.ref(!1),T=t.ref(null),S=t.ref(null),b=t.computed(()=>r.debugMode),C=t.ref("None"),N=t.ref(!1),h=t.ref({requestSent:0,apiResponseReceived:0,firstStreamObject:0,ourStreamStart:0,apiStreamEnd:0,ourStreamEnd:0}),R=t.ref(new Hs({apiKey:r.apiKey,baseUrl:r.apiBaseUrl}));t.watch([()=>r.apiKey,()=>r.apiBaseUrl],([M,L])=>{R.value=new Hs({apiKey:M,baseUrl:L})},{immediate:!1});const v=async()=>{var M,L;if(!r.apiKey){g.value=_(),f.value=!1;return}f.value=!0,T.value=null;try{const U={"api-key":r.apiKey,"Content-Type":"application/json",accept:"application/json"},V=`${r.apiBaseUrl}/v1/organizations/${r.organizationId}/assistants`,de=new AbortController,ge=setTimeout(()=>de.abort(),1e4),ie=await fetch(V,{method:"GET",headers:U,mode:"cors",signal:de.signal});if(clearTimeout(ge),!ie.ok)throw new Error(`Failed to fetch assistants: ${ie.status} ${ie.statusText}`);const oe=await ie.json(),ne=Array.isArray(oe)?oe:oe.data||[];g.value=ne.map(z=>({id:z.id.toString(),name:z.name||`Assistant ${z.id}`,description:z.description||"",default:z.isDefault||!1})),g.value.length>0&&!g.value.some(z=>z.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{f.value=!1}},y=async()=>{var M,L;if(!r.apiKey){p.value=m(),E.value=!1;return}E.value=!0,T.value=null;try{const U={"api-key":r.apiKey,"Content-Type":"application/json",accept:"application/json"},V=`${r.apiBaseUrl}/v1/organizations/${r.organizationId}/models`,de=new AbortController,ge=setTimeout(()=>de.abort(),1e4),ie=await fetch(V,{method:"GET",headers:U,mode:"cors",signal:de.signal});if(clearTimeout(ge),!ie.ok)throw new Error(`Failed to fetch models: ${ie.status} ${ie.statusText}`);const oe=await ie.json(),z=(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}));z.length>0&&(z[0].default=!0),p.value=z}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}`)),p.value=[]}finally{E.value=!1}},w=async()=>{if(!r.apiKey)return Promise.resolve();try{const M=new AbortController,L=setTimeout(()=>M.abort(),5e3),U=await fetch(`${r.apiBaseUrl}/v1/organizations/${r.organizationId}/models`,{method:"GET",headers:{"api-key":r.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 ge,ie,oe,ne;if(!r.apiKey||!r.organizationId||!(g.value.find(z=>z.default)||g.value[0]))return;const V=Date.now().toString()+"_assistant",de={id:V,content:"Thinking...",sender:"assistant",timestamp:new Date,type:"text"};x.value.push(de),C.value=`➕ ADDED assistant message with ID: ${V} at index: ${x.value.length-1}`,i.value&&Rt(i.value);try{const z={organization_id:r.organizationId,assistant_id:"221",thread_id:(ge=S.value)==null?void 0:ge.toString(),inputs:[{role:"user",texts:[{text:M}],files:[]}],model:"ftg-2.0",tools:{web_search:{is_enabled:typeof r.webSearch=="string"?r.webSearch==="true":r.webSearch},file_search:{is_enabled:typeof r.fileSearch=="string"?r.fileSearch==="true":r.fileSearch}},tool_choice:"auto"};S.value;const G=x.value.findIndex(re=>re.id===V);let se="";C.value=`🔍 INDEX LOOKUP: ${V} -> ${G} (total: ${x.value.length})`,N.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 re=await fetch(`${r.apiBaseUrl}/v1/model/response`,{method:"POST",headers:{"api-key":r.apiKey,"Content-Type":"application/json",Accept:"text/event-stream"},body:JSON.stringify(z)}),Se=re.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 _e="",ve=0,Ie="";try{const Q=(ie=re.body)==null?void 0:ie.getReader(),we=new TextDecoder;if(Q){for(;;){const{done:lt,value:ht}=await Q.read();if(lt)break;const ct=we.decode(ht,{stream:!0});Ie+=ct,C.value=`📥 CHUNK RECEIVED: ${ct.length} bytes (buffer: ${Ie.length})`;let We=0,St=[],Je=0,Me=!1;for(let le=0;le<Ie.length;le++){const ye=Ie[le];if(ye==='"'&&(le===0||Ie[le-1]!=="\\"||le>1&&Ie[le-2]==="\\")&&(Me=!Me),!Me&&(ye==="{"?Je++:ye==="}"&&Je--,Je===0)){const et=Ie.slice(We,le+1);We=le+1;try{const tt=JSON.parse(et);St.push(tt)}catch(tt){C.value=`⚠️ JSON PARSE ERROR: ${tt.message}`}}}Ie=Ie.slice(We),St.forEach(le=>{C.value=`📥 REAL-TIME EVENT: ${le.event} | Response: ${le.response?le.response.substring(0,30)+"...":"null"}`,le.event==="response.output_text.delta"&&le.response?(ve++,_e+=le.response,G!==-1&&G<x.value.length&&(x.value[G]={...x.value[G],content:_e},C.value=`⚡ REAL-TIME ${ve}: "${le.response}" (total: ${_e.length} chars)`),i.value&&Rt(i.value)):le.event==="response.completed"&&(le.threadId&&(S.value=le.threadId),le.response&&G!==-1&&G<x.value.length&&(x.value[G]={...x.value[G],content:le.response}),C.value=`🏁 REAL-TIME COMPLETE: Thread ${le.threadId} - ${ve} deltas processed`,N.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(),N.value=!1;return}catch(re){throw C.value=`Service failed: ${(re==null?void 0:re.message)??"Unknown"} (Status: ${(re==null?void 0:re.status)??"N/A"})`,N.value=!1,re}}catch(z){N.value=!1;const G=x.value.findIndex(se=>se.id===V);G!==-1&&(x.value[G]={...x.value[G],content:"Sorry, I encountered an error while processing your message. Please try again."}),(ne=l.value)==null||ne.showErrorBanner(`Failed to send message: ${z instanceof Error?z.message:"Unknown error"}`)}},H=new He({html:!0,linkify:!1,typographer:!0,breaks:!0,highlight:(M,L)=>{let U=M;if(L&&Gd.getLanguage(L))try{U=Gd.highlight(M,{language:L}).value}catch{}else U=H.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%]">
77
77
  <div class="flex justify-between items-center p-2.5 bg-slate-900">
78
78
  <div class="text-sm text-gray-300">${L||"plaintext"}</div>
79
79
  <div class="flex gap-2 items-center cursor-pointer">