@arcteninc/core 0.0.69 → 0.0.70
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/components/ArctenAgent.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +6 -5
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArctenAgent.d.ts","sourceRoot":"","sources":["../../src/components/ArctenAgent.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ArctenAgent.d.ts","sourceRoot":"","sources":["../../src/components/ArctenAgent.tsx"],"names":[],"mappings":"AAwLA,MAAM,MAAM,YAAY,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;AAEnD,MAAM,WAAW,gBAAgB;IAC/B,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;IAClC,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,GAAG,sBAAsB,GAAG,eAAe,GAAG,cAAc,CAAC;IAC3E,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,KAAK,CAAC,EAAE,YAAY,EAAE,CAAC;IACvB,SAAS,CAAC,EAAE,YAAY,EAAE,CAAC;IAC3B,YAAY,CAAC,EAAE,GAAG,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAC;IAC1C,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACnC,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,wBAAgB,WAAW,CAAC,EAC1B,KAAc,EACd,MAAkB,EAClB,KAAc,EACd,QAAe,EACf,KAAc,EACd,IAAgB,EAChB,YAAkB,EAClB,QAAc,EACd,QAAc,EACd,iBAAyB,EACzB,KAAU,EACV,SAAc,EACd,YAAY,EACZ,YAAiB,EACjB,aAAmC,EACnC,UAAqC,EACrC,IAAI,EACJ,YAAiB,EACjB,aAAa,GACd,EAAE,gBAAgB,kDAy+ClB"}
|
package/dist/index.cjs
CHANGED
|
@@ -16,7 +16,7 @@ Please:
|
|
|
16
16
|
useAgent({ tools: [...], toolMetadata: toolMetadata })
|
|
17
17
|
(Pass the full object for better minification support, or toolMetadata.functions for backward compatibility)
|
|
18
18
|
`);if("functions"in e&&typeof e.functions=="object"){const o=e;n=o.functions,s=o.toolOrder}else n=e,s=void 0;const i=new Set;return t.map(o=>{const r=Rh(o,n,i,s);if(!r){const a=o.name,u=o[Pt]||a||"unnamed";return typeof process<"u"&&(process.env.NODE_ENV==="development"||process.env.NODE_ENV!=="production")&&typeof console<"u"&&console.warn&&console.warn(`⚠️ [@arcteninc/core] No metadata found for tool "${u}". This tool will be excluded.
|
|
19
|
-
To fix: Run "arcten-extract-types ." and ensure "${u}" is used in ArctenAgent/useAgent.`),null}return i.add(r.meta.name),{name:r.meta.name,description:r.meta.description,jsonSchema:r.meta.parameters}}).filter(o=>o!==null)}function Nh({toolName:t,description:e,args:n,onApprove:s,onDeny:i}){const o=Object.keys(n).length>0;return h.jsx("div",{className:"bg-stone-100 dark:bg-stone-800 border border-border rounded-lg px-3 py-2.5 my-1.5",children:h.jsxs("div",{className:"flex items-start gap-2",children:[h.jsxs("div",{className:"flex-1 min-w-0",children:[h.jsx("div",{className:"flex items-center gap-1.5 mb-1",children:h.jsx("span",{className:"text-sm font-medium text-foreground",children:t})}),o&&h.jsx("div",{className:"space-y-0.5 mb-1.5",children:Object.entries(n).map(([r,a])=>h.jsxs("div",{className:"flex items-start gap-1.5 text-xs",children:[h.jsxs("span",{className:"text-muted-foreground min-w-[60px]",children:[r,":"]}),h.jsx("span",{className:"font-mono text-foreground",children:typeof a=="string"?a:JSON.stringify(a)})]},r))})]}),h.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[h.jsxs(gn,{size:"sm",variant:"ghost",className:"h-6 px-2 text-xs",onClick:s,children:[h.jsx(J.Check,{className:"h-3 w-3 mr-1"}),"Approve"]}),h.jsx(gn,{size:"sm",variant:"ghost",className:"h-6 px-2 text-xs text-muted-foreground",onClick:i,children:h.jsx(J.X,{className:"h-3 w-3"})})]})]})})}function Ih({toolName:t,args:e,isDenied:n,isSafe:s}){const[i,o]=m.useState(!1);if(t==="fetchDocContent")return null;const r=["k","maxResults","_organizationId"];t==="searchDocs"&&r.push("filters");const a=Object.fromEntries(Object.entries(e).filter(([u])=>!r.includes(u))),c=Object.keys(a).length>0;return h.jsxs("div",{className:"my-1",children:[h.jsxs("button",{onClick:()=>c&&o(!i),className:`inline-flex items-center gap-1.5 text-xs rounded-md px-2 py-1 transition-colors ${n?"bg-red-100 dark:bg-red-950/30 text-red-700 dark:text-red-400":"bg-green-100 dark:bg-green-950/30 text-green-700 dark:text-green-400"} ${c?"cursor-pointer hover:bg-opacity-80":""}`,children:[c&&h.jsx("span",{className:"transition-transform duration-200",children:i?h.jsx(J.ChevronDown,{className:"h-3 w-3"}):h.jsx(J.ChevronRight,{className:"h-3 w-3"})}),n?h.jsx(J.X,{className:"h-3 w-3"}):s?h.jsx(J.Zap,{className:"h-3 w-3"}):h.jsx(J.Check,{className:"h-3 w-3"}),h.jsxs("span",{className:"font-medium",children:[n?"Denied":s?"Auto-executed":"Executed"," ",t]})]}),i&&c&&h.jsx("div",{className:"mt-1 ml-6 p-2 bg-stone-50 dark:bg-stone-900 rounded-md border border-border",children:h.jsx("div",{className:"space-y-0.5",children:Object.entries(a).map(([u,l])=>h.jsxs("div",{className:"flex items-start gap-1.5 text-xs",children:[h.jsxs("span",{className:"text-muted-foreground min-w-[60px]",children:[u,":"]}),h.jsx("span",{className:"font-mono text-foreground",children:typeof l=="string"?l:JSON.stringify(l)})]},u))})})]})}function Lh({...t}){return h.jsx(bs.Root,{"data-slot":"collapsible",...t})}function Oh({...t}){return h.jsx(bs.CollapsibleTrigger,{"data-slot":"collapsible-trigger",...t})}function Fh({...t}){return h.jsx(bs.CollapsibleContent,{"data-slot":"collapsible-content",...t})}const Bh=m.lazy(()=>import("streamdown").then(t=>({default:t.Streamdown}))),ni=m.memo(({className:t,...e})=>typeof window>"u"?null:h.jsx(m.Suspense,{fallback:null,children:h.jsx(Bh,{className:tt("size-full [&>*:first-child]:mt-0 [&>*:last-child]:mb-0",t),...e})}),(t,e)=>t.children===e.children);ni.displayName="Response";const $h=Object.freeze(Object.defineProperty({__proto__:null,Response:ni},Symbol.toStringTag,{value:"Module"})),zh=({children:t,as:e="p",className:n,duration:s=2,spread:i=2})=>{const o=Eh.create(e),r=m.useMemo(()=>(t?.length??0)*i,[t,i]);return h.jsx(o,{animate:{backgroundPosition:"0% center"},className:tt("relative inline-block bg-[length:250%_100%,auto] bg-clip-text text-transparent","[--bg:linear-gradient(90deg,#0000_calc(50%-var(--spread)),var(--color-background),#0000_calc(50%+var(--spread)))] [background-repeat:no-repeat,padding-box]",n),initial:{backgroundPosition:"100% center"},style:{"--spread":`${r}px`,backgroundImage:"var(--bg), linear-gradient(var(--color-muted-foreground), var(--color-muted-foreground))"},transition:{repeat:Number.POSITIVE_INFINITY,duration:s,ease:"linear"},children:t})},Uh=m.memo(zh),ya=m.createContext(null),_h=()=>{const t=m.useContext(ya);if(!t)throw new Error("Reasoning components must be used within Reasoning");return t},Wh=1e3,Kh=1e3,xa=m.memo(({className:t,isStreaming:e=!1,open:n,defaultOpen:s=!0,onOpenChange:i,duration:o,children:r,...a})=>{const[c,u]=fi.useControllableState({prop:n,defaultProp:s,onChange:i}),[l,d]=fi.useControllableState({prop:o,defaultProp:0}),[f,p]=m.useState(!1),[y,v]=m.useState(null);m.useEffect(()=>{e?y===null&&v(Date.now()):y!==null&&(d(Math.ceil((Date.now()-y)/Kh)),v(null))},[e,y,d]),m.useEffect(()=>{if(s&&!e&&c&&!f){const x=setTimeout(()=>{u(!1),p(!0)},Wh);return()=>clearTimeout(x)}},[e,c,s,u,f]);const S=x=>{u(x)};return h.jsx(ya.Provider,{value:{isStreaming:e,isOpen:c,setIsOpen:u,duration:l},children:h.jsx(Lh,{className:tt("not-prose mb-4",t),onOpenChange:S,open:c,...a,children:r})})}),Hh=(t,e)=>t||e===0?h.jsx(Uh,{duration:1,children:"Thinking..."}):e===void 0?h.jsx("p",{children:"Thought for a few seconds"}):h.jsxs("p",{children:["Thought for ",e," seconds"]}),va=m.memo(({className:t,children:e,...n})=>{const{isStreaming:s,isOpen:i,duration:o}=_h();return h.jsx(Oh,{className:tt("flex w-full items-center gap-2 text-muted-foreground text-sm transition-colors hover:text-foreground",t),...n,children:e??h.jsxs(h.Fragment,{children:[h.jsx(J.BrainIcon,{className:"size-4"}),Hh(s,o),h.jsx(J.ChevronDownIcon,{className:tt("size-4 transition-transform",i?"rotate-180":"rotate-0")})]})})}),ba=m.memo(({className:t,children:e,...n})=>h.jsx(Fh,{className:tt("mt-4 text-sm","data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-top-2 data-[state=open]:slide-in-from-top-2 text-muted-foreground outline-none data-[state=closed]:animate-out data-[state=open]:animate-in",t),...n,children:h.jsx(ni,{className:"grid gap-2",children:e})}));xa.displayName="Reasoning";va.displayName="ReasoningTrigger";ba.displayName="ReasoningContent";function Xh(t){const e=/(?:^|\n)(?:#+\s*)?(?:References|References:)(?:\*\*)?\s*\n?([\s\S]*?)(?=\n\n|\n#|$)/i,n=t.match(e),s=new Map;if(n){const u=n[1],l=/\[(\d+)\]\s*(https?:\/\/[^\s\)]+)/g;let d;for(;(d=l.exec(u))!==null;){const f=parseInt(d[1],10),p=d[2].replace(/[.,;:!?]+$/,"");s.set(f,p)}}const i=[];let o=0;const r=/```[\s\S]*?```|`[^`]+`/g;let a;for(;(a=r.exec(t))!==null;)a.index>o&&i.push({type:"text",content:t.slice(o,a.index),start:o,end:a.index}),i.push({type:"code",content:a[0],start:a.index,end:a.index+a[0].length}),o=a.index+a[0].length;return o<t.length&&i.push({type:"text",content:t.slice(o),start:o,end:t.length}),i.map(u=>{if(u.type==="code")return u.content;let l=u.content;l=l.replace(/\[(\d+)\]\((https?:\/\/[^\)]+)\)/g,(v,S,x)=>{const b=parseInt(S,10);return`<sup><a href="${x.replace(/"/g,""")}" target="_blank" rel="noopener noreferrer" class="text-blue-600 dark:text-blue-400 hover:underline font-medium">[${b}]</a></sup>`});const d=/\[([^\]]+)\]\([^\)]+\)/g,f=[];let p;for(;(p=d.exec(l))!==null;)f.push({start:p.index,end:p.index+p[0].length});return l.replace(/\[(\d+)\]/g,(v,S,x)=>{if(f.some(M=>x>=M.start&&x<M.end))return v;const T=parseInt(S,10),D=s.get(T);return D?`<sup><a href="${D.replace(/"/g,""")}" target="_blank" rel="noopener noreferrer" class="text-blue-600 dark:text-blue-400 hover:underline font-medium">[${T}]</a></sup>`:v})}).join("")}function $e(t){if(typeof t=="string")try{const e=JSON.parse(t);return $e(e)}catch{return t}if(Array.isArray(t))return t.map($e);if(t&&typeof t=="object"){const e={};for(const[n,s]of Object.entries(t))e[n]=$e(s);return e}return t}function qn(t){if(typeof t=="string"){try{const e=JSON.parse(t);if(e&&typeof e=="object"&&!Array.isArray(e))return $e(e)}catch{}return{}}return t&&typeof t=="object"&&!Array.isArray(t)?$e(t):{}}function Gh({theme:t="auto",layout:e="sidebar",model:n="auto",animated:s=!0,title:i="Chat",logo:o=void 0,defaultWidth:r=384,minWidth:a=300,maxWidth:c=800,initiallyExpanded:u=!1,tools:l=[],safeTools:d=[],toolMetadata:f,systemPrompt:p="",tokenEndpoint:y="/api/arcten/token",apiBaseUrl:v="https://api.arcten.com",user:S,initialState:x={},sharedStateId:b}){const[T,D]=m.useState(null),M=m.useRef(null),[I,R]=m.useState(null),[E,_]=m.useState(null),B=m.useRef(null),[ct,It]=m.useState(x),pt=m.useRef(x),[oe,Lt]=m.useState(!1),[Pn,U]=m.useState(null),$=m.useRef(!1),[Z,ot]=m.useState(u),[lt,Ot]=m.useState(r),[jt,ae]=m.useState(600),[Ae,Ft]=m.useState(!1),[z,gt]=m.useState(!1),[st,Kt]=m.useState(!1),[it,Ht]=m.useState({x:100,y:100}),[Pe,Me]=m.useState(!1),[ce,yt]=m.useState({x:0,y:0}),[Mn,je]=m.useState(!1),Xt=m.useRef(null),le=m.useRef(null),[Et,Gt]=m.useState(""),[Ze,jn]=m.useState(null),[En,Qe]=m.useState("Thinking..."),[Ee,ke]=m.useState(new Set),[kn,Dn]=m.useState(""),[C,A]=m.useState([]),[j,k]=m.useState(!1),[L,K]=m.useState([]),[G,kt]=m.useState(()=>typeof window<"u"?crypto.randomUUID():null),[xt,ue]=m.useState(!1),[si,tn]=m.useState(!1),[Jh,en]=m.useState([]),qt=m.useMemo(()=>[...l,...d],[l,d]),Tt=m.useMemo(()=>ga(qt,f),[qt,f]),ii=m.useMemo(()=>new Set(Tt.map(g=>g.name)),[Tt]),ri=m.useMemo(()=>Tt.filter(g=>ii.has(g.name)),[Tt,ii]),oi=m.useMemo(()=>{const g=new Map,w=new Map(Tt.map(N=>[N.name,N]));return qt.forEach(N=>{const P=N[Pt];if(P){const F=w.get(P);if(F){g.set(F.name,N);return}}const O=Tt.find(F=>F.name===N.name);O&&g.set(O.name,N)}),g},[qt,Tt]),ai=m.useMemo(()=>{const g=new Set,w=new Map(Tt.map(N=>[N.name,N]));return d.forEach(N=>{const P=N[Pt];if(P&&w.has(P))g.add(P);else{const O=Tt.find(F=>F.name===N.name);O&&g.add(O.name)}}),g},[d,Tt]),ci=["Thinking...","Pondering...","Contemplating...","Considering...","Analyzing...","Processing...","Reasoning...","Mulling it over...","Computing...","Cooking up a response...","Brewing ideas...","Connecting the dots...","Piecing it together...","Spinning up thoughts...","Loading brain cells...","Sharpening pencils...","Herding ideas...","Warming up neurons...","Stirring the think-pot...","Plotting a plan...","Wiggling the logic wires...","Rolling ideas around...","Charging the brainstorm...","Booting the brain...","Dusting off the cortex...","Running mental diagnostics...","Fetching cleverness...","Whisking up notions...","Tuning the idea radio...","Juggling possibilities...","Breathing in inspiration...","Squeezing the thought sponge...","Tickling the gray matter...","Bubbling up insights...","Spicing the soup of thought...","Lacing up hypotheses...","Winding the idea clock...","Casting the net for clues...","Polishing the crystal ball...","Mapping the maze...","Crunching the brain-biscuits...","Cueing the eureka moment...","Summoning the muse...","Knocking on insight’s door...","Combing the noodle...","Sailing the think-ship...","Scooping brain gelato...","Testing wild hunches...","Tick-tocking the neurons...","Planting idea seeds...","Shaking the thought snow globe...","Unlocking the mental toolbox...","Nudging the puzzle pieces...","Lighting the idea bulb...","Preheating the oven of insight...","Mixing the mental trail mix...","Spooling up reasoning reels...","Skimming the mind-palace index...","Surfing the thought waves...","Kicking the tires on ideas...","Rattling the idea can...","Waving the logic wand..."];m.useEffect(()=>{if(typeof window<"u"){const g=localStorage.getItem("arcten-sidebar-expanded");g&&ot(JSON.parse(g));const w=localStorage.getItem("arcten-sidebar-width");w&&Ot(parseInt(w));const N=localStorage.getItem("arcten-sidebar-height");N&&ae(parseInt(N));const P=localStorage.getItem("arcten-sidebar-detached");P&>(JSON.parse(P));const O=localStorage.getItem("arcten-sidebar-position");if(O){const ut=JSON.parse(O),Ct=50,$t=Math.max(Ct-r,Math.min(ut.x,window.innerWidth-Ct)),at=Math.max(0,Math.min(ut.y,window.innerHeight-Ct));Ht({x:$t,y:at})}const F=localStorage.getItem("arcten-sidebar-minimized");F&&Kt(JSON.parse(F)),je(!0)}},[]);const Bt=m.useMemo(()=>S,[S?.id]);m.useEffect(()=>((async()=>{try{const w=await fetch(y,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({user:Bt})});if(!w.ok)throw new Error("Failed to fetch token");const N=await w.json();D(N.clientToken),M.current=N.clientToken,_(N.expiresAt),R(null)}catch(w){R(w instanceof Error?w.message:"Failed to fetch token")}})(),()=>{B.current&&clearTimeout(B.current)}),[y,Bt]),m.useEffect(()=>{if(!E)return;B.current&&clearTimeout(B.current);const g=Math.floor(Date.now()/1e3),w=E-g,P=Math.max(0,w-5);return B.current=setTimeout(async()=>{try{const O=await fetch(y,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({user:Bt})});if(!O.ok)throw new Error("Failed to refresh token");const F=await O.json();D(F.clientToken),M.current=F.clientToken,_(F.expiresAt),R(null)}catch(O){console.error("Token refresh failed:",O),R(O instanceof Error?O.message:"Failed to refresh token")}},P*1e3),()=>{B.current&&clearTimeout(B.current)}},[E,y,Bt]),m.useEffect(()=>{(async()=>{if(qt.length!==0)try{const w=qt.map(P=>({name:P.name,code:P.toString()})),N=await fetch(`${v}/tools/describe`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tools:w})});if(N.ok){const P=await N.json();A(P.tools)}}catch(w){console.error("Failed to fetch tool descriptions:",w)}})()},[qt]),m.useEffect(()=>{Promise.resolve().then(()=>$h).then(g=>{jn(()=>g.Response)})},[]),m.useEffect(()=>{const g=()=>{Dn(window.location.pathname)};g(),window.addEventListener("popstate",g);const w=setInterval(g,500);return()=>{window.removeEventListener("popstate",g),clearInterval(w)}},[]);const Vn=m.useCallback(async()=>{if(!(!Bt?.id||!T)){tn(!0);try{const w=await(await fetch(`${v}/conversations`,{headers:{Authorization:`Bearer ${T}`}})).json();K(w.conversations||[])}catch(g){console.error("Failed to fetch conversations:",g)}finally{tn(!1)}}},[Bt?.id,T,v]);m.useEffect(()=>{Bt?.id&&T&&Vn()},[Bt?.id,T,Vn]);function wa(g){const w=Math.floor((Date.now()-g)/1e3);return w<60?"now":w<3600?`${Math.floor(w/60)}m`:w<86400?`${Math.floor(w/3600)}h`:`${Math.floor(w/86400)}d`}function Ta(){const g=crypto.randomUUID();kt(g),sn([]),en([]),ue(!1),b||(pt.current=x,It(x),$.current=!1)}async function Sa(g){if(T)try{await fetch(`${v}/conversations/${g}`,{method:"DELETE",headers:{Authorization:`Bearer ${T}`}}),K(L.filter(w=>w._id!==g)),g===G&&Ta()}catch(w){console.error("Failed to delete conversation:",w)}}async function Ca(g){kt(g.chatId),ue(!1),tn(!0);try{const w=await fetch(`${v}/conversations/${g.chatId}/messages`,{headers:{Authorization:`Bearer ${M.current}`}});if(!w.ok)throw new Error(`Failed to fetch messages: ${w.statusText}`);const P=(await w.json()).messages||[];sn(P),en(P)}catch(w){console.error("Failed to load conversation messages:",w);const N=g.messages||[];sn(N),en(N)}finally{tn(!1)}}const Aa=async(g,w={})=>{const N=w.headers?new Headers(w.headers):new Headers;return N.delete("user-agent"),N.delete("User-Agent"),fetch(g,{...w,headers:N})},{messages:De,sendMessage:Pa,status:St,error:li,stop:nn,addToolResult:Ve,setMessages:sn}=kr.useChat({id:G||void 0,transport:new pn.DefaultChatTransport({api:`${v}/chat`,fetch:Aa,headers:()=>{const g={};return M.current&&(g.Authorization=`Bearer ${M.current}`),g},body:()=>({tools:ri.map(w=>({name:w.name,description:w.description,inputSchema:w.jsonSchema})),systemPrompt:p,currentRoute:kn,state:pt.current})}),sendAutomaticallyWhen:pn.lastAssistantMessageIsCompleteWithToolCalls});m.useEffect(()=>{if(!G||!M.current)return;(async()=>{Lt(!0),U(null);try{let w={};if(b){const O=await fetch(`${v.replace("/chat","")}/convex/api/query`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${M.current}`},body:JSON.stringify({path:"sharedStates:getByStateId",args:{stateId:b},format:"json"})});if(!O.ok){const ut=await O.text().catch(()=>"Unknown error");throw new Error(`Failed to fetch shared state: ${O.status} ${ut}`)}w=(await O.json())?.value||{}}else{const O=await fetch(`${v.replace("/chat","")}/convex/api/query`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${M.current}`},body:JSON.stringify({path:"conversations:getStateByChatId",args:{chatId:G},format:"json"})});if(!O.ok){const ut=await O.text().catch(()=>"Unknown error");throw new Error(`Failed to fetch conversation state: ${O.status} ${ut}`)}w=(await O.json())?.value||{}}const N=!$.current;let P;N?(P={...x,...w},$.current=!0):P=w,pt.current=P,It(P)}catch(w){console.error("Failed to fetch state:",w);const N=w instanceof Error?w:new Error(String(w));U(N),$.current||(pt.current=x,It(x),$.current=!0)}finally{Lt(!1)}})()},[G,b,v]),m.useEffect(()=>{Z&&le.current&&le.current.focus()},[Z,De]);function Ma(){ot(!0),localStorage.setItem("arcten-sidebar-expanded","true")}function ja(){ot(!1),localStorage.setItem("arcten-sidebar-expanded","false")}m.useEffect(()=>{},[Z]),m.useEffect(()=>{Xt.current&&Xt.current.scrollIntoView({behavior:"smooth"})},[De]),m.useEffect(()=>{function g(w){w.key==="Escape"&&(St==="streaming"||St==="submitted")&&(w.preventDefault(),nn())}return window.addEventListener("keydown",g),()=>window.removeEventListener("keydown",g)},[St,nn]);function Ea(){const g=crypto.randomUUID();kt(g),sn([]),en([]),ue(!1)}function ui(g){if(g.preventDefault(),!Et.trim())return;(St==="streaming"||St==="submitted")&&nn();const w=ci[Math.floor(Math.random()*ci.length)]||"Thinking...";Qe(w),Pa({text:Et}),Gt("")}function ka(g){const w=g.target.value;Gt(w)}m.useEffect(()=>{if(!Ae)return;function g(N){if(z){const P=N.clientX-it.x,O=N.clientY-it.y;P>=a&&P<=c&&Ot(P),O>=400&&O<=1e3&&ae(O)}else{const P=window.innerWidth-N.clientX;P>=a&&P<=c&&Ot(P)}}function w(){Ft(!1),localStorage.setItem("arcten-sidebar-width",lt.toString()),localStorage.setItem("arcten-sidebar-height",jt.toString())}return window.addEventListener("mousemove",g),window.addEventListener("mouseup",w),()=>{window.removeEventListener("mousemove",g),window.removeEventListener("mouseup",w)}},[Ae,lt,jt,z,it,a,c]);function Da(g){g.preventDefault(),Ft(!0)}function Va(){gt(!0),Kt(!1),localStorage.setItem("arcten-sidebar-detached","true"),localStorage.setItem("arcten-sidebar-minimized","false")}function Ra(){gt(!1),Kt(!1),localStorage.setItem("arcten-sidebar-detached","false"),localStorage.setItem("arcten-sidebar-minimized","false")}function di(){Kt(!st),localStorage.setItem("arcten-sidebar-minimized",JSON.stringify(!st))}function Na(g){z&&(Me(!0),yt({x:g.clientX-it.x,y:g.clientY-it.y}))}return m.useEffect(()=>{if(!z)return;function g(){Ht(w=>{const P=window.innerWidth-50,O=window.innerHeight-50,F=50-lt,ut=0,Ct=Math.max(F,Math.min(w.x,P)),$t=Math.max(ut,Math.min(w.y,O));if(Ct!==w.x||$t!==w.y){const at={x:Ct,y:$t};return localStorage.setItem("arcten-sidebar-position",JSON.stringify(at)),at}return w})}return window.addEventListener("resize",g),()=>window.removeEventListener("resize",g)},[z,lt]),m.useEffect(()=>{if(!Pe)return;function g(N){const P=N.clientX-ce.x,O=N.clientY-ce.y,F=50,ut=window.innerWidth-F,Ct=window.innerHeight-F,$t=F-lt,at=0,Dt=Math.max($t,Math.min(P,ut)),At=Math.max(at,Math.min(O,Ct));Ht({x:Dt,y:At})}function w(){Me(!1),localStorage.setItem("arcten-sidebar-position",JSON.stringify(it))}return window.addEventListener("mousemove",g),window.addEventListener("mouseup",w),()=>{window.removeEventListener("mousemove",g),window.removeEventListener("mouseup",w)}},[Pe,ce,it,lt]),Mn?I?h.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:h.jsxs("div",{className:"p-4 bg-destructive/10 text-destructive text-sm rounded-lg",children:["Authentication error: ",I]})}):T?h.jsx(tu,{features:kh,children:h.jsx(ln,{id:"arcten-sidebar","data-theme":t,"data-layout":e,"data-model":n,initial:z?{opacity:0,scale:.95,filter:"blur(4px)"}:!1,animate:z?{opacity:1,scale:1,filter:"blur(0px)"}:{},transition:{duration:.2,ease:"easeOut"},className:`
|
|
19
|
+
To fix: Run "arcten-extract-types ." and ensure "${u}" is used in ArctenAgent/useAgent.`),null}return i.add(r.meta.name),{name:r.meta.name,description:r.meta.description,jsonSchema:r.meta.parameters}}).filter(o=>o!==null)}function Nh({toolName:t,description:e,args:n,onApprove:s,onDeny:i}){const o=Object.keys(n).length>0;return h.jsx("div",{className:"bg-stone-100 dark:bg-stone-800 border border-border rounded-lg px-3 py-2.5 my-1.5",children:h.jsxs("div",{className:"flex items-start gap-2",children:[h.jsxs("div",{className:"flex-1 min-w-0",children:[h.jsx("div",{className:"flex items-center gap-1.5 mb-1",children:h.jsx("span",{className:"text-sm font-medium text-foreground",children:t})}),o&&h.jsx("div",{className:"space-y-0.5 mb-1.5",children:Object.entries(n).map(([r,a])=>h.jsxs("div",{className:"flex items-start gap-1.5 text-xs",children:[h.jsxs("span",{className:"text-muted-foreground min-w-[60px]",children:[r,":"]}),h.jsx("span",{className:"font-mono text-foreground",children:typeof a=="string"?a:JSON.stringify(a)})]},r))})]}),h.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[h.jsxs(gn,{size:"sm",variant:"ghost",className:"h-6 px-2 text-xs",onClick:s,children:[h.jsx(J.Check,{className:"h-3 w-3 mr-1"}),"Approve"]}),h.jsx(gn,{size:"sm",variant:"ghost",className:"h-6 px-2 text-xs text-muted-foreground",onClick:i,children:h.jsx(J.X,{className:"h-3 w-3"})})]})]})})}function Ih({toolName:t,args:e,isDenied:n,isSafe:s}){const[i,o]=m.useState(!1);if(t==="fetchDocContent")return null;const r=["k","maxResults","_organizationId"];t==="searchDocs"&&r.push("filters");const a=Object.fromEntries(Object.entries(e).filter(([u])=>!r.includes(u))),c=Object.keys(a).length>0;return h.jsxs("div",{className:"my-1",children:[h.jsxs("button",{onClick:()=>c&&o(!i),className:`inline-flex items-center gap-1.5 text-xs rounded-md px-2 py-1 transition-colors ${n?"bg-red-100 dark:bg-red-950/30 text-red-700 dark:text-red-400":"bg-green-100 dark:bg-green-950/30 text-green-700 dark:text-green-400"} ${c?"cursor-pointer hover:bg-opacity-80":""}`,children:[c&&h.jsx("span",{className:"transition-transform duration-200",children:i?h.jsx(J.ChevronDown,{className:"h-3 w-3"}):h.jsx(J.ChevronRight,{className:"h-3 w-3"})}),n?h.jsx(J.X,{className:"h-3 w-3"}):s?h.jsx(J.Zap,{className:"h-3 w-3"}):h.jsx(J.Check,{className:"h-3 w-3"}),h.jsxs("span",{className:"font-medium",children:[n?"Denied":s?"Auto-executed":"Executed"," ",t]})]}),i&&c&&h.jsx("div",{className:"mt-1 ml-6 p-2 bg-stone-50 dark:bg-stone-900 rounded-md border border-border",children:h.jsx("div",{className:"space-y-0.5",children:Object.entries(a).map(([u,l])=>h.jsxs("div",{className:"flex items-start gap-1.5 text-xs",children:[h.jsxs("span",{className:"text-muted-foreground min-w-[60px]",children:[u,":"]}),h.jsx("span",{className:"font-mono text-foreground",children:typeof l=="string"?l:JSON.stringify(l)})]},u))})})]})}function Lh({...t}){return h.jsx(bs.Root,{"data-slot":"collapsible",...t})}function Oh({...t}){return h.jsx(bs.CollapsibleTrigger,{"data-slot":"collapsible-trigger",...t})}function Fh({...t}){return h.jsx(bs.CollapsibleContent,{"data-slot":"collapsible-content",...t})}const Bh=m.lazy(()=>import("streamdown").then(t=>({default:t.Streamdown}))),ni=m.memo(({className:t,...e})=>typeof window>"u"?null:h.jsx(m.Suspense,{fallback:null,children:h.jsx(Bh,{className:tt("size-full [&>*:first-child]:mt-0 [&>*:last-child]:mb-0",t),...e})}),(t,e)=>t.children===e.children);ni.displayName="Response";const $h=Object.freeze(Object.defineProperty({__proto__:null,Response:ni},Symbol.toStringTag,{value:"Module"})),zh=({children:t,as:e="p",className:n,duration:s=2,spread:i=2})=>{const o=Eh.create(e),r=m.useMemo(()=>(t?.length??0)*i,[t,i]);return h.jsx(o,{animate:{backgroundPosition:"0% center"},className:tt("relative inline-block bg-[length:250%_100%,auto] bg-clip-text text-transparent","[--bg:linear-gradient(90deg,#0000_calc(50%-var(--spread)),var(--color-background),#0000_calc(50%+var(--spread)))] [background-repeat:no-repeat,padding-box]",n),initial:{backgroundPosition:"100% center"},style:{"--spread":`${r}px`,backgroundImage:"var(--bg), linear-gradient(var(--color-muted-foreground), var(--color-muted-foreground))"},transition:{repeat:Number.POSITIVE_INFINITY,duration:s,ease:"linear"},children:t})},Uh=m.memo(zh),ya=m.createContext(null),_h=()=>{const t=m.useContext(ya);if(!t)throw new Error("Reasoning components must be used within Reasoning");return t},Wh=1e3,Kh=1e3,xa=m.memo(({className:t,isStreaming:e=!1,open:n,defaultOpen:s=!0,onOpenChange:i,duration:o,children:r,...a})=>{const[c,u]=fi.useControllableState({prop:n,defaultProp:s,onChange:i}),[l,d]=fi.useControllableState({prop:o,defaultProp:0}),[f,p]=m.useState(!1),[y,v]=m.useState(null);m.useEffect(()=>{e?y===null&&v(Date.now()):y!==null&&(d(Math.ceil((Date.now()-y)/Kh)),v(null))},[e,y,d]),m.useEffect(()=>{if(s&&!e&&c&&!f){const x=setTimeout(()=>{u(!1),p(!0)},Wh);return()=>clearTimeout(x)}},[e,c,s,u,f]);const S=x=>{u(x)};return h.jsx(ya.Provider,{value:{isStreaming:e,isOpen:c,setIsOpen:u,duration:l},children:h.jsx(Lh,{className:tt("not-prose mb-4",t),onOpenChange:S,open:c,...a,children:r})})}),Hh=(t,e)=>t||e===0?h.jsx(Uh,{duration:1,children:"Thinking..."}):e===void 0?h.jsx("p",{children:"Thought for a few seconds"}):h.jsxs("p",{children:["Thought for ",e," seconds"]}),va=m.memo(({className:t,children:e,...n})=>{const{isStreaming:s,isOpen:i,duration:o}=_h();return h.jsx(Oh,{className:tt("flex w-full items-center gap-2 text-muted-foreground text-sm transition-colors hover:text-foreground",t),...n,children:e??h.jsxs(h.Fragment,{children:[h.jsx(J.BrainIcon,{className:"size-4"}),Hh(s,o),h.jsx(J.ChevronDownIcon,{className:tt("size-4 transition-transform",i?"rotate-180":"rotate-0")})]})})}),ba=m.memo(({className:t,children:e,...n})=>h.jsx(Fh,{className:tt("mt-4 text-sm","data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-top-2 data-[state=open]:slide-in-from-top-2 text-muted-foreground outline-none data-[state=closed]:animate-out data-[state=open]:animate-in",t),...n,children:h.jsx(ni,{className:"grid gap-2",children:e})}));xa.displayName="Reasoning";va.displayName="ReasoningTrigger";ba.displayName="ReasoningContent";function Xh(t){const e=/(?:^|\n)(?:#+\s*)?(?:References|References:)(?:\*\*)?\s*\n?([\s\S]*?)(?=\n\n|\n#|$)/i,n=t.match(e),s=new Map;if(n&&n[1]){const u=n[1],l=/\[(\d+)\]\s*(https?:\/\/[^\s\)]+)/g;let d;for(;(d=l.exec(u))!==null;)if(d[1]&&d[2]){const f=parseInt(d[1],10),p=d[2].replace(/[.,;:!?]+$/,"");s.set(f,p)}}const i=[];let o=0;const r=/```[\s\S]*?```|`[^`]+`/g;let a;for(;(a=r.exec(t))!==null;)a.index>o&&i.push({type:"text",content:t.slice(o,a.index),start:o,end:a.index}),i.push({type:"code",content:a[0],start:a.index,end:a.index+a[0].length}),o=a.index+a[0].length;return o<t.length&&i.push({type:"text",content:t.slice(o),start:o,end:t.length}),i.map(u=>{if(u.type==="code")return u.content;let l=u.content;l=l.replace(/\[(\d+)\]\((https?:\/\/[^\)]+)\)/g,(v,S,x)=>{const b=parseInt(S,10);return`<sup><a href="${x.replace(/"/g,""")}" target="_blank" rel="noopener noreferrer" class="text-blue-600 dark:text-blue-400 hover:underline font-medium">[${b}]</a></sup>`});const d=/\[([^\]]+)\]\([^\)]+\)/g,f=[];let p;for(;(p=d.exec(l))!==null;)f.push({start:p.index,end:p.index+p[0].length});return l.replace(/\[(\d+)\]/g,(v,S,x)=>{if(f.some(M=>x>=M.start&&x<M.end))return v;const T=parseInt(S,10),D=s.get(T);return D?`<sup><a href="${D.replace(/"/g,""")}" target="_blank" rel="noopener noreferrer" class="text-blue-600 dark:text-blue-400 hover:underline font-medium">[${T}]</a></sup>`:v})}).join("")}function $e(t){if(typeof t=="string")try{const e=JSON.parse(t);return $e(e)}catch{return t}if(Array.isArray(t))return t.map($e);if(t&&typeof t=="object"){const e={};for(const[n,s]of Object.entries(t))e[n]=$e(s);return e}return t}function qn(t){if(typeof t=="string"){try{const e=JSON.parse(t);if(e&&typeof e=="object"&&!Array.isArray(e))return $e(e)}catch{}return{}}return t&&typeof t=="object"&&!Array.isArray(t)?$e(t):{}}function Gh({theme:t="auto",layout:e="sidebar",model:n="auto",animated:s=!0,title:i="Chat",logo:o=void 0,defaultWidth:r=384,minWidth:a=300,maxWidth:c=800,initiallyExpanded:u=!1,tools:l=[],safeTools:d=[],toolMetadata:f,systemPrompt:p="",tokenEndpoint:y="/api/arcten/token",apiBaseUrl:v="https://api.arcten.com",user:S,initialState:x={},sharedStateId:b}){const[T,D]=m.useState(null),M=m.useRef(null),[I,R]=m.useState(null),[E,_]=m.useState(null),B=m.useRef(null),[ct,It]=m.useState(x),pt=m.useRef(x),[oe,Lt]=m.useState(!1),[Pn,U]=m.useState(null),$=m.useRef(!1),[Z,ot]=m.useState(u),[lt,Ot]=m.useState(r),[jt,ae]=m.useState(600),[Ae,Ft]=m.useState(!1),[z,gt]=m.useState(!1),[st,Kt]=m.useState(!1),[it,Ht]=m.useState({x:100,y:100}),[Pe,Me]=m.useState(!1),[ce,yt]=m.useState({x:0,y:0}),[Mn,je]=m.useState(!1),Xt=m.useRef(null),le=m.useRef(null),[Et,Gt]=m.useState(""),[Ze,jn]=m.useState(null),[En,Qe]=m.useState("Thinking..."),[Ee,ke]=m.useState(new Set),[kn,Dn]=m.useState(""),[C,A]=m.useState([]),[j,k]=m.useState(!1),[L,K]=m.useState([]),[G,kt]=m.useState(()=>typeof window<"u"?crypto.randomUUID():null),[xt,ue]=m.useState(!1),[si,tn]=m.useState(!1),[Jh,en]=m.useState([]),qt=m.useMemo(()=>[...l,...d],[l,d]),Tt=m.useMemo(()=>ga(qt,f),[qt,f]),ii=m.useMemo(()=>new Set(Tt.map(g=>g.name)),[Tt]),ri=m.useMemo(()=>Tt.filter(g=>ii.has(g.name)),[Tt,ii]),oi=m.useMemo(()=>{const g=new Map,w=new Map(Tt.map(N=>[N.name,N]));return qt.forEach(N=>{const P=N[Pt];if(P){const F=w.get(P);if(F){g.set(F.name,N);return}}const O=Tt.find(F=>F.name===N.name);O&&g.set(O.name,N)}),g},[qt,Tt]),ai=m.useMemo(()=>{const g=new Set,w=new Map(Tt.map(N=>[N.name,N]));return d.forEach(N=>{const P=N[Pt];if(P&&w.has(P))g.add(P);else{const O=Tt.find(F=>F.name===N.name);O&&g.add(O.name)}}),g},[d,Tt]),ci=["Thinking...","Pondering...","Contemplating...","Considering...","Analyzing...","Processing...","Reasoning...","Mulling it over...","Computing...","Cooking up a response...","Brewing ideas...","Connecting the dots...","Piecing it together...","Spinning up thoughts...","Loading brain cells...","Sharpening pencils...","Herding ideas...","Warming up neurons...","Stirring the think-pot...","Plotting a plan...","Wiggling the logic wires...","Rolling ideas around...","Charging the brainstorm...","Booting the brain...","Dusting off the cortex...","Running mental diagnostics...","Fetching cleverness...","Whisking up notions...","Tuning the idea radio...","Juggling possibilities...","Breathing in inspiration...","Squeezing the thought sponge...","Tickling the gray matter...","Bubbling up insights...","Spicing the soup of thought...","Lacing up hypotheses...","Winding the idea clock...","Casting the net for clues...","Polishing the crystal ball...","Mapping the maze...","Crunching the brain-biscuits...","Cueing the eureka moment...","Summoning the muse...","Knocking on insight’s door...","Combing the noodle...","Sailing the think-ship...","Scooping brain gelato...","Testing wild hunches...","Tick-tocking the neurons...","Planting idea seeds...","Shaking the thought snow globe...","Unlocking the mental toolbox...","Nudging the puzzle pieces...","Lighting the idea bulb...","Preheating the oven of insight...","Mixing the mental trail mix...","Spooling up reasoning reels...","Skimming the mind-palace index...","Surfing the thought waves...","Kicking the tires on ideas...","Rattling the idea can...","Waving the logic wand..."];m.useEffect(()=>{if(typeof window<"u"){const g=localStorage.getItem("arcten-sidebar-expanded");g&&ot(JSON.parse(g));const w=localStorage.getItem("arcten-sidebar-width");w&&Ot(parseInt(w));const N=localStorage.getItem("arcten-sidebar-height");N&&ae(parseInt(N));const P=localStorage.getItem("arcten-sidebar-detached");P&>(JSON.parse(P));const O=localStorage.getItem("arcten-sidebar-position");if(O){const ut=JSON.parse(O),Ct=50,$t=Math.max(Ct-r,Math.min(ut.x,window.innerWidth-Ct)),at=Math.max(0,Math.min(ut.y,window.innerHeight-Ct));Ht({x:$t,y:at})}const F=localStorage.getItem("arcten-sidebar-minimized");F&&Kt(JSON.parse(F)),je(!0)}},[]);const Bt=m.useMemo(()=>S,[S?.id]);m.useEffect(()=>((async()=>{try{const w=await fetch(y,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({user:Bt})});if(!w.ok)throw new Error("Failed to fetch token");const N=await w.json();D(N.clientToken),M.current=N.clientToken,_(N.expiresAt),R(null)}catch(w){R(w instanceof Error?w.message:"Failed to fetch token")}})(),()=>{B.current&&clearTimeout(B.current)}),[y,Bt]),m.useEffect(()=>{if(!E)return;B.current&&clearTimeout(B.current);const g=Math.floor(Date.now()/1e3),w=E-g,P=Math.max(0,w-5);return B.current=setTimeout(async()=>{try{const O=await fetch(y,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({user:Bt})});if(!O.ok)throw new Error("Failed to refresh token");const F=await O.json();D(F.clientToken),M.current=F.clientToken,_(F.expiresAt),R(null)}catch(O){console.error("Token refresh failed:",O),R(O instanceof Error?O.message:"Failed to refresh token")}},P*1e3),()=>{B.current&&clearTimeout(B.current)}},[E,y,Bt]),m.useEffect(()=>{(async()=>{if(qt.length!==0)try{const w=qt.map(P=>({name:P.name,code:P.toString()})),N=await fetch(`${v}/tools/describe`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({tools:w})});if(N.ok){const P=await N.json();A(P.tools)}}catch(w){console.error("Failed to fetch tool descriptions:",w)}})()},[qt]),m.useEffect(()=>{Promise.resolve().then(()=>$h).then(g=>{jn(()=>g.Response)})},[]),m.useEffect(()=>{const g=()=>{Dn(window.location.pathname)};g(),window.addEventListener("popstate",g);const w=setInterval(g,500);return()=>{window.removeEventListener("popstate",g),clearInterval(w)}},[]);const Vn=m.useCallback(async()=>{if(!(!Bt?.id||!T)){tn(!0);try{const w=await(await fetch(`${v}/conversations`,{headers:{Authorization:`Bearer ${T}`}})).json();K(w.conversations||[])}catch(g){console.error("Failed to fetch conversations:",g)}finally{tn(!1)}}},[Bt?.id,T,v]);m.useEffect(()=>{Bt?.id&&T&&Vn()},[Bt?.id,T,Vn]);function wa(g){const w=Math.floor((Date.now()-g)/1e3);return w<60?"now":w<3600?`${Math.floor(w/60)}m`:w<86400?`${Math.floor(w/3600)}h`:`${Math.floor(w/86400)}d`}function Ta(){const g=crypto.randomUUID();kt(g),sn([]),en([]),ue(!1),b||(pt.current=x,It(x),$.current=!1)}async function Sa(g){if(T)try{await fetch(`${v}/conversations/${g}`,{method:"DELETE",headers:{Authorization:`Bearer ${T}`}}),K(L.filter(w=>w._id!==g)),g===G&&Ta()}catch(w){console.error("Failed to delete conversation:",w)}}async function Ca(g){kt(g.chatId),ue(!1),tn(!0);try{const w=await fetch(`${v}/conversations/${g.chatId}/messages`,{headers:{Authorization:`Bearer ${M.current}`}});if(!w.ok)throw new Error(`Failed to fetch messages: ${w.statusText}`);const P=(await w.json()).messages||[];sn(P),en(P)}catch(w){console.error("Failed to load conversation messages:",w);const N=g.messages||[];sn(N),en(N)}finally{tn(!1)}}const Aa=async(g,w={})=>{const N=w.headers?new Headers(w.headers):new Headers;return N.delete("user-agent"),N.delete("User-Agent"),fetch(g,{...w,headers:N})},{messages:De,sendMessage:Pa,status:St,error:li,stop:nn,addToolResult:Ve,setMessages:sn}=kr.useChat({id:G||void 0,transport:new pn.DefaultChatTransport({api:`${v}/chat`,fetch:Aa,headers:()=>{const g={};return M.current&&(g.Authorization=`Bearer ${M.current}`),g},body:()=>({tools:ri.map(w=>({name:w.name,description:w.description,inputSchema:w.jsonSchema})),systemPrompt:p,currentRoute:kn,state:pt.current})}),sendAutomaticallyWhen:pn.lastAssistantMessageIsCompleteWithToolCalls});m.useEffect(()=>{if(!G||!M.current)return;(async()=>{Lt(!0),U(null);try{let w={};if(b){const O=await fetch(`${v.replace("/chat","")}/convex/api/query`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${M.current}`},body:JSON.stringify({path:"sharedStates:getByStateId",args:{stateId:b},format:"json"})});if(!O.ok){const ut=await O.text().catch(()=>"Unknown error");throw new Error(`Failed to fetch shared state: ${O.status} ${ut}`)}w=(await O.json())?.value||{}}else{const O=await fetch(`${v.replace("/chat","")}/convex/api/query`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${M.current}`},body:JSON.stringify({path:"conversations:getStateByChatId",args:{chatId:G},format:"json"})});if(!O.ok){const ut=await O.text().catch(()=>"Unknown error");throw new Error(`Failed to fetch conversation state: ${O.status} ${ut}`)}w=(await O.json())?.value||{}}const N=!$.current;let P;N?(P={...x,...w},$.current=!0):P=w,pt.current=P,It(P)}catch(w){console.error("Failed to fetch state:",w);const N=w instanceof Error?w:new Error(String(w));U(N),$.current||(pt.current=x,It(x),$.current=!0)}finally{Lt(!1)}})()},[G,b,v]),m.useEffect(()=>{Z&&le.current&&le.current.focus()},[Z,De]);function Ma(){ot(!0),localStorage.setItem("arcten-sidebar-expanded","true")}function ja(){ot(!1),localStorage.setItem("arcten-sidebar-expanded","false")}m.useEffect(()=>{},[Z]),m.useEffect(()=>{Xt.current&&Xt.current.scrollIntoView({behavior:"smooth"})},[De]),m.useEffect(()=>{function g(w){w.key==="Escape"&&(St==="streaming"||St==="submitted")&&(w.preventDefault(),nn())}return window.addEventListener("keydown",g),()=>window.removeEventListener("keydown",g)},[St,nn]);function Ea(){const g=crypto.randomUUID();kt(g),sn([]),en([]),ue(!1)}function ui(g){if(g.preventDefault(),!Et.trim())return;(St==="streaming"||St==="submitted")&&nn();const w=ci[Math.floor(Math.random()*ci.length)]||"Thinking...";Qe(w),Pa({text:Et}),Gt("")}function ka(g){const w=g.target.value;Gt(w)}m.useEffect(()=>{if(!Ae)return;function g(N){if(z){const P=N.clientX-it.x,O=N.clientY-it.y;P>=a&&P<=c&&Ot(P),O>=400&&O<=1e3&&ae(O)}else{const P=window.innerWidth-N.clientX;P>=a&&P<=c&&Ot(P)}}function w(){Ft(!1),localStorage.setItem("arcten-sidebar-width",lt.toString()),localStorage.setItem("arcten-sidebar-height",jt.toString())}return window.addEventListener("mousemove",g),window.addEventListener("mouseup",w),()=>{window.removeEventListener("mousemove",g),window.removeEventListener("mouseup",w)}},[Ae,lt,jt,z,it,a,c]);function Da(g){g.preventDefault(),Ft(!0)}function Va(){gt(!0),Kt(!1),localStorage.setItem("arcten-sidebar-detached","true"),localStorage.setItem("arcten-sidebar-minimized","false")}function Ra(){gt(!1),Kt(!1),localStorage.setItem("arcten-sidebar-detached","false"),localStorage.setItem("arcten-sidebar-minimized","false")}function di(){Kt(!st),localStorage.setItem("arcten-sidebar-minimized",JSON.stringify(!st))}function Na(g){z&&(Me(!0),yt({x:g.clientX-it.x,y:g.clientY-it.y}))}return m.useEffect(()=>{if(!z)return;function g(){Ht(w=>{const P=window.innerWidth-50,O=window.innerHeight-50,F=50-lt,ut=0,Ct=Math.max(F,Math.min(w.x,P)),$t=Math.max(ut,Math.min(w.y,O));if(Ct!==w.x||$t!==w.y){const at={x:Ct,y:$t};return localStorage.setItem("arcten-sidebar-position",JSON.stringify(at)),at}return w})}return window.addEventListener("resize",g),()=>window.removeEventListener("resize",g)},[z,lt]),m.useEffect(()=>{if(!Pe)return;function g(N){const P=N.clientX-ce.x,O=N.clientY-ce.y,F=50,ut=window.innerWidth-F,Ct=window.innerHeight-F,$t=F-lt,at=0,Dt=Math.max($t,Math.min(P,ut)),At=Math.max(at,Math.min(O,Ct));Ht({x:Dt,y:At})}function w(){Me(!1),localStorage.setItem("arcten-sidebar-position",JSON.stringify(it))}return window.addEventListener("mousemove",g),window.addEventListener("mouseup",w),()=>{window.removeEventListener("mousemove",g),window.removeEventListener("mouseup",w)}},[Pe,ce,it,lt]),Mn?I?h.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:h.jsxs("div",{className:"p-4 bg-destructive/10 text-destructive text-sm rounded-lg",children:["Authentication error: ",I]})}):T?h.jsx(tu,{features:kh,children:h.jsx(ln,{id:"arcten-sidebar","data-theme":t,"data-layout":e,"data-model":n,initial:z?{opacity:0,scale:.95,filter:"blur(4px)"}:!1,animate:z?{opacity:1,scale:1,filter:"blur(0px)"}:{},transition:{duration:.2,ease:"easeOut"},className:`
|
|
20
20
|
${z?"fixed z-50 shadow-xl rounded-xl":"h-screen flex-shrink-0 relative rounded-l-2xl"}
|
|
21
21
|
${Z?"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"}
|
|
22
22
|
${z?"border border-border":"border-l border-border"}
|
package/dist/index.mjs
CHANGED
|
@@ -5347,13 +5347,14 @@ ka.displayName = "ReasoningTrigger";
|
|
|
5347
5347
|
Na.displayName = "ReasoningContent";
|
|
5348
5348
|
function yf(t) {
|
|
5349
5349
|
const e = /(?:^|\n)(?:#+\s*)?(?:References|References:)(?:\*\*)?\s*\n?([\s\S]*?)(?=\n\n|\n#|$)/i, n = t.match(e), s = /* @__PURE__ */ new Map();
|
|
5350
|
-
if (n) {
|
|
5350
|
+
if (n && n[1]) {
|
|
5351
5351
|
const u = n[1], l = /\[(\d+)\]\s*(https?:\/\/[^\s\)]+)/g;
|
|
5352
5352
|
let d;
|
|
5353
|
-
for (; (d = l.exec(u)) !== null; )
|
|
5354
|
-
|
|
5355
|
-
|
|
5356
|
-
|
|
5353
|
+
for (; (d = l.exec(u)) !== null; )
|
|
5354
|
+
if (d[1] && d[2]) {
|
|
5355
|
+
const h = parseInt(d[1], 10), m = d[2].replace(/[.,;:!?]+$/, "");
|
|
5356
|
+
s.set(h, m);
|
|
5357
|
+
}
|
|
5357
5358
|
}
|
|
5358
5359
|
const i = [];
|
|
5359
5360
|
let o = 0;
|