@arcteninc/core 0.0.164 → 0.0.166
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.mjs +1 -2
- package/dist/lib/useGenerate.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -12,5 +12,5 @@
|
|
|
12
12
|
${X?"bg-stone-50 dark:bg-stone-900":"bg-stone-100 dark:bg-stone-800 hover:bg-stone-200 dark:hover:bg-stone-700 transition-colors duration-200"}
|
|
13
13
|
${H?"border border-border":"border-l border-border"}
|
|
14
14
|
${X?"":"w-[30px]"}
|
|
15
|
-
`,style:X?H?{width:`${K}px`,height:Ee?"auto":`${ye}px`,left:`${Ce.x}px`,top:`${Ce.y}px`}:{width:`${K}px`}:void 0,onClick:X?void 0:Gn,children:X?u.jsxs(u.Fragment,{children:[!H&&u.jsx("div",{className:"absolute left-0 top-0 bottom-0 w-1 cursor-col-resize hover:bg-blue-500/40 hover:w-1 transition-all group",onMouseDown:zt,children:u.jsx("div",{className:"absolute left-0 top-0 bottom-0 w-3 -translate-x-1"})}),H&&u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"absolute bottom-0 right-0 w-4 h-4 cursor-nwse-resize",onMouseDown:T=>{T.preventDefault(),tt(!0)}}),u.jsx("div",{className:"absolute bottom-0 left-4 right-4 h-3 cursor-move hover:bg-blue-500/20 group",onMouseDown:T=>{T.preventDefault(),T.stopPropagation(),ae(!0),ct({x:T.clientX-Ce.x,y:T.clientY-Ce.y})},children:u.jsx("div",{className:"absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-8 h-1 rounded-full bg-stone-400/30 group-hover:bg-blue-500/40 transition-colors"})}),u.jsx("div",{className:"absolute top-0 right-0 bottom-0 w-1 cursor-ew-resize hover:bg-blue-500/40",onMouseDown:T=>{T.preventDefault(),tt(!0)}})]}),u.jsxs("div",{className:"flex flex-col h-full",children:[u.jsxs("div",{className:`flex items-center justify-between p-3 border-b border-border ${H?"cursor-move":""}`,onMouseDown:H?Je:void 0,children:[u.jsx("h2",{className:`text-base font-semibold ${H&&Ee?"cursor-pointer":""}`,onClick:H&&Ee?T=>{T.stopPropagation(),Yn()}:void 0,children:r}),u.jsxs("div",{className:"flex items-center gap-1",onClick:T=>T.stopPropagation(),children:[u.jsxs(mt,{children:[u.jsx(pt,{asChild:!0,children:u.jsx("button",{type:"button",className:se(Et({variant:"ghost",size:"icon"}),"h-8 w-8"),onClick:Hn,"aria-label":"New chat",children:u.jsx(te.Plus,{className:"h-4 w-4"})})}),u.jsx(gt,{children:"Start a new conversation"})]}),u.jsxs(mt,{children:[u.jsx(pt,{asChild:!0,children:u.jsx("button",{type:"button",className:se(Et({variant:"ghost",size:"icon"}),"h-8 w-8"),onClick:H?bn:ws,"aria-label":H?"Dock sidebar":"Float sidebar",children:H?u.jsx(te.Dock,{className:"h-4 w-4"}):u.jsx(te.PictureInPicture2,{className:"h-4 w-4"})})}),u.jsx(gt,{children:H?"Dock to sidebar":"Undock to floating window"})]}),u.jsxs(mt,{children:[u.jsx(pt,{asChild:!0,children:u.jsx("button",{type:"button",className:se(Et({variant:"ghost",size:"icon"}),"h-8 w-8"),onClick:H?Yn:it,"aria-label":H?Ee?"Maximize":"Minimize":"Close sidebar",children:H?Ee?u.jsx(te.Maximize2,{className:"h-4 w-4"}):u.jsx(te.Minimize2,{className:"h-4 w-4"}):u.jsx(te.X,{className:"h-4 w-4"})})}),u.jsx(gt,{children:H?Ee?"Maximize window":"Minimize to header":"Close the chat"})]})]})]}),!Ee&&u.jsxs(u.Fragment,{children:[E&&He.length>0&&u.jsxs("div",{className:`border-b border-border ${xe?"flex flex-col flex-1":""}`,children:[u.jsxs("div",{className:"flex items-center justify-between px-3 py-1",children:[u.jsx("h3",{className:"text-xs font-semibold text-muted-foreground",children:"Recent chats"}),u.jsx(je,{variant:"ghost",className:"h-auto px-2 py-1 text-xs text-muted-foreground hover:text-foreground",onClick:()=>{pn(!xe)},children:xe?"Show less":"View all"})]}),u.jsx("div",{className:`px-2 pb-2 space-y-0.5 ${xe?"flex-1 overflow-y-auto":""}`,children:He.slice(0,xe?void 0:3).map(T=>u.jsxs("div",{className:"group relative",children:[u.jsxs(Oh,{type:"button",className:se(Et({variant:"ghost"}),"w-full justify-between h-auto py-1 px-3 font-normal active:scale-[0.99]"),onClick:()=>{Ue(T.chatId||T._id),pn(!1)},children:[u.jsx("span",{className:"text-xs truncate",children:T.title}),u.jsx("div",{className:"ml-2 flex items-center",children:u.jsx("span",{className:"text-xs text-muted-foreground group-hover:hidden",children:Pt(T.updatedAt)})})]}),u.jsx("button",{type:"button",className:"absolute right-2 top-1/2 -translate-y-1/2 h-6 w-6 p-0 hidden group-hover:flex items-center justify-center text-muted-foreground hover:text-foreground rounded-md hover:bg-accent transition-colors",onClick:_=>{_.stopPropagation(),Ye(T._id)},"aria-label":"Delete conversation",children:u.jsx(te.X,{className:"h-3 w-3"})})]},T._id))})]}),u.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden relative",children:[u.jsx("div",{className:"flex-1 overflow-y-auto p-4 space-y-4 scroll-smooth",children:Pe.length===0?u.jsxs("div",{className:"flex flex-col items-center justify-center h-full",children:[o&&u.jsx("div",{className:"mb-6",children:o}),u.jsx("h3",{className:"text-lg font-semibold text-center mb-2",children:"How can I help you?"}),st.length>0&&u.jsx("div",{className:"mt-4 px-4 max-w-md mx-auto",children:u.jsxs("div",{className:"flex flex-wrap gap-2 justify-center",children:[(Bt?st:st.slice(0,10)).map(T=>u.jsxs(mt,{children:[u.jsx(pt,{asChild:!0,children:u.jsx(Cs,{variant:"secondary",className:"cursor-pointer text-xs px-2 py-1 hover:bg-stone-200 dark:hover:bg-stone-700 transition-colors",onClick:()=>{ke(T.sampleUsage),Tt.current?.focus()},children:T.friendlyName})}),u.jsx(gt,{children:u.jsxs("div",{className:"max-w-xs",children:[u.jsx("p",{className:"font-medium",children:T.description}),u.jsxs("p",{className:"text-xs text-muted-foreground mt-2",children:[u.jsx("span",{className:"font-medium",children:"Example:"}),' "',T.sampleUsage,'"']}),T.paramCount>0&&u.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[u.jsx("span",{className:"font-medium",children:"Parameters:"})," ",T.params.join(", ")]})]})})]},T.name)),st.length>10&&!Bt&&u.jsxs(mt,{children:[u.jsx(pt,{asChild:!0,children:u.jsxs(Cs,{variant:"secondary",className:"cursor-pointer text-xs px-2 py-1 hover:bg-stone-200 dark:hover:bg-stone-700 transition-colors",onClick:()=>dt(!0),children:["+",st.length-10," more"]})}),u.jsx(gt,{children:u.jsxs("div",{className:"max-w-xs",children:[u.jsx("p",{className:"font-medium mb-2",children:"Additional tools:"}),u.jsx("div",{className:"space-y-1 max-h-64 overflow-y-auto pr-2",children:st.slice(10).map(T=>u.jsxs("div",{children:[u.jsxs("span",{className:"font-medium text-xs",children:[T.friendlyName,":"]}),u.jsx("span",{className:"text-xs text-muted-foreground ml-1",children:T.description})]},T.name))}),u.jsx("p",{className:"text-xs text-muted-foreground mt-2 italic",children:"Click to show all tools"})]})})]}),Bt&&st.length>10&&u.jsx(Cs,{variant:"secondary",className:"cursor-pointer text-xs px-2 py-1 hover:bg-stone-200 dark:hover:bg-stone-700 transition-colors",onClick:()=>dt(!1),children:"Show less"})]})})]}):u.jsxs(u.Fragment,{children:[Pe.map(T=>{const z=T.parts.filter(W=>W.type==="text").map(W=>W.text).join("");let Z=T.parts;T.role==="assistant"&&T.parts.some(me=>me.timestamp)&&(Z=[...T.parts].sort((me,ne)=>{const Se=me.timestamp||0,de=ne.timestamp||0;return Se-de}));let Y=[],J=new Map,De=[],re,ue=!0;if(T.role==="assistant"){const W=Z.filter(de=>de.type==="text"&&de.text),me=[],ne=[];W.forEach(de=>{const{citations:Ze,citationMap:ve,groupedCitations:g,referencesText:y}=vo(de.text);Y.push(...Ze),me.push(ve),g&&ne.push(...g),y&&(re=y)}),me.forEach(de=>{de.forEach((Ze,ve)=>{J.has(ve)||J.set(ve,Ze)})}),De=Array.from(new Map(ne.map(de=>[de.url,de])).values()).sort((de,Ze)=>(de.numbers[0]||0)-(Ze.numbers[0]||0)),ue=!(Ne==="streaming"&&T.id===Pe.at(-1)?.id)}return u.jsx("div",{className:`${T.role==="user"?"flex justify-end":"w-full"}`,children:u.jsx("div",{className:`${T.role==="user"?"max-w-[85%] text-right":"w-full"}`,children:T.role==="user"?u.jsx($h,{initial:{opacity:0,filter:"blur(4px)"},animate:{opacity:1,filter:"blur(0px)"},transition:{duration:.3,ease:"easeOut"},className:"text-sm whitespace-pre-wrap inline-block bg-stone-100 dark:bg-stone-800 px-3 py-2 rounded-xl",children:z}):u.jsx("div",{className:"space-y-2",children:Z.map((W,me)=>{if(W.type?.startsWith("tool-")){const ne=W.type?.replace("tool-","")||"",Se=Re.find(ve=>ve.name===ne),de=W.state==="input-available",Ze=W.state==="output-available";if(de&&Ke.has(ne),de){if(Ke.has(ne))return null;const ve=zs(W.input);return u.jsx(ts,{initial:{opacity:0,y:10,filter:"blur(4px)"},animate:{opacity:1,y:0,filter:"blur(0px)"},transition:{duration:.3,ease:"easeOut"},children:u.jsx(Lh,{toolName:ne,description:Se?.description||"",args:ve,onApprove:async()=>{if(Lt.has(W.toolCallId))return;nt(y=>new Set(y).add(W.toolCallId));const g=gn.get(ne);if(g)try{const y=await g(...Object.values(ve));rt({toolCallId:W.toolCallId,tool:ne,output:y})}catch(y){rt({toolCallId:W.toolCallId,tool:ne,output:`Error: ${y}`})}},onDeny:async()=>{Lt.has(W.toolCallId)||(nt(g=>new Set(g).add(W.toolCallId)),rt({toolCallId:W.toolCallId,tool:ne,output:"User denied tool execution"}))}})},`${W.toolCallId}-${me}`)}else if(Ze){const ve=W.output==="User denied tool execution",g=zs(W.input);return u.jsx(Fh,{toolName:ne,args:g,isDenied:ve,isSafe:Ke.has(ne)},`${W.toolCallId}-${me}`)}return null}if(W.type==="text"&&W.text&&hn){const{processedText:ne}=vo(W.text),ve=!Z.slice(me+1).some(g=>g.type==="text"&&g.text)&&ue&&J.size>0;return u.jsx(Zh,{text:ne,citations:Y,citationMap:J,groupedCitations:ve?De:void 0,referencesText:ve?re:void 0,ResponseComponent:hn,className:"text-sm prose prose-sm dark:prose-invert max-w-none",showCitations:V,showReferences:ve},`${T.id}-${me}`)}return W.type==="reasoning"&&W.text?u.jsxs(cl,{className:"w-full",isStreaming:Ne==="streaming"&&me===T.parts.length-1&&T.id===Pe.at(-1)?.id,children:[u.jsx(ul,{}),u.jsx(dl,{children:W.text})]},`${T.id}-${me}`):null})})})},T.id)}),u.jsx("div",{ref:Be})]})}),Xn&&u.jsxs("div",{className:"px-4 py-2 bg-destructive/10 text-destructive text-xs",children:["Error: ",Xn.message]}),u.jsxs("div",{className:"p-4 border-t border-border relative overflow-visible",children:[u.jsx(sd,{mode:"wait",children:(Ne==="streaming"||Ne==="submitted")&&u.jsxs(ts,{initial:{opacity:0,filter:"blur(4px)",y:5},animate:{opacity:1,filter:"blur(0px)",y:0},exit:{opacity:0,filter:"blur(4px)",y:5},transition:{duration:.2,ease:"easeOut"},className:"absolute left-1/2 -translate-x-1/2 -top-6 flex items-center gap-1.5 bg-stone-100 dark:bg-stone-800 px-3 py-1.5 rounded-full shadow-lg border border-border z-50",children:[u.jsx(ts,{className:"w-2 h-2 bg-stone-400 dark:bg-stone-600",animate:{rotate:[0,0,90,90],borderRadius:["50%","30%","30%","50%"],scale:[.75,1,1,.75]},transition:{duration:2,repeat:1/0,ease:"easeInOut",times:[0,.4,.6,1]}}),u.jsx("p",{className:"text-xs text-muted-foreground",children:$t})]})}),u.jsxs("form",{onSubmit:xn,className:"relative",children:[u.jsx(Ao,{ref:Tt,value:jt,onChange:ht,placeholder:"Ask anything..",className:"w-full pr-12 resize-none border border-border rounded-xl px-4 py-3",minHeight:24,maxHeight:200,onKeyDown:T=>{T.key==="Enter"&&!T.shiftKey&&(T.preventDefault(),xn(T))}}),Ne==="streaming"||Ne==="submitted"?u.jsxs(mt,{children:[u.jsx(pt,{asChild:!0,children:u.jsx("button",{type:"button",className:se(Et({variant:"ghost",size:"icon"}),"absolute top-1/2 -translate-y-1/2 right-2 h-8 w-8"),onClick:Ut,children:u.jsx(te.Square,{className:"h-4 w-4"})})}),u.jsxs(gt,{children:[u.jsx(ni,{children:"Escape"})," to stop"]})]}):u.jsxs(mt,{children:[u.jsx(pt,{asChild:!0,children:u.jsx("button",{type:"submit",className:se(Et({variant:"ghost",size:"icon"}),"absolute top-1/2 -translate-y-1/2 right-2 h-8 w-8"),disabled:!jt.trim(),children:u.jsx(te.ArrowRight,{className:"h-4 w-4"})})}),u.jsxs(gt,{children:[u.jsx(ni,{children:"Enter"})," to send"]})]})]})]})]}),u.jsxs("a",{href:"https://arcten.com",target:"_blank",rel:"noopener noreferrer",className:"group flex items-center justify-center gap-1.5 py-3 text-xs text-muted-foreground/40 hover:text-muted-foreground/60 transition-all",children:[u.jsx("span",{className:"whitespace-nowrap",children:"Powered by"}),u.jsx("div",{className:"w-4 h-2 bg-current rounded-t-full flex-shrink-0"}),u.jsx("span",{className:"whitespace-nowrap",children:"Arcten"})]})]})]})]}):u.jsxs("div",{className:"flex flex-col items-center justify-center gap-3 h-full cursor-pointer",children:[u.jsx(te.BotMessageSquare,{className:"h-5 w-5 text-stone-600 dark:text-stone-400"}),u.jsx("span",{className:"text-xs font-medium text-stone-600 dark:text-stone-400 [writing-mode:vertical-lr]",children:"AI agent"})]})})}):u.jsx("div",{className:"fixed right-0 top-0 h-screen w-96 flex items-center justify-center p-4 bg-stone-50 dark:bg-stone-900 border-l border-border",children:u.jsx("div",{className:"p-4 text-muted-foreground text-sm",children:"Loading..."})}):null}function cm(e){return u.jsx(ml,{children:u.jsx(lm,{...e})})}function um(e={}){const{apiBaseUrl:t="https://api.arcten.com",tokenEndpoint:n="/token",clientToken:s,skipTokenFetch:r=!1}=e,[o,i]=h.useState(!1),[a,l]=h.useState(null),c=h.useRef(s||null);h.useEffect(()=>{if(s){c.current=s;return}if(r)return;(async()=>{try{const p=await fetch(`${t}${n}`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include"});if(p.ok){const x=await p.json();c.current=x.token}}catch(p){console.error("[useGenerate] Failed to fetch token:",p)}})()},[t,n,s,r]);const d=h.useCallback(async m=>{i(!0),l(null);try{const p={"Content-Type":"application/json"};c.current&&(p.Authorization=`Bearer ${c.current}`);const x=await fetch(`${t}/generate`,{method:"POST",headers:p,body:JSON.stringify(m)});if(!x.ok){const S=await x.json().catch(()=>({}));throw new Error(S.error||`HTTP ${x.status}`)}return await x.json()}catch(p){const x=p instanceof Error?p.message:String(p);throw l(x),p}finally{i(!1)}},[t]),f=h.useCallback(async(m,p)=>{i(!0),l(null);try{const x={"Content-Type":"application/json"};c.current&&(x.Authorization=`Bearer ${c.current}`);const b=await fetch(`${t}/generate/stream`,{method:"POST",headers:x,body:JSON.stringify(m)});if(!b.ok){const E=await b.json().catch(()=>({}));throw new Error(E.error||`HTTP ${b.status}`)}const S=b.body?.getReader();if(!S)throw new Error("No response body");const v=new TextDecoder;let M=null;for(;;){const{done:E,value:L}=await S.read();if(E)break;const O=v.decode(L,{stream:!0}).split(`
|
|
15
|
+
`,style:X?H?{width:`${K}px`,height:Ee?"auto":`${ye}px`,left:`${Ce.x}px`,top:`${Ce.y}px`}:{width:`${K}px`}:void 0,onClick:X?void 0:Gn,children:X?u.jsxs(u.Fragment,{children:[!H&&u.jsx("div",{className:"absolute left-0 top-0 bottom-0 w-1 cursor-col-resize hover:bg-blue-500/40 hover:w-1 transition-all group",onMouseDown:zt,children:u.jsx("div",{className:"absolute left-0 top-0 bottom-0 w-3 -translate-x-1"})}),H&&u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"absolute bottom-0 right-0 w-4 h-4 cursor-nwse-resize",onMouseDown:T=>{T.preventDefault(),tt(!0)}}),u.jsx("div",{className:"absolute bottom-0 left-4 right-4 h-3 cursor-move hover:bg-blue-500/20 group",onMouseDown:T=>{T.preventDefault(),T.stopPropagation(),ae(!0),ct({x:T.clientX-Ce.x,y:T.clientY-Ce.y})},children:u.jsx("div",{className:"absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-8 h-1 rounded-full bg-stone-400/30 group-hover:bg-blue-500/40 transition-colors"})}),u.jsx("div",{className:"absolute top-0 right-0 bottom-0 w-1 cursor-ew-resize hover:bg-blue-500/40",onMouseDown:T=>{T.preventDefault(),tt(!0)}})]}),u.jsxs("div",{className:"flex flex-col h-full",children:[u.jsxs("div",{className:`flex items-center justify-between p-3 border-b border-border ${H?"cursor-move":""}`,onMouseDown:H?Je:void 0,children:[u.jsx("h2",{className:`text-base font-semibold ${H&&Ee?"cursor-pointer":""}`,onClick:H&&Ee?T=>{T.stopPropagation(),Yn()}:void 0,children:r}),u.jsxs("div",{className:"flex items-center gap-1",onClick:T=>T.stopPropagation(),children:[u.jsxs(mt,{children:[u.jsx(pt,{asChild:!0,children:u.jsx("button",{type:"button",className:se(Et({variant:"ghost",size:"icon"}),"h-8 w-8"),onClick:Hn,"aria-label":"New chat",children:u.jsx(te.Plus,{className:"h-4 w-4"})})}),u.jsx(gt,{children:"Start a new conversation"})]}),u.jsxs(mt,{children:[u.jsx(pt,{asChild:!0,children:u.jsx("button",{type:"button",className:se(Et({variant:"ghost",size:"icon"}),"h-8 w-8"),onClick:H?bn:ws,"aria-label":H?"Dock sidebar":"Float sidebar",children:H?u.jsx(te.Dock,{className:"h-4 w-4"}):u.jsx(te.PictureInPicture2,{className:"h-4 w-4"})})}),u.jsx(gt,{children:H?"Dock to sidebar":"Undock to floating window"})]}),u.jsxs(mt,{children:[u.jsx(pt,{asChild:!0,children:u.jsx("button",{type:"button",className:se(Et({variant:"ghost",size:"icon"}),"h-8 w-8"),onClick:H?Yn:it,"aria-label":H?Ee?"Maximize":"Minimize":"Close sidebar",children:H?Ee?u.jsx(te.Maximize2,{className:"h-4 w-4"}):u.jsx(te.Minimize2,{className:"h-4 w-4"}):u.jsx(te.X,{className:"h-4 w-4"})})}),u.jsx(gt,{children:H?Ee?"Maximize window":"Minimize to header":"Close the chat"})]})]})]}),!Ee&&u.jsxs(u.Fragment,{children:[E&&He.length>0&&u.jsxs("div",{className:`border-b border-border ${xe?"flex flex-col flex-1":""}`,children:[u.jsxs("div",{className:"flex items-center justify-between px-3 py-1",children:[u.jsx("h3",{className:"text-xs font-semibold text-muted-foreground",children:"Recent chats"}),u.jsx(je,{variant:"ghost",className:"h-auto px-2 py-1 text-xs text-muted-foreground hover:text-foreground",onClick:()=>{pn(!xe)},children:xe?"Show less":"View all"})]}),u.jsx("div",{className:`px-2 pb-2 space-y-0.5 ${xe?"flex-1 overflow-y-auto":""}`,children:He.slice(0,xe?void 0:3).map(T=>u.jsxs("div",{className:"group relative",children:[u.jsxs(Oh,{type:"button",className:se(Et({variant:"ghost"}),"w-full justify-between h-auto py-1 px-3 font-normal active:scale-[0.99]"),onClick:()=>{Ue(T.chatId||T._id),pn(!1)},children:[u.jsx("span",{className:"text-xs truncate",children:T.title}),u.jsx("div",{className:"ml-2 flex items-center",children:u.jsx("span",{className:"text-xs text-muted-foreground group-hover:hidden",children:Pt(T.updatedAt)})})]}),u.jsx("button",{type:"button",className:"absolute right-2 top-1/2 -translate-y-1/2 h-6 w-6 p-0 hidden group-hover:flex items-center justify-center text-muted-foreground hover:text-foreground rounded-md hover:bg-accent transition-colors",onClick:_=>{_.stopPropagation(),Ye(T._id)},"aria-label":"Delete conversation",children:u.jsx(te.X,{className:"h-3 w-3"})})]},T._id))})]}),u.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden relative",children:[u.jsx("div",{className:"flex-1 overflow-y-auto p-4 space-y-4 scroll-smooth",children:Pe.length===0?u.jsxs("div",{className:"flex flex-col items-center justify-center h-full",children:[o&&u.jsx("div",{className:"mb-6",children:o}),u.jsx("h3",{className:"text-lg font-semibold text-center mb-2",children:"How can I help you?"}),st.length>0&&u.jsx("div",{className:"mt-4 px-4 max-w-md mx-auto",children:u.jsxs("div",{className:"flex flex-wrap gap-2 justify-center",children:[(Bt?st:st.slice(0,10)).map(T=>u.jsxs(mt,{children:[u.jsx(pt,{asChild:!0,children:u.jsx(Cs,{variant:"secondary",className:"cursor-pointer text-xs px-2 py-1 hover:bg-stone-200 dark:hover:bg-stone-700 transition-colors",onClick:()=>{ke(T.sampleUsage),Tt.current?.focus()},children:T.friendlyName})}),u.jsx(gt,{children:u.jsxs("div",{className:"max-w-xs",children:[u.jsx("p",{className:"font-medium",children:T.description}),u.jsxs("p",{className:"text-xs text-muted-foreground mt-2",children:[u.jsx("span",{className:"font-medium",children:"Example:"}),' "',T.sampleUsage,'"']}),T.paramCount>0&&u.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[u.jsx("span",{className:"font-medium",children:"Parameters:"})," ",T.params.join(", ")]})]})})]},T.name)),st.length>10&&!Bt&&u.jsxs(mt,{children:[u.jsx(pt,{asChild:!0,children:u.jsxs(Cs,{variant:"secondary",className:"cursor-pointer text-xs px-2 py-1 hover:bg-stone-200 dark:hover:bg-stone-700 transition-colors",onClick:()=>dt(!0),children:["+",st.length-10," more"]})}),u.jsx(gt,{children:u.jsxs("div",{className:"max-w-xs",children:[u.jsx("p",{className:"font-medium mb-2",children:"Additional tools:"}),u.jsx("div",{className:"space-y-1 max-h-64 overflow-y-auto pr-2",children:st.slice(10).map(T=>u.jsxs("div",{children:[u.jsxs("span",{className:"font-medium text-xs",children:[T.friendlyName,":"]}),u.jsx("span",{className:"text-xs text-muted-foreground ml-1",children:T.description})]},T.name))}),u.jsx("p",{className:"text-xs text-muted-foreground mt-2 italic",children:"Click to show all tools"})]})})]}),Bt&&st.length>10&&u.jsx(Cs,{variant:"secondary",className:"cursor-pointer text-xs px-2 py-1 hover:bg-stone-200 dark:hover:bg-stone-700 transition-colors",onClick:()=>dt(!1),children:"Show less"})]})})]}):u.jsxs(u.Fragment,{children:[Pe.map(T=>{const z=T.parts.filter(W=>W.type==="text").map(W=>W.text).join("");let Z=T.parts;T.role==="assistant"&&T.parts.some(me=>me.timestamp)&&(Z=[...T.parts].sort((me,ne)=>{const Se=me.timestamp||0,de=ne.timestamp||0;return Se-de}));let Y=[],J=new Map,De=[],re,ue=!0;if(T.role==="assistant"){const W=Z.filter(de=>de.type==="text"&&de.text),me=[],ne=[];W.forEach(de=>{const{citations:Ze,citationMap:ve,groupedCitations:g,referencesText:y}=vo(de.text);Y.push(...Ze),me.push(ve),g&&ne.push(...g),y&&(re=y)}),me.forEach(de=>{de.forEach((Ze,ve)=>{J.has(ve)||J.set(ve,Ze)})}),De=Array.from(new Map(ne.map(de=>[de.url,de])).values()).sort((de,Ze)=>(de.numbers[0]||0)-(Ze.numbers[0]||0)),ue=!(Ne==="streaming"&&T.id===Pe.at(-1)?.id)}return u.jsx("div",{className:`${T.role==="user"?"flex justify-end":"w-full"}`,children:u.jsx("div",{className:`${T.role==="user"?"max-w-[85%] text-right":"w-full"}`,children:T.role==="user"?u.jsx($h,{initial:{opacity:0,filter:"blur(4px)"},animate:{opacity:1,filter:"blur(0px)"},transition:{duration:.3,ease:"easeOut"},className:"text-sm whitespace-pre-wrap inline-block bg-stone-100 dark:bg-stone-800 px-3 py-2 rounded-xl",children:z}):u.jsx("div",{className:"space-y-2",children:Z.map((W,me)=>{if(W.type?.startsWith("tool-")){const ne=W.type?.replace("tool-","")||"",Se=Re.find(ve=>ve.name===ne),de=W.state==="input-available",Ze=W.state==="output-available";if(de&&Ke.has(ne),de){if(Ke.has(ne))return null;const ve=zs(W.input);return u.jsx(ts,{initial:{opacity:0,y:10,filter:"blur(4px)"},animate:{opacity:1,y:0,filter:"blur(0px)"},transition:{duration:.3,ease:"easeOut"},children:u.jsx(Lh,{toolName:ne,description:Se?.description||"",args:ve,onApprove:async()=>{if(Lt.has(W.toolCallId))return;nt(y=>new Set(y).add(W.toolCallId));const g=gn.get(ne);if(g)try{const y=await g(...Object.values(ve));rt({toolCallId:W.toolCallId,tool:ne,output:y})}catch(y){rt({toolCallId:W.toolCallId,tool:ne,output:`Error: ${y}`})}},onDeny:async()=>{Lt.has(W.toolCallId)||(nt(g=>new Set(g).add(W.toolCallId)),rt({toolCallId:W.toolCallId,tool:ne,output:"User denied tool execution"}))}})},`${W.toolCallId}-${me}`)}else if(Ze){const ve=W.output==="User denied tool execution",g=zs(W.input);return u.jsx(Fh,{toolName:ne,args:g,isDenied:ve,isSafe:Ke.has(ne)},`${W.toolCallId}-${me}`)}return null}if(W.type==="text"&&W.text&&hn){const{processedText:ne}=vo(W.text),ve=!Z.slice(me+1).some(g=>g.type==="text"&&g.text)&&ue&&J.size>0;return u.jsx(Zh,{text:ne,citations:Y,citationMap:J,groupedCitations:ve?De:void 0,referencesText:ve?re:void 0,ResponseComponent:hn,className:"text-sm prose prose-sm dark:prose-invert max-w-none",showCitations:V,showReferences:ve},`${T.id}-${me}`)}return W.type==="reasoning"&&W.text?u.jsxs(cl,{className:"w-full",isStreaming:Ne==="streaming"&&me===T.parts.length-1&&T.id===Pe.at(-1)?.id,children:[u.jsx(ul,{}),u.jsx(dl,{children:W.text})]},`${T.id}-${me}`):null})})})},T.id)}),u.jsx("div",{ref:Be})]})}),Xn&&u.jsxs("div",{className:"px-4 py-2 bg-destructive/10 text-destructive text-xs",children:["Error: ",Xn.message]}),u.jsxs("div",{className:"p-4 border-t border-border relative overflow-visible",children:[u.jsx(sd,{mode:"wait",children:(Ne==="streaming"||Ne==="submitted")&&u.jsxs(ts,{initial:{opacity:0,filter:"blur(4px)",y:5},animate:{opacity:1,filter:"blur(0px)",y:0},exit:{opacity:0,filter:"blur(4px)",y:5},transition:{duration:.2,ease:"easeOut"},className:"absolute left-1/2 -translate-x-1/2 -top-6 flex items-center gap-1.5 bg-stone-100 dark:bg-stone-800 px-3 py-1.5 rounded-full shadow-lg border border-border z-50",children:[u.jsx(ts,{className:"w-2 h-2 bg-stone-400 dark:bg-stone-600",animate:{rotate:[0,0,90,90],borderRadius:["50%","30%","30%","50%"],scale:[.75,1,1,.75]},transition:{duration:2,repeat:1/0,ease:"easeInOut",times:[0,.4,.6,1]}}),u.jsx("p",{className:"text-xs text-muted-foreground",children:$t})]})}),u.jsxs("form",{onSubmit:xn,className:"relative",children:[u.jsx(Ao,{ref:Tt,value:jt,onChange:ht,placeholder:"Ask anything..",className:"w-full pr-12 resize-none border border-border rounded-xl px-4 py-3",minHeight:24,maxHeight:200,onKeyDown:T=>{T.key==="Enter"&&!T.shiftKey&&(T.preventDefault(),xn(T))}}),Ne==="streaming"||Ne==="submitted"?u.jsxs(mt,{children:[u.jsx(pt,{asChild:!0,children:u.jsx("button",{type:"button",className:se(Et({variant:"ghost",size:"icon"}),"absolute top-1/2 -translate-y-1/2 right-2 h-8 w-8"),onClick:Ut,children:u.jsx(te.Square,{className:"h-4 w-4"})})}),u.jsxs(gt,{children:[u.jsx(ni,{children:"Escape"})," to stop"]})]}):u.jsxs(mt,{children:[u.jsx(pt,{asChild:!0,children:u.jsx("button",{type:"submit",className:se(Et({variant:"ghost",size:"icon"}),"absolute top-1/2 -translate-y-1/2 right-2 h-8 w-8"),disabled:!jt.trim(),children:u.jsx(te.ArrowRight,{className:"h-4 w-4"})})}),u.jsxs(gt,{children:[u.jsx(ni,{children:"Enter"})," to send"]})]})]})]})]}),u.jsxs("a",{href:"https://arcten.com",target:"_blank",rel:"noopener noreferrer",className:"group flex items-center justify-center gap-1.5 py-3 text-xs text-muted-foreground/40 hover:text-muted-foreground/60 transition-all",children:[u.jsx("span",{className:"whitespace-nowrap",children:"Powered by"}),u.jsx("div",{className:"w-4 h-2 bg-current rounded-t-full flex-shrink-0"}),u.jsx("span",{className:"whitespace-nowrap",children:"Arcten"})]})]})]})]}):u.jsxs("div",{className:"flex flex-col items-center justify-center gap-3 h-full cursor-pointer",children:[u.jsx(te.BotMessageSquare,{className:"h-5 w-5 text-stone-600 dark:text-stone-400"}),u.jsx("span",{className:"text-xs font-medium text-stone-600 dark:text-stone-400 [writing-mode:vertical-lr]",children:"AI agent"})]})})}):u.jsx("div",{className:"fixed right-0 top-0 h-screen w-96 flex items-center justify-center p-4 bg-stone-50 dark:bg-stone-900 border-l border-border",children:u.jsx("div",{className:"p-4 text-muted-foreground text-sm",children:"Loading..."})}):null}function cm(e){return u.jsx(ml,{children:u.jsx(lm,{...e})})}function um(e={}){const{apiBaseUrl:t="https://api.arcten.com",tokenEndpoint:n="/token",clientToken:s,skipTokenFetch:r=!1}=e,[o,i]=h.useState(!1),[a,l]=h.useState(null),c=h.useRef(s||null);h.useEffect(()=>{if(s){c.current=s;return}if(r)return;(async()=>{try{const p=await fetch(`${t}${n}`,{method:"POST",headers:{"Content-Type":"application/json"}});if(p.ok){const x=await p.json();c.current=x.token}}catch(p){console.error("[useGenerate] Failed to fetch token:",p)}})()},[t,n,s,r]);const d=h.useCallback(async m=>{i(!0),l(null);try{const p={"Content-Type":"application/json"};c.current&&(p.Authorization=`Bearer ${c.current}`);const x=await fetch(`${t}/generate`,{method:"POST",headers:p,body:JSON.stringify(m)});if(!x.ok){const S=await x.json().catch(()=>({}));throw new Error(S.error||`HTTP ${x.status}`)}return await x.json()}catch(p){const x=p instanceof Error?p.message:String(p);throw l(x),p}finally{i(!1)}},[t]),f=h.useCallback(async(m,p)=>{i(!0),l(null);try{const x={"Content-Type":"application/json"};c.current&&(x.Authorization=`Bearer ${c.current}`);const b=await fetch(`${t}/generate/stream`,{method:"POST",headers:x,body:JSON.stringify(m)});if(!b.ok){const E=await b.json().catch(()=>({}));throw new Error(E.error||`HTTP ${b.status}`)}const S=b.body?.getReader();if(!S)throw new Error("No response body");const v=new TextDecoder;let M=null;for(;;){const{done:E,value:L}=await S.read();if(E)break;const O=v.decode(L,{stream:!0}).split(`
|
|
16
16
|
`).filter(k=>k.startsWith("data: "));for(const k of O){const P=k.slice(6).trim();if(P)try{const V=JSON.parse(P);if(V.error)throw new Error(V.error);V.done&&V.object?M={object:V.object,usage:V.usage,finishReason:V.finishReason}:V.partial&&p&&p(V.partial)}catch{}}}if(!M)throw new Error("Stream ended without final result");return M}catch(x){const b=x instanceof Error?x.message:String(x);throw l(b),x}finally{i(!1)}},[t]);return{generate:d,streamGenerate:f,isLoading:o,error:a}}exports.verifyToken=Nl.verifyToken;exports.ARCTEN_ORIGINAL_NAME=Oe;exports.ArctenAgent=cm;exports.SecureModalProvider=ml;exports.extractToolsMetadata=mr;exports.preserveToolName=Dl;exports.useAgent=Po;exports.useGenerate=um;exports.useSecureModal=hl;
|
package/dist/index.mjs
CHANGED
|
@@ -8727,8 +8727,7 @@ function Qm(e = {}) {
|
|
|
8727
8727
|
try {
|
|
8728
8728
|
const m = await fetch(`${t}${n}`, {
|
|
8729
8729
|
method: "POST",
|
|
8730
|
-
headers: { "Content-Type": "application/json" }
|
|
8731
|
-
credentials: "include"
|
|
8730
|
+
headers: { "Content-Type": "application/json" }
|
|
8732
8731
|
});
|
|
8733
8732
|
if (m.ok) {
|
|
8734
8733
|
const b = await m.json();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGenerate.d.ts","sourceRoot":"","sources":["../../src/lib/useGenerate.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,eAAe;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,MAAM,CAAC,EAAE,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,WAAW,CAAC;IACnD,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAA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