"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const q=require("react/jsx-runtime");require("@langchain/langgraph-sdk");const e=require("react"),x=require("./ChatRuntime.cjs.js"),l=require("./client.cjs.js"),T=require("../utils/logger.cjs.js"),$=require("../node_modules/.pnpm/uuid@13.0.0/node_modules/uuid/dist/validate.cjs.js"),g=e.createContext(void 0);function R(a){return $(a)?{assistant_id:a}:{graph_id:a}}function j({children:a,initialMode:v="single"}){const{apiUrl:t,assistantId:s,identity:r}=x.useChatRuntime(),[k,i]=e.useState([]),[m,C]=e.useState(!1),[u,c]=e.useState(null),[w,b]=e.useState(),[S,y]=e.useState(v);e.useEffect(()=>{const n=new URLSearchParams(window.location.search).get("thread");n&&c(n)},[]);const d=e.useCallback(async()=>{if(!t||!s)return[];if(!r?.authToken)return T.logger.error("No authToken available for getThreads"),[];const n=await l.createClient(t,r?.authToken??void 0).threads.search({metadata:{...R(s)},limit:100});return Array.isArray(n)?n:[]},[t,s,r]),P=e.useCallback(async o=>{if(!t)return;if(!r?.authToken){T.logger.error("No authToken available for deleteThread");return}await l.createClient(t,r?.authToken??void 0).threads.delete(o),i(f=>f.filter(h=>h.thread_id!==o)),u===o&&c(null)},[t,u,r]),p=e.useCallback(async(o,n)=>{if(!t)return;if(!r?.authToken){T.logger.error("No authToken available for updateThread");return}await l.createClient(t,r?.authToken??void 0).threads.update(o,{metadata:n});const h=await d();i(h)},[t,d,r]);return q.jsx(g.Provider,{value:{mode:S,setMode:y,threadId:u,setThreadId:c,getThreads:d,threads:k,setThreads:i,configuration:w,setConfiguration:b,threadsLoading:m,setThreadsLoading:C,deleteThread:P,updateThread:p},children:a})}function L(){const a=e.useContext(g);if(!a)throw new Error("useThread must be used within a ThreadProvider");return a}exports.ThreadProvider=j;exports.useThread=L;
//# sourceMappingURL=Thread.cjs.js.map
