zen-code 4.10.1 → 5.0.0

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.
Files changed (89) hide show
  1. package/dist/app.js +151 -2699
  2. package/dist/chunk-069q9hkz.js +1 -0
  3. package/dist/chunk-06trk066.js +1 -0
  4. package/dist/chunk-0kfw8bwn.js +2 -0
  5. package/dist/chunk-0mq8786q.js +281 -0
  6. package/dist/chunk-0qz8rr2k.js +1 -0
  7. package/dist/chunk-1d47g6nc.js +2 -0
  8. package/dist/chunk-1gssqf6g.js +88 -0
  9. package/dist/chunk-1rcc9xzn.js +79 -0
  10. package/dist/chunk-2bjeg40f.js +1 -0
  11. package/dist/chunk-2gd8vzrf.js +2 -0
  12. package/dist/chunk-2gprcgep.js +6 -0
  13. package/dist/chunk-3k3c686f.js +1 -0
  14. package/dist/chunk-43h0n2td.js +1 -0
  15. package/dist/chunk-492hjs9k.js +26 -0
  16. package/dist/chunk-4eaqmt3c.js +16 -0
  17. package/dist/chunk-4fs853nh.js +2 -0
  18. package/dist/chunk-5fe27s34.js +2 -0
  19. package/dist/chunk-5hqvapp1.js +7 -0
  20. package/dist/chunk-6b3vfr39.js +2 -0
  21. package/dist/chunk-6j695pam.js +5 -0
  22. package/dist/chunk-6saqxa3z.js +2 -0
  23. package/dist/chunk-78ksrp8v.js +41 -0
  24. package/dist/chunk-7cx9kda0.js +228 -0
  25. package/dist/chunk-7qba2raw.js +2 -0
  26. package/dist/chunk-81b2s97q.js +1 -0
  27. package/dist/chunk-88w3txtb.js +160 -0
  28. package/dist/chunk-8ygdre0g.js +1 -0
  29. package/dist/chunk-9011y634.js +6 -0
  30. package/dist/chunk-9zcr1qh6.js +1 -0
  31. package/dist/chunk-a0nr8jva.js +2 -0
  32. package/dist/chunk-agevsn2e.js +1 -0
  33. package/dist/chunk-akc3s5aw.js +6 -0
  34. package/dist/chunk-b0beqmg2.js +2 -0
  35. package/dist/chunk-b175s7dm.js +1 -0
  36. package/dist/chunk-bk32cwxa.js +5 -0
  37. package/dist/chunk-bn077sjq.js +213 -0
  38. package/dist/chunk-c9yrpb3g.js +18 -0
  39. package/dist/chunk-cb0f54ar.js +3 -0
  40. package/dist/chunk-ctqtahz4.js +1 -0
  41. package/dist/chunk-d2sr8fnm.js +3 -0
  42. package/dist/chunk-d5gzkkgg.js +1 -0
  43. package/dist/chunk-dh2f4xyb.js +3 -0
  44. package/dist/chunk-dr32dt9y.js +1 -0
  45. package/dist/chunk-dv1vt080.js +1 -0
  46. package/dist/chunk-dz9sqfph.js +2 -0
  47. package/dist/chunk-e7mbewmw.js +1 -0
  48. package/dist/chunk-em03xqy9.js +1 -0
  49. package/dist/chunk-fkt5b511.js +1 -0
  50. package/dist/chunk-gphssgy6.js +2 -0
  51. package/dist/chunk-h2hk7vx4.js +1 -0
  52. package/dist/chunk-h7ypcqp3.js +279 -0
  53. package/dist/chunk-j8tq0e8m.js +2 -0
  54. package/dist/chunk-jd1razfg.js +91 -0
  55. package/dist/chunk-jhxvctg5.js +8 -0
  56. package/dist/chunk-kada5fyh.js +1 -0
  57. package/dist/chunk-kgc6ws03.js +1 -0
  58. package/dist/chunk-mk8ggmt8.js +17 -0
  59. package/dist/chunk-mv5m8bf4.js +140 -0
  60. package/dist/chunk-mv8a5svx.js +1 -0
  61. package/dist/chunk-n61yv4t5.js +2 -0
  62. package/dist/chunk-nt2yp4jh.js +1 -0
  63. package/dist/chunk-p7ew4trx.js +1 -0
  64. package/dist/chunk-pgnhcznr.js +4 -0
  65. package/dist/chunk-q8cfxky4.js +8 -0
  66. package/dist/chunk-q8zsxwd8.js +81 -0
  67. package/dist/chunk-qfa5v4n5.js +1 -0
  68. package/dist/chunk-qhzztj83.js +1 -0
  69. package/dist/chunk-snmkgfbe.js +15 -0
  70. package/dist/chunk-ss4bh5wb.js +2 -0
  71. package/dist/chunk-sv0k2v66.js +1 -0
  72. package/dist/chunk-tbav8trq.js +23 -0
  73. package/dist/chunk-tmyzfvsy.js +1 -0
  74. package/dist/chunk-ts4jreym.js +7 -0
  75. package/dist/chunk-tws3wcnm.js +2 -0
  76. package/dist/chunk-v0e9bsvt.js +89 -0
  77. package/dist/chunk-vwj4n000.js +4 -0
  78. package/dist/chunk-wd6s7gg7.js +175 -0
  79. package/dist/chunk-y524zd2h.js +54 -0
  80. package/dist/chunk-yb71zqvt.js +2 -0
  81. package/dist/chunk-yejgw2hm.js +112 -0
  82. package/dist/chunk-yfjs6pf8.js +3 -0
  83. package/dist/chunk-zhqdp4ak.js +2 -0
  84. package/dist/chunk-zkd3m39v.js +1 -0
  85. package/dist/cli.js +1 -3116
  86. package/dist/nonInteractive.js +180 -1950
  87. package/dist/zen-core.js +644 -0
  88. package/dist/zen-keyboard.js +3 -358
  89. package/package.json +5 -3
@@ -0,0 +1 @@
1
+ import"./chunk-4fs853nh.js";var V=((f)=>{return f.NETWORK_ERROR="NETWORK_ERROR",f.CONNECTION_TIMEOUT="CONNECTION_TIMEOUT",f.INTERNAL_ERROR="INTERNAL_ERROR",f.THREAD_NOT_FOUND="THREAD_NOT_FOUND",f.THREAD_BUSY="THREAD_BUSY",f.RUN_NOT_FOUND="RUN_NOT_FOUND",f.GRAPH_NOT_FOUND="GRAPH_NOT_FOUND",f.INVALID_REQUEST="INVALID_REQUEST",f})(V||{});class N extends Error{constructor(f,w,x){super(w);this.code=f,this.statusCode=x,this.name="RemoteApiError"}}async function O(f,w,x){try{let z=f;if(x?.query){let W=new URLSearchParams;Object.entries(x.query).forEach(([Z,_])=>{W.append(Z,String(_))}),z+=`?${W.toString()}`}let Q=await fetch(z,{method:w,headers:{"Content-Type":"application/json"},body:x?.body?JSON.stringify(x.body):void 0}),H=await Q.json();if(!Q.ok||!H.success)throw new N(H.error?.code||V.INTERNAL_ERROR,H.error?.message||"Unknown error",Q.status);return H}catch(z){if(z instanceof N)throw z;throw new N(V.NETWORK_ERROR,`Network error: ${z instanceof Error?z.message:"Unknown error"}`)}}async function J(f,w){return O(f,"GET",{query:w})}async function F(f,w,x){return O(f,"POST",{body:w,query:x})}async function Y(f,w,x){return O(f,"PUT",{body:w,query:x})}async function $(f,w){return O(f,"DELETE",{query:w})}class j{constructor(f,w){this.serverUrl=f,this.httpClient=w,this.serverUrl=f.replace(/\/$/,""),this.httpClient=w||fetch}async setup(){await F(`${this.serverUrl}/setup`)}async create(f){return(await F(`${this.serverUrl}/threads`,f)).data}async search(f){let w={};if(f?.ids!==void 0&&f.ids.length>0)w.ids=JSON.stringify(f.ids);if(f?.metadata!==void 0)w.metadata=JSON.stringify(f.metadata);if(f?.limit!==void 0)w.limit=f.limit;if(f?.offset!==void 0)w.offset=f.offset;if(f?.status!==void 0)w.status=f.status;if(f?.sortBy!==void 0)w.sortBy=f.sortBy;if(f?.sortOrder!==void 0)w.sortOrder=f.sortOrder;if(f?.values!==void 0)w.values=JSON.stringify(f.values);if(f?.select!==void 0)w.select=JSON.stringify(f.select);if(f?.withoutDetails!==void 0)w.withoutDetails=f.withoutDetails;return(await J(`${this.serverUrl}/threads`,w)).data}async get(f){return(await J(`${this.serverUrl}/threads/${f}`)).data}async set(f,w){await Y(`${this.serverUrl}/threads/${f}`,w)}async delete(f){await $(`${this.serverUrl}/threads/${f}`)}async updateState(f,w){return(await F(`${this.serverUrl}/threads/${f}/state`,w)).data}async createRun(f,w,x){return(await F(`${this.serverUrl}/threads/${f}/runs`,x||{},{assistantId:w})).data}async listRuns(f,w){let x={};if(w?.limit!==void 0)x.limit=w.limit;if(w?.offset!==void 0)x.offset=w.offset;if(w?.status!==void 0)x.status=w.status;return(await J(`${this.serverUrl}/threads/${f}/runs`,x)).data}async updateRun(f,w){await Y(`${this.serverUrl}/runs/${f}`,w)}async count(f){let w={};if(f?.ids!==void 0&&f.ids.length>0)w.ids=JSON.stringify(f.ids);if(f?.metadata!==void 0)w.metadata=JSON.stringify(f.metadata);if(f?.status!==void 0)w.status=f.status;if(f?.values!==void 0)w.values=JSON.stringify(f.values);return(await J(`${this.serverUrl}/threads/count`,w)).data}async patch(f,w){return(await F(`${this.serverUrl}/threads/${f}`,w)).data}async getState(f,w){let x={};if(w?.subgraphs!==void 0)x.subgraphs=w.subgraphs;if(w?.checkpointId!==void 0)x.checkpointId=w.checkpointId;return(await F(`${this.serverUrl}/threads/${f}/state`,x)).data}async getStateHistory(f,w){let x={};if(w?.limit!==void 0)x.limit=w.limit;if(w?.before!==void 0)x.before=w.before;return(await F(`${this.serverUrl}/threads/${f}/history`,x)).data}async copy(f){return(await F(`${this.serverUrl}/threads/${f}/copy`)).data}async setTitleIfNull(f,w){try{return(await F(`${this.serverUrl}/threads/${f}/title`,{title:w})).data.success}catch(x){let z=await this.get(f);if(z?.title===null||z?.title===void 0)return await this.set(f,{title:w}),!0;return!1}}}export{j as RemoteKyselyThreadsManager};
@@ -0,0 +1,2 @@
1
+ var O=(h)=>typeof h==="object"&&h!==null,A=(h)=>{if(!O(h))return!1;if(h instanceof RegExp||h instanceof Error||h instanceof Date||h instanceof Map||h instanceof Set||h instanceof WeakMap||h instanceof WeakSet||h instanceof Promise||h instanceof ArrayBuffer||h instanceof DataView||ArrayBuffer.isView(h)||globalThis.Blob&&h instanceof globalThis.Blob)return!1;if(typeof h.$$typeof==="symbol"||typeof h.asymmetricMatch==="function")return!1;return!0},S=Symbol("mapObjectSkip"),P=(h,f)=>{if(f){let d=Object.keys(h),M=Object.getOwnPropertySymbols(h).filter((z)=>Object.getOwnPropertyDescriptor(h,z)?.enumerable);return[...d,...M]}return Object.keys(h)},N=(h,f,d,M=new WeakMap)=>{let{target:z={},...Y}={deep:!1,includeSymbols:!1,...d};if(M.has(h))return M.get(h);M.set(h,z);let $=(q)=>q.map((Q)=>A(Q)?N(Q,f,Y,M):Q);if(Array.isArray(h))return $(h);for(let q of P(h,Y.includeSymbols)){let Q=h[q],I=f(q,Q);if(I===S)continue;if(!Array.isArray(I))throw TypeError(`Mapper must return an array or mapObjectSkip, got ${I===null?"null":typeof I}`);if(I.length<2)throw TypeError(`Mapper must return an array with at least 2 elements [key, value], got ${I.length} elements`);let[J,X,{shouldRecurse:_=!0}={}]=I;if(J==="__proto__")continue;if(Y.deep&&_&&A(X))X=Array.isArray(X)?$(X):N(X,f,Y,M);try{z[J]=X}catch(G){if(G.name==="TypeError"&&G.message.includes("read only"))continue;throw G}}return z};function K(h,f,d){if(!O(h))throw TypeError(`Expected an object, got \`${h}\` (${typeof h})`);if(Array.isArray(h))throw TypeError("Expected an object, got an array");return N(h,(z,Y)=>f(z,Y,h),d)}var w=/[\p{Lu}]/u,U=/[\p{Ll}]/u,L=/^[\p{Lu}](?![\p{Lu}])/u,V=/[_.\- ]+/,R=/([\p{Alpha}\p{N}_]|$)/u,k=new RegExp("^"+V.source),j=new RegExp(V.source+R.source,"gu"),y=new RegExp(String.raw`\d+`+R.source,"gu"),b=(h,f,d,M)=>{let z=!1,Y=!1,$=!1,q=!1;for(let Q=0;Q<h.length;Q++){let I=h[Q];if(q=Q>2?h[Q-3]==="-":!0,z&&w.test(I))h=h.slice(0,Q)+"-"+h.slice(Q),z=!1,$=Y,Y=!0,Q++;else if(Y&&$&&U.test(I)&&(!q||M))h=h.slice(0,Q-1)+"-"+h.slice(Q-1),$=Y,Y=!1,z=!0;else z=f(I)===I&&d(I)!==I,$=Y,Y=d(I)===I&&f(I)!==I}return h},m=(h,f)=>h.replace(L,(d)=>f(d)),C=(h,f,d)=>{let M="",z=!1,Y=!1,$=[...h];for(let q=0;q<$.length;q++){let Q=$[q],I=w.test(Q),J=q+1<$.length&&w.test($[q+1]);if(z&&/[\p{Alpha}]/u.test(Q))M+=Q,z=!1,Y=I;else if(d&&I&&(Y||J))M+=Q,Y=!0;else if(/\d/.test(Q))M+=Q,z=!0,Y=!1;else if(V.test(Q))M+=Q,Y=!1;else M+=f(Q),z=!1,Y=!1}return M},l=(h,f,{capitalizeAfterNumber:d})=>{let M=d?(z,Y,$,q)=>{let Q=q.charAt($+z.length);if(V.test(Q))return z;return Y?z.slice(0,-Y.length)+f(Y):z}:(z)=>z;return h.replaceAll(y,M).replaceAll(j,(z,Y)=>f(Y))};function W(h,f){if(!(typeof h==="string"||Array.isArray(h)))throw TypeError("Expected the input to be `string | string[]`");if(f={pascalCase:!1,preserveConsecutiveUppercase:!1,capitalizeAfterNumber:!0,...f},Array.isArray(h))h=h.map(($)=>$.trim()).filter(($)=>$.length>0).join("-");else h=h.trim();if(h.length===0)return"";let d=h.match(/^[_$]*/)[0];if(h=h.slice(d.length),h.length===0)return d;let M=f.locale===!1?($)=>$.toLowerCase():($)=>$.toLocaleLowerCase(f.locale),z=f.locale===!1?($)=>$.toUpperCase():($)=>$.toLocaleUpperCase(f.locale);if(h.length===1){if(V.test(h))return d;return d+(f.pascalCase?z(h):M(h))}if(h!==M(h))h=b(h,M,z,f.preserveConsecutiveUppercase);if(h=h.replace(k,""),f.capitalizeAfterNumber)h=f.preserveConsecutiveUppercase?m(h,M):M(h);else h=C(h,M,f.preserveConsecutiveUppercase);if(f.pascalCase&&h.length>0)h=z(h[0])+h.slice(1);return d+l(h,z,f)}class D extends Map{#d=0;#h=new Map;#f=new Map;#z;#Q;#Y;constructor(h={}){super();if(!(h.maxSize&&h.maxSize>0))throw TypeError("`maxSize` must be a number greater than 0");if(typeof h.maxAge==="number"&&h.maxAge===0)throw TypeError("`maxAge` must be a number greater than 0");this.#z=h.maxSize,this.#Q=h.maxAge||Number.POSITIVE_INFINITY,this.#Y=h.onEviction}get __oldCache(){return this.#f}#$(h){if(typeof this.#Y!=="function")return;for(let[f,d]of h)this.#Y(f,d.value)}#M(h,f){if(typeof f.expiry==="number"&&f.expiry<=Date.now()){if(typeof this.#Y==="function")this.#Y(h,f.value);return this.delete(h)}return!1}#J(h,f){if(this.#M(h,f)===!1)return f.value}#q(h,f){return f.expiry?this.#J(h,f):f.value}#x(h,f){let d=f.get(h);return this.#q(h,d)}#H(h,f){if(this.#h.set(h,f),this.#d++,this.#d>=this.#z)this.#d=0,this.#$(this.#f),this.#f=this.#h,this.#h=new Map}#X(h,f){this.#f.delete(h),this.#H(h,f)}*#I(){for(let h of this.#f){let[f,d]=h;if(!this.#h.has(f)){if(this.#M(f,d)===!1)yield h}}for(let h of this.#h){let[f,d]=h;if(this.#M(f,d)===!1)yield h}}get(h){if(this.#h.has(h)){let f=this.#h.get(h);return this.#q(h,f)}if(this.#f.has(h)){let f=this.#f.get(h);if(this.#M(h,f)===!1)return this.#X(h,f),f.value}}set(h,f,{maxAge:d=this.#Q}={}){let M=typeof d==="number"&&d!==Number.POSITIVE_INFINITY?Date.now()+d:void 0;if(this.#h.has(h))this.#h.set(h,{value:f,expiry:M});else this.#H(h,{value:f,expiry:M});return this}has(h){if(this.#h.has(h))return!this.#M(h,this.#h.get(h));if(this.#f.has(h))return!this.#M(h,this.#f.get(h));return!1}peek(h){if(this.#h.has(h))return this.#x(h,this.#h);if(this.#f.has(h))return this.#x(h,this.#f)}expiresIn(h){let f=this.#h.get(h)??this.#f.get(h);if(f)return f.expiry?f.expiry-Date.now():Number.POSITIVE_INFINITY}delete(h){let f=this.#h.delete(h);if(f)this.#d--;return this.#f.delete(h)||f}clear(){this.#h.clear(),this.#f.clear(),this.#d=0}resize(h){if(!(h&&h>0))throw TypeError("`maxSize` must be a number greater than 0");let f=[...this.#I()],d=f.length-h;if(d<0)this.#h=new Map(f),this.#f=new Map,this.#d=f.length;else{if(d>0)this.#$(f.slice(0,d));this.#f=new Map(f.slice(d)),this.#h=new Map,this.#d=0}this.#z=h}evict(h=1){let f=Number(h);if(!f||f<=0)return;let d=[...this.#I()],M=Math.trunc(Math.min(f,Math.max(d.length-1,0)));if(M<=0)return;this.#$(d.slice(0,M)),this.#f=new Map(d.slice(M)),this.#h=new Map,this.#d=0}*keys(){for(let[h]of this)yield h}*values(){for(let[,h]of this)yield h}*[Symbol.iterator](){for(let h of this.#h){let[f,d]=h;if(this.#M(f,d)===!1)yield[f,d.value]}for(let h of this.#f){let[f,d]=h;if(!this.#h.has(f)){if(this.#M(f,d)===!1)yield[f,d.value]}}}*entriesDescending(){let h=[...this.#h];for(let f=h.length-1;f>=0;--f){let d=h[f],[M,z]=d;if(this.#M(M,z)===!1)yield[M,z.value]}h=[...this.#f];for(let f=h.length-1;f>=0;--f){let d=h[f],[M,z]=d;if(!this.#h.has(M)){if(this.#M(M,z)===!1)yield[M,z.value]}}}*entriesAscending(){for(let[h,f]of this.#I())yield[h,f.value]}get size(){if(!this.#d)return this.#f.size;let h=0;for(let f of this.#f.keys())if(!this.#h.has(f))h++;return Math.min(this.#d+h,this.#z)}get maxSize(){return this.#z}get maxAge(){return this.#Q}entries(){return this.entriesAscending()}forEach(h,f=this){for(let[d,M]of this.entriesAscending())h.call(f,M,d,this)}get[Symbol.toStringTag](){return"QuickLRU"}toString(){return`QuickLRU(${this.size}/${this.maxSize})`}[Symbol.for("nodejs.util.inspect.custom")](){return this.toString()}}var v=(h,f)=>h.some((d)=>{if(typeof d==="string")return d===f;return d.lastIndex=0,d.test(f)}),c=(h)=>h.trim()!==""&&!Number.isNaN(Number(h)),E=new D({maxSize:1e5}),s=(h)=>ArrayBuffer.isView(h)||h instanceof Date||h instanceof RegExp||h instanceof Error||h instanceof Map||h instanceof Set||h instanceof WeakMap||h instanceof WeakSet||h instanceof Promise,T=(h)=>typeof h==="object"&&h!==null&&!s(h),B=(h,f={},d=new WeakMap,M)=>{if(!T(h))return h;if(d.has(h))return d.get(h);let{exclude:z,pascalCase:Y=!1,stopPaths:$,deep:q=!1,preserveConsecutiveUppercase:Q=!1}=f,I=new Set($);if(Array.isArray(h)){let H=[];d.set(h,H);for(let x of h)H.push(T(x)?B(x,f,d,M):x);return H}let J={};d.set(h,J);let _=K(h,((H)=>(x,F)=>{if(q&&T(F)){let Z=H===void 0?x:`${H}.${x}`;if(!I.has(Z))F=Array.isArray(F)?F.map((g)=>T(g)?B(g,f,d,Z):g):B(F,f,d,Z)}if(typeof x==="string"&&!c(x)&&!(z&&v(z,x))){let Z=Y?`${x}_`:x;if(E.has(Z))x=E.get(Z);else if(x=W(x,{pascalCase:Y,locale:!1,preserveConsecutiveUppercase:Q}),x.length<100)E.set(Z,x)}return[x,F]})(M),{deep:!1});Object.assign(J,_);let G=Object.getOwnPropertySymbols(h);for(let H of G)J[H]=q&&T(h[H])?B(h[H],f,d,M):h[H];return J};function o(h,f){let d=new WeakMap;if(Array.isArray(h))return h.map((M)=>T(M)?B(M,f,d,void 0):M);return B(h,f,d)}
2
+ export{o as n};
@@ -0,0 +1,6 @@
1
+ import{Dk as T}from"./chunk-mv5m8bf4.js";import{Wl as R}from"./chunk-4fs853nh.js";var I=R(T(),1);import A from"fs/promises";import z from"path";import O from"os";class U{skillsDir;projectSkillsDir;constructor(){let b=O.homedir();this.skillsDir=z.join(b,".claude","skills"),this.projectSkillsDir=z.join(process.cwd(),".claude","skills")}async listSkills(){let b=new Map,g=await this.listSkillsInDir(this.skillsDir);for(let q of g)b.set(q.name,q);let x=await this.listSkillsInDir(this.projectSkillsDir);for(let q of x)b.set(q.name,q);return Array.from(b.values())}async listSkillsInDir(b){try{let g=await A.readdir(b,{withFileTypes:!0}),x=[];for(let q of g){let F=z.join(b,q.name),J=await A.lstat(F).catch(()=>null);if(!J)continue;let K=await A.stat(F).catch(()=>null);if(!K||!K.isDirectory())continue;if(J.isSymbolicLink()){let C=z.resolve(F),G=z.resolve(b),N=C.substring(G.length);if(!(C===G||N.startsWith("/")||N==="")){let Q=O.homedir();if(!C.startsWith(Q))continue}}let L=z.join(F,"SKILL.md");try{let C=await A.readFile(L,"utf-8"),G=this.parseFrontmatter(C);x.push({name:q.name,description:G.description||"",path:L})}catch{}}return x}catch{return[]}}async getSkill(b){let g=z.join(this.projectSkillsDir,b,"SKILL.md");try{let q=await A.readFile(g,"utf-8");return this.parseSkillContent(q)}catch{}let x=z.join(this.skillsDir,b,"SKILL.md");try{let q=await A.readFile(x,"utf-8");return this.parseSkillContent(q)}catch{return null}}async saveSkill(b,g){let x=z.join(this.skillsDir,b);await A.mkdir(x,{recursive:!0});let q=this.formatSkillContent(g);await A.writeFile(z.join(x,"SKILL.md"),q,"utf-8")}async deleteSkill(b){let g=z.join(this.skillsDir,b);await A.rm(g,{recursive:!0,force:!0})}async syncFromRemote(b){let g=await b.listRemoteSkills();for(let x of g){let q=await b.fetchSkill(x.name);if(q)await this.saveSkill(x.name,q)}}parseFrontmatter(b){let g=b.match(/^---\n(.+?)\n---/s);if(!g)return{};try{return I.default.parse(g[1])}catch{return{}}}parseSkillContent(b){let g=this.parseFrontmatter(b),x=b.replace(/^---\n.+?\n---\n*/s,"");return{frontmatter:g,markdown:x}}formatSkillContent(b){return`---
2
+ ${I.default.stringify(b.frontmatter).trim()}
3
+ ---
4
+
5
+ ${b.markdown}`}}
6
+ export{U as yk};
@@ -0,0 +1 @@
1
+ import{E as w}from"./chunk-1d47g6nc.js";import{H as $}from"./chunk-5fe27s34.js";import"./chunk-5hqvapp1.js";import{$ as _,U as h,Y as G,fa as Y,ia as U,ka as Z}from"./chunk-h7ypcqp3.js";import{Wl as K}from"./chunk-4fs853nh.js";var z=K(h(),1);var y=K(Y(),1),b=({onClose:H})=>{let{config:v,updateConfig:L}=w(),N=$(),B=v?.active_agent||"default",O=z.useCallback(async()=>{return await N.agents.list.query()},[N]),Q=z.useCallback((q,F,J)=>{let P=q.id===B;return y.jsxDEV(U,{isSelected:J,isCurrent:P,children:[y.jsxDEV(G,{bold:!0,children:[F+1,". ",q.id]},void 0,!0,void 0,this),y.jsxDEV(_,{},void 0,!1,void 0,this),y.jsxDEV(G,{dimColor:!0,children:q.description.slice(0,20)},void 0,!1,void 0,this)]},`agent-${q.id}`,!0,void 0,this)},[B]),R=z.useCallback((q)=>{return q.id===B},[B]),W=z.useCallback(async(q)=>{let F=q.id==="default"?"":q.id;L({active_agent:F}),H()},[L,H]),X=z.useCallback((q)=>{let F=q.find((J)=>J.id===B);return F?y.jsxDEV(G,{color:"gray",dimColor:!0,children:["当前 Agent: ",y.jsxDEV(G,{color:"green",children:F.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this):null},[B]),M=z.useMemo(()=>({id:"agent",title:"Agent 选择",icon:"\uD83E\uDD16",dataSource:O,searchable:!0,searchFields:["id","name","description"],searchPlaceholder:"搜索 agent (名称/描述)...",filterable:!0,filters:[{id:"default",label:"默认",predicate:(q)=>q.id==="default"},{id:"custom",label:"自定义",predicate:(q)=>q.id!=="default"}],defaultFilter:"all",itemHeight:1,visibleCount:15,renderItem:Q,isSelected:R,onSelect:W,showCount:!0,statusInfo:X}),[O,Q,R,W,X]);return y.jsxDEV(Z,{config:M,onClose:H},void 0,!1,void 0,this)},k=b;export{k as default};
@@ -0,0 +1 @@
1
+ import{K as R,M as v,N as _,O as b}from"./chunk-5hqvapp1.js";import{U as S,X as J,Y as W,fa as h,ga as q}from"./chunk-h7ypcqp3.js";import{Kl as U}from"./chunk-dh2f4xyb.js";import{Wl as w}from"./chunk-4fs853nh.js";var G=w(S(),1);function M({limit:X=100,enabled:H=!0}={}){return v({queryKey:b.errors.list(),queryFn:async()=>{return U.getRecentErrors(X)},enabled:H,staleTime:5000,refetchInterval:5000})}function O(){let X=R();return _({mutationFn:async(H)=>{return U.deleteError(H)},onSuccess:()=>{X.invalidateQueries({queryKey:b.errors.all})}})}function Q(){let X=R();return _({mutationFn:async()=>{U.clearAll()},onSuccess:()=>{X.invalidateQueries({queryKey:b.errors.all})}})}var z=w(h(),1);import{join as B}from"node:path";var T={error:{emoji:"❌",color:"red",label:"错误"},warning:{emoji:"⚠️",color:"yellow",label:"警告"}},p={Agent:{emoji:"\uD83E\uDD16",label:"Agent"},Tool:{emoji:"\uD83D\uDD27",label:"Tool"},Terminal:{emoji:"\uD83D\uDCBB",label:"Terminal"},System:{emoji:"⚙️",label:"System"},Unknown:{emoji:"❓",label:"Unknown"}};function g(X){let H=new Date(X),Z=new Date,P=Z.getTime()-H.getTime();if(P<60000)return"刚刚";if(P<3600000)return`${Math.floor(P/60000)}分钟前`;if(H.toDateString()===Z.toDateString())return H.toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit"});return H.toLocaleDateString("zh-CN",{month:"short",day:"numeric"})}function c(X,H=80){if(X.length<=H)return X;return X.slice(0,H-3)+"..."}var d=({onClose:X})=>{let{data:H=[],isLoading:Z}=M({limit:50}),P=O(),N=Q(),L=G.useCallback(async()=>{await N.mutateAsync()},[N]);q((Y,A)=>{if(A.escape)X();if(A.ctrl&&Y==="l")L()},{isActive:!0});let f=B(process.cwd(),".zen-code","errors.json"),F=G.default.useMemo(()=>{let Y=H.filter(($)=>$.level==="error").length,A=H.filter(($)=>$.level==="warning").length;return{errorCount:Y,warningCount:A}},[H]);return z.jsxDEV(J,{flexDirection:"column",paddingX:1,paddingY:1,children:[z.jsxDEV(J,{marginBottom:1,children:[z.jsxDEV(W,{bold:!0,color:"cyan",children:"\uD83D\uDCCB 错误日志"},void 0,!1,void 0,this),z.jsxDEV(J,{marginLeft:2,children:[z.jsxDEV(W,{color:"red",children:["❌ ",F.errorCount]},void 0,!0,void 0,this),z.jsxDEV(W,{children:" "},void 0,!1,void 0,this),z.jsxDEV(W,{color:"yellow",children:["⚠️ ",F.warningCount]},void 0,!0,void 0,this),z.jsxDEV(W,{dimColor:!0,children:["| Total: ",H.length]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Z&&z.jsxDEV(J,{marginBottom:1,children:z.jsxDEV(W,{dimColor:!0,children:"加载中..."},void 0,!1,void 0,this)},void 0,!1,void 0,this),!Z&&H.length>0&&z.jsxDEV(J,{flexDirection:"column",children:H.slice(0,20).map((Y,A)=>{let $=T[Y.level],K=p[Y.source]||p.Unknown,k=g(Y.timestamp),I=c(Y.message);return z.jsxDEV(J,{flexDirection:"column",marginBottom:1,children:[z.jsxDEV(J,{children:z.jsxDEV(W,{color:$.color,children:[$.emoji," ",I]},void 0,!0,void 0,this)},void 0,!1,void 0,this),z.jsxDEV(J,{marginLeft:2,children:[z.jsxDEV(W,{dimColor:!0,children:[K.emoji," ",K.label," | ",k]},void 0,!0,void 0,this),Y.file&&z.jsxDEV(W,{dimColor:!0,color:"gray",children:[" ","| \uD83D\uDCC4 ",Y.file,Y.line&&`:${Y.line}`]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},Y.id,!0,void 0,this)})},void 0,!1,void 0,this),!Z&&H.length===0&&z.jsxDEV(J,{flexDirection:"column",marginBottom:1,children:[z.jsxDEV(J,{marginBottom:1,children:z.jsxDEV(W,{dimColor:!0,children:"暂无错误记录"},void 0,!1,void 0,this)},void 0,!1,void 0,this),z.jsxDEV(J,{marginBottom:1,children:z.jsxDEV(W,{dimColor:!0,children:"错误将自动收集到:"},void 0,!1,void 0,this)},void 0,!1,void 0,this),z.jsxDEV(J,{marginBottom:1,children:z.jsxDEV(W,{color:"yellow",children:f},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV(J,{marginTop:1,children:z.jsxDEV(W,{dimColor:!0,children:"按 ESC 返回 | Ctrl+L 清空所有"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},E=d;export{E as default};
@@ -0,0 +1,26 @@
1
+ import{fe as z}from"./chunk-vwj4n000.js";import"./chunk-4fs853nh.js";class I{db;pragmaPromise=null;constructor(x){this.db=x}ensurePragma(){if(!this.pragmaPromise)this.pragmaPromise=this.doEnsurePragma();return this.pragmaPromise}async doEnsurePragma(){await z`PRAGMA busy_timeout = 5000`.execute(this.db),await z`PRAGMA journal_mode = WAL`.execute(this.db),await z`PRAGMA synchronous = NORMAL`.execute(this.db),await z`PRAGMA wal_autocheckpoint = 1000`.execute(this.db)}dateToDb(x){return x.toISOString()}dbToDate(x){return new Date(x)}jsonToDb(x){return JSON.stringify(x)}dbToJson(x){if(typeof x==="string")try{return JSON.parse(x)}catch{return x}return x}buildJsonQuery(x,E,F,B){let G=`$.${JSON.stringify(F)}`;if(B===null)return z`
2
+ json_type(${z.ref(E)}, ${z.lit(G)}) = 'null'
3
+ `;let C;if(typeof B==="string")C=B;else if(typeof B==="number")C=B;else if(typeof B==="boolean")C=B?1:0;else C=JSON.stringify(B);return z`json_extract(${z.ref(E)}, ${z.lit(G)}) = ${z.lit(C)}`}now(){return new Date().toISOString()}async createTables(x){await this.ensurePragma(),await z`
4
+ CREATE TABLE IF NOT EXISTS threads (
5
+ thread_id TEXT PRIMARY KEY,
6
+ created_at TEXT NOT NULL,
7
+ updated_at TEXT NOT NULL,
8
+ metadata TEXT NOT NULL DEFAULT '{}',
9
+ status TEXT NOT NULL DEFAULT 'idle',
10
+ "values" TEXT,
11
+ interrupts TEXT NOT NULL DEFAULT '{}',
12
+ title TEXT
13
+ )
14
+ `.execute(x),await this.addColumnIfNotExists(x,"threads","title","TEXT"),await z`
15
+ CREATE TABLE IF NOT EXISTS runs (
16
+ run_id TEXT PRIMARY KEY,
17
+ thread_id TEXT NOT NULL,
18
+ assistant_id TEXT NOT NULL,
19
+ created_at TEXT NOT NULL,
20
+ updated_at TEXT NOT NULL,
21
+ status TEXT NOT NULL DEFAULT 'pending',
22
+ metadata TEXT NOT NULL DEFAULT '{}',
23
+ multitask_strategy TEXT NOT NULL DEFAULT 'reject',
24
+ FOREIGN KEY (thread_id) REFERENCES threads(thread_id) ON DELETE CASCADE
25
+ )
26
+ `.execute(x)}async addColumnIfNotExists(x,E,F,B){if(!(await z`PRAGMA table_info(${z.raw(E)})`.execute(x)).rows.map((H)=>H.name).includes(F))await z`ALTER TABLE ${z.raw(E)} ADD COLUMN ${z.raw(F)} ${z.raw(B)}`.execute(x)}async createIndexes(x){await z`CREATE INDEX IF NOT EXISTS idx_threads_status ON threads(status)`.execute(x),await z`CREATE INDEX IF NOT EXISTS idx_threads_created_at ON threads(created_at)`.execute(x),await z`CREATE INDEX IF NOT EXISTS idx_threads_updated_at ON threads(updated_at)`.execute(x),await z`CREATE INDEX IF NOT EXISTS idx_runs_thread_id ON runs(thread_id)`.execute(x),await z`CREATE INDEX IF NOT EXISTS idx_runs_status ON runs(status)`.execute(x)}}export{I as SQLiteAdapter};
@@ -0,0 +1,16 @@
1
+ import{Bg as U1,Cg as c$,Dg as q1,Fg as V8,Gg as z1,fg as f$,sg as b$,tg as sQ,vg as D8,yg as V0,zg as kQ}from"./chunk-88w3txtb.js";import{Di as j8,Gh as gQ,Gj as n8,Hh as e8,Nh as X1,Ni as QQ,Pi as H1,Qi as DQ,Rj as q$,Si as rQ,Tj as YQ,Uj as C$,Wi as K1,Xj as Z0,_h as F1,ak as yQ,dj as M8,ej as X$,li as a0,mj as XQ,nj as F$,oj as M1,pj as K8,ri as e0,sj as x1}from"./chunk-v0e9bsvt.js";import{Qk as L$}from"./chunk-qfa5v4n5.js";import{Bl as iQ}from"./chunk-78ksrp8v.js";import{Dl as Z$,El as h8,Jl as N$}from"./chunk-yb71zqvt.js";var T="__start__",A="__end__",xQ="__input__",H$="__copy__",p="__error__",k0="__pregel_ns_writes",WQ="__pregel_send",g0="__pregel_call",AQ="__pregel_read",m="__pregel_checkpointer",EQ="__pregel_resuming",Y0="__pregel_task_id",K0="__pregel_stream";var X0="__pregel_resume_map",JQ="__pregel_scratchpad",M0="__pregel_previous",U$="__pregel_durability",w8="checkpoint_id",FQ="checkpoint_ns",V$="__pregel_node_finished",ZQ="checkpoint_map",R8="__pregel_abort_signals",S="__interrupt__",o="__resume__",m0="__no_writes__",jQ="__return__",aQ="__previous__",E="langsmith:hidden",D$="langsmith:nostream",T8="__self__",c="__pregel_tasks",r="__pregel_push",x0="__pregel_pull",n="00000000-0000-0000-0000-000000000000",G$=["langsmith:hidden","__input__","__interrupt__","__resume__","__error__","__no_writes__","__pregel_send","__pregel_read","__pregel_checkpointer","__pregel_durability","__pregel_stream","__pregel_resuming","__pregel_task_id","__pregel_call","__pregel_resume_value","__pregel_scratchpad","__pregel_previous","checkpoint_map","checkpoint_ns","checkpoint_id"],k="|",e=":",f0=Symbol.for("langgraph.command"),h0=class{[f0];constructor(Q){this[f0]=Q}};function u0(Q){let $=Q;return $!==null&&$!==void 0&&typeof $.node==="string"&&$.args!==void 0}var uQ=class{lg_name="Send";node;args;constructor(Q,$){this.node=Q,this.args=G0($)}toJSON(){return{lg_name:this.lg_name,node:this.node,args:this.args}}};function d(Q){return Q instanceof uQ}var j$="__overwrite__";function d0(Q){if(typeof Q==="object"&&Q!==null&&j$ in Q)return[!0,Q[j$]];return[!1,void 0]}function K$(Q){return d0(Q)[0]}function F0(Q){if(!Q||typeof Q!=="object")return!1;if(!("__interrupt__"in Q))return!1;return Array.isArray(Q.__interrupt__)}var a=class extends h0{lg_name="Command";lc_direct_tool_output=!0;graph;update;resume;goto=[];static PARENT="__parent__";constructor(Q){super(Q);if(this.resume=Q.resume,this.graph=Q.graph,this.update=Q.update,Q.goto)this.goto=Array.isArray(Q.goto)?G0(Q.goto):[G0(Q.goto)]}_updateAsTuples(){if(this.update&&typeof this.update==="object"&&!Array.isArray(this.update))return Object.entries(this.update);else if(Array.isArray(this.update)&&this.update.every((Q)=>Array.isArray(Q)&&Q.length===2&&typeof Q[0]==="string"))return this.update;else return[["__root__",this.update]]}toJSON(){let Q;if(typeof this.goto==="string")Q=this.goto;else if(d(this.goto))Q=this.goto.toJSON();else Q=this.goto?.map(($)=>{if(typeof $==="string")return $;else return $.toJSON()});return{lg_name:this.lg_name,update:this.update,resume:this.resume,goto:Q}}};function u(Q){if(typeof Q!=="object")return!1;if(Q===null||Q===void 0)return!1;if("lg_name"in Q&&Q.lg_name==="Command")return!0;return!1}function G0(Q,$=new Map){if(Q!==void 0&&Q!==null&&typeof Q==="object"){if($.has(Q))return $.get(Q);let J;if(Array.isArray(Q))J=[],$.set(Q,J),Q.forEach((Z,q)=>{J[q]=G0(Z,$)});else if(u(Q)&&!(Q instanceof a))J=new a(Q),$.set(Q,J);else if(u0(Q)&&!(Q instanceof uQ))J=new uQ(Q.node,Q.args),$.set(Q,J);else if(u(Q)||d(Q))J=Q,$.set(Q,J);else if("lc_serializable"in Q&&Q.lc_serializable)J=Q,$.set(Q,J);else{J={},$.set(Q,J);for(let[Z,q]of Object.entries(Q))J[Z]=G0(q,$)}return J}return Q}var OQ=class extends Error{lc_error_code;constructor(Q,$){let J=Q??"";if($?.lc_error_code)J=`${J}
2
+
3
+ Troubleshooting URL: https://docs.langchain.com/oss/javascript/langgraph/${$.lc_error_code}/
4
+ `;super(J);this.lc_error_code=$?.lc_error_code}},p0=class extends OQ{get is_bubble_up(){return!0}},l0=class extends OQ{constructor(Q,$){super(Q,$);this.name="GraphRecursionError"}static get unminifiable_name(){return"GraphRecursionError"}},dQ=class extends OQ{constructor(Q,$){super(Q,$);this.name="GraphValueError"}static get unminifiable_name(){return"GraphValueError"}},PQ=class extends p0{interrupts;constructor(Q,$){super(JSON.stringify(Q,null,2),$);this.name="GraphInterrupt",this.interrupts=Q??[]}static get unminifiable_name(){return"GraphInterrupt"}},A0=class extends PQ{constructor(Q,$){super([{value:Q}],$);this.name="NodeInterrupt"}static get unminifiable_name(){return"NodeInterrupt"}},O0=class extends p0{command;constructor(Q){super();this.name="ParentCommand",this.command=Q}static get unminifiable_name(){return"ParentCommand"}};function o0(Q){return Q!==void 0&&Q.name===O0.unminifiable_name}function pQ(Q){return Q!==void 0&&Q.is_bubble_up===!0}function wQ(Q){return Q!==void 0&&[PQ.unminifiable_name,A0.unminifiable_name].includes(Q.name)}var P0=class extends OQ{constructor(Q,$){super(Q,$);this.name="EmptyInputError"}static get unminifiable_name(){return"EmptyInputError"}},v=class extends OQ{constructor(Q,$){super(Q,$);this.name="EmptyChannelError"}static get unminifiable_name(){return"EmptyChannelError"}},w=class extends OQ{constructor(Q,$){super(Q,$);this.name="InvalidUpdateError"}static get unminifiable_name(){return"InvalidUpdateError"}};var c0=class extends OQ{constructor(Q,$){super(Q,$);this.name="UnreachableNodeError"}static get unminifiable_name(){return"UnreachableNodeError"}};var B0=class extends OQ{constructor(Q,$){super(Q,$);this.name="StateGraphInputError",this.message="Invalid StateGraph input. Make sure to pass a valid StateDefinition, Annotation.Root, or Zod schema."}static get unminifiable_name(){return"StateGraphInputError"}};var V=(Q)=>BigInt(Q),C=(Q,$=0)=>new DataView(Q.buffer,Q.byteOffset+$,Q.byteLength-$),O$=V("0x9E3779B1"),P$=V("0x85EBCA77"),_1=V("0xC2B2AE3D"),lQ=V("0x9E3779B185EBCA87"),eQ=V("0xC2B2AE3D27D4EB4F"),w$=V("0x165667B19E3779F9"),_8=V("0x85EBCA77C2B2AE63"),N1=V("0x27D4EB2F165667C5"),I1=V("0x165667919E3779F9"),y1=V("0x9FB21C651E98DF25"),E1=(Q)=>{let $=Q.length;if($%2!==0)throw Error("String should have an even number of characters");let J=$/2,Z=new Uint8Array(J),q=0,z=0;while(z<J){let Y=Q.slice(q,q+=2);Z[z]=Number.parseInt(Y,16),z+=1}return C(Z)},RQ=E1("b8fe6c3923a44bbe7c01812cf721ad1cded46de9839097db7240a4a4b7b3671fcb79e64eccc0e578825ad07dccff7221b8084674f743248ee03590e6813a264c3c2852bb91c300cb88d0658b1b532ea371644897a20df94e3819ef46a9deacd8a8fa763fe39c343ff9dcbbc7c70b4f1d8a51e04bcdb45931c89f7ec9d9787364eac5ac8334d3ebc3c581a0fffa1363eb170ddd51b7f0da49d316552629d4689e2b16be587d47a1fc8ff8b8d17ad031ce45cb3a8f95160428afd7fbcabb4b407e"),L0=(V(1)<<V(128))-V(1),R=(V(1)<<V(64))-V(1),n0=(V(1)<<V(32))-V(1);function W0(Q){if(!Q)throw Error("Assert failed")}function v1(Q){let $=new DataView(new ArrayBuffer(8));return $.setBigUint64(0,Q,!0),$.getBigUint64(0,!1)}function C1(Q){let $=Q;return $=($&V(65535))<<V(16)|($&V(4294901760))>>V(16),$=($&V(16711935))<<V(8)|($&V(4278255360))>>V(8),$}function f1(Q,$){return(Q&n0)*($&n0)&R}function k1(Q,$){return(Q<<$|Q>>V(32)-$)&n0}function R$(Q,$,J){for(let Z=0;Z<8;Z+=1){let q=$.getBigUint64(Z*8,!0),z=q^J.getBigUint64(Z*8,!0);Q[Z^1]+=q,Q[Z]+=f1(z,z>>V(32))}return Q}function M$(Q,$,J,Z){for(let q=0;q<Z;q+=1)R$(Q,C($,q*64),C(J,q*8));return Q}function g1(Q,$){for(let J=0;J<8;J+=1){let Z=$.getBigUint64(J*8,!0),q=Q[J];q=b8(q,V(47)),q^=Z,q*=O$,Q[J]=q&R}return Q}function i0(Q,$){return T$(Q[0]^$.getBigUint64(0,!0),Q[1]^$.getBigUint64(8,!0))}function x$(Q,$,J){let Z=J;return Z+=i0(Q.slice(0),C($,0)),Z+=i0(Q.slice(2),C($,16)),Z+=i0(Q.slice(4),C($,32)),Z+=i0(Q.slice(6),C($,48)),TQ(Z&R)}function m1(Q,$,J,Z,q){let z=Q,Y=Math.floor((J.byteLength-64)/8),X=64*Y,B=Math.floor(($.byteLength-1)/X);for(let F=0;F<B;F+=1)z=M$(z,C($,F*X),J,Y),z=q(z,C(J,J.byteLength-64));{let F=Math.floor(($.byteLength-1-X*B)/64);z=M$(z,C($,B*X),J,F),z=Z(z,C($,$.byteLength-64),C(J,J.byteLength-64-7))}return z}function h1(Q,$){let J=new BigUint64Array([_1,lQ,eQ,w$,_8,P$,N1,O$]);W0(Q.byteLength>128),J=m1(J,Q,$,R$,g1),W0(J.length*8===64);{let Z=x$(J,C($,11),V(Q.byteLength)*lQ&R);return x$(J,C($,$.byteLength-64-11),~(V(Q.byteLength)*eQ)&R)<<V(64)|Z}}function T$(Q,$){let J=Q*$&L0;return J&R^J>>V(64)}function A$(Q,$,J){return T$((Q.getBigUint64(0,!0)^$.getBigUint64(0,!0)+J)&R,(Q.getBigUint64(8,!0)^$.getBigUint64(8,!0)-J)&R)}function r0(Q,$,J,Z,q){let z=Q&R,Y=Q>>V(64)&R;return z+=A$($,Z,q),z^=J.getBigUint64(0,!0)+J.getBigUint64(8,!0),z&=R,Y+=A$(J,C(Z,16),q),Y^=$.getBigUint64(0,!0)+$.getBigUint64(8,!0),Y&=R,Y<<V(64)|z}function TQ(Q){let $=Q;return $^=$>>V(37),$*=I1,$&=R,$^=$>>V(32),$}function s0(Q){let $=Q;return $^=$>>V(33),$*=eQ,$&=R,$^=$>>V(29),$*=w$,$&=R,$^=$>>V(32),$}function u1(Q,$,J){let Z=Q.byteLength;W0(Z>0&&Z<=3);let q=V(Q.getUint8(Z-1))|V(Z<<8)|V(Q.getUint8(0)<<16)|V(Q.getUint8(Z>>1)<<24),z=(q^(V($.getUint32(0,!0))^V($.getUint32(4,!0)))+J)&R,Y=(V($.getUint32(8,!0))^V($.getUint32(12,!0)))-J;return(s0((k1(C1(q),V(13))^Y)&R)&R)<<V(64)|s0(z)}function b8(Q,$){return Q^Q>>$}function d1(Q,$,J){let Z=Q.byteLength;W0(Z>=4&&Z<=8);{let q=Q.getUint32(0,!0),z=Q.getUint32(Z-4,!0),Y=((V(q)|V(z)<<V(32))^($.getBigUint64(16,!0)^$.getBigUint64(24,!0))+J&R)*(lQ+(V(Z)<<V(2)))&L0;return Y+=(Y&R)<<V(65),Y&=L0,Y^=Y>>V(67),b8(b8(Y&R,V(35))*y1&R,V(28))|TQ(Y>>V(64))<<V(64)}}function p1(Q,$,J){let Z=Q.byteLength;W0(Z>=9&&Z<=16);{let q=($.getBigUint64(32,!0)^$.getBigUint64(40,!0))+J&R,z=($.getBigUint64(48,!0)^$.getBigUint64(56,!0))-J&R,Y=Q.getBigUint64(0,!0),X=Q.getBigUint64(Z-8,!0),B=(Y^X^q)*lQ,F=(B&R)+(V(Z-1)<<V(54));B=B&(L0^R)|F,X^=z,B+=X+(X&n0)*(P$-V(1))<<V(64),B&=L0,B^=v1(B>>V(64));let W=(B&R)*eQ;return W+=(B>>V(64))*eQ<<V(64),W&=L0,TQ(W&R)|TQ(W>>V(64))<<V(64)}}function l1(Q,$){let J=Q.byteLength;if(W0(J<=16),J>8)return p1(Q,RQ,$);if(J>=4)return d1(Q,RQ,$);if(J>0)return u1(Q,RQ,$);return s0($^RQ.getBigUint64(64,!0)^RQ.getBigUint64(72,!0))|s0($^RQ.getBigUint64(80,!0)^RQ.getBigUint64(88,!0))<<V(64)}function S8(Q){return~Q+V(1)&R}function o1(Q,$,J){let Z=V(Q.byteLength)*lQ&R,q=V(Q.byteLength-1)/V(32);while(q>=0){let X=Number(q);Z=r0(Z,C(Q,16*X),C(Q,Q.byteLength-16*(X+1)),C($,32*X),J),q-=V(1)}let z=Z+(Z>>V(64))&R;z=TQ(z);let Y=(Z&R)*lQ+(Z>>V(64))*_8+(V(Q.byteLength)-J&R)*eQ;return Y&=R,Y=S8(TQ(Y)),z|Y<<V(64)}function c1(Q,$,J){let Z=V(Q.byteLength)*lQ&R;for(let Y=32;Y<160;Y+=32)Z=r0(Z,C(Q,Y-32),C(Q,Y-16),C($,Y-32),J);Z=TQ(Z&R)|TQ(Z>>V(64))<<V(64);for(let Y=160;Y<=Q.byteLength;Y+=32)Z=r0(Z,C(Q,Y-32),C(Q,Y-16),C($,3+Y-160),J);Z=r0(Z,C(Q,Q.byteLength-16),C(Q,Q.byteLength-32),C($,103),S8(J));let q=Z+(Z>>V(64))&R;q=TQ(q);let z=(Z&R)*lQ+(Z>>V(64))*_8+(V(Q.byteLength)-J&R)*eQ;return z&=R,z=S8(TQ(z)),q|z<<V(64)}function vQ(Q,$=V(0)){let Z=C(typeof Q==="string"?new TextEncoder().encode(Q):Q),q=Z.byteLength,z=(Y)=>Y.toString(16).padStart(32,"0");if(q<=16)return z(l1(Z,$));if(q<=128)return z(o1(Z,RQ,$));if(q<=240)return z(c1(Z,RQ,$));return z(h1(Z,RQ))}function t0(Q){return/^[0-9a-f]{32}$/.test(Q)}function N8(Q){let $=QQ.getRunnableConfig();if(!$)throw Error("Called interrupt() outside the context of a graph.");let J=$.configurable;if(!J)throw Error("No configurable found in config");if(!J[m])throw new dQ("No checkpointer set",{lc_error_code:"MISSING_CHECKPOINTER"});let Z=J[JQ];Z.interruptCounter+=1;let q=Z.interruptCounter;if(Z.resume.length>0&&q<Z.resume.length)return J[WQ]?.([[o,Z.resume]]),Z.resume[q];if(Z.nullResume!==void 0){if(Z.resume.length!==q)throw Error(`Resume length mismatch: ${Z.resume.length} !== ${q}`);let Y=Z.consumeNullResume();return Z.resume.push(Y),J[WQ]?.([[o,Z.resume]]),Y}let z=J[FQ]?.split(k);throw new PQ([{id:z?vQ(z.join(k)):void 0,value:Q}])}var I8=Symbol.for("langgraph.state.reduced_value"),BQ=class{[I8]=!0;valueSchema;inputSchema;reducer;jsonSchemaExtra;constructor(Q,$){this.reducer=$.reducer,this.jsonSchemaExtra=$.jsonSchemaExtra,this.valueSchema=Q,this.inputSchema="inputSchema"in $?$.inputSchema:Q,this.jsonSchemaExtra=$.jsonSchemaExtra}static isInstance(Q){return typeof Q==="object"&&Q!==null&&I8 in Q&&Q[I8]===!0}};function E8(Q){return Q!=null&&Q.lg_is_channel===!0}var l=class{ValueType;UpdateType;lg_is_channel=!0;consume(){return!1}finish(){return!1}isAvailable(){try{return this.get(),!0}catch(Q){if(Q.name===v.unminifiable_name)return!1;throw Q}}equals(Q){return this===Q}},y8=Symbol.for("LG_IS_ONLY_BASE_CHANNEL");function w0(Q){if(Q[y8]===!0)return Q;let $={};for(let J in Q){if(!Object.prototype.hasOwnProperty.call(Q,J))continue;let Z=Q[J];if(E8(Z))$[J]=Z}return Object.assign($,{[y8]:!0}),$}function oQ(Q,$){let J=w0(Q),Z={};for(let q in J){if(!Object.prototype.hasOwnProperty.call(J,q))continue;let z=$.channel_values[q];Z[q]=J[q].fromCheckpoint(z)}return Object.assign(Z,{[y8]:!0}),Z}function HQ(Q,$,J,Z){let q;if($===void 0)q=Q.channel_values;else{q={};for(let z in $){if(!Object.prototype.hasOwnProperty.call($,z))continue;try{q[z]=$[z].checkpoint()}catch(Y){if(Y.name===v.unminifiable_name);else throw Y}}}return{v:4,id:Z?.id??b$(J),ts:new Date().toISOString(),channel_values:q,channel_versions:Q.channel_versions,versions_seen:Q.versions_seen}}var i1=(Q)=>{return Q!=null&&Q.lc_graph_name==="BinaryOperatorAggregate"},bQ=class Q extends l{lc_graph_name="BinaryOperatorAggregate";value;operator;initialValueFactory;constructor($,J){super();this.operator=$,this.initialValueFactory=J,this.value=J?.()}fromCheckpoint($){let J=new Q(this.operator,this.initialValueFactory);if(typeof $<"u")J.value=$;return J}update($){let J=$;if(!J.length)return!1;if(this.value===void 0){let q=J[0],[z,Y]=d0(q);if(z)this.value=Y;else this.value=q;J=J.slice(1)}let Z=!1;for(let q of J)if(K$(q)){if(Z)throw new w("Can receive only one Overwrite value per step.");let[,z]=d0(q);this.value=z,Z=!0;continue}else if(!Z&&this.value!==void 0)this.value=this.operator(this.value,q);return!0}get(){if(this.value===void 0)throw new v;return this.value}checkpoint(){if(this.value===void 0)throw new v;return this.value}isAvailable(){return this.value!==void 0}equals($){if(this===$)return!0;if(!i1($))return!1;return this.operator===$.operator}};var UQ=class Q extends l{lc_graph_name="LastValue";value=[];constructor($){super();if(this.initialValueFactory=$,$)this.value=[$()]}fromCheckpoint($){let J=new Q(this.initialValueFactory);if(typeof $<"u")J.value=[$];return J}update($){if($.length===0)return!1;if($.length!==1)throw new w("LastValue can only receive one value per step.",{lc_error_code:"INVALID_CONCURRENT_GRAPH_UPDATE"});return this.value=[$[$.length-1]],!0}get(){if(this.value.length===0)throw new v;return this.value[0]}checkpoint(){if(this.value.length===0)throw new v;return this.value[0]}isAvailable(){return this.value.length!==0}},v8=class Q extends l{lc_graph_name="LastValueAfterFinish";value=[];finished=!1;fromCheckpoint($){let J=new Q;if(typeof $<"u"){let[Z,q]=$;J.value=[Z],J.finished=q}return J}update($){if($.length===0)return!1;return this.finished=!1,this.value=[$[$.length-1]],!0}get(){if(this.value.length===0||!this.finished)throw new v;return this.value[0]}checkpoint(){if(this.value.length===0)return;return[this.value[0],this.finished]}consume(){if(this.finished)return this.finished=!1,this.value=[],!0;return!1}finish(){if(!this.finished&&this.value.length>0)return this.finished=!0,!0;return!1}isAvailable(){return this.value.length!==0&&this.finished}};function SQ(Q){return typeof Q==="object"&&Q!==null&&"~standard"in Q&&typeof Q["~standard"]==="object"&&Q["~standard"]!==null&&"validate"in Q["~standard"]}function S$(Q){return typeof Q==="object"&&Q!==null&&"~standard"in Q&&typeof Q["~standard"]==="object"&&Q["~standard"]!==null&&"jsonSchema"in Q["~standard"]}function _Q(Q){if(S$(Q))try{return Q["~standard"].jsonSchema.input({target:"draft-07"})}catch{return}}function NQ(Q){if(Q==null)return;if(!SQ(Q))return;try{let $=Q["~standard"].validate(void 0);if($&&typeof $==="object"&&!(("then"in $)&&typeof $.then==="function")){let J=$;if(!J.issues){let Z=J.value;return()=>Z}}}catch{}}var C8=Symbol.for("langgraph.channel.missing"),R0=class Q extends l{lc_graph_name="UntrackedValue";guard;_value=C8;initialValueFactory;constructor($){super();if(this.guard=$?.guard??!0,this.initialValueFactory=$?.initialValueFactory,this.initialValueFactory)this._value=this.initialValueFactory()}fromCheckpoint($){return new Q({guard:this.guard,initialValueFactory:this.initialValueFactory})}update($){if($.length===0)return!1;if($.length!==1&&this.guard)throw new w("UntrackedValue(guard=true) can receive only one value per step. Use guard=false if you want to store any one of multiple values.",{lc_error_code:"INVALID_CONCURRENT_GRAPH_UPDATE"});return this._value=$[$.length-1],!0}get(){if(this._value===C8)throw new v;return this._value}checkpoint(){}isAvailable(){return this._value!==C8}};var f8=class Q extends l{lc_graph_name="Topic";unique=!1;accumulate=!1;seen;values;constructor($){super();this.unique=$?.unique??this.unique,this.accumulate=$?.accumulate??this.accumulate,this.seen=new Set,this.values=[]}fromCheckpoint($){let J=new Q({unique:this.unique,accumulate:this.accumulate});if(typeof $<"u")J.seen=new Set($[0]),J.values=$[1];return J}update($){let J=!1;if(!this.accumulate)J=this.values.length>0,this.values=[];let Z=$.flat();if(Z.length>0)if(this.unique){for(let q of Z)if(!this.seen.has(q))J=!0,this.seen.add(q),this.values.push(q)}else J=!0,this.values.push(...Z);return J}get(){if(this.values.length===0)throw new v;return this.values}checkpoint(){return[[...this.seen],this.values]}isAvailable(){return this.values.length!==0}};var VQ=class Q extends l{lc_graph_name="EphemeralValue";guard;value=[];constructor($=!0){super();this.guard=$}fromCheckpoint($){let J=new Q(this.guard);if(typeof $<"u")J.value=[$];return J}update($){if($.length===0){let J=this.value.length>0;return this.value=[],J}if($.length!==1&&this.guard)throw new w("EphemeralValue can only receive one value per step.");return this.value=[$[$.length-1]],!0}get(){if(this.value.length===0)throw new v;return this.value[0]}checkpoint(){if(this.value.length===0)throw new v;return this.value[0]}isAvailable(){return this.value.length!==0}};var cQ=(Q,$)=>Q.size===$.size&&[...Q].every((J)=>$.has(J)),k8=class Q extends l{lc_graph_name="NamedBarrierValue";names;seen;constructor($){super();this.names=$,this.seen=new Set}fromCheckpoint($){let J=new Q(this.names);if(typeof $<"u")J.seen=new Set($);return J}update($){let J=!1;for(let Z of $)if(this.names.has(Z)){if(!this.seen.has(Z))this.seen.add(Z),J=!0}else throw new w(`Value ${JSON.stringify(Z)} not in names ${JSON.stringify(this.names)}`);return J}get(){if(!cQ(this.names,this.seen))throw new v}checkpoint(){return[...this.seen]}consume(){if(this.seen&&this.names&&cQ(this.seen,this.names))return this.seen=new Set,!0;return!1}isAvailable(){return!!this.names&&cQ(this.names,this.seen)}},g8=class Q extends l{lc_graph_name="NamedBarrierValueAfterFinish";names;seen;finished;constructor($){super();this.names=$,this.seen=new Set,this.finished=!1}fromCheckpoint($){let J=new Q(this.names);if(typeof $<"u"){let[Z,q]=$;J.seen=new Set(Z),J.finished=q}return J}update($){let J=!1;for(let Z of $)if(this.names.has(Z)&&!this.seen.has(Z))this.seen.add(Z),J=!0;else if(!this.names.has(Z))throw new w(`Value ${JSON.stringify(Z)} not in names ${JSON.stringify(this.names)}`);return J}get(){if(!this.finished||!cQ(this.names,this.seen))throw new v}checkpoint(){return[[...this.seen],this.finished]}consume(){if(this.finished&&this.seen&&this.names&&cQ(this.seen,this.names))return this.seen=new Set,this.finished=!1,!0;return!1}finish(){if(!this.finished&&!!this.names&&cQ(this.names,this.seen))return this.finished=!0,!0;return!1}isAvailable(){return this.finished&&!!this.names&&cQ(this.names,this.seen)}};var _$=Symbol.for("langgraph.state.untracked_value"),IQ=class{[_$]=!0;schema;guard;constructor(Q,$){this.schema=Q,this.guard=$?.guard??!0}static isInstance(Q){return typeof Q==="object"&&Q!==null&&_$ in Q}};var m8=Symbol.for("langgraph.state.state_schema"),LQ=class{[m8]=!0;constructor(Q){this.fields=Q}getChannels(){let Q={};for(let[$,J]of Object.entries(this.fields))if(BQ.isInstance(J)){let Z=NQ(J.valueSchema);Q[$]=new bQ(J.reducer,Z)}else if(IQ.isInstance(J)){let Z=J.schema?NQ(J.schema):void 0;Q[$]=new R0({guard:J.guard,initialValueFactory:Z})}else if(SQ(J))Q[$]=new UQ(NQ(J));else throw Error(`Invalid state field "${$}": must be a schema, ReducedValue, UntrackedValue, or ManagedValue`);return Q}getJsonSchema(){let Q={},$=[];for(let[J,Z]of Object.entries(this.fields)){let q;if(BQ.isInstance(Z)){if(q=_Q(Z.valueSchema),Z.jsonSchemaExtra)q={...q??{},...Z.jsonSchemaExtra}}else if(IQ.isInstance(Z))q=Z.schema?_Q(Z.schema):void 0;else if(SQ(Z))q=_Q(Z);if(q){Q[J]=q;let z=!1;if(BQ.isInstance(Z))z=NQ(Z.valueSchema)!==void 0;else if(IQ.isInstance(Z))z=Z.schema?NQ(Z.schema)!==void 0:!1;else z=NQ(Z)!==void 0;if(!z)$.push(J)}}return{type:"object",properties:Q,required:$.length>0?$:void 0}}getInputJsonSchema(){let Q={};for(let[$,J]of Object.entries(this.fields)){let Z;if(BQ.isInstance(J))Z=_Q(J.inputSchema);else if(IQ.isInstance(J))Z=J.schema?_Q(J.schema):void 0;else if(SQ(J))Z=_Q(J);if(Z)Q[$]=Z}return{type:"object",properties:Q}}getChannelKeys(){return Object.entries(this.fields).map(([Q])=>Q)}getAllKeys(){return Object.keys(this.fields)}async validateInput(Q){if(Q==null||typeof Q!=="object")return Q;let $={};for(let[J,Z]of Object.entries(Q)){let q=this.fields[J];if(q===void 0){$[J]=Z;continue}let z;if(BQ.isInstance(q))z=q.inputSchema;else if(IQ.isInstance(q))z=q.schema;else if(SQ(q))z=q;if(z){let Y=await z["~standard"].validate(Z);if(Y.issues)throw Error(`Validation failed for field "${J}": ${JSON.stringify(Y.issues)}`);$[J]=Y.value}else $[J]=Z}return $}static isInstance(Q){return typeof Q==="object"&&Q!==null&&m8 in Q&&Q[m8]===!0}};N$();var Q8="__remove_all__";function CQ(Q,$){let J=Array.isArray(Q)?Q:[Q],Z=Array.isArray($)?$:[$],q=J.map(e0),z=Z.map(e0);for(let W of q)if(W.id===null||W.id===void 0)W.id=h8(),W.lc_kwargs.id=W.id;let Y;for(let W=0;W<z.length;W+=1){let L=z[W];if(L.id===null||L.id===void 0)L.id=h8(),L.lc_kwargs.id=L.id;if(a0.isInstance(L)&&L.id===Q8)Y=W}if(Y!=null)return z.slice(Y+1);let X=[...q],B=new Map(X.map((W,L)=>[W.id,L])),F=new Set;for(let W of z){let L=B.get(W.id);if(L!==void 0)if(a0.isInstance(W))F.add(W.id);else F.delete(W.id),X[L]=W;else{if(a0.isInstance(W))throw Error(`Attempting to delete a message with an ID that doesn't exist ('${W.id}')`);B.set(W.id,X.length),X.push(W)}}return X.filter((W)=>!F.has(W.id))}var r1=iQ.custom().default(()=>[]),n1=iQ.custom(),$8=new BQ(r1,{inputSchema:n1,reducer:CQ,jsonSchemaExtra:{langgraph_type:"messages",description:"A list of chat messages"}});import{AsyncLocalStorage as s1}from"node:async_hooks";function I$(){QQ.initializeGlobalInstance(new s1)}var T0=class{lc_graph_name="AnnotationRoot";spec;constructor(Q){this.spec=Q}static isInstance(Q){return typeof Q==="object"&&Q!==null&&"lc_graph_name"in Q&&Q.lc_graph_name==="AnnotationRoot"}},Q0=function(Q){if(Q)return J8(Q);else return new UQ};Q0.Root=(Q)=>new T0(Q);function J8(Q){if(typeof Q==="object"&&Q&&"reducer"in Q&&Q.reducer)return new bQ(Q.reducer,Q.default);if(typeof Q==="object"&&Q&&"value"in Q&&Q.value)return new bQ(Q.value,Q.default);return new UQ}var t1=["tags","metadata","callbacks","configurable"],a1=["tags","metadata","callbacks","runName","maxConcurrency","recursionLimit","configurable","runId","outputKeys","streamMode","store","writer","interrupt","context","interruptBefore","interruptAfter","checkpointDuring","durability","signal"],e1=25;function b0(...Q){let $={tags:[],metadata:{},callbacks:void 0,recursionLimit:e1,configurable:{}},J=QQ.getRunnableConfig();if(J!==void 0){for(let[Z,q]of Object.entries(J))if(q!==void 0)if(t1.includes(Z)){let z;if(Array.isArray(q))z=[...q];else if(typeof q==="object")if(Z==="callbacks"&&"copy"in q&&typeof q.copy==="function")z=q.copy();else z={...q};else z=q;$[Z]=z}else $[Z]=q}for(let Z of Q){if(Z===void 0)continue;for(let[q,z]of Object.entries(Z))if(z!==void 0&&a1.includes(q))$[q]=z}for(let[Z,q]of Object.entries($.configurable))if($.metadata=$.metadata??{},!Z.startsWith("__")&&(typeof q==="string"||typeof q==="number"||typeof q==="boolean")&&!(Z in $.metadata))$.metadata[Z]=q;return $}function u8(){return QQ.getRunnableConfig()}function Q6(Q){let $=Q??QQ.getRunnableConfig();if($===void 0)throw Error(["Config not retrievable. This is likely because you are running in an environment without support for AsyncLocalStorage.","If you're running `getCurrentTaskInput` in such environment, pass the `config` from the node function directly."].join(`
5
+ `));if($.configurable?.[JQ]?.currentTaskInput===void 0)throw Error("BUG: internal scratchpad not initialized.");return $.configurable[JQ].currentTaskInput}function Z8(Q){return Q.split(k).filter(($)=>!$.match(/^\d+$/)).map(($)=>$.split(e)[0]).join(k)}function y$(Q){let $=Q.split(k);while($.length>1&&$[$.length-1].match(/^\d+$/))$.pop();return $.slice(0,-1).join(k)}var s=class extends YQ{lc_namespace=["langgraph"];func;tags;config;trace=!0;recurse=!0;constructor(Q){super();this.name=Q.name??Q.func.name,this.func=Q.func,this.config=Q.tags?{tags:Q.tags}:void 0,this.trace=Q.trace??this.trace,this.recurse=Q.recurse??this.recurse}async _tracedInvoke(Q,$,J){return new Promise((Z,q)=>{let z=rQ($,{callbacks:J?.getChild()});QQ.runWithConfig(z,async()=>{try{Z(await this.func(Q,z))}catch(Y){q(Y)}})})}async invoke(Q,$){let J,Z=b0($),q=DQ(this.config,Z);if(this.trace)J=await this._callWithConfig(this._tracedInvoke,Q,q);else J=await QQ.runWithConfig(q,async()=>this.func(Q,q));if(YQ.isRunnable(J)&&this.recurse)return await QQ.runWithConfig(q,async()=>J.invoke(Q,q));return J}};function*fQ(Q,$){if($===void 0)yield*Q;else for(let J of Q)yield[$,J]}async function GQ(Q){let $=[];for await(let J of await Q)$.push(J);return $}function $0(Q){let $=[];for(let J of Q)$.push(J);return $}function J0(Q,$){if(!Q)return{configurable:$};else if(!("configurable"in Q))return{...Q,configurable:$};else return{...Q,configurable:{...Q.configurable,...$}}}function E$(Q){return Q!=null&&typeof Q==="function"&&Q instanceof Object.getPrototypeOf(async function*(){}).constructor}function v$(Q){return Q!=null&&typeof Q==="function"&&Q instanceof Object.getPrototypeOf(function*(){}).constructor}var gZ={[Symbol.for("LG_SKIP_WRITE")]:!0};function $6(Q){return typeof Q==="object"&&Q?.[Symbol.for("LG_SKIP_WRITE")]!==void 0}var qQ={[Symbol.for("LG_PASSTHROUGH")]:!0};function q8(Q){return typeof Q==="object"&&Q?.[Symbol.for("LG_PASSTHROUGH")]!==void 0}var d8=Symbol("IS_WRITER"),h=class Q extends s{writes;constructor($,J){let Z=`ChannelWrite<${$.map((q)=>{if(d(q))return q.node;else if("channel"in q)return q.channel;return"..."}).join(",")}>`;super({writes:$,name:Z,tags:J,trace:!1,func:async(q,z)=>{return this._write(q,z??{})}});this.writes=$}async _write($,J){let Z=this.writes.map((q)=>{if(p8(q)&&q8(q.value))return{mapper:q.mapper,value:$};else if(z8(q)&&q8(q.value))return{channel:q.channel,value:$,skipNone:q.skipNone,mapper:q.mapper};else return q});return await Q.doWrite(J,Z),$}static async doWrite($,J){for(let z of J){if(z8(z)){if(z.channel===c)throw new w("Cannot write to the reserved channel TASKS");if(q8(z.value))throw new w("PASSTHROUGH value must be replaced")}if(p8(z)){if(q8(z.value))throw new w("PASSTHROUGH value must be replaced")}}let Z=[];for(let z of J)if(d(z))Z.push([c,z]);else if(p8(z)){let Y=await z.mapper.invoke(z.value,$);if(Y!=null&&Y.length>0)Z.push(...Y)}else if(z8(z)){let Y=z.mapper!==void 0?await z.mapper.invoke(z.value,$):z.value;if($6(Y))continue;if(z.skipNone&&Y===void 0)continue;Z.push([z.channel,Y])}else throw Error(`Invalid write entry: ${JSON.stringify(z)}`);let q=$.configurable?.[WQ];q(Z)}static isWriter($){return $ instanceof Q||d8 in $&&!!$[d8]}static registerWriter($){return Object.defineProperty($,d8,{value:!0})}};function z8(Q){return Q!==void 0&&typeof Q.channel==="string"}function p8(Q){return Q!==void 0&&!z8(Q)&&YQ.isRunnable(Q.mapper)}var k$=class Q extends s{lc_graph_name="ChannelRead";channel;fresh=!1;mapper;constructor($,J,Z=!1){super({trace:!1,func:(q,z)=>Q.doRead(z,this.channel,this.fresh,this.mapper)});this.fresh=Z,this.mapper=J,this.channel=$,this.name=Array.isArray($)?`ChannelRead<${$.join(",")}>`:`ChannelRead<${$}>`}static doRead($,J,Z,q){let z=$.configurable?.[AQ];if(!z)throw Error("Runnable is not configured with a read function. Make sure to call in the context of a Pregel process");if(q)return q(z(J,Z));else return z(J,Z)}},j0=new f$,KQ=class Q extends C${lc_graph_name="PregelNode";channels;triggers=[];mapper;writers=[];bound=j0;kwargs={};metadata={};tags=[];retryPolicy;cachePolicy;subgraphs;ends;constructor($){let{channels:J,triggers:Z,mapper:q,writers:z,bound:Y,kwargs:X,metadata:B,retryPolicy:F,cachePolicy:W,tags:L,subgraphs:H,ends:j}=$,U=[...$.config?.tags?$.config.tags:[],...L??[]];super({...$,bound:$.bound??j0,config:{...$.config?$.config:{},tags:U}});this.channels=J,this.triggers=Z,this.mapper=q,this.writers=z??this.writers,this.bound=Y??this.bound,this.kwargs=X??this.kwargs,this.metadata=B??this.metadata,this.tags=U,this.retryPolicy=F,this.cachePolicy=W,this.subgraphs=H,this.ends=j}getWriters(){let $=[...this.writers];while($.length>1&&$[$.length-1]instanceof h&&$[$.length-2]instanceof h){let J=$.slice(-2),Z=J[0].writes.concat(J[1].writes);$[$.length-2]=new h(Z,J[0].config?.tags),$.pop()}return $}getNode(){let $=this.getWriters();if(this.bound===j0&&$.length===0)return;else if(this.bound===j0&&$.length===1)return $[0];else if(this.bound===j0)return new Z0({first:$[0],middle:$.slice(1,$.length-1),last:$[$.length-1],omitSequenceTags:!0});else if($.length>0)return new Z0({first:this.bound,middle:$.slice(0,$.length-1),last:$[$.length-1],omitSequenceTags:!0});else return this.bound}join($){if(!Array.isArray($))throw Error("channels must be a list");if(typeof this.channels!=="object")throw Error("all channels must be named when using .join()");return new Q({channels:{...this.channels,...Object.fromEntries($.map((J)=>[J,J]))},triggers:this.triggers,mapper:this.mapper,writers:this.writers,bound:this.bound,kwargs:this.kwargs,config:this.config,retryPolicy:this.retryPolicy,cachePolicy:this.cachePolicy})}pipe($){if(h.isWriter($))return new Q({channels:this.channels,triggers:this.triggers,mapper:this.mapper,writers:[...this.writers,$],bound:this.bound,config:this.config,kwargs:this.kwargs,retryPolicy:this.retryPolicy,cachePolicy:this.cachePolicy});else if(this.bound===j0)return new Q({channels:this.channels,triggers:this.triggers,mapper:this.mapper,writers:this.writers,bound:yQ($),config:this.config,kwargs:this.kwargs,retryPolicy:this.retryPolicy,cachePolicy:this.cachePolicy});else return new Q({channels:this.channels,triggers:this.triggers,mapper:this.mapper,writers:this.writers,bound:this.bound.pipe($),config:this.config,kwargs:this.kwargs,retryPolicy:this.retryPolicy,cachePolicy:this.cachePolicy})}};function J6(Q){return"steps"in Q&&Array.isArray(Q.steps)}function S0(Q){return"lg_is_pregel"in Q&&Q.lg_is_pregel===!0}function Y8(Q){let $=[Q];for(let J of $)if(S0(J))return J;else if(J6(J))$.push(...J.steps)}function q0(Q,$,J=!0,Z=!1){try{return Q[$].get()}catch(q){if(q.name===v.unminifiable_name){if(Z)return q;else if(J)return null}throw q}}function MQ(Q,$,J=!0){if(Array.isArray($)){let Z={};for(let q of $)try{Z[q]=q0(Q,q,!J)}catch(z){if(z.name===v.unminifiable_name)continue}return Z}else return q0(Q,$)}function*g$(Q,$){if(Q.graph===a.PARENT)throw new w("There is no parent graph.");if(Q.goto){let J;if(Array.isArray(Q.goto))J=Q.goto;else J=[Q.goto];for(let Z of J)if(d(Z))yield[n,c,Z];else if(typeof Z==="string")yield[n,`branch:to:${Z}`,"__start__"];else throw Error(`In Command.send, expected Send or string, got ${typeof Z}`)}if(Q.resume)if(typeof Q.resume==="object"&&Object.keys(Q.resume).length&&Object.keys(Q.resume).every(t0))for(let[J,Z]of Object.entries(Q.resume)){let q=$.filter((z)=>z[0]===J&&z[1]===o).map((z)=>z[2]).slice(0,1)??[];q.push(Z),yield[J,o,q]}else yield[n,o,Q.resume];if(Q.update){if(typeof Q.update!=="object"||!Q.update)throw Error("Expected cmd.update to be a dict mapping channel names to update values");if(Array.isArray(Q.update))for(let[J,Z]of Q.update)yield[n,J,Z];else for(let[J,Z]of Object.entries(Q.update))yield[n,J,Z]}}function*X8(Q,$){if($!==void 0&&$!==null)if(Array.isArray(Q)&&typeof $==="object"&&!Array.isArray($)){for(let J in $)if(Q.includes(J))yield[J,$[J]]}else if(Array.isArray(Q))throw Error('Input chunk must be an object when "inputChannels" is an array');else yield[Q,$]}function*F8(Q,$,J){if(Array.isArray(Q)){if($===!0||$.find(([Z,q])=>Q.includes(Z)))yield MQ(J,Q)}else if($===!0||$.some(([Z,q])=>Z===Q))yield q0(J,Q)}function*m$(Q,$,J){let Z=$.filter(([X,B])=>{return(X.config===void 0||!X.config.tags?.includes(E))&&B[0][0]!==p&&B[0][0]!==S});if(!Z.length)return;let q;if(Z.some(([X])=>X.writes.some(([B,F])=>B===jQ)))q=Z.flatMap(([X])=>X.writes.filter(([B,F])=>B===jQ).map(([B,F])=>[X.name,F]));else if(!Array.isArray(Q))q=Z.flatMap(([X])=>X.writes.filter(([B,F])=>B===Q).map(([B,F])=>[X.name,F]));else q=Z.flatMap(([X])=>{let{writes:B}=X,F={};for(let[W]of B)if(Q.includes(W))F[W]=(F[W]||0)+1;if(Object.values(F).some((W)=>W>1))return B.filter(([W])=>Q.includes(W)).map(([W,L])=>[X.name,{[W]:L}]);else return[[X.name,Object.fromEntries(B.filter(([W])=>Q.includes(W)))]]});let z={};for(let[X,B]of q){if(!(X in z))z[X]=[];z[X].push(B)}let Y={};for(let X in z)if(z[X].length===1){let[B]=z[X];Y[X]=B}else Y[X]=z[X];if(J)Y.__metadata__={cached:J};yield Y}function B8(Q){let $=typeof Q[T];if($==="number")return 0;if($==="string")return"";for(let J in Q){if(!Object.prototype.hasOwnProperty.call(Q,J))continue;let Z=typeof Q[J];if(Z==="number")return 0;if(Z==="string")return"";break}}function H0(Q,$){if(Object.keys(Q).length>0){let J=B8($);return Object.fromEntries(Object.entries($).filter(([Z,q])=>q>(Q[Z]??J)))}else return $}function h$(Q,$){return Q&&!Array.isArray(Q)&&!(Q instanceof Date)&&typeof Q==="object"?Q:{[$]:Q}}function zQ(Q,$){if(Q===null)return{configurable:$};else if(Q?.configurable===void 0)return{...Q,configurable:$};else return{...Q,configurable:{...Q.configurable,...$}}}function nQ(Q,$){let J=$?.parents??{};if(Object.keys(J).length>0)return zQ(Q,{[ZQ]:{...J,[Q.configurable?.checkpoint_ns??""]:Q.configurable?.checkpoint_id}});else return Q}function U0(...Q){let $=[...new Set(Q.filter(Boolean))];if($.length===0)return{signal:void 0,dispose:void 0};if($.length===1)return{signal:$[0],dispose:void 0};let J=new AbortController,Z=()=>{let z=$.find((Y)=>Y.aborted)?.reason;J.abort(z),$.forEach((Y)=>Y.removeEventListener("abort",Z))};$.forEach((z)=>z.addEventListener("abort",Z,{once:!0}));let q=$.find((z)=>z.aborted);if(q)J.abort(q.reason);return{signal:J.signal,dispose:()=>{$.forEach((z)=>z.removeEventListener("abort",Z))}}}var u$=(Q,$)=>{if(!Q&&!$)return;if(!Q)return $;if(!$)return Q;if(Array.isArray(Q)&&Array.isArray($))return[...Q,...$];if(Array.isArray(Q))return[...Q,$];if(Array.isArray($))return[Q,...$];return[Q,$]};var d$=class{func;name;input;retry;cache;callbacks;__lg_type="call";constructor({func:Q,name:$,input:J,retry:Z,cache:q,callbacks:z}){this.func=Q,this.name=$,this.input=J,this.retry=Z,this.cache=q,this.callbacks=z}};function p$(Q){return typeof Q==="object"&&Q!==null&&"__lg_type"in Q&&Q.__lg_type==="call"}function l$(Q,$){return new Z0({name:Q,first:new s({func:(J)=>$(...J),name:Q,trace:!1,recurse:!1}),last:new h([{channel:jQ,value:qQ}],[E])})}function o$(Q,$){return new s({func:(J,Z)=>{return $(J,Z)},name:Q,trace:!1,recurse:!1})}var i$=(Q)=>{return Q!==void 0?Q+1:1};function Z6(Q,$){if($==null)return!1;for(let J of Q)if($[J])return!0;return!1}function q6(Q){let $;for(let J in Q){if(!Object.prototype.hasOwnProperty.call(Q,J))continue;if($==null)$=Q[J];else $=c$($,Q[J])}return $}function N0(Q,$,J){let Z=B8(Q.channel_versions),q=Q.versions_seen[S]??{},z=!1;if((Q.channel_versions[T]??Z)>(q[T]??Z))z=!0;else for(let X in Q.channel_versions){if(!Object.prototype.hasOwnProperty.call(Q.channel_versions,X))continue;if(Q.channel_versions[X]>(q[X]??Z)){z=!0;break}}let Y=J.some((X)=>$==="*"?!X.config?.tags?.includes(E):$.includes(X.name));return z&&Y}function _0(Q,$,J,Z,q=!1){let z=new Set;if(!Array.isArray(Z)){for(let[X]of J.writes)if(X===Z){z=new Set([X]);break}z=z||new Set}else z=new Set(Z.filter((X)=>J.writes.some(([B,F])=>B===X)));let Y;if(q&&z.size>0){let X=Object.fromEntries(Object.entries($).filter(([W,L])=>z.has(W))),B=HQ(Q,X,-1),F=oQ(X,B);$Q(kQ(B),F,[J],void 0,void 0),Y=MQ({...$,...F},Z)}else Y=MQ($,Z);return Y}function l8(Q,$,J){for(let[Z,q]of J)if([r,c].includes(Z)&&q!=null){if(!d(q))throw new w(`Invalid packet type, expected SendProtocol, got ${JSON.stringify(q)}`);if(!(q.node in $))throw new w(`Invalid node name "${q.node}" in Send packet`)}Q(J)}var z6=new Set([m0,r,o,S,jQ,p]);function $Q(Q,$,J,Z,q){J.sort((H,j)=>{let U=H.path?.slice(0,3)||[],D=j.path?.slice(0,3)||[];for(let M=0;M<Math.min(U.length,D.length);M+=1){if(U[M]<D[M])return-1;if(U[M]>D[M])return 1}return U.length-D.length});let z=J.some((H)=>H.triggers.length>0),Y=w0($);for(let H of J){Q.versions_seen[H.name]??={};for(let j of H.triggers)if(j in Q.channel_versions)Q.versions_seen[H.name][j]=Q.channel_versions[j]}let X=q6(Q.channel_versions),B=new Set(J.flatMap((H)=>H.triggers).filter((H)=>!G$.includes(H))),F=!1;for(let H of B)if(H in Y&&Y[H].consume()){if(Z!==void 0)Q.channel_versions[H]=Z(X),F=!0}let W={};for(let H of J)for(let[j,U]of H.writes)if(z6.has(j));else if(j in Y)W[j]??=[],W[j].push(U);if(X!=null&&Z!=null)X=F?Z(X):X;let L=new Set;for(let[H,j]of Object.entries(W))if(H in Y){let U=Y[H],D;try{D=U.update(j)}catch(M){if(M.name===w.unminifiable_name){let O=new w(`Invalid update for channel "${H}" with values ${JSON.stringify(j)}: ${M.message}`);throw O.lc_error_code=M.lc_error_code,O}else throw M}if(D&&Z!==void 0){if(Q.channel_versions[H]=Z(X),U.isAvailable())L.add(H)}}if(z)for(let H in Y){if(!Object.prototype.hasOwnProperty.call(Y,H))continue;let j=Y[H];if(j.isAvailable()&&!L.has(H)){if(j.update([])&&Z!==void 0){if(Q.channel_versions[H]=Z(X),j.isAvailable())L.add(H)}}}if(z&&!Z6(L,q))for(let H in Y){if(!Object.prototype.hasOwnProperty.call(Y,H))continue;let j=Y[H];if(j.finish()&&Z!==void 0){if(Q.channel_versions[H]=Z(X),j.isAvailable())L.add(H)}}return L}function*Y6(Q,$,J){if(J.updatedChannels!=null&&J.triggerToNodes!=null){let Z=new Set;for(let q of J.updatedChannels){let z=J.triggerToNodes[q];for(let Y of z??[])Z.add(Y)}yield*[...Z].sort();return}if((()=>{for(let Z in Q.channel_versions)if(Q.channel_versions[Z]!==null)return!1;return!0})())return;for(let Z in $){if(!Object.prototype.hasOwnProperty.call($,Z))continue;yield Z}}function tQ(Q,$,J,Z,q,z,Y){let X={},B=Z[c];if(B?.isAvailable()){let F=B.get().length;for(let W=0;W<F;W+=1){let L=L8([r,W],Q,$,J,Z,q,z,Y);if(L!==void 0)X[L.id]=L}}for(let F of Y6(Q,J,Y)){let W=L8([x0,F],Q,$,J,Z,q,z,Y);if(W!==void 0)X[W.id]=W}return X}function L8(Q,$,J,Z,q,z,Y,X){let{step:B,checkpointer:F,manager:W}=X,L=z.configurable??{},H=L.checkpoint_ns??"";if(Q[0]===r&&p$(Q[Q.length-1])){let j=Q[Q.length-1],U=l$(j.name,j.func),D=[r],M=H===""?j.name:`${H}${k}${j.name}`,O=sQ(JSON.stringify([M,B.toString(),j.name,r,Q[1],Q[2]]),$.id),_=`${M}${e}${O}`,P=[...Q.slice(0,3),!0],I={langgraph_step:B,langgraph_node:j.name,langgraph_triggers:D,langgraph_path:P,langgraph_checkpoint_ns:_};if(Y){let N=[];return{name:j.name,input:j.input,proc:U,writes:N,config:rQ(DQ(z,{metadata:I,store:X.store??z.store}),{runName:j.name,callbacks:W?.getChild(`graph:step:${B}`),configurable:{[Y0]:O,[WQ]:(f)=>l8((K)=>N.push(...K),Z,f),[AQ]:(f,K=!1)=>_0($,q,{name:j.name,writes:N,triggers:D,path:P},f,K),[m]:F??L[m],[ZQ]:{...L[ZQ],[H]:$.id},[JQ]:o8({pendingWrites:J??[],taskId:O,currentTaskInput:j.input,resumeMap:z.configurable?.[X0],namespaceHash:vQ(_)}),[M0]:$.channel_values[aQ],checkpoint_id:void 0,checkpoint_ns:_}}),triggers:D,retry_policy:j.retry,cache_key:j.cache?{key:vQ((j.cache.keyFunc??JSON.stringify)([j.input])),ns:[k0,j.name??"__dynamic__"],ttl:j.cache.ttl}:void 0,id:O,path:P,writers:[]}}else return{id:O,name:j.name,interrupts:[],path:P}}else if(Q[0]===r){let j=typeof Q[1]==="number"?Q[1]:parseInt(Q[1],10);if(!q[c]?.isAvailable())return;let U=q[c].get();if(j<0||j>=U.length)return;let D=u0(U[j])&&!d(U[j])?new uQ(U[j].node,U[j].args):U[j];if(!u0(D)){console.warn(`Ignoring invalid packet ${JSON.stringify(D)} in pending sends.`);return}if(!(D.node in Z)){console.warn(`Ignoring unknown node name ${D.node} in pending sends.`);return}let M=[r],O=H===""?D.node:`${H}${k}${D.node}`,_=sQ(JSON.stringify([O,B.toString(),D.node,r,j.toString()]),$.id),P=`${O}${e}${_}`,I={langgraph_step:B,langgraph_node:D.node,langgraph_triggers:M,langgraph_path:Q.slice(0,3),langgraph_checkpoint_ns:P};if(Y){let N=Z[D.node],f=N.getNode();if(f!==void 0){if(N.metadata!==void 0)I={...I,...N.metadata};let K=[];return{name:D.node,input:D.args,proc:f,subgraphs:N.subgraphs,writes:K,config:rQ(DQ(z,{metadata:I,tags:N.tags,store:X.store??z.store}),{runName:D.node,callbacks:W?.getChild(`graph:step:${B}`),configurable:{[Y0]:_,[WQ]:(x)=>l8((b)=>K.push(...b),Z,x),[AQ]:(x,b=!1)=>_0($,q,{name:D.node,writes:K,triggers:M,path:Q},x,b),[m]:F??L[m],[ZQ]:{...L[ZQ],[H]:$.id},[JQ]:o8({pendingWrites:J??[],taskId:_,currentTaskInput:D.args,resumeMap:z.configurable?.[X0],namespaceHash:vQ(P)}),[M0]:$.channel_values[aQ],checkpoint_id:void 0,checkpoint_ns:P}}),triggers:M,retry_policy:N.retryPolicy,cache_key:N.cachePolicy?{key:vQ((N.cachePolicy.keyFunc??JSON.stringify)([D.args])),ns:[k0,N.name??"__dynamic__",D.node],ttl:N.cachePolicy.ttl}:void 0,id:_,path:Q,writers:N.getWriters()}}}else return{id:_,name:D.node,interrupts:[],path:Q}}else if(Q[0]===x0){let j=Q[1].toString(),U=Z[j];if(U===void 0)return;if(J?.length){let _=H===""?j:`${H}${k}${j}`,P=sQ(JSON.stringify([_,B.toString(),j,x0,j]),$.id);if(J.some((I)=>I[0]===P&&I[1]!==p))return}let D=B8($.channel_versions);if(D===void 0)return;let M=$.versions_seen[j]??{},O=U.triggers.find((_)=>{if(!q[_].isAvailable())return!1;return($.channel_versions[_]??D)>(M[_]??D)});if(O!==void 0){let _=X6(U,q,Y);if(_===void 0)return;let P=H===""?j:`${H}${k}${j}`,I=sQ(JSON.stringify([P,B.toString(),j,x0,[O]]),$.id),N=`${P}${e}${I}`,f={langgraph_step:B,langgraph_node:j,langgraph_triggers:[O],langgraph_path:Q,langgraph_checkpoint_ns:N};if(Y){let K=U.getNode();if(K!==void 0){if(U.metadata!==void 0)f={...f,...U.metadata};let x=[];return{name:j,input:_,proc:K,subgraphs:U.subgraphs,writes:x,config:rQ(DQ(z,{metadata:f,tags:U.tags,store:X.store??z.store}),{runName:j,callbacks:W?.getChild(`graph:step:${B}`),configurable:{[Y0]:I,[WQ]:(b)=>l8((G)=>{x.push(...G)},Z,b),[AQ]:(b,G=!1)=>_0($,q,{name:j,writes:x,triggers:[O],path:Q},b,G),[m]:F??L[m],[ZQ]:{...L[ZQ],[H]:$.id},[JQ]:o8({pendingWrites:J??[],taskId:I,currentTaskInput:_,resumeMap:z.configurable?.[X0],namespaceHash:vQ(N)}),[M0]:$.channel_values[aQ],checkpoint_id:void 0,checkpoint_ns:N}}),triggers:[O],retry_policy:U.retryPolicy,cache_key:U.cachePolicy?{key:vQ((U.cachePolicy.keyFunc??JSON.stringify)([_])),ns:[k0,U.name??"__dynamic__",j],ttl:U.cachePolicy.ttl}:void 0,id:I,path:Q,writers:U.getWriters()}}}else return{id:I,name:j,interrupts:[],path:Q}}}}function X6(Q,$,J){let Z;if(typeof Q.channels==="object"&&!Array.isArray(Q.channels)){Z={};for(let[q,z]of Object.entries(Q.channels))if(Q.triggers.includes(z))try{Z[q]=q0($,z,!1)}catch(Y){if(Y.name===v.unminifiable_name)return;else throw Y}else if(z in $)try{Z[q]=q0($,z,!1)}catch(Y){if(Y.name===v.unminifiable_name)continue;else throw Y}}else if(Array.isArray(Q.channels)){let q=!1;for(let z of Q.channels)try{Z=q0($,z,!1),q=!0;break}catch(Y){if(Y.name===v.unminifiable_name)continue;else throw Y}if(!q)return}else throw Error(`Invalid channels type, expected list or dict, got ${Q.channels}`);if(J&&Q.mapper!==void 0)Z=Q.mapper(Z);return Z}function r$(Q,$){if(typeof Q.args!=="object"||Q.args===null)return Q;let J={};for(let[Z,q]of Object.entries(Q.args)){let z=$[Z];if(!z||z.lc_graph_name!=="UntrackedValue")J[Z]=q}return new uQ(Q.node,J)}function o8({pendingWrites:Q,taskId:$,currentTaskInput:J,resumeMap:Z,namespaceHash:q}){let z=Q.find(([X,B])=>X===n&&B===o)?.[2],Y={callCounter:0,interruptCounter:-1,resume:(()=>{let X=Q.filter(([B,F])=>B===$&&F===o).flatMap(([B,F,W])=>W);if(Z!=null&&q in Z){let B=Z[q];X.push(B)}return X})(),nullResume:z,subgraphCounter:0,currentTaskInput:J,consumeNullResume:()=>{if(Y.nullResume)return delete Y.nullResume,Q.splice(Q.findIndex(([X,B])=>X===n&&B===o),1),z}};return Y}var I0={blue:{start:"\x1B[34m",end:"\x1B[0m"},green:{start:"\x1B[32m",end:"\x1B[0m"},yellow:{start:"\x1B[33;1m",end:"\x1B[0m"}},y0=(Q,$)=>`${Q.start}${$}${Q.end}`;function*c8(Q){for(let{id:$,name:J,input:Z,config:q,triggers:z,writes:Y}of Q){if(q?.tags?.includes(E))continue;yield{id:$,name:J,input:Z,triggers:z,interrupts:Y.filter(([X,B])=>{return X===$&&B===S}).map(([,X])=>{return X})}}}function F6(Q){if(typeof Q!=="object"||Q===null)return!1;return"$writes"in Q&&Array.isArray(Q.$writes)}function n$(Q){let $={};for(let[J,Z]of Q){let q=String(J);if(q in $){let z=F6($[q])?$[q].$writes:[$[q]];z.push(Z),$[q]={$writes:z}}else $[q]=Z}return $}function*s$(Q,$){for(let[{id:J,name:Z,config:q},z]of Q){if(q?.tags?.includes(E))continue;yield{id:J,name:Z,result:n$(z.filter(([Y])=>{return Array.isArray($)?$.includes(Y):Y===$})),interrupts:z.filter((Y)=>Y[0]===S).map((Y)=>Y[1])}}}function*t$(Q,$,J,Z,q,z,Y,X){function B(L){let H={};if(L.callbacks!=null)H.callbacks=L.callbacks;if(L.configurable!=null)H.configurable=L.configurable;if(L.maxConcurrency!=null)H.max_concurrency=L.maxConcurrency;if(L.metadata!=null)H.metadata=L.metadata;if(L.recursionLimit!=null)H.recursion_limit=L.recursionLimit;if(L.runId!=null)H.run_id=L.runId;if(L.runName!=null)H.run_name=L.runName;if(L.tags!=null)H.tags=L.tags;return H}let F=Q.configurable?.checkpoint_ns,W={};for(let L of q){if(!((L.subgraphs?.length)?L.subgraphs:[L.proc]).find(Y8))continue;let H=`${L.name}:${L.id}`;if(F)H=`${F}|${H}`;W[L.id]={configurable:{thread_id:Q.configurable?.thread_id,checkpoint_ns:H}}}yield{config:B(Q),values:MQ($,J),metadata:Z,next:q.map((L)=>L.name),tasks:i8(q,z,W,X),parentConfig:Y?B(Y):void 0}}function i8(Q,$,J,Z){return Q.map((q)=>{let z=$.find(([F,W])=>F===q.id&&W===p)?.[2],Y=$.filter(([F,W])=>F===q.id&&W===S).map(([,,F])=>F),X=(()=>{if(z||Y.length||!$.length)return;let F=$.findIndex(([W,L])=>W===q.id&&L===jQ);if(F>=0)return $[F][2];if(typeof Z==="string")return $.find(([W,L])=>W===q.id&&L===Z)?.[2];if(Array.isArray(Z)){let W=$.filter(([L,H])=>L===q.id&&Z.includes(H)).map(([,L,H])=>[L,H]);if(!W.length)return;return n$(W)}})();if(z)return{id:q.id,name:q.name,path:q.path,error:z,interrupts:Y,result:X};let B=J?.[q.id];return{id:q.id,name:q.name,path:q.path,interrupts:Y,...B!==void 0?{state:B}:{},result:X}})}function a$(Q,$,J){console.log([`${y0(I0.blue,`[${Q}:checkpoint]`)}`,`\x1B[1m State at the end of step ${Q}:\x1B[0m
6
+ `,JSON.stringify(MQ($,J),null,2)].join(""))}function W8(Q,$){let J=$.length;console.log([`${y0(I0.blue,`[${Q}:tasks]`)}`,`\x1B[1m Starting step ${Q} with ${J} task${J===1?"":"s"}:\x1B[0m
7
+ `,$.map((Z)=>`- ${y0(I0.green,String(Z.name))} -> ${JSON.stringify(Z.input,null,2)}`).join(`
8
+ `)].join(""))}function e$(Q,$,J){let Z={};for(let[q,z]of $)if(J.includes(q)){if(!Z[q])Z[q]=[];Z[q].push(z)}console.log([`${y0(I0.blue,`[${Q}:writes]`)}`,`\x1B[1m Finished step ${Q} with writes to ${Object.keys(Z).length} channel${Object.keys(Z).length!==1?"s":""}:\x1B[0m
9
+ `,Object.entries(Z).map(([q,z])=>`- ${y0(I0.yellow,q)} -> ${z.map((Y)=>JSON.stringify(Y)).join(", ")}`).join(`
10
+ `)].join(""))}var s8=class extends n8{_abortController;_innerReader;constructor(Q,$){let J=Q.getReader(),Z=$??new AbortController;super({start(q){return z();function z(){return J.read().then(({done:Y,value:X})=>{if(Y){q.close();return}return q.enqueue(X),z()})}}});this._abortController=Z,this._innerReader=J}async cancel(Q){this._abortController.abort(Q),this._innerReader.releaseLock()}get signal(){return this._abortController.signal}},H8=class extends n8{modes;controller;passthroughFn;_closed=!1;get closed(){return this._closed}constructor(Q){let $,J=new Promise((Z)=>{$=Z});super({start:(Z)=>{$(Z)}});J.then((Z)=>{this.controller=Z}),this.passthroughFn=Q.passthroughFn,this.modes=Q.modes}push(Q){this.passthroughFn?.(Q),this.controller.enqueue(Q)}close(){try{this.controller.close()}catch(Q){}finally{this._closed=!0}}error(Q){this.controller.error(Q)}},J1=class extends j8{name="StreamToolsHandler";streamFn;runs={};constructor(Q){super();this.streamFn=Q}handleToolStart(Q,$,J,Z,q,z,Y,X){if(!z||q&&q.includes(E))return;let B=z.langgraph_checkpoint_ns?.split("|")??[],F={ns:B,toolCallId:X,toolName:Y??"unknown",input:$};this.runs[J]=F,this.streamFn([B,"tools",{event:"on_tool_start",toolCallId:F.toolCallId,name:F.toolName,input:$}])}handleToolEvent(Q,$){let J=this.runs[$];if(!J)return;this.streamFn([J.ns,"tools",{event:"on_tool_event",toolCallId:J.toolCallId,name:J.toolName,data:Q}])}handleToolEnd(Q,$){let J=this.runs[$];if(delete this.runs[$],!J)return;this.streamFn([J.ns,"tools",{event:"on_tool_end",toolCallId:J.toolCallId,name:J.toolName,output:Q}])}handleToolError(Q,$){let J=this.runs[$];if(delete this.runs[$],!J)return;this.streamFn([J.ns,"tools",{event:"on_tool_error",toolCallId:J.toolCallId,name:J.toolName,error:Q}])}};function B6(Q){return JSON.stringify(Q,function($,J){let Z=this[$];if(Z!=null&&typeof Z==="object"&&"toDict"in Z&&typeof Z.toDict==="function"){let{type:q,data:z}=Z.toDict();return{...z,type:q}}return J})}function L6(Q){if(Q instanceof Error)return{error:Q.name,message:Q.message};return{error:"Error",message:JSON.stringify(Q)}}function t8(Q){if(typeof Q!=="object"||Q==null)return!1;return"configurable"in Q&&typeof Q.configurable==="object"&&Q.configurable!=null}function r8(Q){if(!t8(Q)||!Q.configurable.thread_id)return null;return{thread_id:Q.configurable.thread_id,checkpoint_ns:Q.configurable.checkpoint_ns||"",checkpoint_id:Q.configurable.checkpoint_id||null,checkpoint_map:Q.configurable.checkpoint_map||null}}function Q1(Q){if(t8(Q)){let $=Object.fromEntries(Object.entries(Q.configurable).filter(([Z])=>!Z.startsWith("__"))),J={...Q,configurable:$};return delete J.callbacks,J}return Q}function $1(Q){let $={...Q,checkpoint:r8(Q.config),parent_checkpoint:r8(Q.parentConfig),config:Q1(Q.config),parent_config:Q1(Q.parentConfig),tasks:Q.tasks.map((J)=>{if(t8(J.state)){let Z=r8(J.state);if(Z!=null){let q={...J,checkpoint:Z};return delete q.state,q}}return J})};return delete $.parentConfig,$}function Z1(Q){let $=new TextEncoder;return new ReadableStream({async start(J){let Z=(q)=>{J.enqueue($.encode(`event: ${q.event}
11
+ data: ${B6(q.data)}
12
+
13
+ `))};try{for await(let q of Q){let[z,Y,X]=q,B=X;if(Y==="debug"){let F=X;if(F.type==="checkpoint")B={...F,payload:$1(F.payload)}}if(Y==="checkpoints")B=$1(X);Z({event:z?.length?`${Y}|${z.join("|")}`:Y,data:B})}}catch(q){Z({event:"error",data:L6(q)})}J.close()}})}var U8=Symbol.for("INPUT_DONE"),a8=Symbol.for("INPUT_RESUMING"),W6=25;function j6(...Q){return new H8({passthroughFn:($)=>{for(let J of Q)if(J.modes.has($[1]))J.push($)},modes:new Set(Q.flatMap(($)=>Array.from($.modes)))})}var H6=class extends z1{cache;queue=Promise.resolve();constructor(Q){super();this.cache=Q}async get(Q){return this.enqueueOperation("get",Q)}async set(Q){return this.enqueueOperation("set",Q)}async clear(Q){return this.enqueueOperation("clear",Q)}async stop(){await this.queue}enqueueOperation(Q,...$){let J=this.queue.then(()=>{return this.cache[Q](...$)});return this.queue=J.then(()=>{return},()=>{return}),J}},Y1=class Q{input;output;config;checkpointer;checkpointerGetNextVersion;channels;checkpoint;checkpointIdSaved;checkpointConfig;checkpointMetadata;checkpointNamespace;checkpointPendingWrites=[];checkpointPreviousVersions;step;stop;durability;outputKeys;streamKeys;nodes;skipDoneTasks;prevCheckpointConfig;updatedChannels;status="pending";tasks={};stream;checkpointerPromises=[];isNested;_checkpointerChainedPromise=Promise.resolve();store;cache;manager;interruptAfter;interruptBefore;toInterrupt=[];debug=!1;triggerToNodes;get isResuming(){let $=!1;if(T in this.checkpoint.channel_versions)$=!0;else for(let X in this.checkpoint.channel_versions)if(Object.prototype.hasOwnProperty.call(this.checkpoint.channel_versions,X)){$=!0;break}let J=this.config.configurable?.[EQ]!==void 0&&this.config.configurable?.[EQ],Z=this.input===null||this.input===void 0,q=u(this.input)&&this.input.resume!=null,z=this.input===a8,Y=!this.isNested&&this.config.metadata?.run_id!==void 0&&this.checkpointMetadata?.run_id!==void 0&&this.config.metadata.run_id===this.checkpointMetadata?.run_id;return $&&(J||Z||q||z||Y)}constructor($){if(this.input=$.input,this.checkpointer=$.checkpointer,this.checkpointer!==void 0)this.checkpointerGetNextVersion=this.checkpointer.getNextVersion.bind(this.checkpointer);else this.checkpointerGetNextVersion=i$;this.checkpoint=$.checkpoint,this.checkpointMetadata=$.checkpointMetadata,this.checkpointPreviousVersions=$.checkpointPreviousVersions,this.channels=$.channels,this.checkpointPendingWrites=$.checkpointPendingWrites,this.step=$.step,this.stop=$.stop,this.config=$.config,this.checkpointConfig=$.checkpointConfig,this.isNested=$.isNested,this.manager=$.manager,this.outputKeys=$.outputKeys,this.streamKeys=$.streamKeys,this.nodes=$.nodes,this.skipDoneTasks=$.skipDoneTasks,this.store=$.store,this.cache=$.cache?new H6($.cache):void 0,this.stream=$.stream,this.checkpointNamespace=$.checkpointNamespace,this.prevCheckpointConfig=$.prevCheckpointConfig,this.interruptAfter=$.interruptAfter,this.interruptBefore=$.interruptBefore,this.durability=$.durability,this.debug=$.debug,this.triggerToNodes=$.triggerToNodes}static async initialize($){let{config:J,stream:Z}=$;if(Z!==void 0&&J.configurable?.[K0]!==void 0)Z=j6(Z,J.configurable[K0]);let q=J.configurable?!("checkpoint_id"in J.configurable):!0,z=J.configurable?.[JQ];if(J.configurable&&z){if(z.subgraphCounter>0)J=zQ(J,{[FQ]:[J.configurable[FQ],z.subgraphCounter.toString()].join(k)});z.subgraphCounter+=1}let Y=AQ in(J.configurable??{});if(!Y&&J.configurable?.checkpoint_ns!==void 0&&J.configurable?.checkpoint_ns!=="")J=zQ(J,{checkpoint_ns:"",checkpoint_id:void 0});let X=J;if(J.configurable?.[ZQ]!==void 0&&J.configurable?.[ZQ]?.[J.configurable?.checkpoint_ns])X=zQ(J,{checkpoint_id:J.configurable[ZQ][J.configurable?.checkpoint_ns]});let B=J.configurable?.checkpoint_ns?.split(k)??[],F=await $.checkpointer?.getTuple(X)??{config:J,checkpoint:V0(),metadata:{source:"input",step:-2,parents:{}},pendingWrites:[]};X={...J,...F.config,configurable:{checkpoint_ns:"",...J.configurable,...F.config.configurable}};let W=F.parentConfig,L=kQ(F.checkpoint),H={...F.metadata},j=F.pendingWrites??[],U=oQ($.channelSpecs,L),D=(H.step??0)+1,M=D+(J.recursionLimit??W6)+1,O={...L.channel_versions},_=$.store?new V8($.store):void 0;if(_)await _.start();return new Q({input:$.input,config:J,checkpointer:$.checkpointer,checkpoint:L,checkpointMetadata:H,checkpointConfig:X,prevCheckpointConfig:W,checkpointNamespace:B,channels:U,isNested:Y,manager:$.manager,skipDoneTasks:q,step:D,stop:M,checkpointPreviousVersions:O,checkpointPendingWrites:j,outputKeys:$.outputKeys??[],streamKeys:$.streamKeys??[],nodes:$.nodes,stream:Z,store:_,cache:$.cache,interruptAfter:$.interruptAfter,interruptBefore:$.interruptBefore,durability:$.durability,debug:$.debug,triggerToNodes:$.triggerToNodes})}_checkpointerPutAfterPrevious($){this._checkpointerChainedPromise=this._checkpointerChainedPromise.then(()=>{return this.checkpointer?.put($.config,$.checkpoint,$.metadata,$.newVersions)}),this.checkpointerPromises.push(this._checkpointerChainedPromise)}putWrites($,J){let Z=J;if(Z.length===0)return;if(Z.every(([B])=>(B in q1)))Z=Array.from(new Map(Z.map((B)=>[B[0],B])).values());let q=!1;for(let B in this.channels)if(Object.prototype.hasOwnProperty.call(this.channels,B)){if(this.channels[B].lc_graph_name==="UntrackedValue"){q=!0;break}}let z=Z;if(q)z=Z.filter(([B])=>{let F=this.channels[B];return!F||F.lc_graph_name!=="UntrackedValue"}).map(([B,F])=>{if(B===c&&d(F))return[B,r$(F,this.channels)];return[B,F]});this.checkpointPendingWrites=this.checkpointPendingWrites.filter((B)=>B[0]!==$);for(let[B,F]of z)this.checkpointPendingWrites.push([$,B,F]);let Y=zQ(this.checkpointConfig,{[FQ]:this.config.configurable?.checkpoint_ns??"",[w8]:this.checkpoint.id});if(this.durability!=="exit"&&this.checkpointer!=null)this.checkpointerPromises.push(this.checkpointer.putWrites(Y,z,$));if(this.tasks)this._outputWrites($,Z);if(!J.length||!this.cache||!this.tasks)return;let X=this.tasks[$];if(X==null||X.cache_key==null)return;if(J[0][0]===p||J[0][0]===S)return;this.cache.set([{key:[X.cache_key.ns,X.cache_key.key],value:X.writes,ttl:X.cache_key.ttl}])}_outputWrites($,J,Z=!1){let q=this.tasks[$];if(q!==void 0){if(q.config!==void 0&&(q.config.tags??[]).includes(E))return;if(J.length>0){if(J[0][0]===S){if(q.path?.[0]===r&&q.path?.[q.path.length-1]===!0)return;let z=J.filter((Y)=>Y[0]===S).flatMap((Y)=>Y[1]);this._emit([["updates",{[S]:z}],["values",{[S]:z}]])}else if(J[0][0]!==p)this._emit($0(fQ(m$(this.outputKeys,[[q,J]],Z),"updates")))}if(!Z)this._emit($0(fQ(s$([[q,J]],this.streamKeys),"tasks")))}}async _matchCachedWrites(){if(!this.cache)return[];let $=[],J=([Y,X])=>{return`ns:${Y.join(",")}|key:${X}`},Z=[],q={};for(let Y of Object.values(this.tasks))if(Y.cache_key!=null&&!Y.writes.length)Z.push([Y.cache_key.ns,Y.cache_key.key]),q[J([Y.cache_key.ns,Y.cache_key.key])]=Y;if(Z.length===0)return[];let z=await this.cache.get(Z);for(let{key:Y,value:X}of z){let B=q[J(Y)];if(B!=null)B.writes.push(...X),$.push({task:B,result:X})}return $}async tick($){if(this.store&&!this.store.isRunning)await this.store?.start();let{inputKeys:J=[]}=$;if(this.status!=="pending")throw Error(`Cannot tick when status is no longer "pending". Current status: "${this.status}"`);if(![U8,a8].includes(this.input))await this._first(J);else if(this.toInterrupt.length>0)throw this.status="interrupt_before",new PQ;else if(Object.values(this.tasks).every((q)=>q.writes.length>0)){let q=Object.values(this.tasks).flatMap((Y)=>Y.writes);this.updatedChannels=$Q(this.checkpoint,this.channels,Object.values(this.tasks),this.checkpointerGetNextVersion,this.triggerToNodes);let z=await GQ(fQ(F8(this.outputKeys,q,this.channels),"values"));if(this._emit(z),this.checkpointPendingWrites=[],await this._putCheckpoint({source:"loop"}),N0(this.checkpoint,this.interruptAfter,Object.values(this.tasks)))throw this.status="interrupt_after",new PQ;if(this.config.configurable?.[EQ]!==void 0)delete this.config.configurable?.[EQ]}else return!1;if(this.step>this.stop)return this.status="out_of_steps",!1;if(this.tasks=tQ(this.checkpoint,this.checkpointPendingWrites,this.nodes,this.channels,this.config,!0,{step:this.step,checkpointer:this.checkpointer,isResuming:this.isResuming,manager:this.manager,store:this.store,stream:this.stream,triggerToNodes:this.triggerToNodes,updatedChannels:this.updatedChannels}),this.checkpointer)this._emit(await GQ(fQ(t$(this.checkpointConfig,this.channels,this.streamKeys,this.checkpointMetadata,Object.values(this.tasks),this.checkpointPendingWrites,this.prevCheckpointConfig,this.outputKeys),"checkpoints")));if(Object.values(this.tasks).length===0)return this.status="done",!1;if(this.skipDoneTasks&&this.checkpointPendingWrites.length>0){for(let[q,z,Y]of this.checkpointPendingWrites){if(z===p||z===S||z===o)continue;let X=Object.values(this.tasks).find((B)=>B.id===q);if(X)X.writes.push([z,Y])}for(let q of Object.values(this.tasks))if(q.writes.length>0)this._outputWrites(q.id,q.writes,!0)}if(Object.values(this.tasks).every((q)=>q.writes.length>0))return this.tick({inputKeys:J});if(N0(this.checkpoint,this.interruptBefore,Object.values(this.tasks)))throw this.status="interrupt_before",new PQ;let Z=await GQ(fQ(c8(Object.values(this.tasks)),"tasks"));return this._emit(Z),!0}async finishAndHandleError($){if(this.durability==="exit"&&(!this.isNested||typeof $<"u"||this.checkpointNamespace.every((Z)=>!Z.includes(e))))this._putCheckpoint(this.checkpointMetadata),this._flushPendingWrites();let J=this._suppressInterrupt($);if(J||$===void 0)this.output=MQ(this.channels,this.outputKeys);if(J){if(this.tasks!==void 0&&this.checkpointPendingWrites.length>0&&Object.values(this.tasks).some((Z)=>Z.writes.length>0))this.updatedChannels=$Q(this.checkpoint,this.channels,Object.values(this.tasks),this.checkpointerGetNextVersion,this.triggerToNodes),this._emit($0(fQ(F8(this.outputKeys,Object.values(this.tasks).flatMap((Z)=>Z.writes),this.channels),"values")));if(wQ($)&&!$.interrupts.length)this._emit([["updates",{[S]:[]}],["values",{[S]:[]}]])}return J}async acceptPush($,J,Z){if(this.interruptAfter?.length>0&&N0(this.checkpoint,this.interruptAfter,[$])){this.toInterrupt.push($);return}let q=L8([r,$.path??[],J,$.id,Z],this.checkpoint,this.checkpointPendingWrites,this.nodes,this.channels,$.config??{},!0,{step:this.step,checkpointer:this.checkpointer,manager:this.manager,store:this.store,stream:this.stream});if(!q)return;if(this.interruptBefore?.length>0&&N0(this.checkpoint,this.interruptBefore,[q])){this.toInterrupt.push(q);return}if(this._emit($0(fQ(c8([q]),"tasks"))),this.debug)W8(this.step,[q]);if(this.tasks[q.id]=q,this.skipDoneTasks)this._matchWrites({[q.id]:q});let z=await this._matchCachedWrites();for(let{task:Y}of z)this._outputWrites(Y.id,Y.writes,!0);return q}_suppressInterrupt($){return wQ($)&&!this.isNested}async _first($){let{configurable:J}=this.config,Z=J?.[JQ];if(Z&&Z.nullResume!==void 0)this.putWrites(n,[[o,Z.nullResume]]);if(u(this.input)){let Y=this.input.resume!=null;if(this.input.resume!=null&&typeof this.input.resume==="object"&&Object.keys(this.input.resume).every(t0))this.config.configurable??={},this.config.configurable[X0]=this.input.resume;if(Y&&this.checkpointer==null)throw Error("Cannot use Command(resume=...) without checkpointer");let X={};for(let[B,F,W]of g$(this.input,this.checkpointPendingWrites))X[B]??=[],X[B].push([F,W]);if(Object.keys(X).length===0)throw new P0("Received empty Command input");for(let[B,F]of Object.entries(X))this.putWrites(B,F)}let q=(this.checkpointPendingWrites??[]).filter((Y)=>Y[0]===n).map((Y)=>Y.slice(1));if(q.length>0)$Q(this.checkpoint,this.channels,[{name:xQ,writes:q,triggers:[]}],this.checkpointerGetNextVersion,this.triggerToNodes);let z=u(this.input)&&q.length>0;if(this.isResuming||z){for(let X in this.channels){if(!Object.prototype.hasOwnProperty.call(this.channels,X))continue;if(this.checkpoint.channel_versions[X]!==void 0){let B=this.checkpoint.channel_versions[X];this.checkpoint.versions_seen[S]={...this.checkpoint.versions_seen[S],[X]:B}}}let Y=await GQ(fQ(F8(this.outputKeys,!0,this.channels),"values"));this._emit(Y)}if(this.isResuming)this.input=a8;else if(z)await this._putCheckpoint({source:"input"}),this.input=U8;else{let Y=await GQ(X8($,this.input));if(Y.length>0){let X=tQ(this.checkpoint,this.checkpointPendingWrites,this.nodes,this.channels,this.config,!0,{step:this.step});this.updatedChannels=$Q(this.checkpoint,this.channels,Object.values(X).concat([{name:xQ,writes:Y,triggers:[]}]),this.checkpointerGetNextVersion,this.triggerToNodes),await this._putCheckpoint({source:"input"}),this.input=U8}else if(!(EQ in(this.config.configurable??{})))throw new P0(`Received no input writes for ${JSON.stringify($,null,2)}`);else this.input=U8}if(!this.isNested)this.config=zQ(this.config,{[EQ]:this.isResuming})}_emit($){for(let[J,Z]of $){if(this.stream.modes.has(J))this.stream.push([this.checkpointNamespace,J,Z]);if((J==="checkpoints"||J==="tasks")&&this.stream.modes.has("debug")){let q=J==="checkpoints"?this.step-1:this.step,z=new Date().toISOString(),Y=(()=>{if(J==="checkpoints")return"checkpoint";else if(typeof Z==="object"&&Z!=null&&"result"in Z)return"task_result";else return"task"})();this.stream.push([this.checkpointNamespace,"debug",{step:q,type:Y,timestamp:z,payload:Z}])}}}_putCheckpoint($){let J=this.checkpointMetadata===$,Z=this.checkpointer!=null&&(this.durability!=="exit"||J),q=(z)=>{this.prevCheckpointConfig=this.checkpointConfig?.configurable?.checkpoint_id?this.checkpointConfig:void 0,this.checkpointConfig=zQ(this.checkpointConfig,{[FQ]:this.config.configurable?.checkpoint_ns??""});let Y={...this.checkpoint.channel_versions},X=H0(this.checkpointPreviousVersions,Y);this.checkpointPreviousVersions=Y,this._checkpointerPutAfterPrevious({config:{...this.checkpointConfig},checkpoint:kQ(z),metadata:{...this.checkpointMetadata},newVersions:X}),this.checkpointConfig={...this.checkpointConfig,configurable:{...this.checkpointConfig.configurable,checkpoint_id:this.checkpoint.id}}};if(!J)this.checkpointMetadata={...$,step:this.step,parents:this.config.configurable?.[ZQ]??{}};if(this.checkpoint=HQ(this.checkpoint,Z?this.channels:void 0,this.step,J?{id:this.checkpoint.id}:void 0),Z)q(this.checkpoint);if(!J)this.step+=1}_flushPendingWrites(){if(this.checkpointer==null)return;if(this.checkpointPendingWrites.length===0)return;let $=zQ(this.checkpointConfig,{[FQ]:this.config.configurable?.checkpoint_ns??"",[w8]:this.checkpoint.id}),J={};for(let[Z,q,z]of this.checkpointPendingWrites)J[Z]??=[],J[Z].push([q,z]);for(let[Z,q]of Object.entries(J))this.checkpointerPromises.push(this.checkpointer.putWrites($,q,Z))}_matchWrites($){for(let[J,Z,q]of this.checkpointPendingWrites){if(Z===p||Z===S||Z===o)continue;let z=Object.values($).find((Y)=>Y.id===J);if(z)z.writes.push([Z,q])}for(let J of Object.values($))if(J.writes.length>0)this._outputWrites(J.id,J.writes,!0)}};function U6(Q){return gQ(Q?.message)}var B1=class extends j8{name="StreamMessagesHandler";streamFn;metadatas={};seen={};emittedChatModelRunIds={};stableMessageIdMap={};lc_prefer_streaming=!0;constructor(Q){super();this.streamFn=Q}_emit(Q,$,J,Z=!1){if(Z&&$.id!==void 0&&this.seen[$.id]!==void 0)return;let q=$.id;if(J!=null)if(X1($))q??=`run-${J}-tool-${$.tool_call_id}`;else{if(q==null||q===`run-${J}`)q=this.stableMessageIdMap[J]??q??`run-${J}`;this.stableMessageIdMap[J]??=q}if(q!==$.id)$.id=q,$.lc_kwargs.id=q;if($.id!=null)this.seen[$.id]=$;this.streamFn([Q[0],"messages",[$,Q[1]]])}handleChatModelStart(Q,$,J,Z,q,z,Y,X){if(Y&&(!z||!z.includes(D$)&&!z.includes("nostream")))this.metadatas[J]=[Y.langgraph_checkpoint_ns.split("|"),{tags:z,name:X,...Y}]}handleLLMNewToken(Q,$,J,Z,q,z){let Y=z?.chunk;if(this.emittedChatModelRunIds[J]=!0,this.metadatas[J]!==void 0)if(U6(Y))this._emit(this.metadatas[J],Y.message,J);else this._emit(this.metadatas[J],new F1({content:Q}),J)}handleLLMEnd(Q,$){if(this.metadatas[$]===void 0)return;if(!this.emittedChatModelRunIds[$]){let J=Q.generations?.[0]?.[0];if(gQ(J?.message))this._emit(this.metadatas[$],J?.message,$,!0);delete this.emittedChatModelRunIds[$]}delete this.metadatas[$],delete this.stableMessageIdMap[$]}handleLLMError(Q,$){delete this.metadatas[$]}handleChainStart(Q,$,J,Z,q,z,Y,X){if(z!==void 0&&X===z.langgraph_node&&(q===void 0||!q.includes(E))){if(this.metadatas[J]=[z.langgraph_checkpoint_ns.split("|"),{tags:q,name:X,...z}],typeof $==="object"){for(let B of Object.values($))if((gQ(B)||e8(B))&&B.id!==void 0)this.seen[B.id]=B;else if(Array.isArray(B)){for(let F of B)if((gQ(F)||e8(F))&&F.id!==void 0)this.seen[F.id]=F}}}}handleChainEnd(Q,$){let J=this.metadatas[$];if(delete this.metadatas[$],J!==void 0){if(gQ(Q))this._emit(J,Q,$,!0);else if(Array.isArray(Q)){for(let Z of Q)if(gQ(Z))this._emit(J,Z,$,!0)}else if(Q!=null&&typeof Q==="object"){for(let Z of Object.values(Q))if(gQ(Z))this._emit(J,Z,$,!0);else if(Array.isArray(Z)){for(let q of Z)if(gQ(q))this._emit(J,q,$,!0)}}}}handleChainError(Q,$){delete this.metadatas[$]}};var V6=500,D6=2,G6=128000,K6=3,M6=[400,401,402,403,404,405,406,407,409],x6=(Q)=>{if(Q.message.startsWith("Cancel")||Q.message.startsWith("AbortError")||Q.name==="AbortError")return!1;if(Q.name==="GraphValueError")return!1;if(Q?.code==="ECONNABORTED")return!1;let $=Q?.response?.status??Q?.status;if($&&M6.includes(+$))return!1;if(Q?.error?.code==="insufficient_quota")return!1;return!0};async function Q$(Q,$,J,Z){let q=Q.retry_policy??$,z=q!==void 0?q.initialInterval??V6:0,Y=0,X,B,{config:F}=Q;if(J)F=zQ(F,J);F={...F,signal:Z};while(!0){if(Z?.aborted)break;Q.writes.splice(0,Q.writes.length),X=void 0;try{B=await Q.proc.invoke(Q.input,F);break}catch(W){if(X=W,X.pregelTaskId=Q.id,o0(X)){let j=F?.configurable?.checkpoint_ns,U=X.command;if(U.graph===j){for(let D of Q.writers)await D.invoke(U,F);X=void 0;break}else if(U.graph===a.PARENT){let D=y$(j);X.command=new a({...X.command,graph:D})}}if(pQ(X))break;if(q===void 0)break;if(Y+=1,Y>=(q.maxAttempts??K6))break;if(!(q.retryOn??x6)(X))break;z=Math.min(q.maxInterval??G6,z*(q.backoffFactor??D6));let L=q.jitter?Math.floor(z+Math.random()*1000):z;await new Promise((j)=>setTimeout(j,L));let H=X.name??X.constructor.unminifiable_name??X.constructor.name;if(q?.logWarning??!0)console.log(`Retrying task "${String(Q.name)}" after ${z.toFixed(2)}ms (attempt ${Y}) after ${H}: ${X}`);F=zQ(F,{[EQ]:!0})}}return{task:Q,result:B,error:X,signalAborted:Z?.aborted}}var $$=Symbol.for("promiseAdded");function A6(){let Q={next:()=>{return},wait:Promise.resolve($$)};function $(J){Q.next=()=>{Q.wait=new Promise($),J($$)}}return Q.wait=new Promise($),Q}var L1=class{nodeFinished;loop;constructor({loop:Q,nodeFinished:$}){this.loop=Q,this.nodeFinished=$}async tick(Q={}){let{timeout:$,retryPolicy:J,onStepWrite:Z,maxConcurrency:q}=Q,z=new Set,Y,X=new AbortController,B=X.signal,F=$?AbortSignal.timeout($):void 0,W=Object.values(this.loop.tasks).filter((U)=>U.writes.length===0),{signals:L,disposeCombinedSignal:H}=this._initializeAbortSignals({exceptionSignal:B,stepTimeoutSignal:F,signal:Q.signal}),j=this._executeTasksWithRetry(W,{signals:L,retryPolicy:J,maxConcurrency:q});for await(let{task:U,error:D,signalAborted:M}of j)if(this._commit(U,D),wQ(D))Y=D;else if(pQ(D)&&!wQ(Y))Y=D;else if(D&&(z.size===0||!M))X.abort(),z.add(D);if(H?.(),Z?.(this.loop.step,Object.values(this.loop.tasks).map((U)=>U.writes).flat()),z.size===1)throw Array.from(z)[0];else if(z.size>1)throw AggregateError(Array.from(z),`Multiple errors occurred during superstep ${this.loop.step}. See the "errors" field of this exception for more details.`);if(wQ(Y))throw Y;if(pQ(Y)&&this.loop.isNested)throw Y}_initializeAbortSignals({exceptionSignal:Q,stepTimeoutSignal:$,signal:J}){let Z=this.loop.config.configurable?.[R8]??{},q=Z.externalAbortSignal??J,z=$??Z.timeoutAbortSignal,{signal:Y,dispose:X}=U0(q,z,Q),B={externalAbortSignal:q,timeoutAbortSignal:z,composedAbortSignal:Y};return this.loop.config=zQ(this.loop.config,{[R8]:B}),{signals:B,disposeCombinedSignal:X}}async*_executeTasksWithRetry(Q,$){let{retryPolicy:J,maxConcurrency:Z,signals:q}=$??{},z=A6(),Y={},X={executingTasksMap:Y,barrier:z,retryPolicy:J,scheduleTask:async(H,j,U)=>this.loop.acceptPush(H,j,U)};if(q?.composedAbortSignal?.aborted)throw Error("Abort");let B=0,F,W=U0(q?.externalAbortSignal,q?.timeoutAbortSignal),L=W.signal?new Promise((H,j)=>{F=()=>j(Error("Abort")),W.signal?.addEventListener("abort",F,{once:!0})}):void 0;while((B===0||Object.keys(Y).length>0)&&Q.length){for(;Object.values(Y).length<(Z??Q.length)&&B<Q.length;B+=1){let j=Q[B];Y[j.id]=Q$(j,J,{[g0]:W1?.bind(X,this,j)},q?.composedAbortSignal).catch((U)=>{return{task:j,error:U,signalAborted:q?.composedAbortSignal?.aborted}})}let H=await Promise.race([...Object.values(Y),...L?[L]:[],z.wait]);if(H===$$)continue;if(yield H,F!=null)W.signal?.removeEventListener("abort",F),W.dispose?.();delete Y[H.task.id]}}_commit(Q,$){if($!==void 0)if(wQ($)){if($.interrupts.length){let J=$.interrupts.map((q)=>[S,q]),Z=Q.writes.filter((q)=>q[0]===o);if(Z.length)J.push(...Z);this.loop.putWrites(Q.id,J)}}else if(pQ($)&&Q.writes.length)this.loop.putWrites(Q.id,Q.writes);else this.loop.putWrites(Q.id,[[p,{message:$.message,name:$.name}]]);else{if(this.nodeFinished&&(Q.config?.tags==null||!Q.config.tags.includes(E)))this.nodeFinished(String(Q.name));if(Q.writes.length===0)Q.writes.push([m0,null]);this.loop.putWrites(Q.id,Q.writes)}}};async function W1(Q,$,J,Z,q,z={}){let Y=$.config?.configurable?.[JQ];if(!Y)throw Error(`BUG: No scratchpad found on task ${$.name}__${$.id}`);let X=Y.callCounter;Y.callCounter+=1;let B=new d$({func:J,name:Z,input:q,cache:z.cache,retry:z.retry,callbacks:z.callbacks}),F=await this.scheduleTask($,X,B);if(!F)return;let W=this.executingTasksMap[F.id];if(W!==void 0)return W;if(F.writes.length>0){let L=F.writes.filter(([j])=>j===jQ),H=F.writes.filter(([j])=>j===p);if(L.length>0){if(L.length===1)return Promise.resolve(L[0][1]);throw Error(`BUG: multiple returns found for task ${F.name}__${F.id}`)}if(H.length>0){if(H.length===1){let j=H[0][1],U=j instanceof Error?j:Error(String(j));return Promise.reject(U)}throw Error(`BUG: multiple errors found for task ${F.name}__${F.id}`)}return}else{let L=Q$(F,z.retry,{[g0]:W1.bind(this,Q,F)});return this.executingTasksMap[F.id]=L,this.barrier.next(),L.then(({result:H,error:j})=>{if(j)return Promise.reject(j);return H})}}var mQ=class extends Error{constructor(Q){super(Q);this.name="GraphValidationError"}};function j1({nodes:Q,channels:$,inputChannels:J,outputChannels:Z,streamChannels:q,interruptAfterNodes:z,interruptBeforeNodes:Y}){if(!$)throw new mQ("Channels not provided");let X=new Set,B=new Set;for(let[F,W]of Object.entries(Q)){if(F===S)throw new mQ(`"Node name ${S} is reserved"`);if(W.constructor===KQ)W.triggers.forEach((L)=>X.add(L));else throw new mQ(`Invalid node type ${typeof W}, expected PregelNode`)}for(let F of X)if(!(F in $))throw new mQ(`Subscribed channel '${String(F)}' not in channels`);if(!Array.isArray(J)){if(!X.has(J))throw new mQ(`Input channel ${String(J)} is not subscribed to by any node`)}else if(J.every((F)=>!X.has(F)))throw new mQ(`None of the input channels ${J} are subscribed to by any node`);if(!Array.isArray(Z))B.add(Z);else Z.forEach((F)=>B.add(F));if(q&&!Array.isArray(q))B.add(q);else if(Array.isArray(q))q.forEach((F)=>B.add(F));for(let F of B)if(!(F in $))throw new mQ(`Output channel '${String(F)}' not in channels`);if(z&&z!=="*"){for(let F of z)if(!(F in Q))throw new mQ(`Node ${String(F)} not in nodes`)}if(Y&&Y!=="*"){for(let F of Y)if(!(F in Q))throw new mQ(`Node ${String(F)} not in nodes`)}}function J$(Q,$){if(Array.isArray(Q)){for(let J of Q)if(!(J in $))throw Error(`Key ${String(J)} not found in channels`)}else if(!(Q in $))throw Error(`Key ${String(Q)} not found in channels`)}var V1=class{static subscribeTo(Q,$){let{key:J,tags:Z}={key:void 0,tags:void 0,...$??{}};if(Array.isArray(Q)&&J!==void 0)throw Error("Can't specify a key when subscribing to multiple channels");let q;if(typeof Q==="string")if(J)q={[J]:Q};else q=[Q];else q=Object.fromEntries(Q.map((z)=>[z,z]));return new KQ({channels:q,triggers:Array.isArray(Q)?Q:[Q],tags:Z})}static writeTo(Q,$){let J=[];for(let Z of Q)J.push({channel:Z,value:qQ,skipNone:!1});for(let[Z,q]of Object.entries($??{}))if(YQ.isRunnable(q)||typeof q==="function")J.push({channel:Z,value:qQ,skipNone:!0,mapper:yQ(q)});else J.push({channel:Z,value:q,skipNone:!1});return new h(J)}},O6=class extends YQ{lc_namespace=["langgraph","pregel"];invoke(Q,$){throw Error("Not implemented")}withConfig(Q){return super.withConfig(Q)}stream(Q,$){return super.stream(Q,$)}},G8=class extends O6{static lc_name(){return"LangGraph"}lc_namespace=["langgraph","pregel"];lg_is_pregel=!0;nodes;channels;inputChannels;outputChannels;autoValidate=!0;streamMode=["values"];streamChannels;interruptAfter;interruptBefore;stepTimeout;debug=!1;checkpointer;retryPolicy;config;store;cache;userInterrupt;triggerToNodes={};constructor(Q){super(Q);let{streamMode:$}=Q;if($!=null&&!Array.isArray($))$=[$];if(this.nodes=Q.nodes,this.channels=Q.channels,c in this.channels&&"lc_graph_name"in this.channels[c]&&this.channels[c].lc_graph_name!=="Topic")throw Error(`Channel '${c}' is reserved and cannot be used in the graph.`);else this.channels[c]=new f8({accumulate:!1});if(this.autoValidate=Q.autoValidate??this.autoValidate,this.streamMode=$??this.streamMode,this.inputChannels=Q.inputChannels,this.outputChannels=Q.outputChannels,this.streamChannels=Q.streamChannels??this.streamChannels,this.interruptAfter=Q.interruptAfter,this.interruptBefore=Q.interruptBefore,this.stepTimeout=Q.stepTimeout??this.stepTimeout,this.debug=Q.debug??this.debug,this.checkpointer=Q.checkpointer,this.retryPolicy=Q.retryPolicy,this.config=Q.config,this.store=Q.store,this.cache=Q.cache,this.name=Q.name,this.triggerToNodes=Q.triggerToNodes??this.triggerToNodes,this.userInterrupt=Q.userInterrupt,this.autoValidate)this.validate()}withConfig(Q){let $=DQ(this.config,Q);return new this.constructor({...this,config:$})}validate(){j1({nodes:this.nodes,channels:this.channels,outputChannels:this.outputChannels,inputChannels:this.inputChannels,streamChannels:this.streamChannels,interruptAfterNodes:this.interruptAfter,interruptBeforeNodes:this.interruptBefore});for(let[Q,$]of Object.entries(this.nodes))for(let J of $.triggers)this.triggerToNodes[J]??=[],this.triggerToNodes[J].push(Q);return this}get streamChannelsList(){if(Array.isArray(this.streamChannels))return this.streamChannels;else if(this.streamChannels)return[this.streamChannels];else return Object.keys(this.channels)}get streamChannelsAsIs(){if(this.streamChannels)return this.streamChannels;else return Object.keys(this.channels)}async getGraphAsync(Q){return this.getGraph(Q)}*getSubgraphs(Q,$){for(let[J,Z]of Object.entries(this.nodes)){if(Q!==void 0){if(!Q.startsWith(J))continue}let q=Z.subgraphs?.length?Z.subgraphs:[Z.bound];for(let z of q){let Y=Y8(z);if(Y!==void 0){if(J===Q){yield[J,Y];return}if(Q===void 0)yield[J,Y];if($){let X=Q;if(Q!==void 0)X=Q.slice(J.length+1);for(let[B,F]of Y.getSubgraphs(X,$))yield[`${J}${k}${B}`,F]}}}}}async*getSubgraphsAsync(Q,$){yield*this.getSubgraphs(Q,$)}async _prepareStateSnapshot({config:Q,saved:$,subgraphCheckpointer:J,applyPendingWrites:Z=!1}){if($===void 0)return{values:{},next:[],config:Q,tasks:[]};let q=oQ(this.channels,$.checkpoint);if($.pendingWrites?.length){let L=$.pendingWrites.filter(([H,j])=>H===n).map(([H,j,U])=>[String(j),U]);if(L.length>0)$Q($.checkpoint,q,[{name:xQ,writes:L,triggers:[]}],void 0,this.triggerToNodes)}let z=Object.values(tQ($.checkpoint,$.pendingWrites,this.nodes,q,$.config,!0,{step:($.metadata?.step??-1)+1,store:this.store})),Y=await GQ(this.getSubgraphsAsync()),X=$.config.configurable?.checkpoint_ns??"",B={};for(let L of z){let H=Y.find(([U])=>U===L.name);if(!H)continue;let j=`${String(L.name)}${e}${L.id}`;if(X)j=`${X}${k}${j}`;if(J===void 0){let U={configurable:{thread_id:$.config.configurable?.thread_id,checkpoint_ns:j}};B[L.id]=U}else{let U={configurable:{[m]:J,thread_id:$.config.configurable?.thread_id,checkpoint_ns:j}},D=H[1];B[L.id]=await D.getState(U,{subgraphs:!0})}}if(Z&&$.pendingWrites?.length){let L=Object.fromEntries(z.map((j)=>[j.id,j]));for(let[j,U,D]of $.pendingWrites){if([p,S,D8].includes(U))continue;if(!(j in L))continue;L[j].writes.push([String(U),D])}let H=z.filter((j)=>j.writes.length>0);if(H.length>0)$Q($.checkpoint,q,H,void 0,this.triggerToNodes)}let F=$?.metadata;if(F&&$?.config?.configurable?.thread_id)F={...F,thread_id:$.config.configurable.thread_id};let W=z.filter((L)=>L.writes.length===0).map((L)=>L.name);return{values:MQ(q,this.streamChannelsAsIs),next:W,tasks:i8(z,$?.pendingWrites??[],B,this.streamChannelsAsIs),metadata:F,config:nQ($.config,$.metadata),createdAt:$.checkpoint.ts,parentConfig:$.parentConfig}}async getState(Q,$){let J=Q.configurable?.[m]??this.checkpointer;if(!J)throw new dQ("No checkpointer set",{lc_error_code:"MISSING_CHECKPOINTER"});let Z=Q.configurable?.checkpoint_ns??"";if(Z!==""&&Q.configurable?.[m]===void 0){let Y=Z8(Z);for await(let[X,B]of this.getSubgraphsAsync(Y,!0))if(X===Y)return await B.getState(J0(Q,{[m]:J}),{subgraphs:$?.subgraphs});throw Error(`Subgraph with namespace "${Y}" not found.`)}let q=DQ(this.config,Q),z=await J.getTuple(Q);return await this._prepareStateSnapshot({config:q,saved:z,subgraphCheckpointer:$?.subgraphs?J:void 0,applyPendingWrites:!Q.configurable?.checkpoint_id})}async*getStateHistory(Q,$){let J=Q.configurable?.[m]??this.checkpointer;if(!J)throw new dQ("No checkpointer set",{lc_error_code:"MISSING_CHECKPOINTER"});let Z=Q.configurable?.checkpoint_ns??"";if(Z!==""&&Q.configurable?.[m]===void 0){let z=Z8(Z);for await(let[Y,X]of this.getSubgraphsAsync(z,!0))if(Y===z){yield*X.getStateHistory(J0(Q,{[m]:J}),$);return}throw Error(`Subgraph with namespace "${z}" not found.`)}let q=DQ(this.config,Q,{configurable:{checkpoint_ns:Z}});for await(let z of J.list(q,$))yield this._prepareStateSnapshot({config:z.config,saved:z})}async bulkUpdateState(Q,$){let J=Q.configurable?.[m]??this.checkpointer;if(!J)throw new dQ("No checkpointer set",{lc_error_code:"MISSING_CHECKPOINTER"});if($.length===0)throw Error("No supersteps provided");if($.some((Y)=>Y.updates.length===0))throw Error("No updates provided");let Z=Q.configurable?.checkpoint_ns??"";if(Z!==""&&Q.configurable?.[m]===void 0){let Y=Z8(Z);for await(let[,X]of this.getSubgraphsAsync(Y,!0))return await X.bulkUpdateState(J0(Q,{[m]:J}),$);throw Error(`Subgraph "${Y}" not found`)}let q=async(Y,X)=>{let B=this.config?DQ(this.config,Y):Y,F=await J.getTuple(B),W=F!==void 0?kQ(F.checkpoint):V0(),L={...F?.checkpoint.channel_versions},H=F?.metadata?.step??-1,j=J0(B,{checkpoint_ns:B.configurable?.checkpoint_ns??""}),U=B.metadata??{};if(F?.config.configurable)j=J0(B,F.config.configurable),U={...F.metadata,...U};let{values:D,asNode:M}=X[0];if(D==null&&M===void 0){if(X.length>1)throw new w("Cannot create empty checkpoint with multiple updates");return nQ(await J.put(j,HQ(W,void 0,H),{source:"update",step:H+1,parents:F?.metadata?.parents??{}},{}),F?F.metadata:void 0)}let O=oQ(this.channels,W);if(D===null&&M===A){if(X.length>1)throw new w("Cannot apply multiple updates when clearing state");if(F){let K=tQ(W,F.pendingWrites||[],this.nodes,O,F.config,!0,{step:(F.metadata?.step??-1)+1,checkpointer:J,store:this.store}),x=(F.pendingWrites||[]).filter((b)=>b[0]===n).map((b)=>b.slice(1));if(x.length>0)$Q(W,O,[{name:xQ,writes:x,triggers:[]}],J.getNextVersion.bind(J),this.triggerToNodes);for(let[b,G,y]of F.pendingWrites||[]){if([p,S,D8].includes(G))continue;if(!(b in K))continue;K[b].writes.push([G,y])}$Q(W,O,Object.values(K),J.getNextVersion.bind(J),this.triggerToNodes)}return nQ(await J.put(j,HQ(W,O,H),{...U,source:"update",step:H+1,parents:F?.metadata?.parents??{}},H0(L,W.channel_versions)),F?F.metadata:void 0)}if(M===H$){if(X.length>1)throw new w("Cannot copy checkpoint with multiple updates");if(F==null)throw new w("Cannot copy a non-existent checkpoint");let K=(G)=>{if(!Array.isArray(G))return!1;if(G.length===0)return!1;return G.every((y)=>Array.isArray(y)&&y.length===2)},x=HQ(W,void 0,H),b=await J.put(F.parentConfig??J0(F.config,{checkpoint_id:void 0}),x,{source:"fork",step:H+1,parents:F.metadata?.parents??{}},{});if(K(D)){let G=tQ(x,F.pendingWrites,this.nodes,O,b,!1,{step:H+2}),y=Object.values(G).reduce((i,{name:C0,id:P8})=>{return i[C0]??=[],i[C0].push({id:P8}),i},{}),g=D.reduce((i,C0)=>{let[P8,D0]=C0;i[D0]??=[];let b1=i[D0].length,S1=y[D0]?.[b1]?.id;return i[D0].push({values:P8,asNode:D0,taskId:S1}),i},{});return q(nQ(b,F.metadata),Object.values(g).flat())}return nQ(b,F.metadata)}if(M===xQ){if(X.length>1)throw new w("Cannot apply multiple updates when updating as input");let K=await GQ(X8(this.inputChannels,D));if(K.length===0)throw new w(`Received no input writes for ${JSON.stringify(this.inputChannels,null,2)}`);$Q(W,O,[{name:xQ,writes:K,triggers:[]}],J.getNextVersion.bind(this.checkpointer),this.triggerToNodes);let x=F?.metadata?.step!=null?F.metadata.step+1:-1,b=await J.put(j,HQ(W,O,x),{source:"input",step:x,parents:F?.metadata?.parents??{}},H0(L,W.channel_versions));return await J.putWrites(b,K,sQ(xQ,W.id)),nQ(b,F?F.metadata:void 0)}if(B.configurable?.checkpoint_id===void 0&&F?.pendingWrites!==void 0&&F.pendingWrites.length>0){let K=tQ(W,F.pendingWrites,this.nodes,O,F.config,!0,{store:this.store,checkpointer:this.checkpointer,step:(F.metadata?.step??-1)+1}),x=(F.pendingWrites??[]).filter((G)=>G[0]===n).map((G)=>G.slice(1));if(x.length>0)$Q(F.checkpoint,O,[{name:xQ,writes:x,triggers:[]}],void 0,this.triggerToNodes);for(let[G,y,g]of F.pendingWrites){if([p,S,D8].includes(y)||K[G]===void 0)continue;K[G].writes.push([y,g])}let b=Object.values(K).filter((G)=>{return G.writes.length>0});if(b.length>0)$Q(W,O,b,void 0,this.triggerToNodes)}let _=Object.values(W.versions_seen).map((K)=>{return Object.values(K)}).flat().find((K)=>!!K),P=[];if(X.length===1){let{values:K,asNode:x,taskId:b}=X[0];if(x===void 0&&Object.keys(this.nodes).length===1)[x]=Object.keys(this.nodes);else if(x===void 0&&_===void 0){if(typeof this.inputChannels==="string"&&this.nodes[this.inputChannels]!==void 0)x=this.inputChannels}else if(x===void 0){let G=Object.entries(W.versions_seen).map(([y,g])=>{return Object.values(g).map((i)=>{return[i,y]})}).flat().filter(([y,g])=>g!==S).sort(([y],[g])=>U1(y,g));if(G){if(G.length===1)x=G[0][1];else if(G[G.length-1][0]!==G[G.length-2][0])x=G[G.length-1][1]}}if(x===void 0)throw new w('Ambiguous update, specify "asNode"');P.push({values:K,asNode:x,taskId:b})}else for(let{asNode:K,values:x,taskId:b}of X){if(K==null)throw new w('"asNode" is required when applying multiple updates');P.push({values:x,asNode:K,taskId:b})}let I=[];for(let{asNode:K,values:x,taskId:b}of P){if(this.nodes[K]===void 0)throw new w(`Node "${K.toString()}" does not exist`);let G=this.nodes[K].getWriters();if(!G.length)throw new w(`No writers found for node "${K.toString()}"`);I.push({name:K,input:x,proc:G.length>1?Z0.from(G,{omitSequenceTags:!0}):G[0],writes:[],triggers:[S],id:b??sQ(S,W.id),writers:[]})}for(let K of I)await K.proc.invoke(K.input,rQ({...B,store:B?.store??this.store},{runName:B.runName??`${this.getName()}UpdateState`,configurable:{[WQ]:(x)=>K.writes.push(...x),[AQ]:(x,b=!1)=>_0(W,O,K,x,b)}}));for(let K of I){let x=K.writes.filter((b)=>b[0]!==r);if(F!==void 0&&x.length>0)await J.putWrites(j,x,K.id)}$Q(W,O,I,J.getNextVersion.bind(this.checkpointer),this.triggerToNodes);let N=H0(L,W.channel_versions),f=await J.put(j,HQ(W,O,H+1),{source:"update",step:H+1,parents:F?.metadata?.parents??{}},N);for(let K of I){let x=K.writes.filter((b)=>b[0]===r);if(x.length>0)await J.putWrites(f,x,K.id)}return nQ(f,F?F.metadata:void 0)},z=Q;for(let{updates:Y}of $)z=await q(z,Y);return z}async updateState(Q,$,J){return this.bulkUpdateState(Q,[{updates:[{values:$,asNode:J}]}])}_defaults(Q){let{debug:$,streamMode:J,inputKeys:Z,outputKeys:q,interruptAfter:z,interruptBefore:Y,...X}=Q,B=!0,F=$!==void 0?$:this.debug,W=q;if(W===void 0)W=this.streamChannelsAsIs;else J$(W,this.channels);let L=Z;if(L===void 0)L=this.inputChannels;else J$(L,this.channels);let H=Y??this.interruptBefore??[],j=z??this.interruptAfter??[],U;if(J!==void 0)U=Array.isArray(J)?J:[J],B=typeof J==="string";else{if(Q.configurable?.[Y0]!==void 0)U=["values"];else U=this.streamMode;B=!0}let D;if(this.checkpointer===!1)D=void 0;else if(Q!==void 0&&Q.configurable?.[m]!==void 0)D=Q.configurable[m];else if(this.checkpointer===!0)throw Error("checkpointer: true cannot be used for root graphs.");else D=this.checkpointer;let M=Q.store??this.store,O=Q.cache??this.cache;if(Q.durability!=null&&Q.checkpointDuring!=null)throw Error("Cannot use both `durability` and `checkpointDuring` at the same time.");let _=(()=>{if(Q.checkpointDuring==null)return;if(Q.checkpointDuring===!1)return"exit";return"async"})(),P=Q.durability??_??Q?.configurable?.[U$]??"async";return[F,U,L,W,X,H,j,D,M,B,O,P]}async stream(Q,$){let J=new AbortController,Z={recursionLimit:this.config?.recursionLimit,...$,signal:U0($?.signal,J.signal).signal},q=await super.stream(Q,Z);return new s8($?.encoding==="text/event-stream"?Z1(q):q,J)}streamEvents(Q,$,J){let Z=new AbortController,q={recursionLimit:this.config?.recursionLimit,...$,callbacks:u$(this.config?.callbacks,$?.callbacks),signal:U0($?.signal,Z.signal).signal};return new s8(super.streamEvents(Q,q,J),Z)}async _validateInput(Q){return Q}async _validateContext(Q){return Q}async*_streamIterator(Q,$){let J="version"in($??{})?void 0:$?.encoding??void 0,Z=$?.subgraphs,q=b0(this.config,$);if(q.recursionLimit===void 0||q.recursionLimit<1)throw Error('Passed "recursionLimit" must be at least 1.');if(this.checkpointer!==void 0&&this.checkpointer!==!1&&q.configurable===void 0)throw Error('Checkpointer requires one or more of the following "configurable" keys: "thread_id", "checkpoint_ns", "checkpoint_id"');let z=await this._validateInput(Q),{runId:Y,...X}=q,[B,F,,W,L,H,j,U,D,M,O,_]=this._defaults(X);if(typeof L.context<"u")L.context=await this._validateContext(L.context);else L.configurable=await this._validateContext(L.configurable);let P=new H8({modes:new Set(F)});if(this.checkpointer===!0){L.configurable??={};let G=L.configurable[FQ]??"";L.configurable[FQ]=G.split(k).map((y)=>y.split(e)[0]).join(k)}if(F.includes("messages")){let G=new B1((g)=>P.push(g)),{callbacks:y}=L;if(y===void 0)L.callbacks=[G];else if(Array.isArray(y))L.callbacks=y.concat(G);else{let g=y.copy();g.addHandler(G,!0),L.callbacks=g}}if(F.includes("tools")){let G=new J1((g)=>P.push(g)),{callbacks:y}=L;if(y===void 0)L.callbacks=[G];else if(Array.isArray(y))L.callbacks=y.concat(G);else{let g=y.copy();g.addHandler(G,!0),L.callbacks=g}}L.writer??=(G)=>{if(!F.includes("custom"))return;let y=u8()?.configurable?.[FQ]?.split(k).slice(0,-1);P.push([y??[],"custom",G])},L.interrupt??=this.userInterrupt??N8;let I=await(await H1(L))?.handleChainStart(this.toJSON(),h$(Q,"input"),Y,void 0,void 0,void 0,L?.runName??this.getName()),N=w0(this.channels),f,K,b=(async()=>{try{f=await Y1.initialize({input:z,config:L,checkpointer:U,nodes:this.nodes,channelSpecs:N,outputKeys:W,streamKeys:this.streamChannelsAsIs,store:D,cache:O,stream:P,interruptAfter:j,interruptBefore:H,manager:I,debug:this.debug,triggerToNodes:this.triggerToNodes,durability:_});let G=new L1({loop:f,nodeFinished:L.configurable?.[V$]});if($?.subgraphs)f.config.configurable={...f.config.configurable,[K0]:f.stream};if(await this._runLoop({loop:f,runner:G,debug:B,config:L}),_==="sync")await Promise.all(f?.checkpointerPromises??[])}catch(G){K=G}finally{try{if(f)await f.store?.stop(),await f.cache?.stop();await Promise.all(f?.checkpointerPromises??[])}catch(G){K=K??G}if(K)P.error(K);else P.close()}})();try{for await(let G of P){if(G===void 0)throw Error("Data structure error.");let[y,g,i]=G;if(F.includes(g)){if(J==="text/event-stream"){if(Z)yield[y,g,i];else yield[null,g,i];continue}if(Z&&!M)yield[y,g,i];else if(!M)yield[g,i];else if(Z)yield[y,i];else yield i}}}catch(G){throw await I?.handleChainError(K),G}finally{await b}await I?.handleChainEnd(f?.output??{},Y,void 0,void 0,void 0)}async invoke(Q,$){let J=$?.streamMode??"values",Z={...$,outputKeys:$?.outputKeys??this.outputChannels,streamMode:J,encoding:void 0},q=[],z=await this.stream(Q,Z),Y=[],X;for await(let B of z)if(J==="values")if(F0(B))Y.push(B[S]);else X=B;else q.push(B);if(J==="values"){if(Y.length>0){let B=Y.flat(1);if(X==null)return{[S]:B};if(typeof X==="object")return{...X,[S]:B}}return X}return q}async _runLoop(Q){let{loop:$,runner:J,debug:Z,config:q}=Q,z;try{while(await $.tick({inputKeys:this.inputChannels})){for(let{task:Y}of await $._matchCachedWrites())$._outputWrites(Y.id,Y.writes,!0);if(Z)a$($.checkpointMetadata.step,$.channels,this.streamChannelsList);if(Z)W8($.step,Object.values($.tasks));await J.tick({timeout:this.stepTimeout,retryPolicy:this.retryPolicy,onStepWrite:(Y,X)=>{if(Z)e$(Y,X,this.streamChannelsList)},maxConcurrency:q.maxConcurrency,signal:q.signal})}if($.status==="out_of_steps")throw new l0([`Recursion limit of ${q.recursionLimit} reached`,"without hitting a stop condition. You can increase the",'limit by setting the "recursionLimit" config key.'].join(" "),{lc_error_code:"GRAPH_RECURSION_LIMIT"})}catch(Y){if(z=Y,!await $.finishAndHandleError(z))throw Y}finally{if(z===void 0)await $.finishAndHandleError()}}async clearCache(){await this.cache?.clear([])}};N$();var z$=class{path;ends;constructor(Q){if(YQ.isRunnable(Q.path))this.path=Q.path;else this.path=yQ(Q.path);this.ends=Array.isArray(Q.pathMap)?Q.pathMap.reduce(($,J)=>{return $[J]=J,$},{}):Q.pathMap}run(Q,$){return h.registerWriter(new s({name:"<branch_run>",trace:!1,func:async(J,Z)=>{try{return await this._route(J,Z,Q,$)}catch(q){if(q.name===A0.unminifiable_name)console.warn(`[WARN]: 'NodeInterrupt' thrown in conditional edge. This is likely a bug in your graph implementation.
14
+ NodeInterrupt should only be thrown inside a node, not in edge conditions.`);throw q}}}))}async _route(Q,$,J,Z){let q=await this.path.invoke(Z?Z($):Q,$);if(!Array.isArray(q))q=[q];let z;if(this.ends)z=q.map((Y)=>d(Y)?Y:this.ends[Y]);else z=q;if(z.some((Y)=>!Y))throw Error("Branch condition returned unknown or null destination");if(z.filter(d).some((Y)=>Y.node===A))throw new w("Cannot send a packet to the END node");return await J(z,$)??Q}},E0=class{nodes;edges;branches;entryPoint;compiled=!1;constructor(){this.nodes={},this.edges=new Set,this.branches={}}warnIfCompiled(Q){if(this.compiled)console.warn(Q)}get allEdges(){return this.edges}addNode(...Q){function $(Z){return Z.length>=1&&typeof Z[0]!=="string"}let J=$(Q)?Array.isArray(Q[0])?Q[0]:Object.entries(Q[0]):[[Q[0],Q[1],Q[2]]];if(J.length===0)throw Error("No nodes provided in `addNode`");for(let[Z,q,z]of J){for(let X of[k,e])if(Z.includes(X))throw Error(`"${X}" is a reserved character and is not allowed in node names.`);if(this.warnIfCompiled("Adding a node to a graph that has already been compiled. This will not be reflected in the compiled graph."),Z in this.nodes)throw Error(`Node \`${Z}\` already present.`);if(Z===A)throw Error(`Node \`${Z}\` is reserved.`);let Y=yQ(q);this.nodes[Z]={runnable:Y,metadata:z?.metadata,subgraphs:S0(Y)?[Y]:z?.subgraphs,ends:z?.ends}}return this}addEdge(Q,$){if(this.warnIfCompiled("Adding an edge to a graph that has already been compiled. This will not be reflected in the compiled graph."),Q===A)throw Error("END cannot be a start node");if($===T)throw Error("START cannot be an end node");if(Array.from(this.edges).some(([J])=>J===Q)&&!("channels"in this))throw Error(`Already found path for ${Q}. For multiple edges, use StateGraph.`);return this.edges.add([Q,$]),this}addConditionalEdges(Q,$,J){let Z=typeof Q==="object"?Q:{source:Q,path:$,pathMap:J};if(this.warnIfCompiled("Adding an edge to a graph that has already been compiled. This will not be reflected in the compiled graph."),!YQ.isRunnable(Z.path))Z.path=yQ(Z.path);let q=Z.path.getName()==="RunnableLambda"?"condition":Z.path.getName();if(this.branches[Z.source]&&this.branches[Z.source][q])throw Error(`Condition \`${q}\` already present for node \`${Q}\``);return this.branches[Z.source]??={},this.branches[Z.source][q]=new z$(Z),this}setEntryPoint(Q){return this.warnIfCompiled("Setting the entry point of a graph that has already been compiled. This will not be reflected in the compiled graph."),this.addEdge(T,Q)}setFinishPoint(Q){return this.warnIfCompiled("Setting a finish point of a graph that has already been compiled. This will not be reflected in the compiled graph."),this.addEdge(Q,A)}compile({checkpointer:Q,interruptBefore:$,interruptAfter:J,name:Z}={}){this.validate([...Array.isArray($)?$:[],...Array.isArray(J)?J:[]]);let q=new Y$({builder:this,checkpointer:Q,interruptAfter:J,interruptBefore:$,autoValidate:!1,nodes:{},channels:{[T]:new VQ,[A]:new VQ},inputChannels:T,outputChannels:A,streamChannels:[],streamMode:"values",name:Z});for(let[z,Y]of Object.entries(this.nodes))q.attachNode(z,Y);for(let[z,Y]of this.edges)q.attachEdge(z,Y);for(let[z,Y]of Object.entries(this.branches))for(let[X,B]of Object.entries(Y))q.attachBranch(z,X,B);return q.validate()}validate(Q){let $=new Set([...this.allEdges].map(([Z,q])=>Z));for(let[Z]of Object.entries(this.branches))$.add(Z);for(let Z of $)if(Z!==T&&!(Z in this.nodes))throw Error(`Found edge starting at unknown node \`${Z}\``);let J=new Set([...this.allEdges].map(([Z,q])=>q));for(let[Z,q]of Object.entries(this.branches))for(let z of Object.values(q))if(z.ends!=null)for(let Y of Object.values(z.ends))J.add(Y);else{J.add(A);for(let Y of Object.keys(this.nodes))if(Y!==Z)J.add(Y)}for(let Z of Object.values(this.nodes))for(let q of Z.ends??[])J.add(q);for(let Z of Object.keys(this.nodes))if(!J.has(Z))throw new c0([`Node \`${Z}\` is not reachable.`,"","If you are returning Command objects from your node,",'make sure you are passing names of potential destination nodes as an "ends" array','into ".addNode(..., { ends: ["node1", "node2"] })".'].join(`
15
+ `),{lc_error_code:"UNREACHABLE_NODE"});for(let Z of J)if(Z!==A&&!(Z in this.nodes))throw Error(`Found edge ending at unknown node \`${Z}\``);if(Q){for(let Z of Q)if(!(Z in this.nodes))throw Error(`Interrupt node \`${Z}\` is not present`)}this.compiled=!0}},Y$=class extends G8{builder;constructor({builder:Q,...$}){super($);this.builder=Q}attachNode(Q,$){this.channels[Q]=new VQ,this.nodes[Q]=new KQ({channels:[],triggers:[],metadata:$.metadata,subgraphs:$.subgraphs,ends:$.ends}).pipe($.runnable).pipe(new h([{channel:Q,value:qQ}],[E])),this.streamChannels.push(Q)}attachEdge(Q,$){if($===A){if(Q===T)throw Error("Cannot have an edge from START to END");this.nodes[Q].writers.push(new h([{channel:A,value:qQ}],[E]))}else this.nodes[$].triggers.push(Q),this.nodes[$].channels.push(Q)}attachBranch(Q,$,J){if(Q===T&&!this.nodes[T])this.nodes[T]=V1.subscribeTo(T,{tags:[E]});this.nodes[Q].pipe(J.run((q)=>{return new h(q.map((z)=>{if(d(z))return z;return{channel:z===A?A:`branch:${Q}:${$}:${z}`,value:qQ}}),[E])}));let Z=J.ends?Object.values(J.ends):Object.keys(this.nodes);for(let q of Z)if(q!==A){let z=`branch:${Q}:${$}:${q}`;this.channels[z]=new VQ,this.nodes[q].triggers.push(z),this.nodes[q].channels.push(z)}}async getGraphAsync(Q){let $=Q?.xray,J=new q$,Z={[T]:J.addNode({schema:iQ.any()},T)},q={},z={};if($)z=Object.fromEntries((await GQ(this.getSubgraphsAsync())).filter((B)=>D1(B[1])));function Y(B,F,W,L=!1){if(F===A&&q[A]===void 0)q[A]=J.addNode({schema:iQ.any()},A);if(Z[B]===void 0)return;if(q[F]===void 0)throw Error(`End node ${F} not found!`);return J.addEdge(Z[B],q[F],W!==F?W:void 0,L)}for(let[B,F]of Object.entries(this.builder.nodes)){let W=t(B),L=F.runnable,H=F.metadata??{};if(this.interruptBefore?.includes(B)&&this.interruptAfter?.includes(B))H.__interrupt="before,after";else if(this.interruptBefore?.includes(B))H.__interrupt="before";else if(this.interruptAfter?.includes(B))H.__interrupt="after";if($){let j=typeof $==="number"?$-1:$,U=z[B]!==void 0?await z[B].getGraphAsync({...Q,xray:j}):L.getGraph(Q);if(U.trimFirstNode(),U.trimLastNode(),Object.keys(U.nodes).length>1){let O=function(P){return P?P.lc_runnable:!1},_=function(P,I){if(P!==void 0&&!Z$(P))return P;else if(O(I))try{let N=I.getName();return N=N.startsWith("Runnable")?N.slice(8):N,N}catch(N){return I.getName()}else return I.name??"UnknownSchema"},[D,M]=J.extend(U,W);if(D===void 0)throw Error(`Could not extend subgraph "${B}" due to missing entrypoint.`);if(M!==void 0)Z[W]={name:_(M.id,M.data),...M};q[W]={name:_(D.id,D.data),...D}}else{let D=J.addNode(L,W,H);Z[W]=D,q[W]=D}}else{let j=J.addNode(L,W,H);Z[W]=j,q[W]=j}}let X=[...this.builder.allEdges].sort(([B],[F])=>{if(B<F)return-1;else if(F>B)return 1;else return 0});for(let[B,F]of X)Y(t(B),t(F));for(let[B,F]of Object.entries(this.builder.branches)){let W={...Object.fromEntries(Object.keys(this.builder.nodes).filter((L)=>L!==B).map((L)=>[t(L),t(L)])),[A]:A};for(let L of Object.values(F)){let H;if(L.ends!==void 0)H=L.ends;else H=W;for(let[j,U]of Object.entries(H))Y(t(B),t(U),j,!0)}}for(let[B,F]of Object.entries(this.builder.nodes))if(F.ends!==void 0)for(let W of F.ends)Y(t(B),t(W),void 0,!0);return J}getGraph(Q){let $=Q?.xray,J=new q$,Z={[T]:J.addNode({schema:iQ.any()},T)},q={},z={};if($)z=Object.fromEntries($0(this.getSubgraphs()).filter((B)=>D1(B[1])));function Y(B,F,W,L=!1){if(F===A&&q[A]===void 0)q[A]=J.addNode({schema:iQ.any()},A);return J.addEdge(Z[B],q[F],W!==F?W:void 0,L)}for(let[B,F]of Object.entries(this.builder.nodes)){let W=t(B),L=F.runnable,H=F.metadata??{};if(this.interruptBefore?.includes(B)&&this.interruptAfter?.includes(B))H.__interrupt="before,after";else if(this.interruptBefore?.includes(B))H.__interrupt="before";else if(this.interruptAfter?.includes(B))H.__interrupt="after";if($){let j=typeof $==="number"?$-1:$,U=z[B]!==void 0?z[B].getGraph({...Q,xray:j}):L.getGraph(Q);if(U.trimFirstNode(),U.trimLastNode(),Object.keys(U.nodes).length>1){let O=function(P){return P?P.lc_runnable:!1},_=function(P,I){if(P!==void 0&&!Z$(P))return P;else if(O(I))try{let N=I.getName();return N=N.startsWith("Runnable")?N.slice(8):N,N}catch(N){return I.getName()}else return I.name??"UnknownSchema"},[D,M]=J.extend(U,W);if(D===void 0)throw Error(`Could not extend subgraph "${B}" due to missing entrypoint.`);if(M!==void 0)Z[W]={name:_(M.id,M.data),...M};q[W]={name:_(D.id,D.data),...D}}else{let D=J.addNode(L,W,H);Z[W]=D,q[W]=D}}else{let j=J.addNode(L,W,H);Z[W]=j,q[W]=j}}let X=[...this.builder.allEdges].sort(([B],[F])=>{if(B<F)return-1;else if(F>B)return 1;else return 0});for(let[B,F]of X)Y(t(B),t(F));for(let[B,F]of Object.entries(this.builder.branches)){let W={...Object.fromEntries(Object.keys(this.builder.nodes).filter((L)=>L!==B).map((L)=>[t(L),t(L)])),[A]:A};for(let L of Object.values(F)){let H;if(L.ends!==void 0)H=L.ends;else H=W;for(let[j,U]of Object.entries(H))Y(t(B),t(U),j,!0)}}return J}};function D1(Q){return typeof Q.attachNode==="function"&&typeof Q.attachEdge==="function"}function t(Q){if(Q==="subgraph")return`"${Q}"`;return Q}var P6="lg:",w6=class{_map=new Map;_extensionCache=new Map;get(Q){return this._map.get(Q)}extend(Q,$){let J=this.get(Q);this._map.set(Q,$(J))}remove(Q){return this._map.delete(Q),this}has(Q){return this._map.has(Q)}getChannelsForSchema(Q){let $={},J=F$(Q);for(let[Z,q]of Object.entries(J)){let z=this.get(q);if(z?.reducer)$[Z]=new bQ(z.reducer.fn,z.default);else $[Z]=new UQ(z?.default)}return $}getExtendedChannelSchemas(Q,$){if(Object.keys($).length===0)return Q;let J=Object.entries($).filter(([,z])=>z===!0).sort(([z],[Y])=>z.localeCompare(Y)).map(([z,Y])=>`${z}:${Y}`).join("|"),Z=this._extensionCache.get(J)??new Map;if(Z.has(Q))return Z.get(Q);let q=Q;if($.withReducerSchema||$.withJsonSchemaExtrasAsDescription){let z=Object.entries(F$(Q)).map(([Y,X])=>{let B=this.get(X),F=$.withReducerSchema?B?.reducer?.schema??X:X;if($.withJsonSchemaExtrasAsDescription&&B?.jsonSchemaExtra){let W=X$(F)??X$(X),L=JSON.stringify({...B.jsonSchemaExtra,description:W});F=F.describe(`${P6}${L}`)}return[Y,F]});if(q=M1(Q,Object.fromEntries(z)),K1(q))q._def.unknownKeys="strip"}if($.asPartial)q=K8(q);return Z.set(Q,q),this._extensionCache.set(J,Z),q}},v0=new w6;function A1(Q,$){if($.reducer&&!$.default){let J=x1(Q);if(J!=null)$.default=J}if($.reducer){let J=Object.assign(Q,{lg_reducer_schema:$.reducer?.schema??Q});return v0.extend(J,()=>$),J}else return v0.extend(Q,()=>$),Q}function z0(Q){if(Q==null)return!1;if(LQ.isInstance(Q))return!0;if(XQ(Q))return!0;if(typeof Q==="object"&&"lc_graph_name"in Q&&Q.lc_graph_name==="AnnotationRoot")return!0;if(typeof Q==="object"&&!Array.isArray(Q)&&Object.keys(Q).length>0&&Object.values(Q).every(($)=>typeof $==="function"||E8($)))return!0;return!1}function O1(Q){if(typeof Q!=="object"||Q==null)return!1;let $=Q,J="state"in $&&z0($.state),Z="stateSchema"in $&&z0($.stateSchema),q="input"in $&&z0($.input);if(!J&&!Z&&!q)return!1;if("input"in $&&$.input!=null&&!z0($.input))return!1;if("output"in $&&$.output!=null&&!z0($.output))return!1;return!0}var hQ="__root__",x8=Symbol.for("langgraph.state.partial"),A8=class extends E0{channels={};waitingEdges=new Set;_schemaDefinition;_schemaRuntimeDefinition;_inputDefinition;_inputRuntimeDefinition;_outputDefinition;_outputRuntimeDefinition;_schemaDefinitions=new Map;_metaRegistry=v0;_configSchema;_configRuntimeSchema;_interrupt;_writer;constructor(Q,$){super();let J=this._normalizeToStateGraphInit(Q,$),Z=J.state??J.stateSchema??J.input;if(!Z)throw new B0;let q=this._getChannelsFromSchema(Z);if(this._schemaDefinition=q,LQ.isInstance(Z))this._schemaRuntimeDefinition=Z;else if(XQ(Z))this._schemaRuntimeDefinition=Z;if(J.input)if(LQ.isInstance(J.input))this._inputRuntimeDefinition=J.input;else if(XQ(J.input))this._inputRuntimeDefinition=J.input;else this._inputRuntimeDefinition=x8;else this._inputRuntimeDefinition=x8;if(J.output)if(LQ.isInstance(J.output))this._outputRuntimeDefinition=J.output;else if(XQ(J.output))this._outputRuntimeDefinition=J.output;else this._outputRuntimeDefinition=this._schemaRuntimeDefinition;else this._outputRuntimeDefinition=this._schemaRuntimeDefinition;let z=J.input?this._getChannelsFromSchema(J.input):q,Y=J.output?this._getChannelsFromSchema(J.output):q;if(this._inputDefinition=z,this._outputDefinition=Y,this._addSchema(this._schemaDefinition),this._addSchema(this._inputDefinition),this._addSchema(this._outputDefinition),J.context){if(XQ(J.context))this._configRuntimeSchema=J.context}this._interrupt=J.interrupt,this._writer=J.writer}_normalizeToStateGraphInit(Q,$){if(O1(Q)){if(XQ($)||T0.isInstance($))return{...Q,context:$};let J=$;return{...Q,input:Q.input??J?.input,output:Q.output??J?.output,context:Q.context??J?.context,interrupt:Q.interrupt??J?.interrupt,writer:Q.writer??J?.writer,nodes:Q.nodes??J?.nodes}}if(z0(Q)){if(XQ($)||T0.isInstance($))return{state:Q,context:$};let J=$;return{state:Q,input:J?.input,output:J?.output,context:J?.context,interrupt:J?.interrupt,writer:J?.writer,nodes:J?.nodes}}if(T6(Q))return{state:R6(Q.channels)};throw new B0}_getChannelsFromSchema(Q){if(LQ.isInstance(Q))return Q.getChannels();if(XQ(Q))return this._metaRegistry.getChannelsForSchema(Q);if(typeof Q==="object"&&"lc_graph_name"in Q&&Q.lc_graph_name==="AnnotationRoot")return Q.spec;if(typeof Q==="object"&&!Array.isArray(Q)&&Object.keys(Q).length>0)return Q;throw new B0("Invalid schema type. Expected StateSchema, Zod object, AnnotationRoot, or StateDefinition.")}get allEdges(){return new Set([...this.edges,...Array.from(this.waitingEdges).flatMap(([Q,$])=>Q.map((J)=>[J,$]))])}_addSchema(Q){if(this._schemaDefinitions.has(Q))return;this._schemaDefinitions.set(Q,Q);for(let[$,J]of Object.entries(Q)){let Z;if(typeof J==="function")Z=J();else Z=J;if(this.channels[$]!==void 0){if(!this.channels[$].equals(Z)){if(Z.lc_graph_name!=="LastValue")throw Error(`Channel "${$}" already exists with a different type.`)}}else this.channels[$]=Z}}addNode(...Q){function $(Z){return Z.length>=1&&typeof Z[0]!=="string"}let J=$(Q)?Array.isArray(Q[0])?Q[0]:Object.entries(Q[0]).map(([Z,q])=>[Z,q]):[[Q[0],Q[1],Q[2]]];if(J.length===0)throw Error("No nodes provided in `addNode`");for(let[Z,q,z]of J){if(Z in this.channels)throw Error(`${Z} is already being used as a state attribute (a.k.a. a channel), cannot also be used as a node name.`);for(let W of[k,e])if(Z.includes(W))throw Error(`"${W}" is a reserved character and is not allowed in node names.`);if(this.warnIfCompiled("Adding a node to a graph that has already been compiled. This will not be reflected in the compiled graph."),Z in this.nodes)throw Error(`Node \`${Z}\` already present.`);if(Z===A||Z===T)throw Error(`Node \`${Z}\` is reserved.`);let Y=this._schemaDefinition;if(z?.input!==void 0)Y=this._getChannelsFromSchema(z.input);this._addSchema(Y);let X;if(YQ.isRunnable(q))X=q;else if(typeof q==="function")X=new s({func:q,name:Z,trace:!1});else X=yQ(q);let B=z?.cachePolicy;if(typeof B==="boolean")B=B?{}:void 0;let F={runnable:X,retryPolicy:z?.retryPolicy,cachePolicy:B,metadata:z?.metadata,input:Y??this._schemaDefinition,subgraphs:S0(X)?[X]:z?.subgraphs,ends:z?.ends,defer:z?.defer};this.nodes[Z]=F}return this}addEdge(Q,$){if(typeof Q==="string")return super.addEdge(Q,$);if(this.compiled)console.warn("Adding an edge to a graph that has already been compiled. This will not be reflected in the compiled graph.");for(let J of Q){if(J===A)throw Error("END cannot be a start node");if(!Object.keys(this.nodes).some((Z)=>Z===J))throw Error(`Need to add a node named "${J}" first`)}if($===A)throw Error("END cannot be an end node");if(!Object.keys(this.nodes).some((J)=>J===$))throw Error(`Need to add a node named "${$}" first`);return this.waitingEdges.add([Q,$]),this}addSequence(Q){let $=Array.isArray(Q)?Q:Object.entries(Q);if($.length===0)throw Error("Sequence requires at least one node.");let J;for(let[Z,q,z]of $){if(Z in this.nodes)throw Error(`Node names must be unique: node with the name "${Z}" already exists.`);let Y=Z;if(this.addNode(Y,q,z),J!=null)this.addEdge(J,Y);J=Y}return this}compile({checkpointer:Q,store:$,cache:J,interruptBefore:Z,interruptAfter:q,name:z,description:Y}={}){this.validate([...Array.isArray(Z)?Z:[],...Array.isArray(q)?q:[]]);let X=Object.keys(this._schemaDefinitions.get(this._outputDefinition)),B=X.length===1&&X[0]===hQ?hQ:X,F=Object.keys(this.channels),W=F.length===1&&F[0]===hQ?hQ:F,L=this._interrupt,H=new O8({builder:this,checkpointer:Q,interruptAfter:q,interruptBefore:Z,autoValidate:!1,nodes:{},channels:{...this.channels,[T]:new VQ},inputChannels:T,outputChannels:B,streamChannels:W,streamMode:"updates",store:$,cache:J,name:z,description:Y,userInterrupt:L});H.attachNode(T);for(let[j,U]of Object.entries(this.nodes))H.attachNode(j,U);H.attachBranch(T,T8,P1(),{withReader:!1});for(let[j]of Object.entries(this.nodes))H.attachBranch(j,T8,P1(),{withReader:!1});for(let[j,U]of this.edges)H.attachEdge(j,U);for(let[j,U]of this.waitingEdges)H.attachEdge(j,U);for(let[j,U]of Object.entries(this.branches))for(let[D,M]of Object.entries(U))H.attachBranch(j,D,M);return H.validate()}};function R6(Q){let $={};for(let[J,Z]of Object.entries(Q))if(J===hQ)$[J]=J8(Z);else $[J]=J8(Z);return $}var O8=class extends Y${description;_metaRegistry=v0;constructor({description:Q,...$}){super($);this.description=Q}attachNode(Q,$){let J;if(Q===T)J=Object.entries(this.builder._schemaDefinitions.get(this.builder._inputDefinition)).map(([X])=>X);else J=Object.keys(this.builder.channels);function Z(X){if(u(X)){if(X.graph===a.PARENT)return null;return X._updateAsTuples()}else if(Array.isArray(X)&&X.length>0&&X.some((B)=>u(B))){let B=[];for(let F of X)if(u(F)){if(F.graph===a.PARENT)continue;B.push(...F._updateAsTuples())}else B.push([hQ,F]);return B}else if(X!=null)return[[hQ,X]];return null}let q=Q;function z(X){if(!X)return null;else if(u(X)){if(X.graph===a.PARENT)return null;return X._updateAsTuples().filter(([B])=>J.includes(B))}else if(Array.isArray(X)&&X.length>0&&X.some(u)){let B=[];for(let F of X)if(u(F)){if(F.graph===a.PARENT)continue;B.push(...F._updateAsTuples().filter(([W])=>J.includes(W)))}else{let W=z(F);if(W)B.push(...W??[])}return B}else if(typeof X==="object"&&!Array.isArray(X))return Object.entries(X).filter(([B])=>J.includes(B));else{let B=Array.isArray(X)?"array":typeof X;throw new w(`Expected node "${q.toString()}" to return an object or an array containing at least one Command object, received ${B}`,{lc_error_code:"INVALID_GRAPH_NODE_RETURN_VALUE"})}}let Y=[{value:qQ,mapper:new s({func:J.length&&J[0]===hQ?Z:z,trace:!1,recurse:!1})}];if(Q===T)this.nodes[Q]=new KQ({tags:[E],triggers:[T],channels:[T],writers:[new h(Y,[E])]});else{let X=$?.input??this.builder._schemaDefinition,B=Object.fromEntries(Object.keys(this.builder._schemaDefinitions.get(X)).map((L)=>[L,L])),F=Object.keys(B).length===1&&hQ in B,W=`branch:to:${Q}`;this.channels[W]=$?.defer?new v8:new VQ(!1),this.nodes[Q]=new KQ({triggers:[W],channels:F?Object.keys(B):B,writers:[new h(Y,[E])],mapper:F?void 0:(L)=>{return Object.fromEntries(Object.entries(L).filter(([H])=>(H in B)))},bound:$?.runnable,metadata:$?.metadata,retryPolicy:$?.retryPolicy,cachePolicy:$?.cachePolicy,subgraphs:$?.subgraphs,ends:$?.ends})}}attachEdge(Q,$){if($===A)return;if(typeof Q==="string")this.nodes[Q].writers.push(new h([{channel:`branch:to:${$}`,value:null}],[E]));else if(Array.isArray(Q)){let J=`join:${Q.join("+")}:${$}`;this.channels[J]=this.builder.nodes[$].defer?new g8(new Set(Q)):new k8(new Set(Q)),this.nodes[$].triggers.push(J);for(let Z of Q)this.nodes[Z].writers.push(new h([{channel:J,value:Z}],[E]))}}attachBranch(Q,$,J,Z={withReader:!0}){let q=async(z,Y)=>{let X=z.filter((F)=>F!==A);if(!X.length)return;let B=X.map((F)=>{if(d(F))return F;return{channel:F===A?F:`branch:to:${F}`,value:Q}});await h.doWrite({...Y,tags:(Y.tags??[]).concat([E])},B)};this.nodes[Q].writers.push(J.run(q,Z.withReader?(z)=>k$.doRead(z,this.streamChannels??this.outputChannels,!0):void 0))}async _validateInput(Q){if(Q==null)return Q;let $=this.builder._inputRuntimeDefinition,J=this.builder._schemaRuntimeDefinition;if(LQ.isInstance($)){if(u(Q)){let q=Q;if(Q.update)q.update=await $.validateInput(Array.isArray(Q.update)?Object.fromEntries(Q.update):Q.update);return q}return await $.validateInput(Q)}if($===x8&&LQ.isInstance(J)){if(u(Q)){let q=Q;if(Q.update)q.update=await J.validateInput(Array.isArray(Q.update)?Object.fromEntries(Q.update):Q.update);return q}return await J.validateInput(Q)}let Z=(()=>{let q=(z)=>{if(z==null)return;return this._metaRegistry.getExtendedChannelSchemas(z,{withReducerSchema:!0})};if(XQ($))return q($);if($===x8){if(XQ(J))return K8(q(J));return}})();if(u(Q)){let q=Q;if(Q.update&&Z!=null)q.update=M8(Z,Q.update);return q}if(Z!=null)return M8(Z,Q);return Q}isInterrupted(Q){return F0(Q)}async _validateContext(Q){let $=this.builder._configRuntimeSchema;if(XQ($))M8($,Q);return Q}};function T6(Q){return typeof Q==="object"&&Q!==null&&Q.channels!==void 0}function b6(Q){if(d(Q))return[Q];let $=[];if(u(Q))$.push(Q);else if(Array.isArray(Q))$.push(...Q.filter(u));let J=[];for(let Z of $){if(Z.graph===a.PARENT)throw new O0(Z);if(d(Z.goto))J.push(Z.goto);else if(typeof Z.goto==="string")J.push(Z.goto);else if(Array.isArray(Z.goto))J.push(...Z.goto)}return J}function P1(){return new z$({path:new s({func:b6,tags:[E],trace:!1,recurse:!1,name:"<control_branch>"})})}var B$=function($,J){let{name:Z,checkpointer:q,store:z,cache:Y}=typeof $==="string"?{name:$,checkpointer:void 0,store:void 0}:$;if(E$(J)||v$(J))throw Error("Generators are disallowed as entrypoints. For streaming responses, use config.write.");let X="updates",B=o$(Z,J);function F(j){return typeof j==="object"&&j!==null&&"__lg_type"in j&&j.__lg_type==="__pregel_final"}let W=new s({name:"pluckReturnValue",func:(j)=>{return F(j)?j.value:j}}),L=new s({name:"pluckSaveValue",func:(j)=>{return F(j)?j.save:j}}),H=new KQ({bound:B,triggers:[T],channels:[T],writers:[new h([{channel:A,value:qQ,mapper:W},{channel:aQ,value:qQ,mapper:L}],[E])]});return new G8({name:Z,checkpointer:q,nodes:{[Z]:H},channels:{[T]:new VQ,[A]:new UQ,[aQ]:new UQ},inputChannels:T,outputChannels:A,streamChannels:A,streamMode:X,store:z,cache:Y})};B$.final=function({value:$,save:J}){return{value:$,save:J,__lg_type:"__pregel_final"}};var w1=Q0.Root({messages:Q0({reducer:CQ,default:()=>[]})}),W$={reducer:{fn:CQ},jsonSchemaExtra:{langgraph_type:"messages"},default:()=>[]},R1=L$.object({messages:A1(L$.custom(),W$)});I$();
16
+ export{T as Of,A as Pf,uQ as Qf,a as Rf,u as Sf,pQ as Tf,wQ as Uf,Q0 as Vf,Q6 as Wf,N8 as Xf,BQ as Yf,IQ as Zf,LQ as _f,$8 as $f,v0 as ag,A1 as bg,A8 as cg,w1 as dg,W$ as eg};
@@ -0,0 +1,2 @@
1
+ import{createRequire as u}from"node:module";var n=Object.create;var{getPrototypeOf:o,defineProperty:e,getOwnPropertyNames:k,getOwnPropertyDescriptor:p}=Object,l=Object.prototype.hasOwnProperty;function m(a){return this[a]}var q,r,v=(a,b,c)=>{var d=a!=null&&typeof a==="object";if(d){var h=b?q??=new WeakMap:r??=new WeakMap,i=h.get(a);if(i)return i}c=a!=null?n(o(a)):{};let f=b||!a||!a.__esModule?e(c,"default",{value:a,enumerable:!0}):c;for(let g of k(a))if(!l.call(f,g))e(f,g,{get:m.bind(a,g),enumerable:!0});if(d)h.set(a,f);return f},w=(a)=>{var b=(j??=new WeakMap).get(a),c;if(b)return b;if(b=e({},"__esModule",{value:!0}),a&&typeof a==="object"||typeof a==="function"){for(var d of k(a))if(!l.call(b,d))e(b,d,{get:m.bind(a,d),enumerable:!(c=p(a,d))||c.enumerable})}return j.set(a,b),b},j,x=(a,b)=>()=>(b||a((b={exports:{}}).exports,b),b.exports);var s=(a)=>a;function t(a,b){this[a]=s.bind(null,b)}var y=(a,b)=>{for(var c in b)e(a,c,{get:b[c],enumerable:!0,configurable:!0,set:t.bind(b,c)})};var z=(a,b)=>()=>(a&&(b=a(a=0)),b);var B=u(import.meta.url);
2
+ export{v as Wl,w as Xl,x as Yl,y as Zl,z as _l,B as $l};
@@ -0,0 +1,2 @@
1
+ import{U as t}from"./chunk-h7ypcqp3.js";import{Wl as n}from"./chunk-4fs853nh.js";var e=n(t(),1),o=e.createContext(null),i=o.Provider;function c(){let r=e.useContext(o);if(!r)throw Error("useTrpc must be used within ZenCoreProvider");return r.trpc}
2
+ export{i as G,c as H};
@@ -0,0 +1,7 @@
1
+ import{U as c}from"./chunk-h7ypcqp3.js";import{Wl as h,Yl as wY}from"./chunk-4fs853nh.js";var IX=wY((DY)=>{var p=h(c());(function(){function X($){if($==null)return null;if(typeof $==="function")return $.$$typeof===i?null:$.displayName||$.name||null;if(typeof $==="string")return $;switch($){case L:return"Fragment";case k:return"Profiler";case P:return"StrictMode";case b:return"Suspense";case YX:return"SuspenseList";case d:return"Activity"}if(typeof $==="object")switch(typeof $.tag==="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),$.$$typeof){case w:return"Portal";case R:return $.displayName||"Context";case S:return($._context.displayName||"Context")+".Consumer";case g:var V=$.render;return $=$.displayName,$||($=V.displayName||V.name||"",$=$!==""?"ForwardRef("+$+")":"ForwardRef"),$;case O:return V=$.displayName||null,V!==null?V:X($.type)||"Memo";case Q:V=$._payload,$=$._init;try{return X($(V))}catch(D){}}return null}function Y($){return""+$}function G($){try{Y($);var V=!1}catch(_X){V=!0}if(V){V=console;var D=V.error,T=typeof Symbol==="function"&&Symbol.toStringTag&&$[Symbol.toStringTag]||$.constructor.name||"Object";return D.call(V,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",T),Y($)}}function J($){if($===L)return"<>";if(typeof $==="object"&&$!==null&&$.$$typeof===Q)return"<...>";try{var V=X($);return V?"<"+V+">":"<...>"}catch(D){return"<...>"}}function Z(){var $=s.A;return $===null?null:$.getOwner()}function H(){return Error("react-stack-top-frame")}function _($){if(y.call($,"key")){var V=Object.getOwnPropertyDescriptor($,"key").get;if(V&&V.isReactWarning)return!1}return $.key!==void 0}function W($,V){function D(){vX||(vX=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",V))}D.isReactWarning=!0,Object.defineProperty($,"key",{get:D,configurable:!0})}function A(){var $=X(this.type);return gX[$]||(gX[$]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),$=this.props.ref,$!==void 0?$:null}function U($,V,D,T,_X,KX){var I=D.ref;return $={$$typeof:K,type:$,key:V,props:D,_owner:T},(I!==void 0?I:null)!==null?Object.defineProperty($,"ref",{enumerable:!1,get:A}):Object.defineProperty($,"ref",{enumerable:!1,value:null}),$._store={},Object.defineProperty($._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty($,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty($,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:_X}),Object.defineProperty($,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:KX}),Object.freeze&&(Object.freeze($.props),Object.freeze($)),$}function z($,V,D,T,_X,KX){var I=V.children;if(I!==void 0)if(T)if(n(I)){for(T=0;T<I.length;T++)E(I[T]);Object.freeze&&Object.freeze(I)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else E(I);if(y.call(V,"key")){I=X($);var a=Object.keys(V).filter(function(BY){return BY!=="key"});T=0<a.length?"{key: someKey, "+a.join(": ..., ")+": ...}":"{key: someKey}",mX[I+T]||(a=0<a.length?"{"+a.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
2
+ let props = %s;
3
+ <%s {...props} />
4
+ React keys must be passed directly to JSX without using spread:
5
+ let props = %s;
6
+ <%s key={someKey} {...props} />`,T,I,a,I),mX[I+T]=!0)}if(I=null,D!==void 0&&(G(D),I=""+D),_(V)&&(G(V.key),I=""+V.key),"key"in V){D={};for(var TX in V)TX!=="key"&&(D[TX]=V[TX])}else D=V;return I&&W(D,typeof $==="function"?$.displayName||$.name||"Unknown":$),U($,I,D,Z(),_X,KX)}function E($){N($)?$._store&&($._store.validated=1):typeof $==="object"&&$!==null&&$.$$typeof===Q&&($._payload.status==="fulfilled"?N($._payload.value)&&$._payload.value._store&&($._payload.value._store.validated=1):$._store&&($._store.validated=1))}function N($){return typeof $==="object"&&$!==null&&$.$$typeof===K}var K=Symbol.for("react.transitional.element"),w=Symbol.for("react.portal"),L=Symbol.for("react.fragment"),P=Symbol.for("react.strict_mode"),k=Symbol.for("react.profiler"),S=Symbol.for("react.consumer"),R=Symbol.for("react.context"),g=Symbol.for("react.forward_ref"),b=Symbol.for("react.suspense"),YX=Symbol.for("react.suspense_list"),O=Symbol.for("react.memo"),Q=Symbol.for("react.lazy"),d=Symbol.for("react.activity"),i=Symbol.for("react.client.reference"),s=p.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,y=Object.prototype.hasOwnProperty,n=Array.isArray,EX=console.createTask?console.createTask:function(){return null};p={react_stack_bottom_frame:function($){return $()}};var vX,gX={},bX=p.react_stack_bottom_frame.bind(p,H)(),hX=EX(J(H)),mX={};DY.Fragment=L,DY.jsx=function($,V,D){var T=1e4>s.recentlyCreatedOwnerStacks++;return z($,V,D,!1,T?Error("react-stack-top-frame"):bX,T?EX(J($)):hX)},DY.jsxs=function($,V,D){var T=1e4>s.recentlyCreatedOwnerStacks++;return z($,V,D,!0,T?Error("react-stack-top-frame"):bX,T?EX(J($)):hX)}})()});var o=h(c(),1),fX=h(IX(),1),PX=o.createContext(void 0),GX=(X)=>{let Y=o.useContext(PX);if(X)return X;if(!Y)throw Error("No QueryClient set, use QueryClientProvider to set one");return Y},FY=({client:X,children:Y})=>{return o.useEffect(()=>{return X.mount(),()=>{X.unmount()}},[X]),fX.jsx(PX.Provider,{value:X,children:Y})};var M=class{constructor(){this.listeners=new Set,this.subscribe=this.subscribe.bind(this)}subscribe(X){return this.listeners.add(X),this.onSubscribe(),()=>{this.listeners.delete(X),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}};var EY={setTimeout:(X,Y)=>setTimeout(X,Y),clearTimeout:(X)=>clearTimeout(X),setInterval:(X,Y)=>setInterval(X,Y),clearInterval:(X)=>clearInterval(X)},KY=class{#X=EY;#Y=!1;setTimeoutProvider(X){if(this.#Y&&X!==this.#X)console.error("[timeoutManager]: Switching provider after calls to previous provider might result in unexpected behavior.",{previous:this.#X,provider:X});this.#X=X,this.#Y=!1}setTimeout(X,Y){return this.#Y=!0,this.#X.setTimeout(X,Y)}clearTimeout(X){this.#X.clearTimeout(X)}setInterval(X,Y){return this.#Y=!0,this.#X.setInterval(X,Y)}clearInterval(X){this.#X.clearInterval(X)}},q=new KY;function dX(X){setTimeout(X,0)}var x=typeof window>"u"||"Deno"in globalThis;function F(){}function cX(X,Y){return typeof X==="function"?X(Y):X}function JX(X){return typeof X==="number"&&X>=0&&X!==1/0}function VX(X,Y){return Math.max(X+(Y||0)-Date.now(),0)}function C(X,Y){return typeof X==="function"?X(Y):X}function j(X,Y){return typeof X==="function"?X(Y):X}function AX(X,Y){let{type:G="all",exact:J,fetchStatus:Z,predicate:H,queryKey:_,stale:W}=X;if(_){if(J){if(Y.queryHash!==ZX(_,Y.options))return!1}else if(!u(Y.queryKey,_))return!1}if(G!=="all"){let A=Y.isActive();if(G==="active"&&!A)return!1;if(G==="inactive"&&A)return!1}if(typeof W==="boolean"&&Y.isStale()!==W)return!1;if(Z&&Z!==Y.state.fetchStatus)return!1;if(H&&!H(Y))return!1;return!0}function NX(X,Y){let{exact:G,status:J,predicate:Z,mutationKey:H}=X;if(H){if(!Y.options.mutationKey)return!1;if(G){if(v(Y.options.mutationKey)!==v(H))return!1}else if(!u(Y.options.mutationKey,H))return!1}if(J&&Y.state.status!==J)return!1;if(Z&&!Z(Y))return!1;return!0}function ZX(X,Y){return(Y?.queryKeyHashFn||v)(X)}function v(X){return JSON.stringify(X,(Y,G)=>kX(G)?Object.keys(G).sort().reduce((J,Z)=>{return J[Z]=G[Z],J},{}):G)}function u(X,Y){if(X===Y)return!0;if(typeof X!==typeof Y)return!1;if(X&&Y&&typeof X==="object"&&typeof Y==="object")return Object.keys(Y).every((G)=>u(X[G],Y[G]));return!1}var TY=Object.prototype.hasOwnProperty;function zX(X,Y,G=0){if(X===Y)return X;if(G>500)return Y;let J=yX(X)&&yX(Y);if(!J&&!(kX(X)&&kX(Y)))return Y;let H=(J?X:Object.keys(X)).length,_=J?Y:Object.keys(Y),W=_.length,A=J?Array(W):{},U=0;for(let z=0;z<W;z++){let E=J?z:_[z],N=X[E],K=Y[E];if(N===K){if(A[E]=N,J?z<H:TY.call(X,E))U++;continue}if(N===null||K===null||typeof N!=="object"||typeof K!=="object"){A[E]=K;continue}let w=zX(N,K,G+1);if(A[E]=w,w===N)U++}return H===W&&U===H?X:A}function r(X,Y){if(!Y||Object.keys(X).length!==Object.keys(Y).length)return!1;for(let G in X)if(X[G]!==Y[G])return!1;return!0}function yX(X){return Array.isArray(X)&&X.length===Object.keys(X).length}function kX(X){if(!pX(X))return!1;let Y=X.constructor;if(Y===void 0)return!0;let G=Y.prototype;if(!pX(G))return!1;if(!G.hasOwnProperty("isPrototypeOf"))return!1;if(Object.getPrototypeOf(X)!==Object.prototype)return!1;return!0}function pX(X){return Object.prototype.toString.call(X)==="[object Object]"}function lX(X){return new Promise((Y)=>{q.setTimeout(Y,X)})}function $X(X,Y,G){if(typeof G.structuralSharing==="function")return G.structuralSharing(X,Y);else if(G.structuralSharing!==!1){try{return zX(X,Y)}catch(J){throw console.error(`Structural sharing requires data to be JSON serializable. To fix this, turn off structuralSharing or return JSON-serializable data from your queryFn. [${G.queryHash}]: ${J}`),J}return zX(X,Y)}return Y}function uX(X,Y,G=0){let J=[...X,Y];return G&&J.length>G?J.slice(1):J}function iX(X,Y,G=0){let J=[Y,...X];return G&&J.length>G?J.slice(0,-1):J}var l=Symbol();function LX(X,Y){if(X.queryFn===l)console.error(`Attempted to invoke queryFn when set to skipToken. This is likely a configuration error. Query hash: '${X.queryHash}'`);if(!X.queryFn&&Y?.initialPromise)return()=>Y.initialPromise;if(!X.queryFn||X.queryFn===l)return()=>Promise.reject(Error(`Missing queryFn: '${X.queryHash}'`));return X.queryFn}function t(X,Y){if(typeof X==="function")return X(...Y);return!!X}function sX(X,Y,G){let J=!1,Z;return Object.defineProperty(X,"signal",{enumerable:!0,get:()=>{if(Z??=Y(),J)return Z;if(J=!0,Z.aborted)G();else Z.addEventListener("abort",G,{once:!0});return Z}}),X}var IY=class extends M{#X;#Y;#G;constructor(){super();this.#G=(X)=>{if(!x&&window.addEventListener){let Y=()=>X();return window.addEventListener("visibilitychange",Y,!1),()=>{window.removeEventListener("visibilitychange",Y)}}return}}onSubscribe(){if(!this.#Y)this.setEventListener(this.#G)}onUnsubscribe(){if(!this.hasListeners())this.#Y?.(),this.#Y=void 0}setEventListener(X){this.#G=X,this.#Y?.(),this.#Y=X((Y)=>{if(typeof Y==="boolean")this.setFocused(Y);else this.onFocus()})}setFocused(X){if(this.#X!==X)this.#X=X,this.onFocus()}onFocus(){let X=this.isFocused();this.listeners.forEach((Y)=>{Y(X)})}isFocused(){if(typeof this.#X==="boolean")return this.#X;return globalThis.document?.visibilityState!=="hidden"}},e=new IY;function WX(){let X,Y,G=new Promise((Z,H)=>{X=Z,Y=H});G.status="pending",G.catch(()=>{});function J(Z){Object.assign(G,Z),delete G.resolve,delete G.reject}return G.resolve=(Z)=>{J({status:"fulfilled",value:Z}),X(Z)},G.reject=(Z)=>{J({status:"rejected",reason:Z}),Y(Z)},G}var nX=dX;function PY(){let X=[],Y=0,G=(W)=>{W()},J=(W)=>{W()},Z=nX,H=(W)=>{if(Y)X.push(W);else Z(()=>{G(W)})},_=()=>{let W=X;if(X=[],W.length)Z(()=>{J(()=>{W.forEach((A)=>{G(A)})})})};return{batch:(W)=>{let A;Y++;try{A=W()}finally{if(Y--,!Y)_()}return A},batchCalls:(W)=>{return(...A)=>{H(()=>{W(...A)})}},schedule:H,setNotifyFunction:(W)=>{G=W},setBatchNotifyFunction:(W)=>{J=W},setScheduler:(W)=>{Z=W}}}var B=PY();var kY=class extends M{#X=!0;#Y;#G;constructor(){super();this.#G=(X)=>{if(!x&&window.addEventListener){let Y=()=>X(!0),G=()=>X(!1);return window.addEventListener("online",Y,!1),window.addEventListener("offline",G,!1),()=>{window.removeEventListener("online",Y),window.removeEventListener("offline",G)}}return}}onSubscribe(){if(!this.#Y)this.setEventListener(this.#G)}onUnsubscribe(){if(!this.hasListeners())this.#Y?.(),this.#Y=void 0}setEventListener(X){this.#G=X,this.#Y?.(),this.#Y=X(this.setOnline.bind(this))}setOnline(X){if(this.#X!==X)this.#X=X,this.listeners.forEach((G)=>{G(X)})}isOnline(){return this.#X}},XX=new kY;function QY(X){return Math.min(1000*2**X,30000)}function QX(X){return(X??"online")==="online"?XX.isOnline():!0}var UX=class extends Error{constructor(X){super("CancelledError");this.revert=X?.revert,this.silent=X?.silent}};function BX(X){let Y=!1,G=0,J,Z=WX(),H=()=>Z.status!=="pending",_=(L)=>{if(!H()){let P=new UX(L);N(P),X.onCancel?.(P)}},W=()=>{Y=!0},A=()=>{Y=!1},U=()=>e.isFocused()&&(X.networkMode==="always"||XX.isOnline())&&X.canRun(),z=()=>QX(X.networkMode)&&X.canRun(),E=(L)=>{if(!H())J?.(),Z.resolve(L)},N=(L)=>{if(!H())J?.(),Z.reject(L)},K=()=>{return new Promise((L)=>{J=(P)=>{if(H()||U())L(P)},X.onPause?.()}).then(()=>{if(J=void 0,!H())X.onContinue?.()})},w=()=>{if(H())return;let L,P=G===0?X.initialPromise:void 0;try{L=P??X.fn()}catch(k){L=Promise.reject(k)}Promise.resolve(L).then(E).catch((k)=>{if(H())return;let S=X.retry??(x?0:3),R=X.retryDelay??QY,g=typeof R==="function"?R(G,k):R,b=S===!0||typeof S==="number"&&G<S||typeof S==="function"&&S(G,k);if(Y||!b){N(k);return}G++,X.onFail?.(G,k),lX(g).then(()=>{return U()?void 0:K()}).then(()=>{if(Y)N(k);else w()})})};return{promise:Z,status:()=>Z.status,cancel:_,continue:()=>{return J?.(),Z},cancelRetry:W,continueRetry:A,canStart:z,start:()=>{if(z())w();else K().then(w);return Z}}}var wX=class{#X;destroy(){this.clearGcTimeout()}scheduleGc(){if(this.clearGcTimeout(),JX(this.gcTime))this.#X=q.setTimeout(()=>{this.optionalRemove()},this.gcTime)}updateGcTime(X){this.gcTime=Math.max(this.gcTime||0,X??(x?1/0:300000))}clearGcTimeout(){if(this.#X)q.clearTimeout(this.#X),this.#X=void 0}};var rX=class extends wX{#X;#Y;#G;#Z;#J;#W;#H;constructor(X){super();this.#H=!1,this.#W=X.defaultOptions,this.setOptions(X.options),this.observers=[],this.#Z=X.client,this.#G=this.#Z.getQueryCache(),this.queryKey=X.queryKey,this.queryHash=X.queryHash,this.#X=oX(this.options),this.state=X.state??this.#X,this.scheduleGc()}get meta(){return this.options.meta}get promise(){return this.#J?.promise}setOptions(X){if(this.options={...this.#W,...X},this.updateGcTime(this.options.gcTime),this.state&&this.state.data===void 0){let Y=oX(this.options);if(Y.data!==void 0)this.setState(aX(Y.data,Y.dataUpdatedAt)),this.#X=Y}}optionalRemove(){if(!this.observers.length&&this.state.fetchStatus==="idle")this.#G.remove(this)}setData(X,Y){let G=$X(this.state.data,X,this.options);return this.#$({data:G,type:"success",dataUpdatedAt:Y?.updatedAt,manual:Y?.manual}),G}setState(X,Y){this.#$({type:"setState",state:X,setStateOptions:Y})}cancel(X){let Y=this.#J?.promise;return this.#J?.cancel(X),Y?Y.then(F).catch(F):Promise.resolve()}destroy(){super.destroy(),this.cancel({silent:!0})}reset(){this.destroy(),this.setState(this.#X)}isActive(){return this.observers.some((X)=>j(X.options.enabled,this)!==!1)}isDisabled(){if(this.getObserversCount()>0)return!this.isActive();return this.options.queryFn===l||this.state.dataUpdateCount+this.state.errorUpdateCount===0}isStatic(){if(this.getObserversCount()>0)return this.observers.some((X)=>C(X.options.staleTime,this)==="static");return!1}isStale(){if(this.getObserversCount()>0)return this.observers.some((X)=>X.getCurrentResult().isStale);return this.state.data===void 0||this.state.isInvalidated}isStaleByTime(X=0){if(this.state.data===void 0)return!0;if(X==="static")return!1;if(this.state.isInvalidated)return!0;return!VX(this.state.dataUpdatedAt,X)}onFocus(){this.observers.find((Y)=>Y.shouldFetchOnWindowFocus())?.refetch({cancelRefetch:!1}),this.#J?.continue()}onOnline(){this.observers.find((Y)=>Y.shouldFetchOnReconnect())?.refetch({cancelRefetch:!1}),this.#J?.continue()}addObserver(X){if(!this.observers.includes(X))this.observers.push(X),this.clearGcTimeout(),this.#G.notify({type:"observerAdded",query:this,observer:X})}removeObserver(X){if(this.observers.includes(X)){if(this.observers=this.observers.filter((Y)=>Y!==X),!this.observers.length){if(this.#J)if(this.#H)this.#J.cancel({revert:!0});else this.#J.cancelRetry();this.scheduleGc()}this.#G.notify({type:"observerRemoved",query:this,observer:X})}}getObserversCount(){return this.observers.length}invalidate(){if(!this.state.isInvalidated)this.#$({type:"invalidate"})}async fetch(X,Y){if(this.state.fetchStatus!=="idle"&&this.#J?.status()!=="rejected"){if(this.state.data!==void 0&&Y?.cancelRefetch)this.cancel({silent:!0});else if(this.#J)return this.#J.continueRetry(),this.#J.promise}if(X)this.setOptions(X);if(!this.options.queryFn){let W=this.observers.find((A)=>A.options.queryFn);if(W)this.setOptions(W.options)}if(!Array.isArray(this.options.queryKey))console.error("As of v4, queryKey needs to be an Array. If you are using a string like 'repoData', please change it to an Array, e.g. ['repoData']");let G=new AbortController,J=(W)=>{Object.defineProperty(W,"signal",{enumerable:!0,get:()=>{return this.#H=!0,G.signal}})},Z=()=>{let W=LX(this.options,Y),U=(()=>{let z={client:this.#Z,queryKey:this.queryKey,meta:this.meta};return J(z),z})();if(this.#H=!1,this.options.persister)return this.options.persister(W,U,this);return W(U)},_=(()=>{let W={fetchOptions:Y,options:this.options,queryKey:this.queryKey,client:this.#Z,state:this.state,fetchFn:Z};return J(W),W})();if(this.options.behavior?.onFetch(_,this),this.#Y=this.state,this.state.fetchStatus==="idle"||this.state.fetchMeta!==_.fetchOptions?.meta)this.#$({type:"fetch",meta:_.fetchOptions?.meta});this.#J=BX({initialPromise:Y?.initialPromise,fn:_.fetchFn,onCancel:(W)=>{if(W instanceof UX&&W.revert)this.setState({...this.#Y,fetchStatus:"idle"});G.abort()},onFail:(W,A)=>{this.#$({type:"failed",failureCount:W,error:A})},onPause:()=>{this.#$({type:"pause"})},onContinue:()=>{this.#$({type:"continue"})},retry:_.options.retry,retryDelay:_.options.retryDelay,networkMode:_.options.networkMode,canRun:()=>!0});try{let W=await this.#J.start();if(W===void 0)throw console.error(`Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: ${this.queryHash}`),Error(`${this.queryHash} data is undefined`);return this.setData(W),this.#G.config.onSuccess?.(W,this),this.#G.config.onSettled?.(W,this.state.error,this),W}catch(W){if(W instanceof UX){if(W.silent)return this.#J.promise;else if(W.revert){if(this.state.data===void 0)throw W;return this.state.data}}throw this.#$({type:"error",error:W}),this.#G.config.onError?.(W,this),this.#G.config.onSettled?.(this.state.data,W,this),W}finally{this.scheduleGc()}}#$(X){let Y=(G)=>{switch(X.type){case"failed":return{...G,fetchFailureCount:X.failureCount,fetchFailureReason:X.error};case"pause":return{...G,fetchStatus:"paused"};case"continue":return{...G,fetchStatus:"fetching"};case"fetch":return{...G,...xX(G.data,this.options),fetchMeta:X.meta??null};case"success":let J={...G,...aX(X.data,X.dataUpdatedAt),dataUpdateCount:G.dataUpdateCount+1,...!X.manual&&{fetchStatus:"idle",fetchFailureCount:0,fetchFailureReason:null}};return this.#Y=X.manual?J:void 0,J;case"error":let Z=X.error;return{...G,error:Z,errorUpdateCount:G.errorUpdateCount+1,errorUpdatedAt:Date.now(),fetchFailureCount:G.fetchFailureCount+1,fetchFailureReason:Z,fetchStatus:"idle",status:"error",isInvalidated:!0};case"invalidate":return{...G,isInvalidated:!0};case"setState":return{...G,...X.state}}};this.state=Y(this.state),B.batch(()=>{this.observers.forEach((G)=>{G.onQueryUpdate()}),this.#G.notify({query:this,type:"updated",action:X})})}};function xX(X,Y){return{fetchFailureCount:0,fetchFailureReason:null,fetchStatus:QX(Y.networkMode)?"fetching":"paused",...X===void 0&&{error:null,status:"pending"}}}function aX(X,Y){return{data:X,dataUpdatedAt:Y??Date.now(),error:null,isInvalidated:!1,status:"success"}}function oX(X){let Y=typeof X.initialData==="function"?X.initialData():X.initialData,G=Y!==void 0,J=G?typeof X.initialDataUpdatedAt==="function"?X.initialDataUpdatedAt():X.initialDataUpdatedAt:0;return{data:Y,dataUpdateCount:0,dataUpdatedAt:G?J??Date.now():0,error:null,errorUpdateCount:0,errorUpdatedAt:0,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:null,isInvalidated:!1,status:G?"success":"pending",fetchStatus:"idle"}}var SX=class extends M{constructor(X,Y){super();this.options=Y,this.#X=X,this.#$=null,this.#H=WX(),this.bindMethods(),this.setOptions(Y)}#X;#Y=void 0;#G=void 0;#Z=void 0;#J;#W;#H;#$;#B;#N;#L;#z;#V;#_;#U=new Set;bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){if(this.listeners.size===1){if(this.#Y.addObserver(this),tX(this.#Y,this.options))this.#A();else this.updateResult();this.#E()}}onUnsubscribe(){if(!this.hasListeners())this.destroy()}shouldFetchOnReconnect(){return jX(this.#Y,this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return jX(this.#Y,this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,this.#K(),this.#T(),this.#Y.removeObserver(this)}setOptions(X){let Y=this.options,G=this.#Y;if(this.options=this.#X.defaultQueryOptions(X),this.options.enabled!==void 0&&typeof this.options.enabled!=="boolean"&&typeof this.options.enabled!=="function"&&typeof j(this.options.enabled,this.#Y)!=="boolean")throw Error("Expected enabled to be a boolean or a callback that returns a boolean");if(this.#I(),this.#Y.setOptions(this.options),Y._defaulted&&!r(this.options,Y))this.#X.getQueryCache().notify({type:"observerOptionsUpdated",query:this.#Y,observer:this});let J=this.hasListeners();if(J&&eX(this.#Y,G,this.options,Y))this.#A();if(this.updateResult(),J&&(this.#Y!==G||j(this.options.enabled,this.#Y)!==j(Y.enabled,this.#Y)||C(this.options.staleTime,this.#Y)!==C(Y.staleTime,this.#Y)))this.#w();let Z=this.#D();if(J&&(this.#Y!==G||j(this.options.enabled,this.#Y)!==j(Y.enabled,this.#Y)||Z!==this.#_))this.#F(Z)}getOptimisticResult(X){let Y=this.#X.getQueryCache().build(this.#X,X),G=this.createResult(Y,X);if(jY(this,G))this.#Z=G,this.#W=this.options,this.#J=this.#Y.state;return G}getCurrentResult(){return this.#Z}trackResult(X,Y){return new Proxy(X,{get:(G,J)=>{if(this.trackProp(J),Y?.(J),J==="promise"){if(this.trackProp("data"),!this.options.experimental_prefetchInRender&&this.#H.status==="pending")this.#H.reject(Error("experimental_prefetchInRender feature flag is not enabled"))}return Reflect.get(G,J)}})}trackProp(X){this.#U.add(X)}getCurrentQuery(){return this.#Y}refetch({...X}={}){return this.fetch({...X})}fetchOptimistic(X){let Y=this.#X.defaultQueryOptions(X),G=this.#X.getQueryCache().build(this.#X,Y);return G.fetch().then(()=>this.createResult(G,Y))}fetch(X){return this.#A({...X,cancelRefetch:X.cancelRefetch??!0}).then(()=>{return this.updateResult(),this.#Z})}#A(X){this.#I();let Y=this.#Y.fetch(this.options,X);if(!X?.throwOnError)Y=Y.catch(F);return Y}#w(){this.#K();let X=C(this.options.staleTime,this.#Y);if(x||this.#Z.isStale||!JX(X))return;let G=VX(this.#Z.dataUpdatedAt,X)+1;this.#z=q.setTimeout(()=>{if(!this.#Z.isStale)this.updateResult()},G)}#D(){return(typeof this.options.refetchInterval==="function"?this.options.refetchInterval(this.#Y):this.options.refetchInterval)??!1}#F(X){if(this.#T(),this.#_=X,x||j(this.options.enabled,this.#Y)===!1||!JX(this.#_)||this.#_===0)return;this.#V=q.setInterval(()=>{if(this.options.refetchIntervalInBackground||e.isFocused())this.#A()},this.#_)}#E(){this.#w(),this.#F(this.#D())}#K(){if(this.#z)q.clearTimeout(this.#z),this.#z=void 0}#T(){if(this.#V)q.clearInterval(this.#V),this.#V=void 0}createResult(X,Y){let G=this.#Y,J=this.options,Z=this.#Z,H=this.#J,_=this.#W,A=X!==G?X.state:this.#G,{state:U}=X,z={...U},E=!1,N;if(Y._optimisticResults){let Q=this.hasListeners(),d=!Q&&tX(X,Y),i=Q&&eX(X,G,Y,J);if(d||i)z={...z,...xX(U.data,X.options)};if(Y._optimisticResults==="isRestoring")z.fetchStatus="idle"}let{error:K,errorUpdatedAt:w,status:L}=z;N=z.data;let P=!1;if(Y.placeholderData!==void 0&&N===void 0&&L==="pending"){let Q;if(Z?.isPlaceholderData&&Y.placeholderData===_?.placeholderData)Q=Z.data,P=!0;else Q=typeof Y.placeholderData==="function"?Y.placeholderData(this.#L?.state.data,this.#L):Y.placeholderData;if(Q!==void 0)L="success",N=$X(Z?.data,Q,Y),E=!0}if(Y.select&&N!==void 0&&!P)if(Z&&N===H?.data&&Y.select===this.#B)N=this.#N;else try{this.#B=Y.select,N=Y.select(N),N=$X(Z?.data,N,Y),this.#N=N,this.#$=null}catch(Q){this.#$=Q}if(this.#$)K=this.#$,N=this.#N,w=Date.now(),L="error";let k=z.fetchStatus==="fetching",S=L==="pending",R=L==="error",g=S&&k,b=N!==void 0,O={status:L,fetchStatus:z.fetchStatus,isPending:S,isSuccess:L==="success",isError:R,isInitialLoading:g,isLoading:g,data:N,dataUpdatedAt:z.dataUpdatedAt,error:K,errorUpdatedAt:w,failureCount:z.fetchFailureCount,failureReason:z.fetchFailureReason,errorUpdateCount:z.errorUpdateCount,isFetched:z.dataUpdateCount>0||z.errorUpdateCount>0,isFetchedAfterMount:z.dataUpdateCount>A.dataUpdateCount||z.errorUpdateCount>A.errorUpdateCount,isFetching:k,isRefetching:k&&!S,isLoadingError:R&&!b,isPaused:z.fetchStatus==="paused",isPlaceholderData:E,isRefetchError:R&&b,isStale:MX(X,Y),refetch:this.refetch,promise:this.#H,isEnabled:j(Y.enabled,X)!==!1};if(this.options.experimental_prefetchInRender){let Q=O.data!==void 0,d=O.status==="error"&&!Q,i=(n)=>{if(d)n.reject(O.error);else if(Q)n.resolve(O.data)},s=()=>{let n=this.#H=O.promise=WX();i(n)},y=this.#H;switch(y.status){case"pending":if(X.queryHash===G.queryHash)i(y);break;case"fulfilled":if(d||O.data!==y.value)s();break;case"rejected":if(!d||O.error!==y.reason)s();break}}return O}updateResult(){let X=this.#Z,Y=this.createResult(this.#Y,this.options);if(this.#J=this.#Y.state,this.#W=this.options,this.#J.data!==void 0)this.#L=this.#Y;if(r(Y,X))return;this.#Z=Y;let G=()=>{if(!X)return!0;let{notifyOnChangeProps:J}=this.options,Z=typeof J==="function"?J():J;if(Z==="all"||!Z&&!this.#U.size)return!0;let H=new Set(Z??this.#U);if(this.options.throwOnError)H.add("error");return Object.keys(this.#Z).some((_)=>{let W=_;return this.#Z[W]!==X[W]&&H.has(W)})};this.#P({listeners:G()})}#I(){let X=this.#X.getQueryCache().build(this.#X,this.options);if(X===this.#Y)return;let Y=this.#Y;if(this.#Y=X,this.#G=X.state,this.hasListeners())Y?.removeObserver(this),X.addObserver(this)}onQueryUpdate(){if(this.updateResult(),this.hasListeners())this.#E()}#P(X){B.batch(()=>{if(X.listeners)this.listeners.forEach((Y)=>{Y(this.#Z)});this.#X.getQueryCache().notify({query:this.#Y,type:"observerResultsUpdated"})})}};function xY(X,Y){return j(Y.enabled,X)!==!1&&X.state.data===void 0&&!(X.state.status==="error"&&Y.retryOnMount===!1)}function tX(X,Y){return xY(X,Y)||X.state.data!==void 0&&jX(X,Y,Y.refetchOnMount)}function jX(X,Y,G){if(j(Y.enabled,X)!==!1&&C(Y.staleTime,X)!=="static"){let J=typeof G==="function"?G(X):G;return J==="always"||J!==!1&&MX(X,Y)}return!1}function eX(X,Y,G,J){return(X!==Y||j(J.enabled,X)===!1)&&(!G.suspense||X.state.status!=="error")&&MX(X,G)}function MX(X,Y){return j(Y.enabled,X)!==!1&&X.isStaleByTime(C(Y.staleTime,X))}function jY(X,Y){if(!r(X.getCurrentResult(),Y))return!0;return!1}function RX(X){return{onFetch:(Y,G)=>{let J=Y.options,Z=Y.fetchOptions?.meta?.fetchMore?.direction,H=Y.state.data?.pages||[],_=Y.state.data?.pageParams||[],W={pages:[],pageParams:[]},A=0,U=async()=>{let z=!1,E=(w)=>{sX(w,()=>Y.signal,()=>z=!0)},N=LX(Y.options,Y.fetchOptions),K=async(w,L,P)=>{if(z)return Promise.reject();if(L==null&&w.pages.length)return Promise.resolve(w);let S=(()=>{let YX={client:Y.client,queryKey:Y.queryKey,pageParam:L,direction:P?"backward":"forward",meta:Y.options.meta};return E(YX),YX})(),R=await N(S),{maxPages:g}=Y.options,b=P?iX:uX;return{pages:b(w.pages,R,g),pageParams:b(w.pageParams,L,g)}};if(Z&&H.length){let w=Z==="backward",L=w?SY:XY,P={pages:H,pageParams:_},k=L(J,P);W=await K(P,k,w)}else{let w=X??H.length;do{let L=A===0?_[0]??J.initialPageParam:XY(J,W);if(A>0&&L==null)break;W=await K(W,L),A++}while(A<w)}return W};if(Y.options.persister)Y.fetchFn=()=>{return Y.options.persister?.(U,{client:Y.client,queryKey:Y.queryKey,meta:Y.options.meta,signal:Y.signal},G)};else Y.fetchFn=U}}}function XY(X,{pages:Y,pageParams:G}){let J=Y.length-1;return Y.length>0?X.getNextPageParam(Y[J],Y,G[J],G):void 0}function SY(X,{pages:Y,pageParams:G}){return Y.length>0?X.getPreviousPageParam?.(Y[0],Y,G[0],G):void 0}var YY=class extends wX{#X;#Y;#G;#Z;constructor(X){super();this.#X=X.client,this.mutationId=X.mutationId,this.#G=X.mutationCache,this.#Y=[],this.state=X.state||CX(),this.setOptions(X.options),this.scheduleGc()}setOptions(X){this.options=X,this.updateGcTime(this.options.gcTime)}get meta(){return this.options.meta}addObserver(X){if(!this.#Y.includes(X))this.#Y.push(X),this.clearGcTimeout(),this.#G.notify({type:"observerAdded",mutation:this,observer:X})}removeObserver(X){this.#Y=this.#Y.filter((Y)=>Y!==X),this.scheduleGc(),this.#G.notify({type:"observerRemoved",mutation:this,observer:X})}optionalRemove(){if(!this.#Y.length)if(this.state.status==="pending")this.scheduleGc();else this.#G.remove(this)}continue(){return this.#Z?.continue()??this.execute(this.state.variables)}async execute(X){let Y=()=>{this.#J({type:"continue"})},G={client:this.#X,meta:this.options.meta,mutationKey:this.options.mutationKey};this.#Z=BX({fn:()=>{if(!this.options.mutationFn)return Promise.reject(Error("No mutationFn found"));return this.options.mutationFn(X,G)},onFail:(H,_)=>{this.#J({type:"failed",failureCount:H,error:_})},onPause:()=>{this.#J({type:"pause"})},onContinue:Y,retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode,canRun:()=>this.#G.canRun(this)});let J=this.state.status==="pending",Z=!this.#Z.canStart();try{if(J)Y();else{if(this.#J({type:"pending",variables:X,isPaused:Z}),this.#G.config.onMutate)await this.#G.config.onMutate(X,this,G);let _=await this.options.onMutate?.(X,G);if(_!==this.state.context)this.#J({type:"pending",context:_,variables:X,isPaused:Z})}let H=await this.#Z.start();return await this.#G.config.onSuccess?.(H,X,this.state.context,this,G),await this.options.onSuccess?.(H,X,this.state.context,G),await this.#G.config.onSettled?.(H,null,this.state.variables,this.state.context,this,G),await this.options.onSettled?.(H,null,X,this.state.context,G),this.#J({type:"success",data:H}),H}catch(H){try{await this.#G.config.onError?.(H,X,this.state.context,this,G)}catch(_){Promise.reject(_)}try{await this.options.onError?.(H,X,this.state.context,G)}catch(_){Promise.reject(_)}try{await this.#G.config.onSettled?.(void 0,H,this.state.variables,this.state.context,this,G)}catch(_){Promise.reject(_)}try{await this.options.onSettled?.(void 0,H,X,this.state.context,G)}catch(_){Promise.reject(_)}throw this.#J({type:"error",error:H}),H}finally{this.#G.runNext(this)}}#J(X){let Y=(G)=>{switch(X.type){case"failed":return{...G,failureCount:X.failureCount,failureReason:X.error};case"pause":return{...G,isPaused:!0};case"continue":return{...G,isPaused:!1};case"pending":return{...G,context:X.context,data:void 0,failureCount:0,failureReason:null,error:null,isPaused:X.isPaused,status:"pending",variables:X.variables,submittedAt:Date.now()};case"success":return{...G,data:X.data,failureCount:0,failureReason:null,error:null,status:"success",isPaused:!1};case"error":return{...G,data:void 0,error:X.error,failureCount:G.failureCount+1,failureReason:X.error,isPaused:!1,status:"error"}}};this.state=Y(this.state),B.batch(()=>{this.#Y.forEach((G)=>{G.onMutationUpdate(X)}),this.#G.notify({mutation:this,type:"updated",action:X})})}};function CX(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0}}var GY=class extends M{constructor(X={}){super();this.config=X,this.#X=new Set,this.#Y=new Map,this.#G=0}#X;#Y;#G;build(X,Y,G){let J=new YY({client:X,mutationCache:this,mutationId:++this.#G,options:X.defaultMutationOptions(Y),state:G});return this.add(J),J}add(X){this.#X.add(X);let Y=DX(X);if(typeof Y==="string"){let G=this.#Y.get(Y);if(G)G.push(X);else this.#Y.set(Y,[X])}this.notify({type:"added",mutation:X})}remove(X){if(this.#X.delete(X)){let Y=DX(X);if(typeof Y==="string"){let G=this.#Y.get(Y);if(G){if(G.length>1){let J=G.indexOf(X);if(J!==-1)G.splice(J,1)}else if(G[0]===X)this.#Y.delete(Y)}}}this.notify({type:"removed",mutation:X})}canRun(X){let Y=DX(X);if(typeof Y==="string"){let J=this.#Y.get(Y)?.find((Z)=>Z.state.status==="pending");return!J||J===X}else return!0}runNext(X){let Y=DX(X);if(typeof Y==="string")return this.#Y.get(Y)?.find((J)=>J!==X&&J.state.isPaused)?.continue()??Promise.resolve();else return Promise.resolve()}clear(){B.batch(()=>{this.#X.forEach((X)=>{this.notify({type:"removed",mutation:X})}),this.#X.clear(),this.#Y.clear()})}getAll(){return Array.from(this.#X)}find(X){let Y={exact:!0,...X};return this.getAll().find((G)=>NX(Y,G))}findAll(X={}){return this.getAll().filter((Y)=>NX(X,Y))}notify(X){B.batch(()=>{this.listeners.forEach((Y)=>{Y(X)})})}resumePausedMutations(){let X=this.getAll().filter((Y)=>Y.state.isPaused);return B.batch(()=>Promise.all(X.map((Y)=>Y.continue().catch(F))))}};function DX(X){return X.options.scope?.id}var OX=class extends M{#X;#Y=void 0;#G;#Z;constructor(X,Y){super();this.#X=X,this.setOptions(Y),this.bindMethods(),this.#J()}bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(X){let Y=this.options;if(this.options=this.#X.defaultMutationOptions(X),!r(this.options,Y))this.#X.getMutationCache().notify({type:"observerOptionsUpdated",mutation:this.#G,observer:this});if(Y?.mutationKey&&this.options.mutationKey&&v(Y.mutationKey)!==v(this.options.mutationKey))this.reset();else if(this.#G?.state.status==="pending")this.#G.setOptions(this.options)}onUnsubscribe(){if(!this.hasListeners())this.#G?.removeObserver(this)}onMutationUpdate(X){this.#J(),this.#W(X)}getCurrentResult(){return this.#Y}reset(){this.#G?.removeObserver(this),this.#G=void 0,this.#J(),this.#W()}mutate(X,Y){return this.#Z=Y,this.#G?.removeObserver(this),this.#G=this.#X.getMutationCache().build(this.#X,this.options),this.#G.addObserver(this),this.#G.execute(X)}#J(){let X=this.#G?.state??CX();this.#Y={...X,isPending:X.status==="pending",isSuccess:X.status==="success",isError:X.status==="error",isIdle:X.status==="idle",mutate:this.mutate,reset:this.reset}}#W(X){B.batch(()=>{if(this.#Z&&this.hasListeners()){let Y=this.#Y.variables,G=this.#Y.context,J={client:this.#X,meta:this.options.meta,mutationKey:this.options.mutationKey};if(X?.type==="success"){try{this.#Z.onSuccess?.(X.data,Y,G,J)}catch(Z){Promise.reject(Z)}try{this.#Z.onSettled?.(X.data,null,Y,G,J)}catch(Z){Promise.reject(Z)}}else if(X?.type==="error"){try{this.#Z.onError?.(X.error,Y,G,J)}catch(Z){Promise.reject(Z)}try{this.#Z.onSettled?.(void 0,X.error,Y,G,J)}catch(Z){Promise.reject(Z)}}}this.listeners.forEach((Y)=>{Y(this.#Y)})})}};var JY=class extends M{constructor(X={}){super();this.config=X,this.#X=new Map}#X;build(X,Y,G){let J=Y.queryKey,Z=Y.queryHash??ZX(J,Y),H=this.get(Z);if(!H)H=new rX({client:X,queryKey:J,queryHash:Z,options:X.defaultQueryOptions(Y),state:G,defaultOptions:X.getQueryDefaults(J)}),this.add(H);return H}add(X){if(!this.#X.has(X.queryHash))this.#X.set(X.queryHash,X),this.notify({type:"added",query:X})}remove(X){let Y=this.#X.get(X.queryHash);if(Y){if(X.destroy(),Y===X)this.#X.delete(X.queryHash);this.notify({type:"removed",query:X})}}clear(){B.batch(()=>{this.getAll().forEach((X)=>{this.remove(X)})})}get(X){return this.#X.get(X)}getAll(){return[...this.#X.values()]}find(X){let Y={exact:!0,...X};return this.getAll().find((G)=>AX(Y,G))}findAll(X={}){let Y=this.getAll();return Object.keys(X).length>0?Y.filter((G)=>AX(X,G)):Y}notify(X){B.batch(()=>{this.listeners.forEach((Y)=>{Y(X)})})}onFocus(){B.batch(()=>{this.getAll().forEach((X)=>{X.onFocus()})})}onOnline(){B.batch(()=>{this.getAll().forEach((X)=>{X.onOnline()})})}};var MY=class{#X;#Y;#G;#Z;#J;#W;#H;#$;constructor(X={}){this.#X=X.queryCache||new JY,this.#Y=X.mutationCache||new GY,this.#G=X.defaultOptions||{},this.#Z=new Map,this.#J=new Map,this.#W=0}mount(){if(this.#W++,this.#W!==1)return;this.#H=e.subscribe(async(X)=>{if(X)await this.resumePausedMutations(),this.#X.onFocus()}),this.#$=XX.subscribe(async(X)=>{if(X)await this.resumePausedMutations(),this.#X.onOnline()})}unmount(){if(this.#W--,this.#W!==0)return;this.#H?.(),this.#H=void 0,this.#$?.(),this.#$=void 0}isFetching(X){return this.#X.findAll({...X,fetchStatus:"fetching"}).length}isMutating(X){return this.#Y.findAll({...X,status:"pending"}).length}getQueryData(X){let Y=this.defaultQueryOptions({queryKey:X});return this.#X.get(Y.queryHash)?.state.data}ensureQueryData(X){let Y=this.defaultQueryOptions(X),G=this.#X.build(this,Y),J=G.state.data;if(J===void 0)return this.fetchQuery(X);if(X.revalidateIfStale&&G.isStaleByTime(C(Y.staleTime,G)))this.prefetchQuery(Y);return Promise.resolve(J)}getQueriesData(X){return this.#X.findAll(X).map(({queryKey:Y,state:G})=>{let J=G.data;return[Y,J]})}setQueryData(X,Y,G){let J=this.defaultQueryOptions({queryKey:X}),H=this.#X.get(J.queryHash)?.state.data,_=cX(Y,H);if(_===void 0)return;return this.#X.build(this,J).setData(_,{...G,manual:!0})}setQueriesData(X,Y,G){return B.batch(()=>this.#X.findAll(X).map(({queryKey:J})=>[J,this.setQueryData(J,Y,G)]))}getQueryState(X){let Y=this.defaultQueryOptions({queryKey:X});return this.#X.get(Y.queryHash)?.state}removeQueries(X){let Y=this.#X;B.batch(()=>{Y.findAll(X).forEach((G)=>{Y.remove(G)})})}resetQueries(X,Y){let G=this.#X;return B.batch(()=>{return G.findAll(X).forEach((J)=>{J.reset()}),this.refetchQueries({type:"active",...X},Y)})}cancelQueries(X,Y={}){let G={revert:!0,...Y},J=B.batch(()=>this.#X.findAll(X).map((Z)=>Z.cancel(G)));return Promise.all(J).then(F).catch(F)}invalidateQueries(X,Y={}){return B.batch(()=>{if(this.#X.findAll(X).forEach((G)=>{G.invalidate()}),X?.refetchType==="none")return Promise.resolve();return this.refetchQueries({...X,type:X?.refetchType??X?.type??"active"},Y)})}refetchQueries(X,Y={}){let G={...Y,cancelRefetch:Y.cancelRefetch??!0},J=B.batch(()=>this.#X.findAll(X).filter((Z)=>!Z.isDisabled()&&!Z.isStatic()).map((Z)=>{let H=Z.fetch(void 0,G);if(!G.throwOnError)H=H.catch(F);return Z.state.fetchStatus==="paused"?Promise.resolve():H}));return Promise.all(J).then(F)}fetchQuery(X){let Y=this.defaultQueryOptions(X);if(Y.retry===void 0)Y.retry=!1;let G=this.#X.build(this,Y);return G.isStaleByTime(C(Y.staleTime,G))?G.fetch(Y):Promise.resolve(G.state.data)}prefetchQuery(X){return this.fetchQuery(X).then(F).catch(F)}fetchInfiniteQuery(X){return X.behavior=RX(X.pages),this.fetchQuery(X)}prefetchInfiniteQuery(X){return this.fetchInfiniteQuery(X).then(F).catch(F)}ensureInfiniteQueryData(X){return X.behavior=RX(X.pages),this.ensureQueryData(X)}resumePausedMutations(){if(XX.isOnline())return this.#Y.resumePausedMutations();return Promise.resolve()}getQueryCache(){return this.#X}getMutationCache(){return this.#Y}getDefaultOptions(){return this.#G}setDefaultOptions(X){this.#G=X}setQueryDefaults(X,Y){this.#Z.set(v(X),{queryKey:X,defaultOptions:Y})}getQueryDefaults(X){let Y=[...this.#Z.values()],G={};return Y.forEach((J)=>{if(u(X,J.queryKey))Object.assign(G,J.defaultOptions)}),G}setMutationDefaults(X,Y){this.#J.set(v(X),{mutationKey:X,defaultOptions:Y})}getMutationDefaults(X){let Y=[...this.#J.values()],G={};return Y.forEach((J)=>{if(u(X,J.mutationKey))Object.assign(G,J.defaultOptions)}),G}defaultQueryOptions(X){if(X._defaulted)return X;let Y={...this.#G.queries,...this.getQueryDefaults(X.queryKey),...X,_defaulted:!0};if(!Y.queryHash)Y.queryHash=ZX(Y.queryKey,Y);if(Y.refetchOnReconnect===void 0)Y.refetchOnReconnect=Y.networkMode!=="always";if(Y.throwOnError===void 0)Y.throwOnError=!!Y.suspense;if(!Y.networkMode&&Y.persister)Y.networkMode="offlineFirst";if(Y.queryFn===l)Y.enabled=!1;return Y}defaultMutationOptions(X){if(X?._defaulted)return X;return{...this.#G.mutations,...X?.mutationKey&&this.getMutationDefaults(X.mutationKey),...X,_defaulted:!0}}clear(){this.#X.clear(),this.#Y.clear()}};var f=h(c(),1);var HX=h(c(),1),RY=h(IX(),1);function CY(){let X=!1;return{clearReset:()=>{X=!1},reset:()=>{X=!0},isReset:()=>{return X}}}var OY=HX.createContext(CY()),ZY=()=>HX.useContext(OY);var $Y=h(c(),1);var WY=(X,Y,G)=>{let J=G?.state.error&&typeof X.throwOnError==="function"?t(X.throwOnError,[G.state.error,G]):X.throwOnError;if(X.suspense||X.experimental_prefetchInRender||J){if(!Y.isReset())X.retryOnMount=!1}},HY=(X)=>{$Y.useEffect(()=>{X.clearReset()},[X])},_Y=({result:X,errorResetBoundary:Y,throwOnError:G,query:J,suspense:Z})=>{return X.isError&&!Y.isReset()&&!X.isFetching&&J&&(Z&&X.data===void 0||t(G,[X.error,J]))};var FX=h(c(),1),zY=FX.createContext(!1),VY=()=>FX.useContext(zY),K2=zY.Provider;var AY=(X)=>{if(X.suspense){let G=(Z)=>Z==="static"?Z:Math.max(Z??1000,1000),J=X.staleTime;if(X.staleTime=typeof J==="function"?(...Z)=>G(J(...Z)):G(J),typeof X.gcTime==="number")X.gcTime=Math.max(X.gcTime,1000)}},NY=(X,Y)=>X.isLoading&&X.isFetching&&!Y,LY=(X,Y)=>X?.suspense&&Y.isPending,qX=(X,Y,G)=>Y.fetchOptimistic(X).catch(()=>{G.clearReset()});function UY(X,Y,G){if(typeof X!=="object"||Array.isArray(X))throw Error('Bad argument type. Starting with v5, only the "Object" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object');let J=VY(),Z=ZY(),H=GX(G),_=H.defaultQueryOptions(X);H.getDefaultOptions().queries?._experimental_beforeQuery?.(_);let W=H.getQueryCache().get(_.queryHash);if(!_.queryFn)console.error(`[${_.queryHash}]: No queryFn was passed as an option, and no default queryFn was found. The queryFn parameter is only optional when using a default queryFn. More info here: https://tanstack.com/query/latest/docs/framework/react/guides/default-query-function`);_._optimisticResults=J?"isRestoring":"optimistic",AY(_),WY(_,Z,W),HY(Z);let A=!H.getQueryCache().get(_.queryHash),[U]=f.useState(()=>new Y(H,_)),z=U.getOptimisticResult(_),E=!J&&X.subscribed!==!1;if(f.useSyncExternalStore(f.useCallback((N)=>{let K=E?U.subscribe(B.batchCalls(N)):F;return U.updateResult(),K},[U,E]),()=>U.getCurrentResult(),()=>U.getCurrentResult()),f.useEffect(()=>{U.setOptions(_)},[_,U]),LY(_,z))throw qX(_,U,Z);if(_Y({result:z,errorResetBoundary:Z,throwOnError:_.throwOnError,query:W,suspense:_.suspense}))throw z.error;if(H.getDefaultOptions().queries?._experimental_afterQuery?.(_,z),_.experimental_prefetchInRender&&!x&&NY(z,J))(A?qX(_,U,Z):W?.promise)?.catch(F).finally(()=>{U.updateResult()});return!_.notifyOnChangeProps?U.trackResult(z):z}function qY(X,Y){return UY(X,SX,Y)}var m=h(c(),1);function vY(X,Y){let G=GX(Y),[J]=m.useState(()=>new OX(G,X));m.useEffect(()=>{J.setOptions(X)},[J,X]);let Z=m.useSyncExternalStore(m.useCallback((_)=>J.subscribe(B.batchCalls(_)),[J]),()=>J.getCurrentResult(),()=>J.getCurrentResult()),H=m.useCallback((_,W)=>{J.mutate(_,W).catch(F)},[J]);if(Z.error&&t(J.options.throwOnError,[Z.error]))throw Z.error;return{...Z,mutate:H,mutateAsync:Z.mutate}}var T4={config:{all:["config"],detail:()=>["config","detail"]},providers:{all:["providers"],list:()=>["providers","list"],detail:(X)=>["providers","detail",X]},models:{all:["models"],list:(X)=>["models","list",X],available:(X)=>["models","available",X]},skills:{all:["skills"],list:()=>["skills","list"],detail:(X)=>["skills","detail",X]},tasks:{all:["tasks"],list:(X)=>["tasks","list",X],detail:(X)=>["tasks","detail",X]},history:{all:["history"],list:()=>["history","list"],detail:(X)=>["history","detail",X]},knowledge:{all:["knowledge"],memories:()=>["knowledge","memories"],skills:()=>["knowledge","skills"]},agents:{all:["agents"],list:()=>["agents","list"],detail:(X)=>["agents","detail",X]},mcp:{all:["mcp"],config:()=>["mcp","config"]},errors:{all:["errors"],list:()=>["errors","list"],stats:()=>["errors","stats"]}};
7
+ export{MY as I,IX as J,GX as K,FY as L,qY as M,vY as N,T4 as O};
@@ -0,0 +1,2 @@
1
+ import{U as JJ}from"./chunk-h7ypcqp3.js";import{Wl as g,Yl as y}from"./chunk-4fs853nh.js";var C=y((XJ,E)=>{var f="Expected a function",w=NaN,V="[object Symbol]",S=/^\s+|\s+$/g,v=/^[-+]0x[0-9a-f]+$/i,p=/^0b[01]+$/i,d=/^0o[0-7]+$/i,c=parseInt,r=typeof global=="object"&&global&&global.Object===Object&&global,u=typeof self=="object"&&self&&self.Object===Object&&self,o=r||u||Function("return this")(),s=Object.prototype,n=s.toString,l=Math.max,i=Math.min,N=function(){return o.Date.now()};function a(J,Z,$){var Y,j,G,B,Q,P,q=0,F=!1,U=!1,W=!0;if(typeof J!="function")throw TypeError(f);if(Z=I(Z)||0,L($))F=!!$.leading,U="maxWait"in $,G=U?l(I($.maxWait)||0,Z):G,W="trailing"in $?!!$.trailing:W;function _(K){var H=Y,A=j;return Y=j=void 0,q=K,B=J.apply(A,H),B}function h(K){return q=K,Q=setTimeout(D,Z),F?_(K):B}function b(K){var H=K-P,A=K-q,R=Z-H;return U?i(R,G-A):R}function T(K){var H=K-P,A=K-q;return P===void 0||H>=Z||H<0||U&&A>=G}function D(){var K=N();if(T(K))return z(K);Q=setTimeout(D,b(K))}function z(K){if(Q=void 0,W&&Y)return _(K);return Y=j=void 0,B}function m(){if(Q!==void 0)clearTimeout(Q);q=0,Y=P=j=Q=void 0}function k(){return Q===void 0?B:z(N())}function O(){var K=N(),H=T(K);if(Y=arguments,j=this,P=K,H){if(Q===void 0)return h(P);if(U)return Q=setTimeout(D,Z),_(P)}if(Q===void 0)Q=setTimeout(D,Z);return B}return O.cancel=m,O.flush=k,O}function L(J){var Z=typeof J;return!!J&&(Z=="object"||Z=="function")}function t(J){return!!J&&typeof J=="object"}function e(J){return typeof J=="symbol"||t(J)&&n.call(J)==V}function I(J){if(typeof J=="number")return J;if(e(J))return w;if(L(J)){var Z=typeof J.valueOf=="function"?J.valueOf():J;J=L(Z)?Z+"":Z}if(typeof J!="string")return J===0?J:+J;J=J.replace(S,"");var $=p.test(J);return $||d.test(J)?c(J.slice(2),$?2:8):v.test(J)?w:+J}E.exports=a});var X=g(JJ(),1),M=g(C(),1);function YJ(J=!1){if(typeof J!=="boolean")throw Error("defaultValue must be `true` or `false`");let[Z,$]=X.useState(J),Y=X.useCallback(()=>{$(!0)},[]),j=X.useCallback(()=>{$(!1)},[]),G=X.useCallback(()=>{$((B)=>!B)},[]);return{value:Z,setValue:$,setTrue:Y,setFalse:j,toggle:G}}var x=typeof window<"u"?X.useLayoutEffect:X.useEffect;function KJ(J,Z){let $=X.useRef(J);x(()=>{$.current=J},[J]),X.useEffect(()=>{if(Z===null)return;let Y=setInterval(()=>{$.current()},Z);return()=>{clearInterval(Y)}},[Z])}function QJ(J){let Z=X.useRef(()=>{throw Error("Cannot call an event handler while rendering.")});return x(()=>{Z.current=J},[J]),X.useCallback((...$)=>{var Y;return(Y=Z.current)==null?void 0:Y.call(Z,...$)},[Z])}function ZJ(J){let Z=X.useRef(J);Z.current=J,X.useEffect(()=>()=>{Z.current()},[])}function $J(J,Z=500,$){let Y=X.useRef();ZJ(()=>{if(Y.current)Y.current.cancel()});let j=X.useMemo(()=>{let G=M.default(J,Z,$),B=(...Q)=>{return G(...Q)};return B.cancel=()=>{G.cancel()},B.isPending=()=>{return!!Y.current},B.flush=()=>{return G.flush()},B},[J,Z,$]);return X.useEffect(()=>{Y.current=M.default(J,Z,$)},[J,Z,$]),j}function jJ(J,Z,$){let Y=($==null?void 0:$.equalityFn)??((q,F)=>q===F),j=J instanceof Function?J():J,[G,B]=X.useState(j),Q=X.useRef(j),P=$J(B,Z,$);if(!Y(Q.current,j))P(j),Q.current=j;return[G,P]}function BJ(){let J=X.useRef(!1);return X.useEffect(()=>{return J.current=!0,()=>{J.current=!1}},[]),X.useCallback(()=>J.current,[])}function GJ(J,Z){let $=X.useRef(J);x(()=>{$.current=J},[J]),X.useEffect(()=>{if(!Z&&Z!==0)return;let Y=setTimeout(()=>{$.current()},Z);return()=>{clearTimeout(Y)}},[Z])}
2
+ export{YJ as x,KJ as y,QJ as z,ZJ as A,jJ as B,BJ as C,GJ as D};