PageSourceSearch

https://horizon-pro-7072.taskade.app/chunks/chunk-7G2UIJPM.js

js horizon-pro-7072.taskade.app collected 2026-10-03 15:03:30 UTC 5,292 bytes, 2 lines download raw bytes

1var __IMPORT_META_ENV={};var __PROCESS_ENV={NODE_ENV:"production"};
2import{a as L}from"/chunks/chunk-2F2XG2RD.js";import{a as T}from"/chunks/chunk-WYEFLEXC.js";import{d as K}from"/chunks/chunk-43M3N6VY.js";function R(s){return s==null||s.trim().length===0}async function I(s,p){if(R(s))throw new Error("Agent ID cannot be empty");let v=`${p?.baseUrl??""}/api/taskade/agents/${encodeURIComponent(s)}/public-conversations`,c=await fetch(v,{method:"POST",headers:{"Content-Type":"application/json"}}),y=c.headers.get("content-type")||"",g=await c.text().catch(()=>"");if(!c.ok)throw new Error(`Failed to create conversation: ${c.status} ${g||"Unknown error"}`);if(!y.includes("application/json"))throw new Error(`Invalid response format: expected JSON, got ${y}. Response: ${g.substring(0,100)}`);try{return JSON.parse(g)}catch(f){throw new Error(`Failed to parse JSON response: ${f instanceof Error?f.message:"Unknown error"}. Response: ${g.substring(0,200)}`)}}async function $(s,p,a,v){if(R(s))throw new Error("Agent ID cannot be empty");if(R(p))throw new Error("Conversation ID cannot be empty");let c=a.trim();if(R(c))throw new Error("Message text cannot be empty");let g=`${v?.baseUrl??""}/api/taskade/agents/${encodeURIComponent(s)}/public-conversations/${encodeURIComponent(p)}/messages`,f=await fetch(g,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:c})}),m=f.headers.get("content-type")||"",i=await f.text().catch(()=>"");if(!f.ok){let u=`Failed to send message: ${f.status}`;try{let t=JSON.parse(i);t.message&&(u=t.message)}catch{i&&(u=`${u}: ${i.substring(0,100)}`)}throw new Error(u)}if(!m.includes("application/json"))throw new Error(`Invalid response format: expected JSON, got ${m}. Response: ${i.substring(0,100)}`);try{return JSON.parse(i)}catch(u){throw new Error(`Failed to parse JSON response: ${u instanceof Error?u.message:"Unknown error"}. Response: ${i.substring(0,200)}`)}}var r=K(L());function Q(s,p,a){let[v,c]=(0,r.useState)(new Map),[y,g]=(0,r.useState)(!1),[f,m]=(0,r.useState)(null),[i,u]=(0,r.useState)(p),t=(0,r.useRef)(null),A=(0,r.useRef)([]),S=(0,r.useRef)(null),w=(0,r.useRef)(p),D=(0,r.useRef)(p);(0,r.useEffect)(()=>{let n=D.current,e=p;n!==e&&e!=null&&n!=null&&(c(new Map),t.current&&t.current.clearMessages()),u(e),w.current=e,D.current=e},[p]),(0,r.useEffect)(()=>()=>{t.current&&(t.current.disconnect(),t.current=null,S.current=null)},[]);let F=(0,r.useMemo)(()=>{let n=Array.from(v.values());return n.sort((e,x)=>e.id.localeCompare(x.id)),n},[v]);(0,r.useEffect)(()=>{if(!i){t.current&&(t.current.clearMessages(),t.current.disconnect(),t.current=null,S.current=null,g(!1)),c(new Map),w.current=null;return}w.current=i,A.current.forEach(l=>l()),A.current=[];let n=[],e=!0,x=()=>{e=!1,n.forEach(l=>l())};try{if(!s)throw new Error("Invalid parameters: agentId is required");let l=()=>{let C=t.current;C&&c(d=>{let E=new Map(d);for(let[M,h]of C.messages){let U=d.get(M);if(!U||U.role==="assistant"){let G={...U,...h,id:M,role:"assistant",content:typeof h.content=="string"&&h.content.length>0?h.content:U?.content||""};E.set(M,G)}}return E})},o,b=t.current,O=b&&S.current!==s;if(O&&b&&(c(C=>{let d=new Map(C);for(let[E,M]of b.messages)if(!d.has(E))d.set(E,M);else{let h=C.get(E);if(h?.role==="user")continue;(h?.role==="assistant"||!h)&&d.set(E,{...h,...M,id:E,role:"assistant"})}return d}),b.disconnect(),t.current=null,S.current=null),t.current&&!O)o=t.current,o.setConversationId(i);else{let C={baseUrl:a?.baseUrl,autoReconnect:a?.autoReconnect??!0,reconnectDelay:a?.reconnectDelay,onError:d=>{e&&m(d),a?.onError?.(d)}};o=new T(s,i,C),t.current=o,S.current=s}let j=o.on("open",()=>{e&&(g(!0),m(null))});n.push(j);let H=o.on("close",()=>{e&&g(!1)});n.push(H);let z=o.on("text-delta",()=>{e&&l()});n.push(z);let q=o.on("finish",()=>{e&&l()});n.push(q);let B=o.on("error",C=>{e&&m(new Error(C.errorText))});n.push(B),A.current=n,a?.autoConnect!==!1&&o.connect()}catch(l){if(e){let o=l instanceof Error?l:new Error("Failed to initialize chat");m(o),console.error("[useAgentChat] Initialization error:",o)}}return x},[s,i,a?.baseUrl,a?.autoReconnect,a?.reconnectDelay,a?.autoConnect,a?.onError]);let k=(0,r.useCallback)(async n=>{let e=i;if(!e)throw new Error("No conversation available. Create a conversation first.");let x={baseUrl:a?.baseUrl};try{m(null);let l=await $(s,e,n,x);if(w.current!==e)return;let o={id:l.messageId,content:n,isComplete:!0,role:"user"};c(b=>{let O=new Map(b);return O.set(l.messageId,o),O})}catch(l){let o=l instanceof Error?l:new Error("Failed to send message");throw m(o),o}},[s,i,a?.baseUrl]),N=(0,r.useCallback)(async()=>{let n={baseUrl:a?.baseUrl},{conversationId:e}=await I(s,n);return u(e),w.current=e,c(new Map),t.current&&t.current.setConversationId(e),e},[s,a?.baseUrl]),J=(0,r.useCallback)(n=>{u(n),w.current=n,c(new Map),t.current&&t.current.setConversationId(n)},[]),P=(0,r.useCallback)(()=>
2{if(!i)throw new Error("Cannot connect: no conversation available. Create a conversation first.");if(!t.current)throw new Error("Cannot connect: stream not initialized. Ensure conversationId is provided.");t.current.connect()},[i]);return{sendMessage:k,messages:F,isConnected:y,error:f,conversationId:i,createConversation:N,switchConversation:J,connect:P}}export{I as a,$ as b,Q as c};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.