@esri/solutions-components 5.1.0-next.150 → 5.1.0-next.152

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 (70) hide show
  1. package/dist/cdn/{KH5WPLZK.js → 2BM4W44V.js} +1 -1
  2. package/dist/cdn/{6K3C5JX2.js → 2HAYT46E.js} +1 -1
  3. package/dist/cdn/3RKQYXNE.js +2 -0
  4. package/dist/cdn/{7WYPODAB.js → 3S5PVZVU.js} +1 -1
  5. package/dist/cdn/3TIQRBWC.js +2 -0
  6. package/dist/cdn/4QOD7X43.js +2 -0
  7. package/dist/cdn/{YWALGZAG.js → 63ZMLOEP.js} +1 -1
  8. package/dist/cdn/{GRQLB7ZG.js → 7GVN2XEM.js} +1 -1
  9. package/dist/cdn/BAFYN4RD.js +2 -0
  10. package/dist/cdn/C4KWJ3PL.js +2 -0
  11. package/dist/cdn/{ZNH7LRND.js → EKUENEEW.js} +1 -1
  12. package/dist/cdn/{TKOGOWYQ.js → EVMBOT65.js} +27 -27
  13. package/dist/cdn/{W7I22AW3.js → FNTXI57U.js} +1 -1
  14. package/dist/cdn/{4SBOBTOR.js → FWRT4BPD.js} +1 -1
  15. package/dist/cdn/{Q2DJUFVO.js → FZKGL66L.js} +1 -1
  16. package/dist/cdn/{7Q5BT35O.js → G6EZOEPB.js} +1 -1
  17. package/dist/cdn/{LTLR4VF3.js → GMSG7ZRV.js} +1 -1
  18. package/dist/cdn/{KETYOYXQ.js → IC6KIGR4.js} +1 -1
  19. package/dist/cdn/{RMO244NW.js → KV76ATT5.js} +1 -1
  20. package/dist/cdn/LGZDNUGT.js +2 -0
  21. package/dist/cdn/{PP7EF7UU.js → LQ4BLDUU.js} +1 -1
  22. package/dist/cdn/{YTU2BYBP.js → M73VTGBI.js} +1 -1
  23. package/dist/cdn/{Q35DDH7J.js → MDXI36JJ.js} +7 -7
  24. package/dist/cdn/{BH42V5CR.js → N7VSZ2CS.js} +1 -1
  25. package/dist/cdn/{G3C6IL5Y.js → OAEWZFWV.js} +1 -1
  26. package/dist/cdn/{6VCG2ITQ.js → ON244IGD.js} +1 -1
  27. package/dist/cdn/{6AUKNSKW.js → QD22B6N2.js} +1 -1
  28. package/dist/cdn/{4FRYNYQ6.js → QGDR24DC.js} +1 -1
  29. package/dist/cdn/{WXL7GVUU.js → RBYAQRK6.js} +1 -1
  30. package/dist/cdn/{42GXADY4.js → RUVOSMTB.js} +1 -1
  31. package/dist/cdn/{Y37QLEAM.js → S4VDUHA7.js} +1 -1
  32. package/dist/cdn/TLM7N22U.js +2 -0
  33. package/dist/cdn/{3A2YSBVB.js → TOIBA2KF.js} +1 -1
  34. package/dist/cdn/{DQQTSOMQ.js → UIGRRD7P.js} +1 -1
  35. package/dist/cdn/{FWLPMS4Q.js → VY5TD3VS.js} +1 -1
  36. package/dist/cdn/X65HFYH4.js +2 -0
  37. package/dist/cdn/{4DAGSZIC.js → XK36P3C4.js} +1 -1
  38. package/dist/cdn/{757HAEJS.js → ZCLYSOQM.js} +1 -1
  39. package/dist/cdn/{QDKHYQJB.js → ZOF7AUSS.js} +1 -1
  40. package/dist/cdn/{YFJZN5K5.js → ZVXEOW2X.js} +1 -1
  41. package/dist/cdn/index.js +1 -1
  42. package/dist/chunks/interfaces.js +9 -9
  43. package/dist/chunks/solution-builder-assistant.js +5 -3
  44. package/dist/components/arcgis-solutions-assistant/customElement.js +195 -170
  45. package/dist/components/solution-builder-assistant/index.js +2 -2
  46. package/dist/components/solution-deployed-card-panel/customElement.js +19 -19
  47. package/dist/components/solution-details-panel/customElement.js +98 -72
  48. package/dist/components/solutions-deploy-app/customElement.js +22 -18
  49. package/dist/components/solutions-deploy-app/index.js +2 -0
  50. package/dist/components/solutions-resources-section/customElement.js +4 -4
  51. package/dist/components/solutions-resources-shell/customElement.d.ts +4 -3
  52. package/dist/components/solutions-resources-shell/customElement.js +95 -53
  53. package/dist/docs/api.json +1 -1
  54. package/dist/docs/docs.json +1 -1
  55. package/dist/docs/vscode.html-custom-data.json +1 -1
  56. package/dist/docs/web-types.json +1 -1
  57. package/dist/loader.js +1 -1
  58. package/dist/solutions-components_commit.txt +8 -5
  59. package/dist/types/lumina.d.ts +1 -1
  60. package/dist/types/preact.d.ts +1 -1
  61. package/dist/types/react.d.ts +1 -1
  62. package/dist/types/stencil.d.ts +1 -1
  63. package/package.json +1 -1
  64. package/dist/cdn/4RJURJQ5.js +0 -2
  65. package/dist/cdn/DO7NLLUV.js +0 -2
  66. package/dist/cdn/JMBANG5V.js +0 -2
  67. package/dist/cdn/OANAQ6HY.js +0 -2
  68. package/dist/cdn/RY6KZ77P.js +0 -2
  69. package/dist/cdn/UCQJWFUW.js +0 -2
  70. package/dist/cdn/XEF5G3BC.js +0 -2
@@ -1,5 +1,5 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
2
- import{b as ba,c as $n,d as Cl}from"./QPIMTXPL.js";var EE=ba((lG,kg)=>{"use strict";var B4=Object.prototype.hasOwnProperty,Jt="~";function Gc(){}Object.create&&(Gc.prototype=Object.create(null),new Gc().__proto__||(Jt=!1));function V4(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function $E(e,t,r,i,n){if(typeof r!="function")throw new TypeError("The listener must be a function");var a=new V4(r,i||e,n),o=Jt?Jt+t:t;return e._events[o]?e._events[o].fn?e._events[o]=[e._events[o],a]:e._events[o].push(a):(e._events[o]=a,e._eventsCount++),e}function $d(e,t){--e._eventsCount===0?e._events=new Gc:delete e._events[t]}function Nt(){this._events=new Gc,this._eventsCount=0}Nt.prototype.eventNames=function(){var t=[],r,i;if(this._eventsCount===0)return t;for(i in r=this._events)B4.call(r,i)&&t.push(Jt?i.slice(1):i);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(r)):t};Nt.prototype.listeners=function(t){var r=Jt?Jt+t:t,i=this._events[r];if(!i)return[];if(i.fn)return[i.fn];for(var n=0,a=i.length,o=new Array(a);n<a;n++)o[n]=i[n].fn;return o};Nt.prototype.listenerCount=function(t){var r=Jt?Jt+t:t,i=this._events[r];return i?i.fn?1:i.length:0};Nt.prototype.emit=function(t,r,i,n,a,o){var s=Jt?Jt+t:t;if(!this._events[s])return!1;var c=this._events[s],u=arguments.length,l,d;if(c.fn){switch(c.once&&this.removeListener(t,c.fn,void 0,!0),u){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,r),!0;case 3:return c.fn.call(c.context,r,i),!0;case 4:return c.fn.call(c.context,r,i,n),!0;case 5:return c.fn.call(c.context,r,i,n,a),!0;case 6:return c.fn.call(c.context,r,i,n,a,o),!0}for(d=1,l=new Array(u-1);d<u;d++)l[d-1]=arguments[d];c.fn.apply(c.context,l)}else{var f=c.length,p;for(d=0;d<f;d++)switch(c[d].once&&this.removeListener(t,c[d].fn,void 0,!0),u){case 1:c[d].fn.call(c[d].context);break;case 2:c[d].fn.call(c[d].context,r);break;case 3:c[d].fn.call(c[d].context,r,i);break;case 4:c[d].fn.call(c[d].context,r,i,n);break;default:if(!l)for(p=1,l=new Array(u-1);p<u;p++)l[p-1]=arguments[p];c[d].fn.apply(c[d].context,l)}}return!0};Nt.prototype.on=function(t,r,i){return $E(this,t,r,i,!1)};Nt.prototype.once=function(t,r,i){return $E(this,t,r,i,!0)};Nt.prototype.removeListener=function(t,r,i,n){var a=Jt?Jt+t:t;if(!this._events[a])return this;if(!r)return $d(this,a),this;var o=this._events[a];if(o.fn)o.fn===r&&(!n||o.once)&&(!i||o.context===i)&&$d(this,a);else{for(var s=0,c=[],u=o.length;s<u;s++)(o[s].fn!==r||n&&!o[s].once||i&&o[s].context!==i)&&c.push(o[s]);c.length?this._events[a]=c.length===1?c[0]:c:$d(this,a)}return this};Nt.prototype.removeAllListeners=function(t){var r;return t?(r=Jt?Jt+t:t,this._events[r]&&$d(this,r)):(this._events=new Gc,this._eventsCount=0),this};Nt.prototype.off=Nt.prototype.removeListener;Nt.prototype.addListener=Nt.prototype.on;Nt.prefixed=Jt;Nt.EventEmitter=Nt;typeof kg<"u"&&(kg.exports=Nt)});var TE=ba((dG,IE)=>{"use strict";IE.exports=(e,t)=>(t=t||(()=>{}),e.then(r=>new Promise(i=>{i(t())}).then(()=>r),r=>new Promise(i=>{i(t())}).then(()=>{throw r})))});var CE=ba((fG,Id)=>{"use strict";var Z4=TE(),Ed=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},AE=(e,t,r)=>new Promise((i,n)=>{if(typeof t!="number"||t<0)throw new TypeError("Expected `milliseconds` to be a positive number");if(t===1/0){i(e);return}let a=setTimeout(()=>{if(typeof r=="function"){try{i(r())}catch(c){n(c)}return}let o=typeof r=="string"?r:`Promise timed out after ${t} milliseconds`,s=r instanceof Error?r:new Ed(o);typeof e.cancel=="function"&&e.cancel(),n(s)},t);Z4(e.then(i,n),()=>{clearTimeout(a)})});Id.exports=AE;Id.exports.default=AE;Id.exports.TimeoutError=Ed});var OE=ba($g=>{"use strict";Object.defineProperty($g,"__esModule",{value:!0});function H4(e,t,r){let i=0,n=e.length;for(;n>0;){let a=n/2|0,o=i+a;r(e[o],t)<=0?(i=++o,n-=a+1):n=a}return i}$g.default=H4});var PE=ba(Ig=>{"use strict";Object.defineProperty(Ig,"__esModule",{value:!0});var G4=OE(),Eg=class{constructor(){this._queue=[]}enqueue(t,r){r=Object.assign({priority:0},r);let i={priority:r.priority,run:t};if(this.size&&this._queue[this.size-1].priority>=r.priority){this._queue.push(i);return}let n=G4.default(this._queue,i,(a,o)=>o.priority-a.priority);this._queue.splice(n,0,i)}dequeue(){let t=this._queue.shift();return t?.run}filter(t){return this._queue.filter(r=>r.priority===t.priority).map(r=>r.run)}get size(){return this._queue.length}};Ig.default=Eg});var Ad=ba(Ag=>{"use strict";Object.defineProperty(Ag,"__esModule",{value:!0});var J4=EE(),NE=CE(),K4=PE(),Td=()=>{},W4=new NE.TimeoutError,Tg=class extends J4{constructor(t){var r,i,n,a;if(super(),this._intervalCount=0,this._intervalEnd=0,this._pendingCount=0,this._resolveEmpty=Td,this._resolveIdle=Td,t=Object.assign({carryoverConcurrencyCount:!1,intervalCap:1/0,interval:0,concurrency:1/0,autoStart:!0,queueClass:K4.default},t),!(typeof t.intervalCap=="number"&&t.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${(i=(r=t.intervalCap)===null||r===void 0?void 0:r.toString())!==null&&i!==void 0?i:""}\` (${typeof t.intervalCap})`);if(t.interval===void 0||!(Number.isFinite(t.interval)&&t.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${(a=(n=t.interval)===null||n===void 0?void 0:n.toString())!==null&&a!==void 0?a:""}\` (${typeof t.interval})`);this._carryoverConcurrencyCount=t.carryoverConcurrencyCount,this._isIntervalIgnored=t.intervalCap===1/0||t.interval===0,this._intervalCap=t.intervalCap,this._interval=t.interval,this._queue=new t.queueClass,this._queueClass=t.queueClass,this.concurrency=t.concurrency,this._timeout=t.timeout,this._throwOnTimeout=t.throwOnTimeout===!0,this._isPaused=t.autoStart===!1}get _doesIntervalAllowAnother(){return this._isIntervalIgnored||this._intervalCount<this._intervalCap}get _doesConcurrentAllowAnother(){return this._pendingCount<this._concurrency}_next(){this._pendingCount--,this._tryToStartAnother(),this.emit("next")}_resolvePromises(){this._resolveEmpty(),this._resolveEmpty=Td,this._pendingCount===0&&(this._resolveIdle(),this._resolveIdle=Td,this.emit("idle"))}_onResumeInterval(){this._onInterval(),this._initializeIntervalIfNeeded(),this._timeoutId=void 0}_isIntervalPaused(){let t=Date.now();if(this._intervalId===void 0){let r=this._intervalEnd-t;if(r<0)this._intervalCount=this._carryoverConcurrencyCount?this._pendingCount:0;else return this._timeoutId===void 0&&(this._timeoutId=setTimeout(()=>{this._onResumeInterval()},r)),!0}return!1}_tryToStartAnother(){if(this._queue.size===0)return this._intervalId&&clearInterval(this._intervalId),this._intervalId=void 0,this._resolvePromises(),!1;if(!this._isPaused){let t=!this._isIntervalPaused();if(this._doesIntervalAllowAnother&&this._doesConcurrentAllowAnother){let r=this._queue.dequeue();return r?(this.emit("active"),r(),t&&this._initializeIntervalIfNeeded(),!0):!1}}return!1}_initializeIntervalIfNeeded(){this._isIntervalIgnored||this._intervalId!==void 0||(this._intervalId=setInterval(()=>{this._onInterval()},this._interval),this._intervalEnd=Date.now()+this._interval)}_onInterval(){this._intervalCount===0&&this._pendingCount===0&&this._intervalId&&(clearInterval(this._intervalId),this._intervalId=void 0),this._intervalCount=this._carryoverConcurrencyCount?this._pendingCount:0,this._processQueue()}_processQueue(){for(;this._tryToStartAnother(););}get concurrency(){return this._concurrency}set concurrency(t){if(!(typeof t=="number"&&t>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${t}\` (${typeof t})`);this._concurrency=t,this._processQueue()}async add(t,r={}){return new Promise((i,n)=>{let a=async()=>{this._pendingCount++,this._intervalCount++;try{let o=this._timeout===void 0&&r.timeout===void 0?t():NE.default(Promise.resolve(t()),r.timeout===void 0?this._timeout:r.timeout,()=>{(r.throwOnTimeout===void 0?this._throwOnTimeout:r.throwOnTimeout)&&n(W4)});i(await o)}catch(o){n(o)}this._next()};this._queue.enqueue(a,r),this._tryToStartAnother(),this.emit("add")})}async addAll(t,r){return Promise.all(t.map(async i=>this.add(i,r)))}start(){return this._isPaused?(this._isPaused=!1,this._processQueue(),this):this}pause(){this._isPaused=!0}clear(){this._queue=new this._queueClass}async onEmpty(){if(this._queue.size!==0)return new Promise(t=>{let r=this._resolveEmpty;this._resolveEmpty=()=>{r(),t()}})}async onIdle(){if(!(this._pendingCount===0&&this._queue.size===0))return new Promise(t=>{let r=this._resolveIdle;this._resolveIdle=()=>{r(),t()}})}get size(){return this._queue.size}sizeBy(t){return this._queue.filter(t).length}get pending(){return this._pendingCount}get isPaused(){return this._isPaused}get timeout(){return this._timeout}set timeout(t){this._timeout=t}};Ag.default=Tg});var xO=ba(Cp=>{"use strict";Cp.byteLength=Z6;Cp.toByteArray=G6;Cp.fromByteArray=W6;var Hn=[],Gr=[],V6=typeof Uint8Array<"u"?Uint8Array:Array,Sw="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(xo=0,bO=Sw.length;xo<bO;++xo)Hn[xo]=Sw[xo],Gr[Sw.charCodeAt(xo)]=xo;var xo,bO;Gr[45]=62;Gr[95]=63;function wO(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");r===-1&&(r=t);var i=r===t?0:4-r%4;return[r,i]}function Z6(e){var t=wO(e),r=t[0],i=t[1];return(r+i)*3/4-i}function H6(e,t,r){return(t+r)*3/4-r}function G6(e){var t,r=wO(e),i=r[0],n=r[1],a=new V6(H6(e,i,n)),o=0,s=n>0?i-4:i,c;for(c=0;c<s;c+=4)t=Gr[e.charCodeAt(c)]<<18|Gr[e.charCodeAt(c+1)]<<12|Gr[e.charCodeAt(c+2)]<<6|Gr[e.charCodeAt(c+3)],a[o++]=t>>16&255,a[o++]=t>>8&255,a[o++]=t&255;return n===2&&(t=Gr[e.charCodeAt(c)]<<2|Gr[e.charCodeAt(c+1)]>>4,a[o++]=t&255),n===1&&(t=Gr[e.charCodeAt(c)]<<10|Gr[e.charCodeAt(c+1)]<<4|Gr[e.charCodeAt(c+2)]>>2,a[o++]=t>>8&255,a[o++]=t&255),a}function J6(e){return Hn[e>>18&63]+Hn[e>>12&63]+Hn[e>>6&63]+Hn[e&63]}function K6(e,t,r){for(var i,n=[],a=t;a<r;a+=3)i=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(e[a+2]&255),n.push(J6(i));return n.join("")}function W6(e){for(var t,r=e.length,i=r%3,n=[],a=16383,o=0,s=r-i;o<s;o+=a)n.push(K6(e,o,o+a>s?s:o+a));return i===1?(t=e[r-1],n.push(Hn[t>>2]+Hn[t<<4&63]+"==")):i===2&&(t=(e[r-2]<<8)+e[r-1],n.push(Hn[t>>10]+Hn[t>>4&63]+Hn[t<<2&63]+"=")),n.join("")}});var He="__start__",Ye="__end__",En="__input__";var Mo="__error__",Ol="__pregel_ns_writes",Nr="__pregel_send",jo="__pregel_call",Yr="__pregel_read",Qr="__pregel_checkpointer",zo="__pregel_resuming",$c="__pregel_task_id",Ec="__pregel_stream",bM="__pregel_resume_value",Do="__pregel_resume_map",ar="__pregel_scratchpad",xa="__pregel_previous",wM="__pregel_durability",Pl="checkpoint_id",Rr="checkpoint_ns",wS="__pregel_node_finished",Mr="checkpoint_map",xS="__pregel_abort_signals",Ue="__interrupt__",_r="__resume__",Ic="__no_writes__",Ci="__return__",Sa="__previous__",lt="langsmith:hidden";var mh="__self__",In="__pregel_tasks",jr="__pregel_push",Nl="__pregel_pull",yr="00000000-0000-0000-0000-000000000000",SS=[lt,En,Ue,_r,Mo,Ic,Nr,Yr,Qr,wM,Ec,zo,$c,jo,bM,ar,xa,Mr,Rr,Pl],ph=Symbol.for("langgraph.command"),kS=class{[ph];constructor(e){this[ph]=e}};function Rl(e){let t=e;return t!=null&&typeof t.node=="string"&&t.args!==void 0}var wa=class{lg_name="Send";node;args;constructor(e,t){this.node=e,this.args=kc(t)}toJSON(){return{lg_name:this.lg_name,node:this.node,args:this.args}}};function mt(e){return e instanceof wa}var Ro="__overwrite__",xM=class{lg_name="Overwrite";[Ro];constructor(e){this[Ro]=e}get value(){return this[Ro]}toJSON(){return{[Ro]:this[Ro]}}static isInstance(e){return!e||typeof e!="object"?!1:"__overwrite__"in e||"lg_name"in e&&e.lg_name==="Overwrite"}};function Ml(e){return typeof e=="object"&&e!==null&&"__overwrite__"in e?[!0,e[Ro]]:[!1,void 0]}function $S(e){return Ml(e)[0]}function ka(e){return!e||typeof e!="object"||!("__interrupt__"in e)?!1:Array.isArray(e[Ue])}var ir=class extends kS{lg_name="Command";lc_direct_tool_output=!0;graph;update;resume;goto=[];static PARENT="__parent__";constructor(e){super(e),this.resume=e.resume,this.graph=e.graph,this.update=e.update,e.goto&&(this.goto=Array.isArray(e.goto)?kc(e.goto):[kc(e.goto)])}_updateAsTuples(){return this.update&&typeof this.update=="object"&&!Array.isArray(this.update)?Object.entries(this.update):Array.isArray(this.update)&&this.update.every(e=>Array.isArray(e)&&e.length===2&&typeof e[0]=="string")?this.update:[["__root__",this.update]]}toJSON(){let e;return typeof this.goto=="string"?e=this.goto:mt(this.goto)?e=this.goto.toJSON():e=this.goto?.map(t=>typeof t=="string"?t:t.toJSON()),{lg_name:this.lg_name,update:this.update,resume:this.resume,goto:e}}};function yt(e){return typeof e!="object"||e==null?!1:"lg_name"in e&&e.lg_name==="Command"}function SM(e){let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function kc(e,t=new Map){if(e!=null&&typeof e=="object"){if(t.has(e))return t.get(e);let r;if(Array.isArray(e))r=[],t.set(e,r),e.forEach((i,n)=>{r[n]=kc(i,t)});else if(e instanceof ir||e instanceof wa||!SM(e))r=e,t.set(e,r);else if(yt(e))r=new ir(e),t.set(e,r);else if(Rl(e))r=new wa(e.node,e.args),t.set(e,r);else if("lc_serializable"in e&&e.lc_serializable)r=e,t.set(e,r);else{r={},t.set(e,r);for(let[i,n]of Object.entries(e))r[i]=kc(n,t)}return r}return e}var en=class extends Error{lc_error_code;constructor(e,t){let r=e??"";t?.lc_error_code&&(r=`${r}
2
+ import{b as ba,c as $n,d as Cl}from"./QPIMTXPL.js";var EE=ba((fG,kg)=>{"use strict";var B4=Object.prototype.hasOwnProperty,Jt="~";function Gc(){}Object.create&&(Gc.prototype=Object.create(null),new Gc().__proto__||(Jt=!1));function V4(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function $E(e,t,r,i,n){if(typeof r!="function")throw new TypeError("The listener must be a function");var a=new V4(r,i||e,n),o=Jt?Jt+t:t;return e._events[o]?e._events[o].fn?e._events[o]=[e._events[o],a]:e._events[o].push(a):(e._events[o]=a,e._eventsCount++),e}function $d(e,t){--e._eventsCount===0?e._events=new Gc:delete e._events[t]}function Nt(){this._events=new Gc,this._eventsCount=0}Nt.prototype.eventNames=function(){var t=[],r,i;if(this._eventsCount===0)return t;for(i in r=this._events)B4.call(r,i)&&t.push(Jt?i.slice(1):i);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(r)):t};Nt.prototype.listeners=function(t){var r=Jt?Jt+t:t,i=this._events[r];if(!i)return[];if(i.fn)return[i.fn];for(var n=0,a=i.length,o=new Array(a);n<a;n++)o[n]=i[n].fn;return o};Nt.prototype.listenerCount=function(t){var r=Jt?Jt+t:t,i=this._events[r];return i?i.fn?1:i.length:0};Nt.prototype.emit=function(t,r,i,n,a,o){var s=Jt?Jt+t:t;if(!this._events[s])return!1;var c=this._events[s],u=arguments.length,l,d;if(c.fn){switch(c.once&&this.removeListener(t,c.fn,void 0,!0),u){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,r),!0;case 3:return c.fn.call(c.context,r,i),!0;case 4:return c.fn.call(c.context,r,i,n),!0;case 5:return c.fn.call(c.context,r,i,n,a),!0;case 6:return c.fn.call(c.context,r,i,n,a,o),!0}for(d=1,l=new Array(u-1);d<u;d++)l[d-1]=arguments[d];c.fn.apply(c.context,l)}else{var f=c.length,p;for(d=0;d<f;d++)switch(c[d].once&&this.removeListener(t,c[d].fn,void 0,!0),u){case 1:c[d].fn.call(c[d].context);break;case 2:c[d].fn.call(c[d].context,r);break;case 3:c[d].fn.call(c[d].context,r,i);break;case 4:c[d].fn.call(c[d].context,r,i,n);break;default:if(!l)for(p=1,l=new Array(u-1);p<u;p++)l[p-1]=arguments[p];c[d].fn.apply(c[d].context,l)}}return!0};Nt.prototype.on=function(t,r,i){return $E(this,t,r,i,!1)};Nt.prototype.once=function(t,r,i){return $E(this,t,r,i,!0)};Nt.prototype.removeListener=function(t,r,i,n){var a=Jt?Jt+t:t;if(!this._events[a])return this;if(!r)return $d(this,a),this;var o=this._events[a];if(o.fn)o.fn===r&&(!n||o.once)&&(!i||o.context===i)&&$d(this,a);else{for(var s=0,c=[],u=o.length;s<u;s++)(o[s].fn!==r||n&&!o[s].once||i&&o[s].context!==i)&&c.push(o[s]);c.length?this._events[a]=c.length===1?c[0]:c:$d(this,a)}return this};Nt.prototype.removeAllListeners=function(t){var r;return t?(r=Jt?Jt+t:t,this._events[r]&&$d(this,r)):(this._events=new Gc,this._eventsCount=0),this};Nt.prototype.off=Nt.prototype.removeListener;Nt.prototype.addListener=Nt.prototype.on;Nt.prefixed=Jt;Nt.EventEmitter=Nt;typeof kg<"u"&&(kg.exports=Nt)});var TE=ba((pG,IE)=>{"use strict";IE.exports=(e,t)=>(t=t||(()=>{}),e.then(r=>new Promise(i=>{i(t())}).then(()=>r),r=>new Promise(i=>{i(t())}).then(()=>{throw r})))});var CE=ba((mG,Id)=>{"use strict";var Z4=TE(),Ed=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},AE=(e,t,r)=>new Promise((i,n)=>{if(typeof t!="number"||t<0)throw new TypeError("Expected `milliseconds` to be a positive number");if(t===1/0){i(e);return}let a=setTimeout(()=>{if(typeof r=="function"){try{i(r())}catch(c){n(c)}return}let o=typeof r=="string"?r:`Promise timed out after ${t} milliseconds`,s=r instanceof Error?r:new Ed(o);typeof e.cancel=="function"&&e.cancel(),n(s)},t);Z4(e.then(i,n),()=>{clearTimeout(a)})});Id.exports=AE;Id.exports.default=AE;Id.exports.TimeoutError=Ed});var OE=ba($g=>{"use strict";Object.defineProperty($g,"__esModule",{value:!0});function H4(e,t,r){let i=0,n=e.length;for(;n>0;){let a=n/2|0,o=i+a;r(e[o],t)<=0?(i=++o,n-=a+1):n=a}return i}$g.default=H4});var PE=ba(Ig=>{"use strict";Object.defineProperty(Ig,"__esModule",{value:!0});var G4=OE(),Eg=class{constructor(){this._queue=[]}enqueue(t,r){r=Object.assign({priority:0},r);let i={priority:r.priority,run:t};if(this.size&&this._queue[this.size-1].priority>=r.priority){this._queue.push(i);return}let n=G4.default(this._queue,i,(a,o)=>o.priority-a.priority);this._queue.splice(n,0,i)}dequeue(){let t=this._queue.shift();return t?.run}filter(t){return this._queue.filter(r=>r.priority===t.priority).map(r=>r.run)}get size(){return this._queue.length}};Ig.default=Eg});var Ad=ba(Ag=>{"use strict";Object.defineProperty(Ag,"__esModule",{value:!0});var J4=EE(),NE=CE(),K4=PE(),Td=()=>{},W4=new NE.TimeoutError,Tg=class extends J4{constructor(t){var r,i,n,a;if(super(),this._intervalCount=0,this._intervalEnd=0,this._pendingCount=0,this._resolveEmpty=Td,this._resolveIdle=Td,t=Object.assign({carryoverConcurrencyCount:!1,intervalCap:1/0,interval:0,concurrency:1/0,autoStart:!0,queueClass:K4.default},t),!(typeof t.intervalCap=="number"&&t.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${(i=(r=t.intervalCap)===null||r===void 0?void 0:r.toString())!==null&&i!==void 0?i:""}\` (${typeof t.intervalCap})`);if(t.interval===void 0||!(Number.isFinite(t.interval)&&t.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${(a=(n=t.interval)===null||n===void 0?void 0:n.toString())!==null&&a!==void 0?a:""}\` (${typeof t.interval})`);this._carryoverConcurrencyCount=t.carryoverConcurrencyCount,this._isIntervalIgnored=t.intervalCap===1/0||t.interval===0,this._intervalCap=t.intervalCap,this._interval=t.interval,this._queue=new t.queueClass,this._queueClass=t.queueClass,this.concurrency=t.concurrency,this._timeout=t.timeout,this._throwOnTimeout=t.throwOnTimeout===!0,this._isPaused=t.autoStart===!1}get _doesIntervalAllowAnother(){return this._isIntervalIgnored||this._intervalCount<this._intervalCap}get _doesConcurrentAllowAnother(){return this._pendingCount<this._concurrency}_next(){this._pendingCount--,this._tryToStartAnother(),this.emit("next")}_resolvePromises(){this._resolveEmpty(),this._resolveEmpty=Td,this._pendingCount===0&&(this._resolveIdle(),this._resolveIdle=Td,this.emit("idle"))}_onResumeInterval(){this._onInterval(),this._initializeIntervalIfNeeded(),this._timeoutId=void 0}_isIntervalPaused(){let t=Date.now();if(this._intervalId===void 0){let r=this._intervalEnd-t;if(r<0)this._intervalCount=this._carryoverConcurrencyCount?this._pendingCount:0;else return this._timeoutId===void 0&&(this._timeoutId=setTimeout(()=>{this._onResumeInterval()},r)),!0}return!1}_tryToStartAnother(){if(this._queue.size===0)return this._intervalId&&clearInterval(this._intervalId),this._intervalId=void 0,this._resolvePromises(),!1;if(!this._isPaused){let t=!this._isIntervalPaused();if(this._doesIntervalAllowAnother&&this._doesConcurrentAllowAnother){let r=this._queue.dequeue();return r?(this.emit("active"),r(),t&&this._initializeIntervalIfNeeded(),!0):!1}}return!1}_initializeIntervalIfNeeded(){this._isIntervalIgnored||this._intervalId!==void 0||(this._intervalId=setInterval(()=>{this._onInterval()},this._interval),this._intervalEnd=Date.now()+this._interval)}_onInterval(){this._intervalCount===0&&this._pendingCount===0&&this._intervalId&&(clearInterval(this._intervalId),this._intervalId=void 0),this._intervalCount=this._carryoverConcurrencyCount?this._pendingCount:0,this._processQueue()}_processQueue(){for(;this._tryToStartAnother(););}get concurrency(){return this._concurrency}set concurrency(t){if(!(typeof t=="number"&&t>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${t}\` (${typeof t})`);this._concurrency=t,this._processQueue()}async add(t,r={}){return new Promise((i,n)=>{let a=async()=>{this._pendingCount++,this._intervalCount++;try{let o=this._timeout===void 0&&r.timeout===void 0?t():NE.default(Promise.resolve(t()),r.timeout===void 0?this._timeout:r.timeout,()=>{(r.throwOnTimeout===void 0?this._throwOnTimeout:r.throwOnTimeout)&&n(W4)});i(await o)}catch(o){n(o)}this._next()};this._queue.enqueue(a,r),this._tryToStartAnother(),this.emit("add")})}async addAll(t,r){return Promise.all(t.map(async i=>this.add(i,r)))}start(){return this._isPaused?(this._isPaused=!1,this._processQueue(),this):this}pause(){this._isPaused=!0}clear(){this._queue=new this._queueClass}async onEmpty(){if(this._queue.size!==0)return new Promise(t=>{let r=this._resolveEmpty;this._resolveEmpty=()=>{r(),t()}})}async onIdle(){if(!(this._pendingCount===0&&this._queue.size===0))return new Promise(t=>{let r=this._resolveIdle;this._resolveIdle=()=>{r(),t()}})}get size(){return this._queue.size}sizeBy(t){return this._queue.filter(t).length}get pending(){return this._pendingCount}get isPaused(){return this._isPaused}get timeout(){return this._timeout}set timeout(t){this._timeout=t}};Ag.default=Tg});var xO=ba(Cp=>{"use strict";Cp.byteLength=Z6;Cp.toByteArray=G6;Cp.fromByteArray=W6;var Hn=[],Gr=[],V6=typeof Uint8Array<"u"?Uint8Array:Array,Sw="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(xo=0,bO=Sw.length;xo<bO;++xo)Hn[xo]=Sw[xo],Gr[Sw.charCodeAt(xo)]=xo;var xo,bO;Gr[45]=62;Gr[95]=63;function wO(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");r===-1&&(r=t);var i=r===t?0:4-r%4;return[r,i]}function Z6(e){var t=wO(e),r=t[0],i=t[1];return(r+i)*3/4-i}function H6(e,t,r){return(t+r)*3/4-r}function G6(e){var t,r=wO(e),i=r[0],n=r[1],a=new V6(H6(e,i,n)),o=0,s=n>0?i-4:i,c;for(c=0;c<s;c+=4)t=Gr[e.charCodeAt(c)]<<18|Gr[e.charCodeAt(c+1)]<<12|Gr[e.charCodeAt(c+2)]<<6|Gr[e.charCodeAt(c+3)],a[o++]=t>>16&255,a[o++]=t>>8&255,a[o++]=t&255;return n===2&&(t=Gr[e.charCodeAt(c)]<<2|Gr[e.charCodeAt(c+1)]>>4,a[o++]=t&255),n===1&&(t=Gr[e.charCodeAt(c)]<<10|Gr[e.charCodeAt(c+1)]<<4|Gr[e.charCodeAt(c+2)]>>2,a[o++]=t>>8&255,a[o++]=t&255),a}function J6(e){return Hn[e>>18&63]+Hn[e>>12&63]+Hn[e>>6&63]+Hn[e&63]}function K6(e,t,r){for(var i,n=[],a=t;a<r;a+=3)i=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(e[a+2]&255),n.push(J6(i));return n.join("")}function W6(e){for(var t,r=e.length,i=r%3,n=[],a=16383,o=0,s=r-i;o<s;o+=a)n.push(K6(e,o,o+a>s?s:o+a));return i===1?(t=e[r-1],n.push(Hn[t>>2]+Hn[t<<4&63]+"==")):i===2&&(t=(e[r-2]<<8)+e[r-1],n.push(Hn[t>>10]+Hn[t>>4&63]+Hn[t<<2&63]+"=")),n.join("")}});var He="__start__",Ye="__end__",En="__input__";var Mo="__error__",Ol="__pregel_ns_writes",Nr="__pregel_send",jo="__pregel_call",Yr="__pregel_read",Qr="__pregel_checkpointer",zo="__pregel_resuming",$c="__pregel_task_id",Ec="__pregel_stream",bM="__pregel_resume_value",Do="__pregel_resume_map",ar="__pregel_scratchpad",xa="__pregel_previous",wM="__pregel_durability",Pl="checkpoint_id",Rr="checkpoint_ns",wS="__pregel_node_finished",Mr="checkpoint_map",xS="__pregel_abort_signals",Ue="__interrupt__",_r="__resume__",Ic="__no_writes__",Ci="__return__",Sa="__previous__",lt="langsmith:hidden";var mh="__self__",In="__pregel_tasks",jr="__pregel_push",Nl="__pregel_pull",yr="00000000-0000-0000-0000-000000000000",SS=[lt,En,Ue,_r,Mo,Ic,Nr,Yr,Qr,wM,Ec,zo,$c,jo,bM,ar,xa,Mr,Rr,Pl],ph=Symbol.for("langgraph.command"),kS=class{[ph];constructor(e){this[ph]=e}};function Rl(e){let t=e;return t!=null&&typeof t.node=="string"&&t.args!==void 0}var wa=class{lg_name="Send";node;args;constructor(e,t){this.node=e,this.args=kc(t)}toJSON(){return{lg_name:this.lg_name,node:this.node,args:this.args}}};function mt(e){return e instanceof wa}var Ro="__overwrite__",xM=class{lg_name="Overwrite";[Ro];constructor(e){this[Ro]=e}get value(){return this[Ro]}toJSON(){return{[Ro]:this[Ro]}}static isInstance(e){return!e||typeof e!="object"?!1:"__overwrite__"in e||"lg_name"in e&&e.lg_name==="Overwrite"}};function Ml(e){return typeof e=="object"&&e!==null&&"__overwrite__"in e?[!0,e[Ro]]:[!1,void 0]}function $S(e){return Ml(e)[0]}function ka(e){return!e||typeof e!="object"||!("__interrupt__"in e)?!1:Array.isArray(e[Ue])}var ir=class extends kS{lg_name="Command";lc_direct_tool_output=!0;graph;update;resume;goto=[];static PARENT="__parent__";constructor(e){super(e),this.resume=e.resume,this.graph=e.graph,this.update=e.update,e.goto&&(this.goto=Array.isArray(e.goto)?kc(e.goto):[kc(e.goto)])}_updateAsTuples(){return this.update&&typeof this.update=="object"&&!Array.isArray(this.update)?Object.entries(this.update):Array.isArray(this.update)&&this.update.every(e=>Array.isArray(e)&&e.length===2&&typeof e[0]=="string")?this.update:[["__root__",this.update]]}toJSON(){let e;return typeof this.goto=="string"?e=this.goto:mt(this.goto)?e=this.goto.toJSON():e=this.goto?.map(t=>typeof t=="string"?t:t.toJSON()),{lg_name:this.lg_name,update:this.update,resume:this.resume,goto:e}}};function yt(e){return typeof e!="object"||e==null?!1:"lg_name"in e&&e.lg_name==="Command"}function SM(e){let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function kc(e,t=new Map){if(e!=null&&typeof e=="object"){if(t.has(e))return t.get(e);let r;if(Array.isArray(e))r=[],t.set(e,r),e.forEach((i,n)=>{r[n]=kc(i,t)});else if(e instanceof ir||e instanceof wa||!SM(e))r=e,t.set(e,r);else if(yt(e))r=new ir(e),t.set(e,r);else if(Rl(e))r=new wa(e.node,e.args),t.set(e,r);else if("lc_serializable"in e&&e.lc_serializable)r=e,t.set(e,r);else{r={},t.set(e,r);for(let[i,n]of Object.entries(e))r[i]=kc(n,t)}return r}return e}var en=class extends Error{lc_error_code;constructor(e,t){let r=e??"";t?.lc_error_code&&(r=`${r}
3
3
 
4
4
  Troubleshooting URL: https://docs.langchain.com/oss/javascript/langgraph/${t.lc_error_code}/
5
5
  `),super(r),this.lc_error_code=t?.lc_error_code}},hh=class extends en{get is_bubble_up(){return!0}},gh=class extends en{constructor(e,t){super(e,t),this.name="GraphRecursionError"}static get unminifiable_name(){return"GraphRecursionError"}},$a=class extends en{constructor(e,t){super(e,t),this.name="GraphValueError"}static get unminifiable_name(){return"GraphValueError"}},ti=class extends hh{interrupts;constructor(e,t){super(JSON.stringify(e,null,2),t),this.name="GraphInterrupt",this.interrupts=e??[]}static get unminifiable_name(){return"GraphInterrupt"}},jl=class extends ti{constructor(e,t){super([{value:e}],t),this.name="NodeInterrupt"}static get unminifiable_name(){return"NodeInterrupt"}},zl=class extends hh{command;constructor(e){super(),this.name="ParentCommand",this.command=e}static get unminifiable_name(){return"ParentCommand"}};function _h(e){return e!==void 0&&e.name===zl.unminifiable_name}function Ea(e){return e!==void 0&&e.is_bubble_up===!0}function ri(e){return e!==void 0&&[ti.unminifiable_name,jl.unminifiable_name].includes(e.name)}var Dl=class extends en{constructor(e,t){super(e,t),this.name="EmptyInputError"}static get unminifiable_name(){return"EmptyInputError"}},Ne=class extends en{constructor(e,t){super(e,t),this.name="EmptyChannelError"}static get unminifiable_name(){return"EmptyChannelError"}},be=class extends en{constructor(e,t){super(e,t),this.name="InvalidUpdateError"}static get unminifiable_name(){return"InvalidUpdateError"}},kM=class extends en{constructor(e,t){super(e,t),this.name="MultipleSubgraphError"}static get unminifiable_name(){return"MultipleSubgraphError"}},yh=class extends en{constructor(e,t){super(e,t),this.name="UnreachableNodeError"}static get unminifiable_name(){return"UnreachableNodeError"}},$M=class extends en{constructor(e,t){super(e,t),this.name="RemoteException"}static get unminifiable_name(){return"RemoteException"}},Tc=class extends en{constructor(e,t){super(e,t),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"}},EM=()=>(globalThis[Symbol.for("LG_CHECKPOINT_SEEN_NS_SET")]===void 0&&(globalThis[Symbol.for("LG_CHECKPOINT_SEEN_NS_SET")]=new Set),globalThis[Symbol.for("LG_CHECKPOINT_SEEN_NS_SET")]);var ES=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;function IM(e){return typeof e=="string"&&ES.test(e)}var Uo=IM;function TM(e){if(!Uo(e))throw TypeError("Invalid UUID");let t;return Uint8Array.of((t=parseInt(e.slice(0,8),16))>>>24,t>>>16&255,t>>>8&255,t&255,(t=parseInt(e.slice(9,13),16))>>>8,t&255,(t=parseInt(e.slice(14,18),16))>>>8,t&255,(t=parseInt(e.slice(19,23),16))>>>8,t&255,(t=parseInt(e.slice(24,36),16))/1099511627776&255,t/4294967296&255,t>>>24&255,t>>>16&255,t>>>8&255,t&255)}var Ac=TM;var $t=[];for(let e=0;e<256;++e)$t.push((e+256).toString(16).slice(1));function Tn(e,t=0){return($t[e[t+0]]+$t[e[t+1]]+$t[e[t+2]]+$t[e[t+3]]+"-"+$t[e[t+4]]+$t[e[t+5]]+"-"+$t[e[t+6]]+$t[e[t+7]]+"-"+$t[e[t+8]]+$t[e[t+9]]+"-"+$t[e[t+10]]+$t[e[t+11]]+$t[e[t+12]]+$t[e[t+13]]+$t[e[t+14]]+$t[e[t+15]]).toLowerCase()}var AM=new Uint8Array(16);function Lo(){return crypto.getRandomValues(AM)}var Cc={};function CM(e,t,r){let i,n=e?._v6??!1;if(e){let a=Object.keys(e);a.length===1&&a[0]==="_v6"&&(e=void 0)}if(e)i=IS(e.random??e.rng?.()??Lo(),e.msecs,e.nsecs,e.clockseq,e.node,t,r);else{let a=Date.now(),o=Lo();OM(Cc,a,o),i=IS(o,Cc.msecs,Cc.nsecs,n?void 0:Cc.clockseq,n?void 0:Cc.node,t,r)}return t??Tn(i)}function OM(e,t,r){return e.msecs??=-1/0,e.nsecs??=0,t===e.msecs?(e.nsecs++,e.nsecs>=1e4&&(e.node=void 0,e.nsecs=0)):t>e.msecs?e.nsecs=0:t<e.msecs&&(e.node=void 0),e.node||(e.node=r.slice(10,16),e.node[0]|=1,e.clockseq=(r[8]<<8|r[9])&16383),e.msecs=t,e}function IS(e,t,r,i,n,a,o=0){if(e.length<16)throw new Error("Random bytes length must be >= 16");if(!a)a=new Uint8Array(16),o=0;else if(o<0||o+16>a.length)throw new RangeError(`UUID byte range ${o}:${o+15} is out of buffer bounds`);t??=Date.now(),r??=0,i??=(e[8]<<8|e[9])&16383,n??=e.slice(10,16),t+=122192928e5;let s=((t&268435455)*1e4+r)%4294967296;a[o++]=s>>>24&255,a[o++]=s>>>16&255,a[o++]=s>>>8&255,a[o++]=s&255;let c=t/4294967296*1e4&268435455;a[o++]=c>>>8&255,a[o++]=c&255,a[o++]=c>>>24&15|16,a[o++]=c>>>16&255,a[o++]=i>>>8|128,a[o++]=i&255;for(let u=0;u<6;++u)a[o++]=n[u];return a}var TS=CM;function vh(e){let t=typeof e=="string"?Ac(e):e,r=PM(t);return typeof e=="string"?Tn(r):r}function PM(e){return Uint8Array.of((e[6]&15)<<4|e[7]>>4&15,(e[7]&15)<<4|(e[4]&240)>>4,(e[4]&15)<<4|(e[5]&240)>>4,(e[5]&15)<<4|(e[0]&240)>>4,(e[0]&15)<<4|(e[1]&240)>>4,(e[1]&15)<<4|(e[2]&240)>>4,96|e[2]&15,e[3],e[8],e[9],e[10],e[11],e[12],e[13],e[14],e[15])}function NM(e){e=unescape(encodeURIComponent(e));let t=new Uint8Array(e.length);for(let r=0;r<e.length;++r)t[r]=e.charCodeAt(r);return t}var AS="6ba7b810-9dad-11d1-80b4-00c04fd430c8",CS="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function bh(e,t,r,i,n,a){let o=typeof r=="string"?NM(r):r,s=typeof i=="string"?Ac(i):i;if(typeof i=="string"&&(i=Ac(i)),i?.length!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let c=new Uint8Array(16+o.length);if(c.set(s),c.set(o,s.length),c=t(c),c[6]=c[6]&15|e,c[8]=c[8]&63|128,n){if(a??=0,a<0||a+16>n.length)throw new RangeError(`UUID byte range ${a}:${a+15} is out of buffer bounds`);for(let u=0;u<16;++u)n[a+u]=c[u];return n}return Tn(c)}function RM(e,t,r){return!t&&!e&&crypto.randomUUID?crypto.randomUUID():MM(e,t,r)}function MM(e,t,r){e=e||{};let i=e.random??e.rng?.()??Lo();if(i.length<16)throw new Error("Random bytes length must be >= 16");if(i[6]=i[6]&15|64,i[8]=i[8]&63|128,t){if(r=r||0,r<0||r+16>t.length)throw new RangeError(`UUID byte range ${r}:${r+15} is out of buffer bounds`);for(let n=0;n<16;++n)t[r+n]=i[n];return t}return Tn(i)}var Ul=RM;function jM(e,t,r,i){switch(e){case 0:return t&r^~t&i;case 1:return t^r^i;case 2:return t&r^t&i^r&i;case 3:return t^r^i}}function wh(e,t){return e<<t|e>>>32-t}function zM(e){let t=[1518500249,1859775393,2400959708,3395469782],r=[1732584193,4023233417,2562383102,271733878,3285377520],i=new Uint8Array(e.length+1);i.set(e),i[e.length]=128,e=i;let n=e.length/4+2,a=Math.ceil(n/16),o=new Array(a);for(let s=0;s<a;++s){let c=new Uint32Array(16);for(let u=0;u<16;++u)c[u]=e[s*64+u*4]<<24|e[s*64+u*4+1]<<16|e[s*64+u*4+2]<<8|e[s*64+u*4+3];o[s]=c}o[a-1][14]=(e.length-1)*8/2**32,o[a-1][14]=Math.floor(o[a-1][14]),o[a-1][15]=(e.length-1)*8&4294967295;for(let s=0;s<a;++s){let c=new Uint32Array(80);for(let m=0;m<16;++m)c[m]=o[s][m];for(let m=16;m<80;++m)c[m]=wh(c[m-3]^c[m-8]^c[m-14]^c[m-16],1);let u=r[0],l=r[1],d=r[2],f=r[3],p=r[4];for(let m=0;m<80;++m){let g=Math.floor(m/20),v=wh(u,5)+jM(g,l,d,f)+p+t[g]+c[m]>>>0;p=f,f=d,d=wh(l,30)>>>0,l=u,u=v}r[0]=r[0]+u>>>0,r[1]=r[1]+l>>>0,r[2]=r[2]+d>>>0,r[3]=r[3]+f>>>0,r[4]=r[4]+p>>>0}return Uint8Array.of(r[0]>>24,r[0]>>16,r[0]>>8,r[0],r[1]>>24,r[1]>>16,r[1]>>8,r[1],r[2]>>24,r[2]>>16,r[2]>>8,r[2],r[3]>>24,r[3]>>16,r[3]>>8,r[3],r[4]>>24,r[4]>>16,r[4]>>8,r[4])}var OS=zM;function xh(e,t,r,i){return bh(80,OS,e,t,r,i)}xh.DNS=AS;xh.URL=CS;var Sh=xh;function DM(e,t,r){e??={},r??=0;let i=TS({...e,_v6:!0},new Uint8Array(16));if(i=vh(i),t){if(r<0||r+16>t.length)throw new RangeError(`UUID byte range ${r}:${r+15} is out of buffer bounds`);for(let n=0;n<16;n++)t[r+n]=i[n];return t}return Tn(i)}var kh=DM;var $h=0,Oc=0;function Pc(e){let t=Date.now();return t<=$h?(Oc+=1,Oc>=1e4&&(Oc=0,t=$h+1)):Oc=0,$h=t,kh({clockseq:e,msecs:t,nsecs:Oc})}function ni(e,t){let r=t.replace(/-/g,"").match(/.{2}/g).map(i=>parseInt(i,16));return Sh(e,new Uint8Array(r))}var Nc="__pregel_tasks",Eh="__error__",Ia="__scheduled__",Ih="__interrupt__",Th="__resume__";var PS="[...]",UM="[Circular]",Ll=[],Fo=[];function LM(){return{depthLimit:Number.MAX_SAFE_INTEGER,edgesLimit:Number.MAX_SAFE_INTEGER}}function NS(e,t,r,i){typeof i>"u"&&(i=LM()),Ch(e,"",0,[],void 0,0,i);var n;try{Fo.length===0?n=JSON.stringify(e,t,r):n=JSON.stringify(e,FM(t),r)}catch{return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]")}finally{for(;Ll.length!==0;){var a=Ll.pop();a.length===4?Object.defineProperty(a[0],a[1],a[3]):a[0][a[1]]=a[2]}}return n}function Ah(e,t,r,i){var n=Object.getOwnPropertyDescriptor(i,r);n.get!==void 0?n.configurable?(Object.defineProperty(i,r,{value:e}),Ll.push([i,r,t,n])):Fo.push([t,r,e]):(i[r]=e,Ll.push([i,r,t]))}function Ch(e,t,r,i,n,a,o){a+=1;var s;if(typeof e=="object"&&e!==null){for(s=0;s<i.length;s++)if(i[s]===e){Ah(UM,e,t,n);return}if(typeof o.depthLimit<"u"&&a>o.depthLimit){Ah(PS,e,t,n);return}if(typeof o.edgesLimit<"u"&&r+1>o.edgesLimit){Ah(PS,e,t,n);return}if(i.push(e),Array.isArray(e))for(s=0;s<e.length;s++)Ch(e[s],s,s,i,e,a,o);else{var c=Object.keys(e);for(s=0;s<c.length;s++){var u=c[s];Ch(e[u],u,s,i,e,a,o)}}i.pop()}}function FM(e){return e=typeof e<"u"?e:function(t,r){return r},function(t,r){if(Fo.length>0)for(var i=0;i<Fo.length;i++){var n=Fo[i];if(n[1]===t&&n[0]===r){r=n[2],Fo.splice(i,1);break}}return e.call(this,t,r)}}var BM=/([A-Z]+)([A-Z][a-z0-9]+)/g,VM=/([a-z0-9])([A-Z])/g,RS=/[-_\s]+/g;function ZM(e){return e.replace(BM,"$1_$2").replace(VM,"$1_$2").replace(RS,"_").toLowerCase()}function HM(e){let t=e.trim();return/[-_\s]/.test(t)?t.replace(RS,"_").toLowerCase().replace(/_+([a-z0-9])/g,(r,i)=>i.toUpperCase()):t}function MS(e,t){return t?.[e]||ZM(e)}function jS(e,t){return t?.[e]||HM(e)}function Fl(e,t,r){let i={};for(let n in e)Object.hasOwn(e,n)&&(i[t(n,r)]=e[n]);return i}var zS="__lc_escaped__";function GM(e){return"lc"in e||Object.keys(e).length===1&&"__lc_escaped__"in e}function JM(e){return{[zS]:e}}function Oh(e){return Object.keys(e).length===1&&"__lc_escaped__"in e}function KM(e){return e!==null&&typeof e=="object"&&"lc_serializable"in e&&typeof e.toJSON=="function"}function WM(e){let t;return e!==null&&typeof e=="object"?"lc_id"in e&&Array.isArray(e.lc_id)?t=e.lc_id:t=[e.constructor?.name??"Object"]:t=[typeof e],{lc:1,type:"not_implemented",id:t}}function Bl(e,t=new WeakSet){if(e!==null&&typeof e=="object"&&!Array.isArray(e)){if(t.has(e))return WM(e);if(KM(e))return e;t.add(e);let r=e;if(GM(r))return t.delete(e),JM(r);let i={};for(let[n,a]of Object.entries(r))i[n]=Bl(a,t);return t.delete(e),i}return Array.isArray(e)?e.map(r=>Bl(r,t)):e}function Vl(e){if(e!==null&&typeof e=="object"&&!Array.isArray(e)){let t=e;if(Oh(t))return t[zS];let r={};for(let[i,n]of Object.entries(t))r[i]=Vl(n);return r}return Array.isArray(e)?e.map(t=>Vl(t)):e}var DS=Object.defineProperty,T=(e,t)=>{let r={};for(var i in e)DS(r,i,{get:e[i],enumerable:!0});return t||DS(r,Symbol.toStringTag,{value:"Module"}),r};var LS=T({Serializable:()=>ut,get_lc_unique_name:()=>Bo});function US(e){return Array.isArray(e)?[...e]:{...e}}function qM(e,t){let r=US(e);for(let[i,n]of Object.entries(t)){let[a,...o]=i.split(".").reverse(),s=r;for(let c of o.reverse()){if(s[c]===void 0)break;s[c]=US(s[c]),s=s[c]}s[a]!==void 0&&(s[a]={lc:1,type:"secret",id:[n]})}return r}function Bo(e){let t=Object.getPrototypeOf(e);return typeof e.lc_name=="function"&&(typeof t.lc_name!="function"||e.lc_name()!==t.lc_name())?e.lc_name():e.name}var ut=class FS{lc_serializable=!1;lc_kwargs;static lc_name(){return this.name}get lc_id(){return[...this.lc_namespace,Bo(this.constructor)]}get lc_secrets(){}get lc_attributes(){}get lc_aliases(){}get lc_serializable_keys(){}constructor(t,...r){this.lc_serializable_keys!==void 0?this.lc_kwargs=Object.fromEntries(Object.entries(t||{}).filter(([i])=>this.lc_serializable_keys?.includes(i))):this.lc_kwargs=t??{}}toJSON(){if(!this.lc_serializable)return this.toJSONNotImplemented();if(this.lc_kwargs instanceof FS||typeof this.lc_kwargs!="object"||Array.isArray(this.lc_kwargs))return this.toJSONNotImplemented();let t={},r={},i=Object.keys(this.lc_kwargs).reduce((s,c)=>(s[c]=c in this?this[c]:this.lc_kwargs[c],s),{});for(let s=Object.getPrototypeOf(this);s;s=Object.getPrototypeOf(s))Object.assign(t,Reflect.get(s,"lc_aliases",this)),Object.assign(r,Reflect.get(s,"lc_secrets",this)),Object.assign(i,Reflect.get(s,"lc_attributes",this));Object.keys(r).forEach(s=>{let c=this,u=i,[l,...d]=s.split(".").reverse();for(let f of d.reverse()){if(!(f in c)||c[f]===void 0)return;(!(f in u)||u[f]===void 0)&&(typeof c[f]=="object"&&c[f]!=null?u[f]={}:Array.isArray(c[f])&&(u[f]=[])),c=c[f],u=u[f]}l in c&&c[l]!==void 0&&(u[l]=u[l]||c[l])});let n={},a=new WeakSet;a.add(this);for(let[s,c]of Object.entries(i))n[s]=Bl(c,a);let o=Fl(Object.keys(r).length?qM(n,r):n,MS,t);return{lc:1,type:"constructor",id:this.lc_id,kwargs:o}}toJSONNotImplemented(){return{lc:1,type:"not_implemented",id:this.lc_id}}};var BS=T({getEnv:()=>JS,getEnvironmentVariable:()=>Ht,getRuntimeEnvironment:()=>Nh,isBrowser:()=>VS,isDeno:()=>Zl,isJsDom:()=>HS,isNode:()=>GS,isWebWorker:()=>ZS}),VS=()=>typeof window<"u"&&typeof window.document<"u",ZS=()=>typeof globalThis=="object"&&globalThis.constructor&&globalThis.constructor.name==="DedicatedWorkerGlobalScope",HS=()=>typeof window<"u"&&window.name==="nodejs"||typeof navigator<"u"&&navigator.userAgent.includes("jsdom"),Zl=()=>typeof Deno<"u",GS=()=>typeof process<"u"&&typeof process.versions<"u"&&typeof process.versions.node<"u"&&!Zl(),JS=()=>{let e;return VS()?e="browser":GS()?e="node":ZS()?e="webworker":HS()?e="jsdom":Zl()?e="deno":e="other",e},Ph;function Nh(){return Ph===void 0&&(Ph={library:"langchain-js",runtime:JS()}),Ph}function Ht(e){try{return typeof process<"u"?process.env?.[e]:Zl()?Deno?.env.get(e):void 0}catch{return}}var KS=[];var WS=T({});var qS=T({});var te="0123456789abcdef".split(""),XM=[-2147483648,8388608,32768,128],tn=[24,16,8,0],Hl=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],vt=[];function rn(e,t){t?(vt[0]=vt[16]=vt[1]=vt[2]=vt[3]=vt[4]=vt[5]=vt[6]=vt[7]=vt[8]=vt[9]=vt[10]=vt[11]=vt[12]=vt[13]=vt[14]=vt[15]=0,this.blocks=vt):this.blocks=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],e?(this.h0=3238371032,this.h1=914150663,this.h2=812702999,this.h3=4144912697,this.h4=4290775857,this.h5=1750603025,this.h6=1694076839,this.h7=3204075428):(this.h0=1779033703,this.h1=3144134277,this.h2=1013904242,this.h3=2773480762,this.h4=1359893119,this.h5=2600822924,this.h6=528734635,this.h7=1541459225),this.block=this.start=this.bytes=this.hBytes=0,this.finalized=this.hashed=!1,this.first=!0,this.is224=e}rn.prototype.update=function(e){if(!this.finalized){var t,r=typeof e;if(r!=="string"){if(r==="object"){if(e===null)throw new Error(ERROR);if(ARRAY_BUFFER&&e.constructor===ArrayBuffer)e=new Uint8Array(e);else if(!Array.isArray(e)&&(!ARRAY_BUFFER||!ArrayBuffer.isView(e)))throw new Error(ERROR)}else throw new Error(ERROR);t=!0}for(var i,n=0,a,o=e.length,s=this.blocks;n<o;){if(this.hashed&&(this.hashed=!1,s[0]=this.block,this.block=s[16]=s[1]=s[2]=s[3]=s[4]=s[5]=s[6]=s[7]=s[8]=s[9]=s[10]=s[11]=s[12]=s[13]=s[14]=s[15]=0),t)for(a=this.start;n<o&&a<64;++n)s[a>>>2]|=e[n]<<tn[a++&3];else for(a=this.start;n<o&&a<64;++n)i=e.charCodeAt(n),i<128?s[a>>>2]|=i<<tn[a++&3]:i<2048?(s[a>>>2]|=(192|i>>>6)<<tn[a++&3],s[a>>>2]|=(128|i&63)<<tn[a++&3]):i<55296||i>=57344?(s[a>>>2]|=(224|i>>>12)<<tn[a++&3],s[a>>>2]|=(128|i>>>6&63)<<tn[a++&3],s[a>>>2]|=(128|i&63)<<tn[a++&3]):(i=65536+((i&1023)<<10|e.charCodeAt(++n)&1023),s[a>>>2]|=(240|i>>>18)<<tn[a++&3],s[a>>>2]|=(128|i>>>12&63)<<tn[a++&3],s[a>>>2]|=(128|i>>>6&63)<<tn[a++&3],s[a>>>2]|=(128|i&63)<<tn[a++&3]);this.lastByteIndex=a,this.bytes+=a-this.start,a>=64?(this.block=s[16],this.start=a-64,this.hash(),this.hashed=!0):this.start=a}return this.bytes>4294967295&&(this.hBytes+=this.bytes/4294967296<<0,this.bytes=this.bytes%4294967296),this}};rn.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var e=this.blocks,t=this.lastByteIndex;e[16]=this.block,e[t>>>2]|=XM[t&3],this.block=e[16],t>=56&&(this.hashed||this.hash(),e[0]=this.block,e[16]=e[1]=e[2]=e[3]=e[4]=e[5]=e[6]=e[7]=e[8]=e[9]=e[10]=e[11]=e[12]=e[13]=e[14]=e[15]=0),e[14]=this.hBytes<<3|this.bytes>>>29,e[15]=this.bytes<<3,this.hash()}};rn.prototype.hash=function(){var e=this.h0,t=this.h1,r=this.h2,i=this.h3,n=this.h4,a=this.h5,o=this.h6,s=this.h7,c=this.blocks,u,l,d,f,p,m,g,v,b,w,S;for(u=16;u<64;++u)p=c[u-15],l=(p>>>7|p<<25)^(p>>>18|p<<14)^p>>>3,p=c[u-2],d=(p>>>17|p<<15)^(p>>>19|p<<13)^p>>>10,c[u]=c[u-16]+l+c[u-7]+d<<0;for(S=t&r,u=0;u<64;u+=4)this.first?(this.is224?(v=300032,p=c[0]-1413257819,s=p-150054599<<0,i=p+24177077<<0):(v=704751109,p=c[0]-210244248,s=p-1521486534<<0,i=p+143694565<<0),this.first=!1):(l=(e>>>2|e<<30)^(e>>>13|e<<19)^(e>>>22|e<<10),d=(n>>>6|n<<26)^(n>>>11|n<<21)^(n>>>25|n<<7),v=e&t,f=v^e&r^S,g=n&a^~n&o,p=s+d+g+Hl[u]+c[u],m=l+f,s=i+p<<0,i=p+m<<0),l=(i>>>2|i<<30)^(i>>>13|i<<19)^(i>>>22|i<<10),d=(s>>>6|s<<26)^(s>>>11|s<<21)^(s>>>25|s<<7),b=i&e,f=b^i&t^v,g=o&s^~o&n,p=a+d+g+Hl[u+1]+c[u+1],m=l+f,o=r+p<<0,r=p+m<<0,l=(r>>>2|r<<30)^(r>>>13|r<<19)^(r>>>22|r<<10),d=(o>>>6|o<<26)^(o>>>11|o<<21)^(o>>>25|o<<7),w=r&i,f=w^r&e^b,g=a&o^~a&s,p=n+d+g+Hl[u+2]+c[u+2],m=l+f,a=t+p<<0,t=p+m<<0,l=(t>>>2|t<<30)^(t>>>13|t<<19)^(t>>>22|t<<10),d=(a>>>6|a<<26)^(a>>>11|a<<21)^(a>>>25|a<<7),S=t&r,f=S^t&i^w,g=a&o^~a&s,p=n+d+g+Hl[u+3]+c[u+3],m=l+f,n=e+p<<0,e=p+m<<0,this.chromeBugWorkAround=!0;this.h0=this.h0+e<<0,this.h1=this.h1+t<<0,this.h2=this.h2+r<<0,this.h3=this.h3+i<<0,this.h4=this.h4+n<<0,this.h5=this.h5+a<<0,this.h6=this.h6+o<<0,this.h7=this.h7+s<<0};rn.prototype.hex=function(){this.finalize();var e=this.h0,t=this.h1,r=this.h2,i=this.h3,n=this.h4,a=this.h5,o=this.h6,s=this.h7,c=te[e>>>28&15]+te[e>>>24&15]+te[e>>>20&15]+te[e>>>16&15]+te[e>>>12&15]+te[e>>>8&15]+te[e>>>4&15]+te[e&15]+te[t>>>28&15]+te[t>>>24&15]+te[t>>>20&15]+te[t>>>16&15]+te[t>>>12&15]+te[t>>>8&15]+te[t>>>4&15]+te[t&15]+te[r>>>28&15]+te[r>>>24&15]+te[r>>>20&15]+te[r>>>16&15]+te[r>>>12&15]+te[r>>>8&15]+te[r>>>4&15]+te[r&15]+te[i>>>28&15]+te[i>>>24&15]+te[i>>>20&15]+te[i>>>16&15]+te[i>>>12&15]+te[i>>>8&15]+te[i>>>4&15]+te[i&15]+te[n>>>28&15]+te[n>>>24&15]+te[n>>>20&15]+te[n>>>16&15]+te[n>>>12&15]+te[n>>>8&15]+te[n>>>4&15]+te[n&15]+te[a>>>28&15]+te[a>>>24&15]+te[a>>>20&15]+te[a>>>16&15]+te[a>>>12&15]+te[a>>>8&15]+te[a>>>4&15]+te[a&15]+te[o>>>28&15]+te[o>>>24&15]+te[o>>>20&15]+te[o>>>16&15]+te[o>>>12&15]+te[o>>>8&15]+te[o>>>4&15]+te[o&15];return this.is224||(c+=te[s>>>28&15]+te[s>>>24&15]+te[s>>>20&15]+te[s>>>16&15]+te[s>>>12&15]+te[s>>>8&15]+te[s>>>4&15]+te[s&15]),c};rn.prototype.toString=rn.prototype.hex;rn.prototype.digest=function(){this.finalize();var e=this.h0,t=this.h1,r=this.h2,i=this.h3,n=this.h4,a=this.h5,o=this.h6,s=this.h7,c=[e>>>24&255,e>>>16&255,e>>>8&255,e&255,t>>>24&255,t>>>16&255,t>>>8&255,t&255,r>>>24&255,r>>>16&255,r>>>8&255,r&255,i>>>24&255,i>>>16&255,i>>>8&255,i&255,n>>>24&255,n>>>16&255,n>>>8&255,n&255,a>>>24&255,a>>>16&255,a>>>8&255,a&255,o>>>24&255,o>>>16&255,o>>>8&255,o&255];return this.is224||c.push(s>>>24&255,s>>>16&255,s>>>8&255,s&255),c};rn.prototype.array=rn.prototype.digest;rn.prototype.arrayBuffer=function(){this.finalize();var e=new ArrayBuffer(this.is224?28:32),t=new DataView(e);return t.setUint32(0,this.h0),t.setUint32(4,this.h1),t.setUint32(8,this.h2),t.setUint32(12,this.h3),t.setUint32(16,this.h4),t.setUint32(20,this.h5),t.setUint32(24,this.h6),this.is224||t.setUint32(28,this.h7),e};var Vo=(...e)=>new rn(!1,!0).update(e.join("")).hex();var XS=T({sha256:()=>Vo});function YS(e){let t=Symbol.for(e);return{brand(r,i){let n=i?Symbol.for(`${e}.${i}`):t;class a extends r{[n]=!0;constructor(...s){super(...s)}static isInstance(s){return typeof s=="object"&&s!==null&&n in s&&s[n]===!0}}return Object.defineProperty(a,"name",{value:r.name}),a},sub(r){return YS(`${e}.${r}`)},isInstance(r){return typeof r=="object"&&r!==null&&t in r&&r[t]===!0}}}var QS=YS("langchain");var ek=T({ContextOverflowError:()=>YM,LangChainError:()=>Rh,ModelAbortError:()=>Jl,addLangChainErrorFields:()=>ii,ns:()=>Gl});function ii(e,t){return e.lc_error_code=t,e.message=`${e.message}
@@ -412,20 +412,20 @@ ${i}`)}return e}function vB(e){let t=e.split(`
412
412
  `));if(t.configurable?.__pregel_scratchpad?.currentTaskInput===void 0)throw new Error("BUG: internal scratchpad not initialized.");return t.configurable[ar].currentTaskInput}function Vm(e){return e.split("|").filter(t=>!t.match(/^\d+$/)).map(t=>t.split(":")[0]).join("|")}function lR(e){let t=e.split("|");for(;t.length>1&&t[t.length-1].match(/^\d+$/);)t.pop();return t.slice(0,-1).join("|")}var C0=["values","updates","messages","tools","custom","tasks"];function mc(e){if(e==null||typeof e!="object")return!1;let t=e;return typeof t.id=="string"&&("source"in t||typeof t.step=="number")&&!("values"in t)&&!("config"in t)}function a9(e){if(!Array.isArray(e)||e.length!==2)return{data:e};let[t,r]=e;if(r==null||typeof r!="object")return{data:e};let i=r,n=typeof i.langgraph_node=="string"?i.langgraph_node:void 0,a=typeof i.run_id=="string"?i.run_id:void 0;return{data:a!=null&&t!=null&&typeof t=="object"?{...t,run_id:a}:t,node:n}}function O0({namespace:e,mode:t,payload:r,seq:i}){let n=Date.now(),a={type:"event"};switch(t){case"messages":{let{data:o,node:s}=a9(r);return[{...a,seq:i,method:"messages",params:{namespace:e,timestamp:n,...s?{node:s}:{},data:o}}]}case"tools":return[{...a,seq:i,method:"tools",params:{namespace:e,timestamp:n,data:o9(r)}}];case"checkpoints":return mc(r)?[{...a,seq:i,method:"checkpoints",params:{namespace:e,timestamp:n,data:r}}]:[];case"values":return[{...a,seq:i,method:"values",params:{namespace:e,timestamp:n,data:r}}];case"updates":{let o=s9(r);return[{...a,seq:i,method:"updates",params:{namespace:e,timestamp:n,...typeof o.node=="string"?{node:o.node}:{},data:o}}]}case"custom":{let o=typeof r=="object"&&r!==null&&!Array.isArray(r)&&"name"in r?r:{payload:r};return[{...a,seq:i,method:"custom",params:{namespace:e,timestamp:n,data:o}}]}case"tasks":return[{...a,seq:i,method:"tasks",params:{namespace:e,timestamp:n,data:r}}];default:return[]}}function o9(e){if(typeof e!="object"||e===null)return{event:"tool-error",tool_call_id:"",message:"Unexpected tools payload shape"};let t=e,r=String(t.toolCallId??"");switch(t.event){case"on_tool_start":return{event:"tool-started",tool_call_id:r,tool_name:String(t.name??"unknown"),input:t.input};case"on_tool_event":return{event:"tool-output-delta",tool_call_id:r,delta:typeof t.data=="string"?t.data:JSON.stringify(t.data??"")};case"on_tool_end":return{event:"tool-finished",tool_call_id:r,output:t.output};case"on_tool_error":{let i=t.error;return{event:"tool-error",tool_call_id:r,message:typeof i=="object"&&i!==null&&"message"in i&&typeof i.message=="string"?i.message:String(i??"unknown error")}}default:return{event:"tool-error",tool_call_id:"",message:`Unknown tool event: ${String(t.event)}`}}}function s9(e){if(typeof e!="object"||e===null)return{values:{}};let t=Object.entries(e);if(t.length===0)return{values:{}};let[r,i]=t[0];return{node:r,values:typeof i=="object"&&i!==null?i:{value:i}}}var P0=Symbol.for("langgraph.stream_channel"),Wr=class N0{[P0]=!0;channelName;#e=[];#o=[];#r=!1;#i;#n;constructor(t){this.channelName=t}static local(){return new N0}static remote(t){return new N0(t)}static isInstance(t){return typeof t=="object"&&t!==null&&P0 in t&&t[P0]===!0}push(t){this.#e.push(t),this.#t(),this.#n?.(t)}iterate(t=0){let r=t;return{next:async()=>{for(;;){if(r<this.#e.length)return{value:this.#e[r++],done:!1};if(this.#r){if(this.#i)throw this.#i;return{value:void 0,done:!0}}await new Promise(i=>this.#o.push(i))}}}}toAsyncIterable(t=0){return{[Symbol.asyncIterator]:()=>this.iterate(t)}}toEventStream(t={}){let r=new TextEncoder,i=this.iterate(t.startAt),n=t.event??this.channelName,a=t.serialize??(o=>JSON.stringify(o)??"null");return new ReadableStream({async pull(o){try{let s=await i.next();if(s.done){o.close();return}let c=[];n!=null&&c.push(`event: ${n}`);for(let u of a(s.value).split(/\r\n|\r|\n/))c.push(`data: ${u}`);o.enqueue(r.encode(`${c.join(`
413
413
  `)}
414
414
 
415
- `))}catch(s){o.error(s)}},async cancel(){await i.return?.()}})}get(t){if(t<0||t>=this.#e.length)throw new RangeError(`StreamChannel index ${t} out of bounds (size=${this.#e.length})`);return this.#e[t]}get size(){return this.#e.length}get done(){return this.#r}close(){this.#r=!0,this.#t()}fail(t){this.#i=t,this.#r=!0,this.#t()}_wire(t){this.#n=t}_close(){this.close()}_fail(t){this.fail(t)}[Symbol.asyncIterator](){return this.iterate()}#t(){let t=this.#o.splice(0);for(let r of t)r()}};function dR(e){return Wr.isInstance(e)}function c9(e){return e!=null&&(typeof e=="object"||typeof e=="function")&&typeof e.then=="function"}var Zm=Symbol("resolveValues"),R0=Symbol("rejectValues"),fR=class{_events=Wr.local();_discoveries=Wr.local();#e=0;#o=!1;#r;#i=!1;#n=[];#t=[];#s=[];#a=new Map;#u=new Map;#c=[];#l=[];register(e,t){this.#a.set(Bt(e),t)}addTransformer(e){let t=this._events.size;this.#t.push(e),e.onRegister&&e.onRegister({push:(r,i)=>this.push(r,i)});for(let r=0;r<t;r+=1)e.process(this._events.get(r));this.#o&&(this.#r!==void 0?e.fail?.(this.#r):e.finalize?.())}wireChannels(e){for(let[t,r]of Object.entries(e)){if(dR(r)){if(this.#s.push(r),typeof r.channelName!="string")continue;r._wire(i=>{this._events.push({type:"event",seq:this.#e++,method:r.channelName,params:{namespace:this.#n,timestamp:Date.now(),data:i}})});continue}c9(r)&&this.#l.push({name:t,promise:Promise.resolve(r)})}}push(e,t){t.method==="values"&&this.#u.set(Bt(e),t.params.data);let r=this.#n;this.#n=e;let i=!0;for(let n of this.#t)n.process(t)||(i=!1);this.#n=r,i&&this._events.push({...t,seq:this.#e++})}close(){this.#o=!0;for(let[r,i]of this.#u.entries()){let n=r?r.split("\0"):[];this.#a.get(Bt(n))?.[Zm](i)}let e=[];for(let r of this.#t){let i=r.finalize?.();i!=null&&typeof i.then=="function"&&e.push(i)}for(let r of this.#s)r._close();let t=this.#l;t.length===0&&e.length===0?(this._events.close(),this._discoveries.close()):Promise.allSettled([...e,...t.map(async({name:r,promise:i})=>{try{let n=await i;this._events.done||this._events.push({type:"event",seq:this.#e++,method:"custom",params:{namespace:[],timestamp:Date.now(),data:{name:r,payload:n}}})}catch{}})]).then(()=>{this._events.close(),this._discoveries.close()});for(let r of this.#a.values())r[Zm](void 0)}fail(e){this.#o=!0,this.#r=e;for(let t of this.#t)t.fail?.(e);for(let t of this.#s)t._fail(e);this._events.fail(e),this._discoveries.fail(e);for(let t of this.#a.values())t[R0](e)}markInterrupted(e){this.#i=!0,this.#c.push(...e)}get interrupted(){return this.#i}get interrupts(){return this.#c}subscribeEvents(e,t=0){let r=this._events.iterate(t);return{async next(){for(;;){let i=await r.next();if(i.done||qn(i.value.params.namespace,e))return i}}}}};async function pR(e,t){let r=0;try{for await(let i of e){let[n,a,o]=i;if(a==="values"&&ka(o)){let c=o[Ue];t.markInterrupted(c.map(u=>({interruptId:u.id??"",payload:u.value})))}let s=O0({namespace:n,mode:a,payload:o,seq:r});r+=s.length;for(let c of s)t.push(n,c)}}catch(i){t.fail(i);return}t.close()}function Bt(e){return e.join("\0")}function qn(e,t){if(t.length>e.length)return!1;for(let r=0;r<t.length;r+=1)if(e[r]!==t[r])return!1;return!0}function Gm(e,t,r=0){return{[Symbol.asyncIterator](){let i=e.iterate(r);return{async next(){for(;;){let n=await i.next();if(n.done)return{value:void 0,done:!0};if(qn(n.value.namespace,t))return{value:n.value,done:!1}}}}}}}var mR="root";function u9(e){if(e.length===0)return mR;let t=e[e.length-1],r=t.indexOf(":");return r===-1?t:t.slice(0,r)}function l9(e){if(e instanceof Error)return e.message;if(typeof e=="string")return e;try{return JSON.stringify(e)}catch{return String(e)}}function Hm(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function d9(e){if(!Hm(e)||e.event!=="started")return;let t=e.cause;if(Hm(t)&&typeof t.type=="string")return t}function f9(e){if(Hm(e)&&"result"in e&&typeof e.name=="string"&&typeof e.id=="string"&&!e.name.startsWith("__"))return{name:e.name,id:e.id}}function M0(e={}){let t=e.rootGraphName??mR,r=e.initialStatus??"running",i=e.emitRootOnRegister??!0,n=e.getGraphName??u9,a=e.serializeError??l9,o=e.getTerminalStatusOverride,s=Wr.local(),c=new Map,u=new Map,l=new Set,d=[],f,p=0,m=!1,g=A=>A.length===0?t:n(A),v=(A,U,G)=>{let Y=Bt(A),Ie=c.get(Y),me=Ie?.graphName??g(A);if(Ie!=null&&Ie.status===U&&Ie.graphName===me&&G?.error==null)return;Ie==null?(Ie={namespace:A,graphName:me,status:U},c.set(Y,Ie)):Ie.status=U;let Sn={event:U,graph_name:me,...G?.cause!=null?{cause:G.cause}:{},...G?.error!=null?{error:G.error}:{}},Or=Date.now();if(s.push({namespace:A,timestamp:Or,...Sn}),!(A.length===0&&!i)&&f!=null){p+=1;try{f.push(A,{type:"event",seq:0,method:"lifecycle",params:{namespace:A,timestamp:Or,data:Sn}})}finally{p-=1}}},b=A=>{let U=Bt(A),G=c.get(U);return G==null&&(G={namespace:A,graphName:g(A),status:void 0},c.set(U,G)),G},w=()=>{if(d.length===0)return;let A=d.splice(0,d.length);for(let U of A){let G=Bt(U.namespace),Y=c.get(G);Y==null||Y.status!=="started"||v(U.namespace,"completed")}},S=A=>{let U=Bt(A.namespace),G=c.get(U);G==null||G.status!=="started"||d.some(Y=>Bt(Y.namespace)===U)||d.push(A)},k=(A,U)=>{for(let G=d.length-1;G>=0;G-=1){let Y=d[G];Y.source.type==="node"&&Y.source.node===U&&Bt(Y.source.parent)===Bt(A)&&d.splice(G,1)}},I=A=>{for(let U=1;U<=A.length;U+=1){let G=A.slice(0,U),Y=Bt(G);if(c.has(Y))continue;b(G);let Ie=u.get(Y);v(G,"started",Ie!=null?{cause:Ie}:void 0)}},Z=()=>l.size>0?"interrupted":"completed",C=A=>{for(let U of c.values())U.namespace.length!==0&&U.status==="started"&&v(U.namespace,A);v([],A),s.close()},y=async()=>{if(o==null)return Z();try{return await o()??Z()}catch{return Z()}},V=(A,U)=>{let G=`${U}:`;for(let Y of c.values()){if(Y.namespace.length!==A.length+1||Y.status!=="started"||!qn(Y.namespace,A))continue;let Ie=Y.namespace[Y.namespace.length-1];if(Ie===U||Ie.startsWith(G))return Y.namespace}},B=(A,U)=>{let G=[...A,`${U.name}:${U.id}`];return c.get(Bt(G))?.status==="started"?G:void 0};return{__native:!0,init(){return{_lifecycleLog:s,lifecycle:Gm(s,[],0)}},onRegister(A){f=A,b([]),i&&v([],r)},process(A){let U=A.params.namespace;if(p>0)return!0;let G=A.method==="tasks"?f9(A.params.data):void 0;if(G!=null&&k(U,G.name),w(),A.method==="lifecycle"){let Y=d9(A.params.data);return Y!=null&&u.set(Bt(U),Y),I(U),!1}if(I(U),A.method==="input"&&Hm(A.params.data)&&A.params.data.event==="requested"){let Y=A.params.data.id;typeof Y=="string"&&l.add(Y)}if(G!=null){let Y=B(U,G);Y!=null&&S({namespace:Y,source:{type:"task"}})}if(A.method==="updates"){let Y=A.params.node;if(typeof Y=="string"&&!Y.startsWith("__")){let Ie=V(U,Y);Ie!=null&&S({namespace:Ie,source:{type:"node",parent:U,node:Y}})}}return!0},finalize(){if(!m){if(m=!0,w(),o==null){C(Z());return}return y().then(C).catch(A=>{s.fail(A)})}},fail(A){if(m)return;m=!0;let U=a(A);for(let G of c.values())G.namespace.length!==0&&G.status==="started"&&v(G.namespace,"failed");v([],"failed",{error:U}),s.fail(A)}}}function hc(e){let t=e;return typeof t.run_id=="string"?`run:${t.run_id}`:e.event==="message-start"&&typeof t.id=="string"?`message:${t.id}`:"__default__"}function bl(e,t){let r=Wr.local(),i=new Map,n=new Set;return{init:()=>({messages:r.toAsyncIterable()}),process(a){if(a.method!=="messages"||!qn(a.params.namespace,e)||a.params.namespace.length!==e.length+1||t!==void 0&&a.params.node!==t)return!0;let o=a.params.data;switch(o.event){case"message-start":{let s=hc(o);if(o.role==="tool"){n.add(s);break}let c=Wr.local(),u=Object.assign(new ca(c.toAsyncIterable()),{namespace:a.params.namespace,node:a.params.node});i.set(s,{source:c,stream:u}),c.push(o),r.push(u);break}case"content-block-start":case"content-block-delta":case"content-block-finish":if(n.has(hc(o)))break;i.get(hc(o))?.source.push(o);break;case"message-finish":{let s=hc(o);if(n.delete(s))break;let c=i.get(s);c&&(c.source.push(o),c.source.close(),i.delete(s));break}case"error":if(n.has(hc(o)))break;i.get(hc(o))?.source.push(o);break}return!0},finalize(){for(let[a,o]of i)o.source.push({event:"message-finish"}),o.source.close(),i.delete(a);n.clear(),r.close()},fail(a){for(let[o,s]of i)s.source.fail(a),i.delete(o);n.clear(),r.fail(a)}}}function wl(e,t,r=0){let i=t.length+1;return{[Symbol.asyncIterator](){let n=e.iterate(r);return{async next(){for(;;){let a=await n.next();if(a.done)return{value:void 0,done:!0};let{ns:o,stream:s}=a.value;if(o.length===i&&qn(o,t))return{value:s,done:!1}}}}}}}function j0(e,t){let{createStream:r}=t,i=new Set;return{__native:!0,init(){return{_discoveries:e._discoveries,subgraphs:wl(e._discoveries,[],0)}},process(n){let a=n.params.namespace;if(a.length===0)return!0;let o=a.slice(0,1),s=Bt(o);if(i.has(s))return!0;i.add(s);let c=r(o,e._discoveries.size,e._events.size);return e.register(o,c),e._discoveries.push({ns:o,stream:c}),!0}}}function z0(e){let t=Wr.local();return{init:()=>({_valuesLog:t}),process(r){return r.method!=="values"||r.params.namespace.length!==e.length||!qn(r.params.namespace,e)||t.push(r.params.data),!0},finalize(){t.close()},fail(r){t.fail(r)}}}function Jm(e){return"__native"in e&&e.__native===!0}var hR=Symbol("setValuesLog"),gR=Symbol("setMessagesIterable"),D0=Symbol("setLifecycleIterable"),U0=Symbol("setSubgraphsIterable"),p9={[Symbol.asyncIterator](){return{next:()=>Promise.resolve({value:void 0,done:!0})}}},L0=class{path;extensions;_mux;#e;#o;#r;#i;#n;#t;#s;#a;#u;#c;constructor(e,t,r=0,i=0,n,a){this.path=e,this._mux=t,this.#o=r,this.#e=i,this.extensions=n??{},this.#r=a??new AbortController,this.#t=new Promise((o,s)=>{this.#i=o,this.#n=s}),this.#t.catch(()=>{})}[Symbol.asyncIterator](){return this._mux.subscribeEvents(this.path,this.#e)}get subgraphs(){return this.#c?this.#c:wl(this._mux._discoveries,this.path,this.#o)}get values(){let e=this.#s,t=this.#t,r=this._mux,i=this.#e,n=this.path,a=e?e.toAsyncIterable():{[Symbol.asyncIterator]:()=>{let o=r.subscribeEvents(n,i);return{async next(){for(;;){let s=await o.next();if(s.done)return{value:void 0,done:!0};if(s.value.method==="values"&&s.value.params.namespace.length===n.length)return{value:s.value.params.data,done:!1}}}}}};return{[Symbol.asyncIterator]:()=>a[Symbol.asyncIterator](),then:t.then.bind(t)}}get messages(){if(this.#a)return this.#a;let e=bl(this.path),t=e.init();return this._mux.addTransformer(e),this.#a=t.messages,this.#a}get lifecycle(){return this.#u??p9}messagesFrom(e){let t=bl(this.path,e),r=t.init();return this._mux.addTransformer(t),r.messages}get output(){return this.#t}get interrupted(){return this._mux.interrupted}get interrupts(){return this._mux.interrupts}abort(e){this.#r.abort(e)}get signal(){return this.#r.signal}[Zm](e){this.#i?.(e),this.#i=void 0}[R0](e){this.#n?.(e),this.#n=void 0}[hR](e){this.#s=e}[gR](e){this.#a=e}[D0](e){this.#u=e}[U0](e){this.#c=e}},_R=class extends L0{name;index;constructor(e,t,r=0,i=0,n,a){super(e,t,r,i,n,a);let o=e[e.length-1]??"",s=o.lastIndexOf(":");if(s>=0){this.name=o.slice(0,s);let c=o.slice(s+1);this.index=/^\d+$/.test(c)?Number(c):0}else this.name=o,this.index=0}};function F0(e,t=[],r){let{abortController:i}=r instanceof AbortController?{abortController:r}:r??{},n=new fR,a=M0(),o=a.init(),s=o._lifecycleLog,c=j0(n,{createStream:(b,w,S)=>{let k=new _R(b,n,w,S);return k[U0](wl(n._discoveries,b,w)),k[D0](Gm(s,b,s.size)),k}}),u=c.init();n.addTransformer(c),n.addTransformer(a);let l=z0([]),d=bl([]);n.addTransformer(l),n.addTransformer(d);let f={},p=[];for(let b of t){let w=b();n.addTransformer(w);let S=w.init();Jm(w)?p.push(S):Object.assign(f,S),typeof S=="object"&&S!==null&&!Jm(w)&&n.wireChannels(S)}let m=new L0([],n,0,0,f,i);for(let b of p)Object.assign(m,b);let g=l.init();m[hR](g._valuesLog);let v=d.init();return m[gR](v.messages),m[D0](o.lifecycle),m[U0](u.subgraphs),n.register([],m),pR(e,n).catch(b=>{}),m}var F=e=>BigInt(e),De=(e,t=0)=>new DataView(e.buffer,e.byteOffset+t,e.byteLength-t),wR=F("0x9E3779B1"),xR=F("0x85EBCA77"),m9=F("0xC2B2AE3D"),da=F("0x9E3779B185EBCA87"),Io=F("0xC2B2AE3D27D4EB4F"),SR=F("0x165667B19E3779F9"),Z0=F("0x85EBCA77C2B2AE63"),h9=F("0x27D4EB2F165667C5"),g9=F("0x165667919E3779F9"),_9=F("0x9FB21C651E98DF25"),y9=e=>{let t=e.length;if(t%2!==0)throw new Error("String should have an even number of characters");let r=t/2,i=new Uint8Array(r),n=0,a=0;for(;a<r;){let o=e.slice(n,n+=2);i[a]=Number.parseInt(o,16),a+=1}return De(i)},Xn=y9("b8fe6c3923a44bbe7c01812cf721ad1cded46de9839097db7240a4a4b7b3671fcb79e64eccc0e578825ad07dccff7221b8084674f743248ee03590e6813a264c3c2852bb91c300cb88d0658b1b532ea371644897a20df94e3819ef46a9deacd8a8fa763fe39c343ff9dcbbc7c70b4f1d8a51e04bcdb45931c89f7ec9d9787364eac5ac8334d3ebc3c581a0fffa1363eb170ddd51b7f0da49d316552629d4689e2b16be587d47a1fc8ff8b8d17ad031ce45cb3a8f95160428afd7fbcabb4b407e"),gc=(F(1)<<F(128))-F(1),ve=(F(1)<<F(64))-F(1),Xm=(F(1)<<F(32))-F(1),Si=64,kR=Si/8,v9=8,Km=4;function _c(e){if(!e)throw new Error("Assert failed")}function b9(e){let t=new DataView(new ArrayBuffer(8));return t.setBigUint64(0,e,!0),t.getBigUint64(0,!1)}function w9(e){let t=e;return t=(t&F(65535))<<F(16)|(t&F(4294901760))>>F(16),t=(t&F(16711935))<<F(8)|(t&F(4278255360))>>F(8),t}function x9(e,t){return(e&Xm)*(t&Xm)&ve}function S9(e,t){return(e<<t|e>>F(32)-t)&Xm}function $R(e,t,r){for(let i=0;i<kR;i+=1){let n=t.getBigUint64(i*8,!0),a=n^r.getBigUint64(i*8,!0);e[i^1]+=n,e[i]+=x9(a,a>>F(32))}return e}function yR(e,t,r,i){for(let n=0;n<i;n+=1)$R(e,De(t,n*Si),De(r,n*8));return e}function k9(e,t){for(let r=0;r<kR;r+=1){let i=t.getBigUint64(r*8,!0),n=e[r];n=B0(n,F(47)),n^=i,n*=wR,e[r]=n&ve}return e}function Wm(e,t){return ER(e[0]^t.getBigUint64(0,!0),e[1]^t.getBigUint64(v9,!0))}function vR(e,t,r){let i=r;return i+=Wm(e.slice(0),De(t,0*Km)),i+=Wm(e.slice(2),De(t,4*Km)),i+=Wm(e.slice(4),De(t,8*Km)),i+=Wm(e.slice(6),De(t,12*Km)),Yn(i&ve)}function $9(e,t,r,i,n){let a=e,o=Math.floor((r.byteLength-Si)/8),s=Si*o,c=Math.floor((t.byteLength-1)/s);for(let u=0;u<c;u+=1)a=yR(a,De(t,u*s),r,o),a=n(a,De(r,r.byteLength-Si));{let u=Math.floor((t.byteLength-1-s*c)/Si);a=yR(a,De(t,c*s),r,u),a=i(a,De(t,t.byteLength-Si),De(r,r.byteLength-Si-7))}return a}function E9(e,t){let r=new BigUint64Array([m9,da,Io,SR,Z0,xR,h9,wR]);_c(e.byteLength>128),r=$9(r,e,t,$R,k9),_c(r.length*8===64);{let i=vR(r,De(t,11),F(e.byteLength)*da&ve);return vR(r,De(t,t.byteLength-Si-11),~(F(e.byteLength)*Io)&ve)<<F(64)|i}}function ER(e,t){let r=e*t&gc;return r&ve^r>>F(64)}function bR(e,t,r){return ER((e.getBigUint64(0,!0)^t.getBigUint64(0,!0)+r)&ve,(e.getBigUint64(8,!0)^t.getBigUint64(8,!0)-r)&ve)}function qm(e,t,r,i,n){let a=e&ve,o=e>>F(64)&ve;return a+=bR(t,i,n),a^=r.getBigUint64(0,!0)+r.getBigUint64(8,!0),a&=ve,o+=bR(r,De(i,16),n),o^=t.getBigUint64(0,!0)+t.getBigUint64(8,!0),o&=ve,o<<F(64)|a}function Yn(e){let t=e;return t^=t>>F(37),t*=g9,t&=ve,t^=t>>F(32),t}function Ym(e){let t=e;return t^=t>>F(33),t*=Io,t&=ve,t^=t>>F(29),t*=SR,t&=ve,t^=t>>F(32),t}function I9(e,t,r){let i=e.byteLength;_c(i>0&&i<=3);let n=F(e.getUint8(i-1))|F(i<<8)|F(e.getUint8(0)<<16)|F(e.getUint8(i>>1)<<24),a=(n^(F(t.getUint32(0,!0))^F(t.getUint32(4,!0)))+r)&ve,o=(F(t.getUint32(8,!0))^F(t.getUint32(12,!0)))-r;return(Ym((S9(w9(n),F(13))^o)&ve)&ve)<<F(64)|Ym(a)}function B0(e,t){return e^e>>t}function T9(e,t,r){let i=e.byteLength;_c(i>=4&&i<=8);{let n=e.getUint32(0,!0),a=e.getUint32(i-4,!0),o=((F(n)|F(a)<<F(32))^(t.getBigUint64(16,!0)^t.getBigUint64(24,!0))+r&ve)*(da+(F(i)<<F(2)))&gc;return o+=(o&ve)<<F(65),o&=gc,o^=o>>F(67),B0(B0(o&ve,F(35))*_9&ve,F(28))|Yn(o>>F(64))<<F(64)}}function A9(e,t,r){let i=e.byteLength;_c(i>=9&&i<=16);{let n=(t.getBigUint64(32,!0)^t.getBigUint64(40,!0))+r&ve,a=(t.getBigUint64(48,!0)^t.getBigUint64(56,!0))-r&ve,o=e.getBigUint64(0,!0),s=e.getBigUint64(i-8,!0),c=(o^s^n)*da,u=(c&ve)+(F(i-1)<<F(54));c=c&(gc^ve)|u,s^=a,c+=s+(s&Xm)*(xR-F(1))<<F(64),c&=gc,c^=b9(c>>F(64));let l=(c&ve)*Io;return l+=(c>>F(64))*Io<<F(64),l&=gc,Yn(l&ve)|Yn(l>>F(64))<<F(64)}}function C9(e,t){let r=e.byteLength;return _c(r<=16),r>8?A9(e,Xn,t):r>=4?T9(e,Xn,t):r>0?I9(e,Xn,t):Ym(t^Xn.getBigUint64(64,!0)^Xn.getBigUint64(72,!0))|Ym(t^Xn.getBigUint64(80,!0)^Xn.getBigUint64(88,!0))<<F(64)}function V0(e){return~e+F(1)&ve}function O9(e,t,r){let i=F(e.byteLength)*da&ve,n=F(e.byteLength-1)/F(32);for(;n>=0;){let s=Number(n);i=qm(i,De(e,16*s),De(e,e.byteLength-16*(s+1)),De(t,32*s),r),n-=F(1)}let a=i+(i>>F(64))&ve;a=Yn(a);let o=(i&ve)*da+(i>>F(64))*Z0+(F(e.byteLength)-r&ve)*Io;return o&=ve,o=V0(Yn(o)),a|o<<F(64)}function P9(e,t,r){let i=F(e.byteLength)*da&ve;for(let o=32;o<160;o+=32)i=qm(i,De(e,o-32),De(e,o-16),De(t,o-32),r);i=Yn(i&ve)|Yn(i>>F(64))<<F(64);for(let o=160;o<=e.byteLength;o+=32)i=qm(i,De(e,o-32),De(e,o-16),De(t,3+o-160),r);i=qm(i,De(e,e.byteLength-16),De(e,e.byteLength-32),De(t,103),V0(r));let n=i+(i>>F(64))&ve;n=Yn(n);let a=(i&ve)*da+(i>>F(64))*Z0+(F(e.byteLength)-r&ve)*Io;return a&=ve,a=V0(Yn(a)),n|a<<F(64)}function ki(e,t=F(0)){let r=new TextEncoder,i=De(typeof e=="string"?r.encode(e):e),n=i.byteLength,a=o=>o.toString(16).padStart(32,"0");return n<=16?a(C9(i,t)):n<=128?a(O9(i,Xn,t)):n<=240?a(P9(i,Xn,t)):a(E9(i,Xn))}function Qm(e){return/^[0-9a-f]{32}$/.test(e)}function H0(e){let t=Ae.getRunnableConfig();if(!t)throw new Error("Called interrupt() outside the context of a graph.");let r=t.configurable;if(!r)throw new Error("No configurable found in config");if(!r.__pregel_checkpointer)throw new $a("No checkpointer set",{lc_error_code:"MISSING_CHECKPOINTER"});let i=r[ar];i.interruptCounter+=1;let n=i.interruptCounter;if(i.resume.length>0&&n<i.resume.length)return r[Nr]?.([[_r,i.resume]]),i.resume[n];if(i.nullResume!==void 0){if(i.resume.length!==n)throw new Error(`Resume length mismatch: ${i.resume.length} !== ${n}`);let o=i.consumeNullResume();return i.resume.push(o),r[Nr]?.([[_r,i.resume]]),o}let a=r[Rr]?.split("|");throw new ti([{id:a?ki(a.join("|")):void 0,value:e}])}var Vt=class extends ae{lc_namespace=["langgraph"];func;tags;config;trace=!0;recurse=!0;constructor(e){super(),this.name=e.name??e.func.name,this.func=e.func,this.config=e.tags?{tags:e.tags}:void 0,this.trace=e.trace??this.trace,this.recurse=e.recurse??this.recurse}async _tracedInvoke(e,t,r){return new Promise((i,n)=>{let a=$e(t,{callbacks:r?.getChild()});Ae.runWithConfig(a,async()=>{try{i(await this.func(e,a))}catch(o){n(o)}})})}async invoke(e,t){let r,i=pc(t),n=xt(this.config,i);return this.trace?r=await this._callWithConfig(this._tracedInvoke,e,n):r=await Ae.runWithConfig(n,async()=>this.func(e,n)),ae.isRunnable(r)&&this.recurse?await Ae.runWithConfig(n,async()=>r.invoke(e,n)):r}};function*$i(e,t){if(t===void 0)yield*e;else for(let r of e)yield[t,r]}async function vn(e){let t=[];for await(let r of await e)t.push(r);return t}function To(e){let t=[];for(let r of e)t.push(r);return t}function Ao(e,t){return e?"configurable"in e?{...e,configurable:{...e.configurable,...t}}:{...e,configurable:t}:{configurable:t}}function G0(e){return e!=null&&typeof e=="function"&&e instanceof Object.getPrototypeOf(async function*(){}).constructor}function J0(e){return e!=null&&typeof e=="function"&&e instanceof Object.getPrototypeOf(function*(){}).constructor}function N9(e){return typeof e=="object"&&e?.[Symbol.for("LG_SKIP_WRITE")]!==void 0}var hr={[Symbol.for("LG_PASSTHROUGH")]:!0};function eh(e){return typeof e=="object"&&e?.[Symbol.for("LG_PASSTHROUGH")]!==void 0}var K0=Symbol("IS_WRITER"),ot=class q0 extends Vt{writes;constructor(t,r){let i=`ChannelWrite<${t.map(n=>mt(n)?n.node:"channel"in n?n.channel:"...").join(",")}>`;super({writes:t,name:i,tags:r,trace:!1,func:async(n,a)=>this._write(n,a??{})}),this.writes=t}async _write(t,r){let i=this.writes.map(n=>W0(n)&&eh(n.value)?{mapper:n.mapper,value:t}:th(n)&&eh(n.value)?{channel:n.channel,value:t,skipNone:n.skipNone,mapper:n.mapper}:n);return await q0.doWrite(r,i),t}static async doWrite(t,r){for(let a of r){if(th(a)){if(a.channel==="__pregel_tasks")throw new be("Cannot write to the reserved channel TASKS");if(eh(a.value))throw new be("PASSTHROUGH value must be replaced")}if(W0(a)&&eh(a.value))throw new be("PASSTHROUGH value must be replaced")}let i=[];for(let a of r)if(mt(a))i.push([In,a]);else if(W0(a)){let o=await a.mapper.invoke(a.value,t);o!=null&&o.length>0&&i.push(...o)}else if(th(a)){let o=a.mapper!==void 0?await a.mapper.invoke(a.value,t):a.value;if(N9(o)||a.skipNone&&o===void 0)continue;i.push([a.channel,o])}else throw new Error(`Invalid write entry: ${JSON.stringify(a)}`);let n=t.configurable?.[Nr];n(i)}static isWriter(t){return t instanceof q0||K0 in t&&!!t[K0]}static registerWriter(t){return Object.defineProperty(t,K0,{value:!0})}};function th(e){return e!==void 0&&typeof e.channel=="string"}function W0(e){return e!==void 0&&!th(e)&&ae.isRunnable(e.mapper)}var IR=class TR extends Vt{lc_graph_name="ChannelRead";channel;fresh=!1;mapper;constructor(t,r,i=!1){super({trace:!1,func:(n,a)=>TR.doRead(a,this.channel,this.fresh,this.mapper)}),this.fresh=i,this.mapper=r,this.channel=t,this.name=Array.isArray(t)?`ChannelRead<${t.join(",")}>`:`ChannelRead<${t}>`}static doRead(t,r,i,n){let a=t.configurable?.[Yr];if(!a)throw new Error("Runnable is not configured with a read function. Make sure to call in the context of a Pregel process");return n?n(a(r,i)):a(r,i)}},yc=new yi,bn=class xl extends Hr{lc_graph_name="PregelNode";channels;triggers=[];mapper;writers=[];bound=yc;kwargs={};metadata={};tags=[];retryPolicy;cachePolicy;subgraphs;ends;constructor(t){let{channels:r,triggers:i,mapper:n,writers:a,bound:o,kwargs:s,metadata:c,retryPolicy:u,cachePolicy:l,tags:d,subgraphs:f,ends:p}=t,m=[...t.config?.tags?t.config.tags:[],...d??[]];super({...t,bound:t.bound??yc,config:{...t.config?t.config:{},tags:m}}),this.channels=r,this.triggers=i,this.mapper=n,this.writers=a??this.writers,this.bound=o??this.bound,this.kwargs=s??this.kwargs,this.metadata=c??this.metadata,this.tags=m,this.retryPolicy=u,this.cachePolicy=l,this.subgraphs=f,this.ends=p}getWriters(){let t=[...this.writers];for(;t.length>1&&t[t.length-1]instanceof ot&&t[t.length-2]instanceof ot;){let r=t.slice(-2),i=r[0].writes.concat(r[1].writes);t[t.length-2]=new ot(i,r[0].config?.tags),t.pop()}return t}getNode(){let t=this.getWriters();if(!(this.bound===yc&&t.length===0))return this.bound===yc&&t.length===1?t[0]:this.bound===yc?new Ar({first:t[0],middle:t.slice(1,t.length-1),last:t[t.length-1],omitSequenceTags:!0}):t.length>0?new Ar({first:this.bound,middle:t.slice(0,t.length-1),last:t[t.length-1],omitSequenceTags:!0}):this.bound}join(t){if(!Array.isArray(t))throw new Error("channels must be a list");if(typeof this.channels!="object")throw new Error("all channels must be named when using .join()");return new xl({channels:{...this.channels,...Object.fromEntries(t.map(r=>[r,r]))},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(t){return ot.isWriter(t)?new xl({channels:this.channels,triggers:this.triggers,mapper:this.mapper,writers:[...this.writers,t],bound:this.bound,config:this.config,kwargs:this.kwargs,retryPolicy:this.retryPolicy,cachePolicy:this.cachePolicy}):this.bound===yc?new xl({channels:this.channels,triggers:this.triggers,mapper:this.mapper,writers:this.writers,bound:tt(t),config:this.config,kwargs:this.kwargs,retryPolicy:this.retryPolicy,cachePolicy:this.cachePolicy}):new xl({channels:this.channels,triggers:this.triggers,mapper:this.mapper,writers:this.writers,bound:this.bound.pipe(t),config:this.config,kwargs:this.kwargs,retryPolicy:this.retryPolicy,cachePolicy:this.cachePolicy})}};function R9(e){return"steps"in e&&Array.isArray(e.steps)}function Sl(e){return"lg_is_pregel"in e&&e.lg_is_pregel===!0}function rh(e){let t=[e];for(let r of t){if(Sl(r))return r;R9(r)&&t.push(...r.steps)}}function Co(e,t,r=!0,i=!1){try{return e[t].get()}catch(n){if(n.name===Ne.unminifiable_name){if(i)return n;if(r)return null}throw n}}function wn(e,t,r=!0){if(Array.isArray(t)){let i={};for(let n of t)try{i[n]=Co(e,n,!r)}catch(a){if(a.name===Ne.unminifiable_name)continue}return i}else return Co(e,t)}function*AR(e,t){if(e.graph===ir.PARENT)throw new be("There is no parent graph.");if(e.goto){let r;Array.isArray(e.goto)?r=e.goto:r=[e.goto];for(let i of r)if(mt(i))yield[yr,In,i];else if(typeof i=="string")yield[yr,`branch:to:${i}`,"__start__"];else throw new Error(`In Command.send, expected Send or string, got ${typeof i}`)}if(e.resume)if(typeof e.resume=="object"&&Object.keys(e.resume).length&&Object.keys(e.resume).every(Qm))for(let[r,i]of Object.entries(e.resume)){let n=t.filter(a=>a[0]===r&&a[1]==="__resume__").map(a=>a[2]).slice(0,1)??[];n.push(i),yield[r,_r,n]}else yield[yr,_r,e.resume];if(e.update){if(typeof e.update!="object"||!e.update)throw new Error("Expected cmd.update to be a dict mapping channel names to update values");if(Array.isArray(e.update))for(let[r,i]of e.update)yield[yr,r,i];else for(let[r,i]of Object.entries(e.update))yield[yr,r,i]}}function*nh(e,t){if(t!=null)if(Array.isArray(e)&&typeof t=="object"&&!Array.isArray(t))for(let r in t)e.includes(r)&&(yield[r,t[r]]);else{if(Array.isArray(e))throw new Error('Input chunk must be an object when "inputChannels" is an array');yield[e,t]}}function*ih(e,t,r){Array.isArray(e)?(t===!0||t.find(([i,n])=>e.includes(i)))&&(yield wn(r,e)):(t===!0||t.some(([i,n])=>i===e))&&(yield Co(r,e))}function*CR(e,t,r){let i=t.filter(([s,c])=>(s.config===void 0||!s.config.tags?.includes("langsmith:hidden"))&&c[0][0]!=="__error__"&&c[0][0]!=="__interrupt__");if(!i.length)return;let n;i.some(([s])=>s.writes.some(([c,u])=>c==="__return__"))?n=i.flatMap(([s])=>s.writes.filter(([c,u])=>c===Ci).map(([c,u])=>[s.name,u])):Array.isArray(e)?n=i.flatMap(([s])=>{let{writes:c}=s,u={};for(let[l]of c)e.includes(l)&&(u[l]=(u[l]||0)+1);return Object.values(u).some(l=>l>1)?c.filter(([l])=>e.includes(l)).map(([l,d])=>[s.name,{[l]:d}]):[[s.name,Object.fromEntries(c.filter(([l])=>e.includes(l)))]]}):n=i.flatMap(([s])=>s.writes.filter(([c,u])=>c===e).map(([c,u])=>[s.name,u]));let a={};for(let[s,c]of n)s in a||(a[s]=[]),a[s].push(c);let o={};for(let s in a)if(a[s].length===1){let[c]=a[s];o[s]=c}else o[s]=a[s];r&&(o.__metadata__={cached:r}),yield o}function ah(e){let t=typeof e[He];if(t==="number")return 0;if(t==="string")return"";for(let r in e){if(!Object.prototype.hasOwnProperty.call(e,r))continue;let i=typeof e[r];if(i==="number")return 0;if(i==="string")return"";break}}function vc(e,t){if(Object.keys(e).length>0){let r=ah(t);return Object.fromEntries(Object.entries(t).filter(([i,n])=>n>(e[i]??r)))}else return t}function OR(e,t){return e&&!Array.isArray(e)&&!(e instanceof Date)&&typeof e=="object"?e:{[t]:e}}function gr(e,t){return e===null?{configurable:t}:e?.configurable===void 0?{...e,configurable:t}:{...e,configurable:{...e.configurable,...t}}}function fa(e,t){let r=t?.parents??{};return Object.keys(r).length>0?gr(e,{[Mr]:{...r,[e.configurable?.checkpoint_ns??""]:e.configurable?.checkpoint_id}}):e}function bc(...e){let t=[...new Set(e.filter(Boolean))];if(t.length===0)return{signal:void 0,dispose:void 0};if(t.length===1)return{signal:t[0],dispose:void 0};let r=new AbortController,i=()=>{let a=t.find(o=>o.aborted)?.reason;r.abort(a),t.forEach(o=>o.removeEventListener("abort",i))};t.forEach(a=>a.addEventListener("abort",i,{once:!0}));let n=t.find(a=>a.aborted);return n&&r.abort(n.reason),{signal:r.signal,dispose:()=>{t.forEach(a=>a.removeEventListener("abort",i))}}}var PR=(e,t)=>{if(!(!e&&!t))return e?t?Array.isArray(e)&&Array.isArray(t)?[...e,...t]:Array.isArray(e)?[...e,t]:Array.isArray(t)?[e,...t]:[e,t]:e:t};var NR=class{func;name;input;retry;cache;callbacks;__lg_type="call";constructor({func:e,name:t,input:r,retry:i,cache:n,callbacks:a}){this.func=e,this.name=t,this.input=r,this.retry=i,this.cache=n,this.callbacks=a}};function RR(e){return typeof e=="object"&&e!==null&&"__lg_type"in e&&e.__lg_type==="call"}function MR(e,t){return new Ar({name:e,first:new Vt({func:r=>t(...r),name:e,trace:!1,recurse:!1}),last:new ot([{channel:Ci,value:hr}],[lt])})}function jR(e,t){return new Vt({func:(r,i)=>t(r,i),name:e,trace:!1,recurse:!1})}function zR({func:e,name:t,cache:r,retry:i},...n){let a=Ae.getRunnableConfig();if(typeof a.configurable?.__pregel_call=="function")return a.configurable[jo](e,t,n,{retry:i,cache:r,callbacks:a.callbacks});throw new Error("Async local storage not initialized. Please call initializeAsyncLocalStorageSingleton() before using this function.")}var DR=e=>e!==void 0?e+1:1;function M9(e,t){if(t==null)return!1;for(let r of e)if(t[r])return!0;return!1}function j9(e){let t;for(let r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t==null?t=e[r]:t=ml(t,e[r]));return t}function $l(e,t,r){let i=ah(e.channel_versions),n=e.versions_seen.__interrupt__??{},a=!1;if((e.channel_versions.__start__??i)>(n.__start__??i))a=!0;else for(let s in e.channel_versions)if(Object.prototype.hasOwnProperty.call(e.channel_versions,s)&&e.channel_versions[s]>(n[s]??i)){a=!0;break}let o=r.some(s=>t==="*"?!s.config?.tags?.includes(lt):t.includes(s.name));return a&&o}function kl(e,t,r,i,n=!1){let a=new Set;if(Array.isArray(i))a=new Set(i.filter(s=>r.writes.some(([c,u])=>c===s)));else{for(let[s]of r.writes)if(s===i){a=new Set([s]);break}a=a||new Set}let o;if(n&&a.size>0){let s=Object.fromEntries(Object.entries(t).filter(([l,d])=>a.has(l))),c=_n(e,s,-1),u=la(s,c);rr(gn(c),u,[r],void 0,void 0),o=wn({...t,...u},i)}else o=wn(t,i);return o}function X0(e,t,r){for(let[i,n]of r)if(["__pregel_push","__pregel_tasks"].includes(i)&&n!=null){if(!mt(n))throw new be(`Invalid packet type, expected SendProtocol, got ${JSON.stringify(n)}`);if(!(n.node in t))throw new be(`Invalid node name "${n.node}" in Send packet`)}e(r)}var z9=new Set([Ic,jr,_r,Ue,Ci,Mo]);function rr(e,t,r,i,n){r.sort((f,p)=>{let m=f.path?.slice(0,3)||[],g=p.path?.slice(0,3)||[];for(let v=0;v<Math.min(m.length,g.length);v+=1){if(m[v]<g[v])return-1;if(m[v]>g[v])return 1}return m.length-g.length});let a=r.some(f=>f.triggers.length>0),o=yl(t);for(let f of r){e.versions_seen[f.name]??={};for(let p of f.triggers)p in e.channel_versions&&(e.versions_seen[f.name][p]=e.channel_versions[p])}let s=j9(e.channel_versions),c=new Set(r.flatMap(f=>f.triggers).filter(f=>!SS.includes(f))),u=!1;for(let f of c)f in o&&o[f].consume()&&i!==void 0&&(e.channel_versions[f]=i(s),u=!0);let l={};for(let f of r)for(let[p,m]of f.writes)z9.has(p)||p in o&&(l[p]??=[],l[p].push(m));s!=null&&i!=null&&(s=u?i(s):s);let d=new Set;for(let[f,p]of Object.entries(l))if(f in o){let m=o[f],g;try{g=m.update(p)}catch(v){if(v.name===be.unminifiable_name){let b=new be(`Invalid update for channel "${f}" with values ${JSON.stringify(p)}: ${v.message}`);throw b.lc_error_code=v.lc_error_code,b}else throw v}g&&i!==void 0&&(e.channel_versions[f]=i(s),m.isAvailable()&&d.add(f))}if(a)for(let f in o){if(!Object.prototype.hasOwnProperty.call(o,f))continue;let p=o[f];p.isAvailable()&&!d.has(f)&&p.update([])&&i!==void 0&&(e.channel_versions[f]=i(s),p.isAvailable()&&d.add(f))}if(a&&!M9(d,n))for(let f in o){if(!Object.prototype.hasOwnProperty.call(o,f))continue;let p=o[f];p.finish()&&i!==void 0&&(e.channel_versions[f]=i(s),p.isAvailable()&&d.add(f))}return d}function*D9(e,t,r){if(r.updatedChannels!=null&&r.triggerToNodes!=null){let i=new Set;for(let n of r.updatedChannels){let a=r.triggerToNodes[n];for(let o of a??[])i.add(o)}yield*[...i].sort();return}if(!(()=>{for(let i in e.channel_versions)if(e.channel_versions[i]!==null)return!1;return!0})())for(let i in t)Object.prototype.hasOwnProperty.call(t,i)&&(yield i)}function pa(e,t,r,i,n,a,o){let s={},c=i[In];if(c?.isAvailable()){let u=c.get().length;for(let l=0;l<u;l+=1){let d=oh([jr,l],e,t,r,i,n,a,o);d!==void 0&&(s[d.id]=d)}}for(let u of D9(e,r,o)){let l=oh([Nl,u],e,t,r,i,n,a,o);l!==void 0&&(s[l.id]=l)}return s}function oh(e,t,r,i,n,a,o,s){let{step:c,checkpointer:u,manager:l}=s,d=a.configurable??{},f=d.checkpoint_ns??"";if(e[0]==="__pregel_push"&&RR(e[e.length-1])){let p=e[e.length-1],m=MR(p.name,p.func),g=[jr],v=f===""?p.name:`${f}|${p.name}`,b=ni(JSON.stringify([v,c.toString(),p.name,jr,e[1],e[2]]),t.id),w=`${v}:${b}`,S=[...e.slice(0,3),!0],k={langgraph_step:c,langgraph_node:p.name,langgraph_triggers:g,langgraph_path:S,langgraph_checkpoint_ns:w,checkpoint_ns:w};if(o){let I=[],Z={checkpointId:t.id,checkpointNs:w,taskId:b,threadId:d.thread_id,runId:a.runId!=null?String(a.runId):void 0,nodeAttempt:1};return{name:p.name,input:p.input,proc:m,writes:I,config:{...$e(xt(a,{metadata:k,store:s.store??a.store}),{runName:p.name,callbacks:l?.getChild(`graph:step:${c}`),configurable:{[$c]:b,[Nr]:C=>X0(y=>I.push(...y),i,C),[Yr]:(C,y=!1)=>kl(t,n,{name:p.name,writes:I,triggers:g,path:S},C,y),[Qr]:u??d.__pregel_checkpointer,[Mr]:{...d[Mr],[f]:t.id},[ar]:Y0({pendingWrites:r??[],taskId:b,currentTaskInput:p.input,resumeMap:a.configurable?.[Do],namespaceHash:ki(w)}),[xa]:t.channel_values[Sa],checkpoint_id:void 0,checkpoint_ns:w}}),executionInfo:Z},triggers:g,retry_policy:p.retry,cache_key:p.cache?{key:ki((p.cache.keyFunc??JSON.stringify)([p.input])),ns:[Ol,p.name??"__dynamic__"],ttl:p.cache.ttl}:void 0,id:b,path:S,writers:[]}}else return{id:b,name:p.name,interrupts:[],path:S}}else if(e[0]==="__pregel_push"){let p=typeof e[1]=="number"?e[1]:parseInt(e[1],10);if(!n.__pregel_tasks?.isAvailable())return;let m=n[In].get();if(p<0||p>=m.length)return;let g=Rl(m[p])&&!mt(m[p])?new wa(m[p].node,m[p].args):m[p];if(!Rl(g)){console.warn(`Ignoring invalid packet ${JSON.stringify(g)} in pending sends.`);return}if(!(g.node in i)){console.warn(`Ignoring unknown node name ${g.node} in pending sends.`);return}let v=[jr],b=f===""?g.node:`${f}|${g.node}`,w=ni(JSON.stringify([b,c.toString(),g.node,jr,p.toString()]),t.id),S=`${b}:${w}`,k={langgraph_step:c,langgraph_node:g.node,langgraph_triggers:v,langgraph_path:e.slice(0,3),langgraph_checkpoint_ns:S,checkpoint_ns:S};if(o){let I=i[g.node],Z=I.getNode();if(Z!==void 0){I.metadata!==void 0&&(k={...k,...I.metadata});let C=[],y={checkpointId:t.id,checkpointNs:S,taskId:w,threadId:d.thread_id,runId:a.runId!=null?String(a.runId):void 0,nodeAttempt:1};return{name:g.node,input:g.args,proc:Z,subgraphs:I.subgraphs,writes:C,config:{...$e(xt(a,{metadata:k,tags:I.tags,store:s.store??a.store}),{runName:g.node,callbacks:l?.getChild(`graph:step:${c}`),configurable:{[$c]:w,[Nr]:V=>X0(B=>C.push(...B),i,V),[Yr]:(V,B=!1)=>kl(t,n,{name:g.node,writes:C,triggers:v,path:e},V,B),[Qr]:u??d.__pregel_checkpointer,[Mr]:{...d[Mr],[f]:t.id},[ar]:Y0({pendingWrites:r??[],taskId:w,currentTaskInput:g.args,resumeMap:a.configurable?.[Do],namespaceHash:ki(S)}),[xa]:t.channel_values[Sa],checkpoint_id:void 0,checkpoint_ns:S}}),executionInfo:y},triggers:v,retry_policy:I.retryPolicy,cache_key:I.cachePolicy?{key:ki((I.cachePolicy.keyFunc??JSON.stringify)([g.args])),ns:[Ol,I.name??"__dynamic__",g.node],ttl:I.cachePolicy.ttl}:void 0,id:w,path:e,writers:I.getWriters()}}}else return{id:w,name:g.node,interrupts:[],path:e}}else if(e[0]==="__pregel_pull"){let p=e[1].toString(),m=i[p];if(m===void 0)return;if(r?.length){let w=f===""?p:`${f}|${p}`,S=ni(JSON.stringify([w,c.toString(),p,Nl,p]),t.id);if(r.some(k=>k[0]===S&&k[1]!=="__error__"))return}let g=ah(t.channel_versions);if(g===void 0)return;let v=t.versions_seen[p]??{},b=m.triggers.find(w=>n[w].isAvailable()?(t.channel_versions[w]??g)>(v[w]??g):!1);if(b!==void 0){let w=U9(m,n,o);if(w===void 0)return;let S=f===""?p:`${f}|${p}`,k=ni(JSON.stringify([S,c.toString(),p,Nl,[b]]),t.id),I=`${S}:${k}`,Z={langgraph_step:c,langgraph_node:p,langgraph_triggers:[b],langgraph_path:e,langgraph_checkpoint_ns:I,checkpoint_ns:I};if(o){let C=m.getNode();if(C!==void 0){m.metadata!==void 0&&(Z={...Z,...m.metadata});let y=[],V={checkpointId:t.id,checkpointNs:I,taskId:k,threadId:d.thread_id,runId:a.runId!=null?String(a.runId):void 0,nodeAttempt:1};return{name:p,input:w,proc:C,subgraphs:m.subgraphs,writes:y,config:{...$e(xt(a,{metadata:Z,tags:m.tags,store:s.store??a.store}),{runName:p,callbacks:l?.getChild(`graph:step:${c}`),configurable:{[$c]:k,[Nr]:B=>X0(A=>{y.push(...A)},i,B),[Yr]:(B,A=!1)=>kl(t,n,{name:p,writes:y,triggers:[b],path:e},B,A),[Qr]:u??d.__pregel_checkpointer,[Mr]:{...d[Mr],[f]:t.id},[ar]:Y0({pendingWrites:r??[],taskId:k,currentTaskInput:w,resumeMap:a.configurable?.[Do],namespaceHash:ki(I)}),[xa]:t.channel_values[Sa],checkpoint_id:void 0,checkpoint_ns:I}}),executionInfo:V},triggers:[b],retry_policy:m.retryPolicy,cache_key:m.cachePolicy?{key:ki((m.cachePolicy.keyFunc??JSON.stringify)([w])),ns:[Ol,m.name??"__dynamic__",p],ttl:m.cachePolicy.ttl}:void 0,id:k,path:e,writers:m.getWriters()}}}else return{id:k,name:p,interrupts:[],path:e}}}}function U9(e,t,r){let i;if(typeof e.channels=="object"&&!Array.isArray(e.channels)){i={};for(let[n,a]of Object.entries(e.channels))if(e.triggers.includes(a))try{i[n]=Co(t,a,!1)}catch(o){if(o.name===Ne.unminifiable_name)return;throw o}else if(a in t)try{i[n]=Co(t,a,!1)}catch(o){if(o.name===Ne.unminifiable_name)continue;throw o}}else if(Array.isArray(e.channels)){let n=!1;for(let a of e.channels)try{i=Co(t,a,!1),n=!0;break}catch(o){if(o.name===Ne.unminifiable_name)continue;throw o}if(!n)return}else throw new Error(`Invalid channels type, expected list or dict, got ${e.channels}`);return r&&e.mapper!==void 0&&(i=e.mapper(i)),i}function UR(e,t){if(typeof e.args!="object"||e.args===null)return e;let r={};for(let[i,n]of Object.entries(e.args)){let a=t[i];(!a||a.lc_graph_name!=="UntrackedValue")&&(r[i]=n)}return new wa(e.node,r)}function Y0({pendingWrites:e,taskId:t,currentTaskInput:r,resumeMap:i,namespaceHash:n}){let a=e.find(([s,c])=>s==="00000000-0000-0000-0000-000000000000"&&c==="__resume__")?.[2],o={callCounter:0,interruptCounter:-1,resume:(()=>{let s=e.filter(([c,u])=>c===t&&u==="__resume__").flatMap(([c,u,l])=>l);if(i!=null&&n in i){let c=i[n];s.push(c)}return s})(),nullResume:a,subgraphCounter:0,currentTaskInput:r,consumeNullResume:()=>{if(o.nullResume)return delete o.nullResume,e.splice(e.findIndex(([s,c])=>s==="00000000-0000-0000-0000-000000000000"&&c==="__resume__"),1),a}};return o}var El={blue:{start:"\x1B[34m",end:"\x1B[0m"},green:{start:"\x1B[32m",end:"\x1B[0m"},yellow:{start:"\x1B[33;1m",end:"\x1B[0m"}},Il=(e,t)=>`${e.start}${t}${e.end}`;function*Q0(e){for(let{id:t,name:r,input:i,config:n,triggers:a,writes:o}of e)n?.tags?.includes("langsmith:hidden")||(yield{id:t,name:r,input:i,triggers:a,interrupts:o.filter(([s,c])=>s===t&&c==="__interrupt__").map(([,s])=>s)})}function L9(e){return typeof e!="object"||e===null?!1:"$writes"in e&&Array.isArray(e.$writes)}function LR(e){let t={};for(let[r,i]of e){let n=String(r);if(n in t){let a=L9(t[n])?t[n].$writes:[t[n]];a.push(i),t[n]={$writes:a}}else t[n]=i}return t}function*FR(e,t){for(let[{id:r,name:i,config:n},a]of e)n?.tags?.includes("langsmith:hidden")||(yield{id:r,name:i,result:LR(a.filter(([o])=>Array.isArray(t)?t.includes(o):o===t)),interrupts:a.filter(o=>o[0]===Ue).map(o=>o[1])})}function*BR(e,t,r,i,n,a,o,s){function c(d){let f={};return d.callbacks!=null&&(f.callbacks=d.callbacks),d.configurable!=null&&(f.configurable=d.configurable),d.maxConcurrency!=null&&(f.max_concurrency=d.maxConcurrency),d.metadata!=null&&(f.metadata=d.metadata),d.recursionLimit!=null&&(f.recursion_limit=d.recursionLimit),d.runId!=null&&(f.run_id=d.runId),d.runName!=null&&(f.run_name=d.runName),d.tags!=null&&(f.tags=d.tags),f}let u=e.configurable?.checkpoint_ns,l={};for(let d of n){if(!(d.subgraphs?.length?d.subgraphs:[d.proc]).find(rh))continue;let f=`${d.name}:${d.id}`;u&&(f=`${u}|${f}`),l[d.id]={configurable:{thread_id:e.configurable?.thread_id,checkpoint_ns:f}}}yield{config:c(e),values:wn(t,r),metadata:i,next:n.map(d=>d.name),tasks:eS(n,a,l,s),parentConfig:o?c(o):void 0}}function eS(e,t,r,i){return e.map(n=>{let a=t.find(([u,l])=>u===n.id&&l==="__error__")?.[2],o=t.filter(([u,l])=>u===n.id&&l==="__interrupt__").map(([,,u])=>u),s=(()=>{if(a||o.length||!t.length)return;let u=t.findIndex(([l,d])=>l===n.id&&d==="__return__");if(u>=0)return t[u][2];if(typeof i=="string")return t.find(([l,d])=>l===n.id&&d===i)?.[2];if(Array.isArray(i)){let l=t.filter(([d,f])=>d===n.id&&i.includes(f)).map(([,d,f])=>[d,f]);return l.length?LR(l):void 0}})();if(a)return{id:n.id,name:n.name,path:n.path,error:a,interrupts:o,result:s};let c=r?.[n.id];return{id:n.id,name:n.name,path:n.path,interrupts:o,...c!==void 0?{state:c}:{},result:s}})}function VR(e,t,r){console.log([`${Il(El.blue,`[${e}:checkpoint]`)}`,`\x1B[1m State at the end of step ${e}:\x1B[0m
415
+ `))}catch(s){o.error(s)}},async cancel(){await i.return?.()}})}get(t){if(t<0||t>=this.#e.length)throw new RangeError(`StreamChannel index ${t} out of bounds (size=${this.#e.length})`);return this.#e[t]}get size(){return this.#e.length}get done(){return this.#r}close(){this.#r=!0,this.#t()}fail(t){this.#i=t,this.#r=!0,this.#t()}_wire(t){this.#n=t}_close(){this.close()}_fail(t){this.fail(t)}[Symbol.asyncIterator](){return this.iterate()}#t(){let t=this.#o.splice(0);for(let r of t)r()}};function dR(e){return Wr.isInstance(e)}var c9="custom:";function u9(e){return`${c9}${e}`}function l9(e){return e!=null&&(typeof e=="object"||typeof e=="function")&&typeof e.then=="function"}var Zm=Symbol("resolveValues"),R0=Symbol("rejectValues"),fR=class{_events=Wr.local();_discoveries=Wr.local();#e=0;#o=!1;#r;#i=!1;#n=[];#t=[];#s=[];#a=new Map;#u=new Map;#c=[];#l=[];register(e,t){this.#a.set(Bt(e),t)}addTransformer(e){let t=this._events.size;this.#t.push(e),e.onRegister&&e.onRegister({push:(r,i)=>this.push(r,i)});for(let r=0;r<t;r+=1)e.process(this._events.get(r));this.#o&&(this.#r!==void 0?e.fail?.(this.#r):e.finalize?.())}wireChannels(e){for(let[t,r]of Object.entries(e)){if(dR(r)){if(this.#s.push(r),typeof r.channelName!="string")continue;let i=u9(r.channelName);r._wire(n=>{this._events.push({type:"event",seq:this.#e++,method:i,params:{namespace:this.#n,timestamp:Date.now(),data:n}})});continue}l9(r)&&this.#l.push({name:t,promise:Promise.resolve(r)})}}push(e,t){t.method==="values"&&this.#u.set(Bt(e),t.params.data);let r=this.#n;this.#n=e;let i=!0;for(let n of this.#t)n.process(t)||(i=!1);this.#n=r,i&&this._events.push({...t,seq:this.#e++})}close(){this.#o=!0;for(let[r,i]of this.#u.entries()){let n=r?r.split("\0"):[];this.#a.get(Bt(n))?.[Zm](i)}let e=[];for(let r of this.#t){let i=r.finalize?.();i!=null&&typeof i.then=="function"&&e.push(i)}for(let r of this.#s)r._close();let t=this.#l;t.length===0&&e.length===0?(this._events.close(),this._discoveries.close()):Promise.allSettled([...e,...t.map(async({name:r,promise:i})=>{try{let n=await i;this._events.done||this._events.push({type:"event",seq:this.#e++,method:"custom",params:{namespace:[],timestamp:Date.now(),data:{name:r,payload:n}}})}catch{}})]).then(()=>{this._events.close(),this._discoveries.close()});for(let r of this.#a.values())r[Zm](void 0)}fail(e){this.#o=!0,this.#r=e;for(let t of this.#t)t.fail?.(e);for(let t of this.#s)t._fail(e);this._events.fail(e),this._discoveries.fail(e);for(let t of this.#a.values())t[R0](e)}markInterrupted(e){this.#i=!0,this.#c.push(...e)}get interrupted(){return this.#i}get interrupts(){return this.#c}subscribeEvents(e,t=0){let r=this._events.iterate(t);return{async next(){for(;;){let i=await r.next();if(i.done||qn(i.value.params.namespace,e))return i}}}}};async function pR(e,t){let r=0;try{for await(let i of e){let[n,a,o]=i;if(a==="values"&&ka(o)){let c=o[Ue];t.markInterrupted(c.map(u=>({interruptId:u.id??"",payload:u.value})))}let s=O0({namespace:n,mode:a,payload:o,seq:r});r+=s.length;for(let c of s)t.push(n,c)}}catch(i){t.fail(i);return}t.close()}function Bt(e){return e.join("\0")}function qn(e,t){if(t.length>e.length)return!1;for(let r=0;r<t.length;r+=1)if(e[r]!==t[r])return!1;return!0}function Gm(e,t,r=0){return{[Symbol.asyncIterator](){let i=e.iterate(r);return{async next(){for(;;){let n=await i.next();if(n.done)return{value:void 0,done:!0};if(qn(n.value.namespace,t))return{value:n.value,done:!1}}}}}}}var mR="root";function d9(e){if(e.length===0)return mR;let t=e[e.length-1],r=t.indexOf(":");return r===-1?t:t.slice(0,r)}function f9(e){if(e instanceof Error)return e.message;if(typeof e=="string")return e;try{return JSON.stringify(e)}catch{return String(e)}}function Hm(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function p9(e){if(!Hm(e)||e.event!=="started")return;let t=e.cause;if(Hm(t)&&typeof t.type=="string")return t}function m9(e){if(Hm(e)&&"result"in e&&typeof e.name=="string"&&typeof e.id=="string"&&!e.name.startsWith("__"))return{name:e.name,id:e.id}}function M0(e={}){let t=e.rootGraphName??mR,r=e.initialStatus??"running",i=e.emitRootOnRegister??!0,n=e.getGraphName??d9,a=e.serializeError??f9,o=e.getTerminalStatusOverride,s=Wr.local(),c=new Map,u=new Map,l=new Set,d=[],f,p=0,m=!1,g=A=>A.length===0?t:n(A),v=(A,U,G)=>{let Y=Bt(A),Ie=c.get(Y),me=Ie?.graphName??g(A);if(Ie!=null&&Ie.status===U&&Ie.graphName===me&&G?.error==null)return;Ie==null?(Ie={namespace:A,graphName:me,status:U},c.set(Y,Ie)):Ie.status=U;let Sn={event:U,graph_name:me,...G?.cause!=null?{cause:G.cause}:{},...G?.error!=null?{error:G.error}:{}},Or=Date.now();if(s.push({namespace:A,timestamp:Or,...Sn}),!(A.length===0&&!i)&&f!=null){p+=1;try{f.push(A,{type:"event",seq:0,method:"lifecycle",params:{namespace:A,timestamp:Or,data:Sn}})}finally{p-=1}}},b=A=>{let U=Bt(A),G=c.get(U);return G==null&&(G={namespace:A,graphName:g(A),status:void 0},c.set(U,G)),G},w=()=>{if(d.length===0)return;let A=d.splice(0,d.length);for(let U of A){let G=Bt(U.namespace),Y=c.get(G);Y==null||Y.status!=="started"||v(U.namespace,"completed")}},S=A=>{let U=Bt(A.namespace),G=c.get(U);G==null||G.status!=="started"||d.some(Y=>Bt(Y.namespace)===U)||d.push(A)},k=(A,U)=>{for(let G=d.length-1;G>=0;G-=1){let Y=d[G];Y.source.type==="node"&&Y.source.node===U&&Bt(Y.source.parent)===Bt(A)&&d.splice(G,1)}},I=A=>{for(let U=1;U<=A.length;U+=1){let G=A.slice(0,U),Y=Bt(G);if(c.has(Y))continue;b(G);let Ie=u.get(Y);v(G,"started",Ie!=null?{cause:Ie}:void 0)}},Z=()=>l.size>0?"interrupted":"completed",C=A=>{for(let U of c.values())U.namespace.length!==0&&U.status==="started"&&v(U.namespace,A);v([],A),s.close()},y=async()=>{if(o==null)return Z();try{return await o()??Z()}catch{return Z()}},V=(A,U)=>{let G=`${U}:`;for(let Y of c.values()){if(Y.namespace.length!==A.length+1||Y.status!=="started"||!qn(Y.namespace,A))continue;let Ie=Y.namespace[Y.namespace.length-1];if(Ie===U||Ie.startsWith(G))return Y.namespace}},B=(A,U)=>{let G=[...A,`${U.name}:${U.id}`];return c.get(Bt(G))?.status==="started"?G:void 0};return{__native:!0,init(){return{_lifecycleLog:s,lifecycle:Gm(s,[],0)}},onRegister(A){f=A,b([]),i&&v([],r)},process(A){let U=A.params.namespace;if(p>0)return!0;let G=A.method==="tasks"?m9(A.params.data):void 0;if(G!=null&&k(U,G.name),w(),A.method==="lifecycle"){let Y=p9(A.params.data);return Y!=null&&u.set(Bt(U),Y),I(U),!1}if(I(U),A.method==="input"&&Hm(A.params.data)&&A.params.data.event==="requested"){let Y=A.params.data.id;typeof Y=="string"&&l.add(Y)}if(G!=null){let Y=B(U,G);Y!=null&&S({namespace:Y,source:{type:"task"}})}if(A.method==="updates"){let Y=A.params.node;if(typeof Y=="string"&&!Y.startsWith("__")){let Ie=V(U,Y);Ie!=null&&S({namespace:Ie,source:{type:"node",parent:U,node:Y}})}}return!0},finalize(){if(!m){if(m=!0,w(),o==null){C(Z());return}return y().then(C).catch(A=>{s.fail(A)})}},fail(A){if(m)return;m=!0;let U=a(A);for(let G of c.values())G.namespace.length!==0&&G.status==="started"&&v(G.namespace,"failed");v([],"failed",{error:U}),s.fail(A)}}}function hc(e){let t=e;return typeof t.run_id=="string"?`run:${t.run_id}`:e.event==="message-start"&&typeof t.id=="string"?`message:${t.id}`:"__default__"}function bl(e,t){let r=Wr.local(),i=new Map,n=new Set;return{init:()=>({messages:r.toAsyncIterable()}),process(a){if(a.method!=="messages"||!qn(a.params.namespace,e)||a.params.namespace.length!==e.length+1||t!==void 0&&a.params.node!==t)return!0;let o=a.params.data;switch(o.event){case"message-start":{let s=hc(o);if(o.role==="tool"){n.add(s);break}let c=Wr.local(),u=Object.assign(new ca(c.toAsyncIterable()),{namespace:a.params.namespace,node:a.params.node});i.set(s,{source:c,stream:u}),c.push(o),r.push(u);break}case"content-block-start":case"content-block-delta":case"content-block-finish":if(n.has(hc(o)))break;i.get(hc(o))?.source.push(o);break;case"message-finish":{let s=hc(o);if(n.delete(s))break;let c=i.get(s);c&&(c.source.push(o),c.source.close(),i.delete(s));break}case"error":if(n.has(hc(o)))break;i.get(hc(o))?.source.push(o);break}return!0},finalize(){for(let[a,o]of i)o.source.push({event:"message-finish"}),o.source.close(),i.delete(a);n.clear(),r.close()},fail(a){for(let[o,s]of i)s.source.fail(a),i.delete(o);n.clear(),r.fail(a)}}}function wl(e,t,r=0){let i=t.length+1;return{[Symbol.asyncIterator](){let n=e.iterate(r);return{async next(){for(;;){let a=await n.next();if(a.done)return{value:void 0,done:!0};let{ns:o,stream:s}=a.value;if(o.length===i&&qn(o,t))return{value:s,done:!1}}}}}}}function j0(e,t){let{createStream:r}=t,i=new Set;return{__native:!0,init(){return{_discoveries:e._discoveries,subgraphs:wl(e._discoveries,[],0)}},process(n){let a=n.params.namespace;if(a.length===0)return!0;let o=a.slice(0,1),s=Bt(o);if(i.has(s))return!0;i.add(s);let c=r(o,e._discoveries.size,e._events.size);return e.register(o,c),e._discoveries.push({ns:o,stream:c}),!0}}}function z0(e){let t=Wr.local();return{init:()=>({_valuesLog:t}),process(r){return r.method!=="values"||r.params.namespace.length!==e.length||!qn(r.params.namespace,e)||t.push(r.params.data),!0},finalize(){t.close()},fail(r){t.fail(r)}}}function Jm(e){return"__native"in e&&e.__native===!0}var hR=Symbol("setValuesLog"),gR=Symbol("setMessagesIterable"),D0=Symbol("setLifecycleIterable"),U0=Symbol("setSubgraphsIterable"),h9={[Symbol.asyncIterator](){return{next:()=>Promise.resolve({value:void 0,done:!0})}}},L0=class{path;extensions;_mux;#e;#o;#r;#i;#n;#t;#s;#a;#u;#c;constructor(e,t,r=0,i=0,n,a){this.path=e,this._mux=t,this.#o=r,this.#e=i,this.extensions=n??{},this.#r=a??new AbortController,this.#t=new Promise((o,s)=>{this.#i=o,this.#n=s}),this.#t.catch(()=>{})}[Symbol.asyncIterator](){return this._mux.subscribeEvents(this.path,this.#e)}get subgraphs(){return this.#c?this.#c:wl(this._mux._discoveries,this.path,this.#o)}get values(){let e=this.#s,t=this.#t,r=this._mux,i=this.#e,n=this.path,a=e?e.toAsyncIterable():{[Symbol.asyncIterator]:()=>{let o=r.subscribeEvents(n,i);return{async next(){for(;;){let s=await o.next();if(s.done)return{value:void 0,done:!0};if(s.value.method==="values"&&s.value.params.namespace.length===n.length)return{value:s.value.params.data,done:!1}}}}}};return{[Symbol.asyncIterator]:()=>a[Symbol.asyncIterator](),then:t.then.bind(t)}}get messages(){if(this.#a)return this.#a;let e=bl(this.path),t=e.init();return this._mux.addTransformer(e),this.#a=t.messages,this.#a}get lifecycle(){return this.#u??h9}messagesFrom(e){let t=bl(this.path,e),r=t.init();return this._mux.addTransformer(t),r.messages}get output(){return this.#t}get interrupted(){return this._mux.interrupted}get interrupts(){return this._mux.interrupts}abort(e){this.#r.abort(e)}get signal(){return this.#r.signal}[Zm](e){this.#i?.(e),this.#i=void 0}[R0](e){this.#n?.(e),this.#n=void 0}[hR](e){this.#s=e}[gR](e){this.#a=e}[D0](e){this.#u=e}[U0](e){this.#c=e}},_R=class extends L0{name;index;constructor(e,t,r=0,i=0,n,a){super(e,t,r,i,n,a);let o=e[e.length-1]??"",s=o.lastIndexOf(":");if(s>=0){this.name=o.slice(0,s);let c=o.slice(s+1);this.index=/^\d+$/.test(c)?Number(c):0}else this.name=o,this.index=0}};function F0(e,t=[],r){let{abortController:i}=r instanceof AbortController?{abortController:r}:r??{},n=new fR,a=M0(),o=a.init(),s=o._lifecycleLog,c=j0(n,{createStream:(b,w,S)=>{let k=new _R(b,n,w,S);return k[U0](wl(n._discoveries,b,w)),k[D0](Gm(s,b,s.size)),k}}),u=c.init();n.addTransformer(c),n.addTransformer(a);let l=z0([]),d=bl([]);n.addTransformer(l),n.addTransformer(d);let f={},p=[];for(let b of t){let w=b();n.addTransformer(w);let S=w.init();Jm(w)?p.push(S):Object.assign(f,S),typeof S=="object"&&S!==null&&!Jm(w)&&n.wireChannels(S)}let m=new L0([],n,0,0,f,i);for(let b of p)Object.assign(m,b);let g=l.init();m[hR](g._valuesLog);let v=d.init();return m[gR](v.messages),m[D0](o.lifecycle),m[U0](u.subgraphs),n.register([],m),pR(e,n).catch(b=>{}),m}var F=e=>BigInt(e),De=(e,t=0)=>new DataView(e.buffer,e.byteOffset+t,e.byteLength-t),wR=F("0x9E3779B1"),xR=F("0x85EBCA77"),g9=F("0xC2B2AE3D"),da=F("0x9E3779B185EBCA87"),Io=F("0xC2B2AE3D27D4EB4F"),SR=F("0x165667B19E3779F9"),Z0=F("0x85EBCA77C2B2AE63"),_9=F("0x27D4EB2F165667C5"),y9=F("0x165667919E3779F9"),v9=F("0x9FB21C651E98DF25"),b9=e=>{let t=e.length;if(t%2!==0)throw new Error("String should have an even number of characters");let r=t/2,i=new Uint8Array(r),n=0,a=0;for(;a<r;){let o=e.slice(n,n+=2);i[a]=Number.parseInt(o,16),a+=1}return De(i)},Xn=b9("b8fe6c3923a44bbe7c01812cf721ad1cded46de9839097db7240a4a4b7b3671fcb79e64eccc0e578825ad07dccff7221b8084674f743248ee03590e6813a264c3c2852bb91c300cb88d0658b1b532ea371644897a20df94e3819ef46a9deacd8a8fa763fe39c343ff9dcbbc7c70b4f1d8a51e04bcdb45931c89f7ec9d9787364eac5ac8334d3ebc3c581a0fffa1363eb170ddd51b7f0da49d316552629d4689e2b16be587d47a1fc8ff8b8d17ad031ce45cb3a8f95160428afd7fbcabb4b407e"),gc=(F(1)<<F(128))-F(1),ve=(F(1)<<F(64))-F(1),Xm=(F(1)<<F(32))-F(1),Si=64,kR=Si/8,w9=8,Km=4;function _c(e){if(!e)throw new Error("Assert failed")}function x9(e){let t=new DataView(new ArrayBuffer(8));return t.setBigUint64(0,e,!0),t.getBigUint64(0,!1)}function S9(e){let t=e;return t=(t&F(65535))<<F(16)|(t&F(4294901760))>>F(16),t=(t&F(16711935))<<F(8)|(t&F(4278255360))>>F(8),t}function k9(e,t){return(e&Xm)*(t&Xm)&ve}function $9(e,t){return(e<<t|e>>F(32)-t)&Xm}function $R(e,t,r){for(let i=0;i<kR;i+=1){let n=t.getBigUint64(i*8,!0),a=n^r.getBigUint64(i*8,!0);e[i^1]+=n,e[i]+=k9(a,a>>F(32))}return e}function yR(e,t,r,i){for(let n=0;n<i;n+=1)$R(e,De(t,n*Si),De(r,n*8));return e}function E9(e,t){for(let r=0;r<kR;r+=1){let i=t.getBigUint64(r*8,!0),n=e[r];n=B0(n,F(47)),n^=i,n*=wR,e[r]=n&ve}return e}function Wm(e,t){return ER(e[0]^t.getBigUint64(0,!0),e[1]^t.getBigUint64(w9,!0))}function vR(e,t,r){let i=r;return i+=Wm(e.slice(0),De(t,0*Km)),i+=Wm(e.slice(2),De(t,4*Km)),i+=Wm(e.slice(4),De(t,8*Km)),i+=Wm(e.slice(6),De(t,12*Km)),Yn(i&ve)}function I9(e,t,r,i,n){let a=e,o=Math.floor((r.byteLength-Si)/8),s=Si*o,c=Math.floor((t.byteLength-1)/s);for(let u=0;u<c;u+=1)a=yR(a,De(t,u*s),r,o),a=n(a,De(r,r.byteLength-Si));{let u=Math.floor((t.byteLength-1-s*c)/Si);a=yR(a,De(t,c*s),r,u),a=i(a,De(t,t.byteLength-Si),De(r,r.byteLength-Si-7))}return a}function T9(e,t){let r=new BigUint64Array([g9,da,Io,SR,Z0,xR,_9,wR]);_c(e.byteLength>128),r=I9(r,e,t,$R,E9),_c(r.length*8===64);{let i=vR(r,De(t,11),F(e.byteLength)*da&ve);return vR(r,De(t,t.byteLength-Si-11),~(F(e.byteLength)*Io)&ve)<<F(64)|i}}function ER(e,t){let r=e*t&gc;return r&ve^r>>F(64)}function bR(e,t,r){return ER((e.getBigUint64(0,!0)^t.getBigUint64(0,!0)+r)&ve,(e.getBigUint64(8,!0)^t.getBigUint64(8,!0)-r)&ve)}function qm(e,t,r,i,n){let a=e&ve,o=e>>F(64)&ve;return a+=bR(t,i,n),a^=r.getBigUint64(0,!0)+r.getBigUint64(8,!0),a&=ve,o+=bR(r,De(i,16),n),o^=t.getBigUint64(0,!0)+t.getBigUint64(8,!0),o&=ve,o<<F(64)|a}function Yn(e){let t=e;return t^=t>>F(37),t*=y9,t&=ve,t^=t>>F(32),t}function Ym(e){let t=e;return t^=t>>F(33),t*=Io,t&=ve,t^=t>>F(29),t*=SR,t&=ve,t^=t>>F(32),t}function A9(e,t,r){let i=e.byteLength;_c(i>0&&i<=3);let n=F(e.getUint8(i-1))|F(i<<8)|F(e.getUint8(0)<<16)|F(e.getUint8(i>>1)<<24),a=(n^(F(t.getUint32(0,!0))^F(t.getUint32(4,!0)))+r)&ve,o=(F(t.getUint32(8,!0))^F(t.getUint32(12,!0)))-r;return(Ym(($9(S9(n),F(13))^o)&ve)&ve)<<F(64)|Ym(a)}function B0(e,t){return e^e>>t}function C9(e,t,r){let i=e.byteLength;_c(i>=4&&i<=8);{let n=e.getUint32(0,!0),a=e.getUint32(i-4,!0),o=((F(n)|F(a)<<F(32))^(t.getBigUint64(16,!0)^t.getBigUint64(24,!0))+r&ve)*(da+(F(i)<<F(2)))&gc;return o+=(o&ve)<<F(65),o&=gc,o^=o>>F(67),B0(B0(o&ve,F(35))*v9&ve,F(28))|Yn(o>>F(64))<<F(64)}}function O9(e,t,r){let i=e.byteLength;_c(i>=9&&i<=16);{let n=(t.getBigUint64(32,!0)^t.getBigUint64(40,!0))+r&ve,a=(t.getBigUint64(48,!0)^t.getBigUint64(56,!0))-r&ve,o=e.getBigUint64(0,!0),s=e.getBigUint64(i-8,!0),c=(o^s^n)*da,u=(c&ve)+(F(i-1)<<F(54));c=c&(gc^ve)|u,s^=a,c+=s+(s&Xm)*(xR-F(1))<<F(64),c&=gc,c^=x9(c>>F(64));let l=(c&ve)*Io;return l+=(c>>F(64))*Io<<F(64),l&=gc,Yn(l&ve)|Yn(l>>F(64))<<F(64)}}function P9(e,t){let r=e.byteLength;return _c(r<=16),r>8?O9(e,Xn,t):r>=4?C9(e,Xn,t):r>0?A9(e,Xn,t):Ym(t^Xn.getBigUint64(64,!0)^Xn.getBigUint64(72,!0))|Ym(t^Xn.getBigUint64(80,!0)^Xn.getBigUint64(88,!0))<<F(64)}function V0(e){return~e+F(1)&ve}function N9(e,t,r){let i=F(e.byteLength)*da&ve,n=F(e.byteLength-1)/F(32);for(;n>=0;){let s=Number(n);i=qm(i,De(e,16*s),De(e,e.byteLength-16*(s+1)),De(t,32*s),r),n-=F(1)}let a=i+(i>>F(64))&ve;a=Yn(a);let o=(i&ve)*da+(i>>F(64))*Z0+(F(e.byteLength)-r&ve)*Io;return o&=ve,o=V0(Yn(o)),a|o<<F(64)}function R9(e,t,r){let i=F(e.byteLength)*da&ve;for(let o=32;o<160;o+=32)i=qm(i,De(e,o-32),De(e,o-16),De(t,o-32),r);i=Yn(i&ve)|Yn(i>>F(64))<<F(64);for(let o=160;o<=e.byteLength;o+=32)i=qm(i,De(e,o-32),De(e,o-16),De(t,3+o-160),r);i=qm(i,De(e,e.byteLength-16),De(e,e.byteLength-32),De(t,103),V0(r));let n=i+(i>>F(64))&ve;n=Yn(n);let a=(i&ve)*da+(i>>F(64))*Z0+(F(e.byteLength)-r&ve)*Io;return a&=ve,a=V0(Yn(a)),n|a<<F(64)}function ki(e,t=F(0)){let r=new TextEncoder,i=De(typeof e=="string"?r.encode(e):e),n=i.byteLength,a=o=>o.toString(16).padStart(32,"0");return n<=16?a(P9(i,t)):n<=128?a(N9(i,Xn,t)):n<=240?a(R9(i,Xn,t)):a(T9(i,Xn))}function Qm(e){return/^[0-9a-f]{32}$/.test(e)}function H0(e){let t=Ae.getRunnableConfig();if(!t)throw new Error("Called interrupt() outside the context of a graph.");let r=t.configurable;if(!r)throw new Error("No configurable found in config");if(!r.__pregel_checkpointer)throw new $a("No checkpointer set",{lc_error_code:"MISSING_CHECKPOINTER"});let i=r[ar];i.interruptCounter+=1;let n=i.interruptCounter;if(i.resume.length>0&&n<i.resume.length)return r[Nr]?.([[_r,i.resume]]),i.resume[n];if(i.nullResume!==void 0){if(i.resume.length!==n)throw new Error(`Resume length mismatch: ${i.resume.length} !== ${n}`);let o=i.consumeNullResume();return i.resume.push(o),r[Nr]?.([[_r,i.resume]]),o}let a=r[Rr]?.split("|");throw new ti([{id:a?ki(a.join("|")):void 0,value:e}])}var Vt=class extends ae{lc_namespace=["langgraph"];func;tags;config;trace=!0;recurse=!0;constructor(e){super(),this.name=e.name??e.func.name,this.func=e.func,this.config=e.tags?{tags:e.tags}:void 0,this.trace=e.trace??this.trace,this.recurse=e.recurse??this.recurse}async _tracedInvoke(e,t,r){return new Promise((i,n)=>{let a=$e(t,{callbacks:r?.getChild()});Ae.runWithConfig(a,async()=>{try{i(await this.func(e,a))}catch(o){n(o)}})})}async invoke(e,t){let r,i=pc(t),n=xt(this.config,i);return this.trace?r=await this._callWithConfig(this._tracedInvoke,e,n):r=await Ae.runWithConfig(n,async()=>this.func(e,n)),ae.isRunnable(r)&&this.recurse?await Ae.runWithConfig(n,async()=>r.invoke(e,n)):r}};function*$i(e,t){if(t===void 0)yield*e;else for(let r of e)yield[t,r]}async function vn(e){let t=[];for await(let r of await e)t.push(r);return t}function To(e){let t=[];for(let r of e)t.push(r);return t}function Ao(e,t){return e?"configurable"in e?{...e,configurable:{...e.configurable,...t}}:{...e,configurable:t}:{configurable:t}}function G0(e){return e!=null&&typeof e=="function"&&e instanceof Object.getPrototypeOf(async function*(){}).constructor}function J0(e){return e!=null&&typeof e=="function"&&e instanceof Object.getPrototypeOf(function*(){}).constructor}function M9(e){return typeof e=="object"&&e?.[Symbol.for("LG_SKIP_WRITE")]!==void 0}var hr={[Symbol.for("LG_PASSTHROUGH")]:!0};function eh(e){return typeof e=="object"&&e?.[Symbol.for("LG_PASSTHROUGH")]!==void 0}var K0=Symbol("IS_WRITER"),ot=class q0 extends Vt{writes;constructor(t,r){let i=`ChannelWrite<${t.map(n=>mt(n)?n.node:"channel"in n?n.channel:"...").join(",")}>`;super({writes:t,name:i,tags:r,trace:!1,func:async(n,a)=>this._write(n,a??{})}),this.writes=t}async _write(t,r){let i=this.writes.map(n=>W0(n)&&eh(n.value)?{mapper:n.mapper,value:t}:th(n)&&eh(n.value)?{channel:n.channel,value:t,skipNone:n.skipNone,mapper:n.mapper}:n);return await q0.doWrite(r,i),t}static async doWrite(t,r){for(let a of r){if(th(a)){if(a.channel==="__pregel_tasks")throw new be("Cannot write to the reserved channel TASKS");if(eh(a.value))throw new be("PASSTHROUGH value must be replaced")}if(W0(a)&&eh(a.value))throw new be("PASSTHROUGH value must be replaced")}let i=[];for(let a of r)if(mt(a))i.push([In,a]);else if(W0(a)){let o=await a.mapper.invoke(a.value,t);o!=null&&o.length>0&&i.push(...o)}else if(th(a)){let o=a.mapper!==void 0?await a.mapper.invoke(a.value,t):a.value;if(M9(o)||a.skipNone&&o===void 0)continue;i.push([a.channel,o])}else throw new Error(`Invalid write entry: ${JSON.stringify(a)}`);let n=t.configurable?.[Nr];n(i)}static isWriter(t){return t instanceof q0||K0 in t&&!!t[K0]}static registerWriter(t){return Object.defineProperty(t,K0,{value:!0})}};function th(e){return e!==void 0&&typeof e.channel=="string"}function W0(e){return e!==void 0&&!th(e)&&ae.isRunnable(e.mapper)}var IR=class TR extends Vt{lc_graph_name="ChannelRead";channel;fresh=!1;mapper;constructor(t,r,i=!1){super({trace:!1,func:(n,a)=>TR.doRead(a,this.channel,this.fresh,this.mapper)}),this.fresh=i,this.mapper=r,this.channel=t,this.name=Array.isArray(t)?`ChannelRead<${t.join(",")}>`:`ChannelRead<${t}>`}static doRead(t,r,i,n){let a=t.configurable?.[Yr];if(!a)throw new Error("Runnable is not configured with a read function. Make sure to call in the context of a Pregel process");return n?n(a(r,i)):a(r,i)}},yc=new yi,bn=class xl extends Hr{lc_graph_name="PregelNode";channels;triggers=[];mapper;writers=[];bound=yc;kwargs={};metadata={};tags=[];retryPolicy;cachePolicy;subgraphs;ends;constructor(t){let{channels:r,triggers:i,mapper:n,writers:a,bound:o,kwargs:s,metadata:c,retryPolicy:u,cachePolicy:l,tags:d,subgraphs:f,ends:p}=t,m=[...t.config?.tags?t.config.tags:[],...d??[]];super({...t,bound:t.bound??yc,config:{...t.config?t.config:{},tags:m}}),this.channels=r,this.triggers=i,this.mapper=n,this.writers=a??this.writers,this.bound=o??this.bound,this.kwargs=s??this.kwargs,this.metadata=c??this.metadata,this.tags=m,this.retryPolicy=u,this.cachePolicy=l,this.subgraphs=f,this.ends=p}getWriters(){let t=[...this.writers];for(;t.length>1&&t[t.length-1]instanceof ot&&t[t.length-2]instanceof ot;){let r=t.slice(-2),i=r[0].writes.concat(r[1].writes);t[t.length-2]=new ot(i,r[0].config?.tags),t.pop()}return t}getNode(){let t=this.getWriters();if(!(this.bound===yc&&t.length===0))return this.bound===yc&&t.length===1?t[0]:this.bound===yc?new Ar({first:t[0],middle:t.slice(1,t.length-1),last:t[t.length-1],omitSequenceTags:!0}):t.length>0?new Ar({first:this.bound,middle:t.slice(0,t.length-1),last:t[t.length-1],omitSequenceTags:!0}):this.bound}join(t){if(!Array.isArray(t))throw new Error("channels must be a list");if(typeof this.channels!="object")throw new Error("all channels must be named when using .join()");return new xl({channels:{...this.channels,...Object.fromEntries(t.map(r=>[r,r]))},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(t){return ot.isWriter(t)?new xl({channels:this.channels,triggers:this.triggers,mapper:this.mapper,writers:[...this.writers,t],bound:this.bound,config:this.config,kwargs:this.kwargs,retryPolicy:this.retryPolicy,cachePolicy:this.cachePolicy}):this.bound===yc?new xl({channels:this.channels,triggers:this.triggers,mapper:this.mapper,writers:this.writers,bound:tt(t),config:this.config,kwargs:this.kwargs,retryPolicy:this.retryPolicy,cachePolicy:this.cachePolicy}):new xl({channels:this.channels,triggers:this.triggers,mapper:this.mapper,writers:this.writers,bound:this.bound.pipe(t),config:this.config,kwargs:this.kwargs,retryPolicy:this.retryPolicy,cachePolicy:this.cachePolicy})}};function j9(e){return"steps"in e&&Array.isArray(e.steps)}function Sl(e){return"lg_is_pregel"in e&&e.lg_is_pregel===!0}function rh(e){let t=[e];for(let r of t){if(Sl(r))return r;j9(r)&&t.push(...r.steps)}}function Co(e,t,r=!0,i=!1){try{return e[t].get()}catch(n){if(n.name===Ne.unminifiable_name){if(i)return n;if(r)return null}throw n}}function wn(e,t,r=!0){if(Array.isArray(t)){let i={};for(let n of t)try{i[n]=Co(e,n,!r)}catch(a){if(a.name===Ne.unminifiable_name)continue}return i}else return Co(e,t)}function*AR(e,t){if(e.graph===ir.PARENT)throw new be("There is no parent graph.");if(e.goto){let r;Array.isArray(e.goto)?r=e.goto:r=[e.goto];for(let i of r)if(mt(i))yield[yr,In,i];else if(typeof i=="string")yield[yr,`branch:to:${i}`,"__start__"];else throw new Error(`In Command.send, expected Send or string, got ${typeof i}`)}if(e.resume)if(typeof e.resume=="object"&&Object.keys(e.resume).length&&Object.keys(e.resume).every(Qm))for(let[r,i]of Object.entries(e.resume)){let n=t.filter(a=>a[0]===r&&a[1]==="__resume__").map(a=>a[2]).slice(0,1)??[];n.push(i),yield[r,_r,n]}else yield[yr,_r,e.resume];if(e.update){if(typeof e.update!="object"||!e.update)throw new Error("Expected cmd.update to be a dict mapping channel names to update values");if(Array.isArray(e.update))for(let[r,i]of e.update)yield[yr,r,i];else for(let[r,i]of Object.entries(e.update))yield[yr,r,i]}}function*nh(e,t){if(t!=null)if(Array.isArray(e)&&typeof t=="object"&&!Array.isArray(t))for(let r in t)e.includes(r)&&(yield[r,t[r]]);else{if(Array.isArray(e))throw new Error('Input chunk must be an object when "inputChannels" is an array');yield[e,t]}}function*ih(e,t,r){Array.isArray(e)?(t===!0||t.find(([i,n])=>e.includes(i)))&&(yield wn(r,e)):(t===!0||t.some(([i,n])=>i===e))&&(yield Co(r,e))}function*CR(e,t,r){let i=t.filter(([s,c])=>(s.config===void 0||!s.config.tags?.includes("langsmith:hidden"))&&c[0][0]!=="__error__"&&c[0][0]!=="__interrupt__");if(!i.length)return;let n;i.some(([s])=>s.writes.some(([c,u])=>c==="__return__"))?n=i.flatMap(([s])=>s.writes.filter(([c,u])=>c===Ci).map(([c,u])=>[s.name,u])):Array.isArray(e)?n=i.flatMap(([s])=>{let{writes:c}=s,u={};for(let[l]of c)e.includes(l)&&(u[l]=(u[l]||0)+1);return Object.values(u).some(l=>l>1)?c.filter(([l])=>e.includes(l)).map(([l,d])=>[s.name,{[l]:d}]):[[s.name,Object.fromEntries(c.filter(([l])=>e.includes(l)))]]}):n=i.flatMap(([s])=>s.writes.filter(([c,u])=>c===e).map(([c,u])=>[s.name,u]));let a={};for(let[s,c]of n)s in a||(a[s]=[]),a[s].push(c);let o={};for(let s in a)if(a[s].length===1){let[c]=a[s];o[s]=c}else o[s]=a[s];r&&(o.__metadata__={cached:r}),yield o}function ah(e){let t=typeof e[He];if(t==="number")return 0;if(t==="string")return"";for(let r in e){if(!Object.prototype.hasOwnProperty.call(e,r))continue;let i=typeof e[r];if(i==="number")return 0;if(i==="string")return"";break}}function vc(e,t){if(Object.keys(e).length>0){let r=ah(t);return Object.fromEntries(Object.entries(t).filter(([i,n])=>n>(e[i]??r)))}else return t}function OR(e,t){return e&&!Array.isArray(e)&&!(e instanceof Date)&&typeof e=="object"?e:{[t]:e}}function gr(e,t){return e===null?{configurable:t}:e?.configurable===void 0?{...e,configurable:t}:{...e,configurable:{...e.configurable,...t}}}function fa(e,t){let r=t?.parents??{};return Object.keys(r).length>0?gr(e,{[Mr]:{...r,[e.configurable?.checkpoint_ns??""]:e.configurable?.checkpoint_id}}):e}function bc(...e){let t=[...new Set(e.filter(Boolean))];if(t.length===0)return{signal:void 0,dispose:void 0};if(t.length===1)return{signal:t[0],dispose:void 0};let r=new AbortController,i=()=>{let a=t.find(o=>o.aborted)?.reason;r.abort(a),t.forEach(o=>o.removeEventListener("abort",i))};t.forEach(a=>a.addEventListener("abort",i,{once:!0}));let n=t.find(a=>a.aborted);return n&&r.abort(n.reason),{signal:r.signal,dispose:()=>{t.forEach(a=>a.removeEventListener("abort",i))}}}var PR=(e,t)=>{if(!(!e&&!t))return e?t?Array.isArray(e)&&Array.isArray(t)?[...e,...t]:Array.isArray(e)?[...e,t]:Array.isArray(t)?[e,...t]:[e,t]:e:t};var NR=class{func;name;input;retry;cache;callbacks;__lg_type="call";constructor({func:e,name:t,input:r,retry:i,cache:n,callbacks:a}){this.func=e,this.name=t,this.input=r,this.retry=i,this.cache=n,this.callbacks=a}};function RR(e){return typeof e=="object"&&e!==null&&"__lg_type"in e&&e.__lg_type==="call"}function MR(e,t){return new Ar({name:e,first:new Vt({func:r=>t(...r),name:e,trace:!1,recurse:!1}),last:new ot([{channel:Ci,value:hr}],[lt])})}function jR(e,t){return new Vt({func:(r,i)=>t(r,i),name:e,trace:!1,recurse:!1})}function zR({func:e,name:t,cache:r,retry:i},...n){let a=Ae.getRunnableConfig();if(typeof a.configurable?.__pregel_call=="function")return a.configurable[jo](e,t,n,{retry:i,cache:r,callbacks:a.callbacks});throw new Error("Async local storage not initialized. Please call initializeAsyncLocalStorageSingleton() before using this function.")}var DR=e=>e!==void 0?e+1:1;function z9(e,t){if(t==null)return!1;for(let r of e)if(t[r])return!0;return!1}function D9(e){let t;for(let r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t==null?t=e[r]:t=ml(t,e[r]));return t}function $l(e,t,r){let i=ah(e.channel_versions),n=e.versions_seen.__interrupt__??{},a=!1;if((e.channel_versions.__start__??i)>(n.__start__??i))a=!0;else for(let s in e.channel_versions)if(Object.prototype.hasOwnProperty.call(e.channel_versions,s)&&e.channel_versions[s]>(n[s]??i)){a=!0;break}let o=r.some(s=>t==="*"?!s.config?.tags?.includes(lt):t.includes(s.name));return a&&o}function kl(e,t,r,i,n=!1){let a=new Set;if(Array.isArray(i))a=new Set(i.filter(s=>r.writes.some(([c,u])=>c===s)));else{for(let[s]of r.writes)if(s===i){a=new Set([s]);break}a=a||new Set}let o;if(n&&a.size>0){let s=Object.fromEntries(Object.entries(t).filter(([l,d])=>a.has(l))),c=_n(e,s,-1),u=la(s,c);rr(gn(c),u,[r],void 0,void 0),o=wn({...t,...u},i)}else o=wn(t,i);return o}function X0(e,t,r){for(let[i,n]of r)if(["__pregel_push","__pregel_tasks"].includes(i)&&n!=null){if(!mt(n))throw new be(`Invalid packet type, expected SendProtocol, got ${JSON.stringify(n)}`);if(!(n.node in t))throw new be(`Invalid node name "${n.node}" in Send packet`)}e(r)}var U9=new Set([Ic,jr,_r,Ue,Ci,Mo]);function rr(e,t,r,i,n){r.sort((f,p)=>{let m=f.path?.slice(0,3)||[],g=p.path?.slice(0,3)||[];for(let v=0;v<Math.min(m.length,g.length);v+=1){if(m[v]<g[v])return-1;if(m[v]>g[v])return 1}return m.length-g.length});let a=r.some(f=>f.triggers.length>0),o=yl(t);for(let f of r){e.versions_seen[f.name]??={};for(let p of f.triggers)p in e.channel_versions&&(e.versions_seen[f.name][p]=e.channel_versions[p])}let s=D9(e.channel_versions),c=new Set(r.flatMap(f=>f.triggers).filter(f=>!SS.includes(f))),u=!1;for(let f of c)f in o&&o[f].consume()&&i!==void 0&&(e.channel_versions[f]=i(s),u=!0);let l={};for(let f of r)for(let[p,m]of f.writes)U9.has(p)||p in o&&(l[p]??=[],l[p].push(m));s!=null&&i!=null&&(s=u?i(s):s);let d=new Set;for(let[f,p]of Object.entries(l))if(f in o){let m=o[f],g;try{g=m.update(p)}catch(v){if(v.name===be.unminifiable_name){let b=new be(`Invalid update for channel "${f}" with values ${JSON.stringify(p)}: ${v.message}`);throw b.lc_error_code=v.lc_error_code,b}else throw v}g&&i!==void 0&&(e.channel_versions[f]=i(s),m.isAvailable()&&d.add(f))}if(a)for(let f in o){if(!Object.prototype.hasOwnProperty.call(o,f))continue;let p=o[f];p.isAvailable()&&!d.has(f)&&p.update([])&&i!==void 0&&(e.channel_versions[f]=i(s),p.isAvailable()&&d.add(f))}if(a&&!z9(d,n))for(let f in o){if(!Object.prototype.hasOwnProperty.call(o,f))continue;let p=o[f];p.finish()&&i!==void 0&&(e.channel_versions[f]=i(s),p.isAvailable()&&d.add(f))}return d}function*L9(e,t,r){if(r.updatedChannels!=null&&r.triggerToNodes!=null){let i=new Set;for(let n of r.updatedChannels){let a=r.triggerToNodes[n];for(let o of a??[])i.add(o)}yield*[...i].sort();return}if(!(()=>{for(let i in e.channel_versions)if(e.channel_versions[i]!==null)return!1;return!0})())for(let i in t)Object.prototype.hasOwnProperty.call(t,i)&&(yield i)}function pa(e,t,r,i,n,a,o){let s={},c=i[In];if(c?.isAvailable()){let u=c.get().length;for(let l=0;l<u;l+=1){let d=oh([jr,l],e,t,r,i,n,a,o);d!==void 0&&(s[d.id]=d)}}for(let u of L9(e,r,o)){let l=oh([Nl,u],e,t,r,i,n,a,o);l!==void 0&&(s[l.id]=l)}return s}function oh(e,t,r,i,n,a,o,s){let{step:c,checkpointer:u,manager:l}=s,d=a.configurable??{},f=d.checkpoint_ns??"";if(e[0]==="__pregel_push"&&RR(e[e.length-1])){let p=e[e.length-1],m=MR(p.name,p.func),g=[jr],v=f===""?p.name:`${f}|${p.name}`,b=ni(JSON.stringify([v,c.toString(),p.name,jr,e[1],e[2]]),t.id),w=`${v}:${b}`,S=[...e.slice(0,3),!0],k={langgraph_step:c,langgraph_node:p.name,langgraph_triggers:g,langgraph_path:S,langgraph_checkpoint_ns:w,checkpoint_ns:w};if(o){let I=[],Z={checkpointId:t.id,checkpointNs:w,taskId:b,threadId:d.thread_id,runId:a.runId!=null?String(a.runId):void 0,nodeAttempt:1};return{name:p.name,input:p.input,proc:m,writes:I,config:{...$e(xt(a,{metadata:k,store:s.store??a.store}),{runName:p.name,callbacks:l?.getChild(`graph:step:${c}`),configurable:{[$c]:b,[Nr]:C=>X0(y=>I.push(...y),i,C),[Yr]:(C,y=!1)=>kl(t,n,{name:p.name,writes:I,triggers:g,path:S},C,y),[Qr]:u??d.__pregel_checkpointer,[Mr]:{...d[Mr],[f]:t.id},[ar]:Y0({pendingWrites:r??[],taskId:b,currentTaskInput:p.input,resumeMap:a.configurable?.[Do],namespaceHash:ki(w)}),[xa]:t.channel_values[Sa],checkpoint_id:void 0,checkpoint_ns:w}}),executionInfo:Z},triggers:g,retry_policy:p.retry,cache_key:p.cache?{key:ki((p.cache.keyFunc??JSON.stringify)([p.input])),ns:[Ol,p.name??"__dynamic__"],ttl:p.cache.ttl}:void 0,id:b,path:S,writers:[]}}else return{id:b,name:p.name,interrupts:[],path:S}}else if(e[0]==="__pregel_push"){let p=typeof e[1]=="number"?e[1]:parseInt(e[1],10);if(!n.__pregel_tasks?.isAvailable())return;let m=n[In].get();if(p<0||p>=m.length)return;let g=Rl(m[p])&&!mt(m[p])?new wa(m[p].node,m[p].args):m[p];if(!Rl(g)){console.warn(`Ignoring invalid packet ${JSON.stringify(g)} in pending sends.`);return}if(!(g.node in i)){console.warn(`Ignoring unknown node name ${g.node} in pending sends.`);return}let v=[jr],b=f===""?g.node:`${f}|${g.node}`,w=ni(JSON.stringify([b,c.toString(),g.node,jr,p.toString()]),t.id),S=`${b}:${w}`,k={langgraph_step:c,langgraph_node:g.node,langgraph_triggers:v,langgraph_path:e.slice(0,3),langgraph_checkpoint_ns:S,checkpoint_ns:S};if(o){let I=i[g.node],Z=I.getNode();if(Z!==void 0){I.metadata!==void 0&&(k={...k,...I.metadata});let C=[],y={checkpointId:t.id,checkpointNs:S,taskId:w,threadId:d.thread_id,runId:a.runId!=null?String(a.runId):void 0,nodeAttempt:1};return{name:g.node,input:g.args,proc:Z,subgraphs:I.subgraphs,writes:C,config:{...$e(xt(a,{metadata:k,tags:I.tags,store:s.store??a.store}),{runName:g.node,callbacks:l?.getChild(`graph:step:${c}`),configurable:{[$c]:w,[Nr]:V=>X0(B=>C.push(...B),i,V),[Yr]:(V,B=!1)=>kl(t,n,{name:g.node,writes:C,triggers:v,path:e},V,B),[Qr]:u??d.__pregel_checkpointer,[Mr]:{...d[Mr],[f]:t.id},[ar]:Y0({pendingWrites:r??[],taskId:w,currentTaskInput:g.args,resumeMap:a.configurable?.[Do],namespaceHash:ki(S)}),[xa]:t.channel_values[Sa],checkpoint_id:void 0,checkpoint_ns:S}}),executionInfo:y},triggers:v,retry_policy:I.retryPolicy,cache_key:I.cachePolicy?{key:ki((I.cachePolicy.keyFunc??JSON.stringify)([g.args])),ns:[Ol,I.name??"__dynamic__",g.node],ttl:I.cachePolicy.ttl}:void 0,id:w,path:e,writers:I.getWriters()}}}else return{id:w,name:g.node,interrupts:[],path:e}}else if(e[0]==="__pregel_pull"){let p=e[1].toString(),m=i[p];if(m===void 0)return;if(r?.length){let w=f===""?p:`${f}|${p}`,S=ni(JSON.stringify([w,c.toString(),p,Nl,p]),t.id);if(r.some(k=>k[0]===S&&k[1]!=="__error__"))return}let g=ah(t.channel_versions);if(g===void 0)return;let v=t.versions_seen[p]??{},b=m.triggers.find(w=>n[w].isAvailable()?(t.channel_versions[w]??g)>(v[w]??g):!1);if(b!==void 0){let w=F9(m,n,o);if(w===void 0)return;let S=f===""?p:`${f}|${p}`,k=ni(JSON.stringify([S,c.toString(),p,Nl,[b]]),t.id),I=`${S}:${k}`,Z={langgraph_step:c,langgraph_node:p,langgraph_triggers:[b],langgraph_path:e,langgraph_checkpoint_ns:I,checkpoint_ns:I};if(o){let C=m.getNode();if(C!==void 0){m.metadata!==void 0&&(Z={...Z,...m.metadata});let y=[],V={checkpointId:t.id,checkpointNs:I,taskId:k,threadId:d.thread_id,runId:a.runId!=null?String(a.runId):void 0,nodeAttempt:1};return{name:p,input:w,proc:C,subgraphs:m.subgraphs,writes:y,config:{...$e(xt(a,{metadata:Z,tags:m.tags,store:s.store??a.store}),{runName:p,callbacks:l?.getChild(`graph:step:${c}`),configurable:{[$c]:k,[Nr]:B=>X0(A=>{y.push(...A)},i,B),[Yr]:(B,A=!1)=>kl(t,n,{name:p,writes:y,triggers:[b],path:e},B,A),[Qr]:u??d.__pregel_checkpointer,[Mr]:{...d[Mr],[f]:t.id},[ar]:Y0({pendingWrites:r??[],taskId:k,currentTaskInput:w,resumeMap:a.configurable?.[Do],namespaceHash:ki(I)}),[xa]:t.channel_values[Sa],checkpoint_id:void 0,checkpoint_ns:I}}),executionInfo:V},triggers:[b],retry_policy:m.retryPolicy,cache_key:m.cachePolicy?{key:ki((m.cachePolicy.keyFunc??JSON.stringify)([w])),ns:[Ol,m.name??"__dynamic__",p],ttl:m.cachePolicy.ttl}:void 0,id:k,path:e,writers:m.getWriters()}}}else return{id:k,name:p,interrupts:[],path:e}}}}function F9(e,t,r){let i;if(typeof e.channels=="object"&&!Array.isArray(e.channels)){i={};for(let[n,a]of Object.entries(e.channels))if(e.triggers.includes(a))try{i[n]=Co(t,a,!1)}catch(o){if(o.name===Ne.unminifiable_name)return;throw o}else if(a in t)try{i[n]=Co(t,a,!1)}catch(o){if(o.name===Ne.unminifiable_name)continue;throw o}}else if(Array.isArray(e.channels)){let n=!1;for(let a of e.channels)try{i=Co(t,a,!1),n=!0;break}catch(o){if(o.name===Ne.unminifiable_name)continue;throw o}if(!n)return}else throw new Error(`Invalid channels type, expected list or dict, got ${e.channels}`);return r&&e.mapper!==void 0&&(i=e.mapper(i)),i}function UR(e,t){if(typeof e.args!="object"||e.args===null)return e;let r={};for(let[i,n]of Object.entries(e.args)){let a=t[i];(!a||a.lc_graph_name!=="UntrackedValue")&&(r[i]=n)}return new wa(e.node,r)}function Y0({pendingWrites:e,taskId:t,currentTaskInput:r,resumeMap:i,namespaceHash:n}){let a=e.find(([s,c])=>s==="00000000-0000-0000-0000-000000000000"&&c==="__resume__")?.[2],o={callCounter:0,interruptCounter:-1,resume:(()=>{let s=e.filter(([c,u])=>c===t&&u==="__resume__").flatMap(([c,u,l])=>l);if(i!=null&&n in i){let c=i[n];s.push(c)}return s})(),nullResume:a,subgraphCounter:0,currentTaskInput:r,consumeNullResume:()=>{if(o.nullResume)return delete o.nullResume,e.splice(e.findIndex(([s,c])=>s==="00000000-0000-0000-0000-000000000000"&&c==="__resume__"),1),a}};return o}var El={blue:{start:"\x1B[34m",end:"\x1B[0m"},green:{start:"\x1B[32m",end:"\x1B[0m"},yellow:{start:"\x1B[33;1m",end:"\x1B[0m"}},Il=(e,t)=>`${e.start}${t}${e.end}`;function*Q0(e){for(let{id:t,name:r,input:i,config:n,triggers:a,writes:o}of e)n?.tags?.includes("langsmith:hidden")||(yield{id:t,name:r,input:i,triggers:a,interrupts:o.filter(([s,c])=>s===t&&c==="__interrupt__").map(([,s])=>s)})}function B9(e){return typeof e!="object"||e===null?!1:"$writes"in e&&Array.isArray(e.$writes)}function LR(e){let t={};for(let[r,i]of e){let n=String(r);if(n in t){let a=B9(t[n])?t[n].$writes:[t[n]];a.push(i),t[n]={$writes:a}}else t[n]=i}return t}function*FR(e,t){for(let[{id:r,name:i,config:n},a]of e)n?.tags?.includes("langsmith:hidden")||(yield{id:r,name:i,result:LR(a.filter(([o])=>Array.isArray(t)?t.includes(o):o===t)),interrupts:a.filter(o=>o[0]===Ue).map(o=>o[1])})}function*BR(e,t,r,i,n,a,o,s){function c(d){let f={};return d.callbacks!=null&&(f.callbacks=d.callbacks),d.configurable!=null&&(f.configurable=d.configurable),d.maxConcurrency!=null&&(f.max_concurrency=d.maxConcurrency),d.metadata!=null&&(f.metadata=d.metadata),d.recursionLimit!=null&&(f.recursion_limit=d.recursionLimit),d.runId!=null&&(f.run_id=d.runId),d.runName!=null&&(f.run_name=d.runName),d.tags!=null&&(f.tags=d.tags),f}let u=e.configurable?.checkpoint_ns,l={};for(let d of n){if(!(d.subgraphs?.length?d.subgraphs:[d.proc]).find(rh))continue;let f=`${d.name}:${d.id}`;u&&(f=`${u}|${f}`),l[d.id]={configurable:{thread_id:e.configurable?.thread_id,checkpoint_ns:f}}}yield{config:c(e),values:wn(t,r),metadata:i,next:n.map(d=>d.name),tasks:eS(n,a,l,s),parentConfig:o?c(o):void 0}}function eS(e,t,r,i){return e.map(n=>{let a=t.find(([u,l])=>u===n.id&&l==="__error__")?.[2],o=t.filter(([u,l])=>u===n.id&&l==="__interrupt__").map(([,,u])=>u),s=(()=>{if(a||o.length||!t.length)return;let u=t.findIndex(([l,d])=>l===n.id&&d==="__return__");if(u>=0)return t[u][2];if(typeof i=="string")return t.find(([l,d])=>l===n.id&&d===i)?.[2];if(Array.isArray(i)){let l=t.filter(([d,f])=>d===n.id&&i.includes(f)).map(([,d,f])=>[d,f]);return l.length?LR(l):void 0}})();if(a)return{id:n.id,name:n.name,path:n.path,error:a,interrupts:o,result:s};let c=r?.[n.id];return{id:n.id,name:n.name,path:n.path,interrupts:o,...c!==void 0?{state:c}:{},result:s}})}function VR(e,t,r){console.log([`${Il(El.blue,`[${e}:checkpoint]`)}`,`\x1B[1m State at the end of step ${e}:\x1B[0m
416
416
  `,JSON.stringify(wn(t,r),null,2)].join(""))}function sh(e,t){let r=t.length;console.log([`${Il(El.blue,`[${e}:tasks]`)}`,`\x1B[1m Starting step ${e} with ${r} task${r===1?"":"s"}:\x1B[0m
417
417
  `,t.map(i=>`- ${Il(El.green,String(i.name))} -> ${JSON.stringify(i.input,null,2)}`).join(`
418
418
  `)].join(""))}function ZR(e,t,r){let i={};for(let[n,a]of t)r.includes(n)&&(i[n]||(i[n]=[]),i[n].push(a));console.log([`${Il(El.blue,`[${e}:writes]`)}`,`\x1B[1m Finished step ${e} with writes to ${Object.keys(i).length} channel${Object.keys(i).length!==1?"s":""}:\x1B[0m
419
419
  `,Object.entries(i).map(([n,a])=>`- ${Il(El.yellow,n)} -> ${a.map(o=>JSON.stringify(o)).join(", ")}`).join(`
420
- `)].join(""))}var ch=class extends dt{_abortController;_innerReader;constructor(e,t){let r=e.getReader(),i=t??new AbortController;super({start(n){return a();function a(){return r.read().then(({done:o,value:s})=>{if(o){n.close();return}return n.enqueue(s),a()})}}}),this._abortController=i,this._innerReader=r}async cancel(e){this._abortController.abort(e),this._innerReader.releaseLock()}get signal(){return this._abortController.signal}},rS=class extends dt{modes;controller;passthroughFn;_closed=!1;get closed(){return this._closed}constructor(e){let t,r=new Promise(i=>{t=i});super({start:i=>{t(i)}}),r.then(i=>{this.controller=i}),this.passthroughFn=e.passthroughFn,this.modes=e.modes}push(e){this._closed||!this.controller||(this.passthroughFn?.(e),this.controller.enqueue(e))}close(){try{this.controller.close()}catch{}finally{this._closed=!0}}error(e){try{this.controller?.error(e)}finally{this._closed=!0}}},JR=class extends xr{name="StreamToolsHandler";streamFn;runs={};constructor(e){super(),this.streamFn=e}handleToolStart(e,t,r,i,n,a,o,s){if(!a||n&&n.includes("langsmith:hidden"))return;let c=a.langgraph_checkpoint_ns?.split("|")??[],u={ns:c,toolCallId:s,toolName:o??"unknown",input:t};this.runs[r]=u,this.streamFn([c,"tools",{event:"on_tool_start",toolCallId:u.toolCallId,name:u.toolName,input:t}])}handleToolEvent(e,t){let r=this.runs[t];r&&this.streamFn([r.ns,"tools",{event:"on_tool_event",toolCallId:r.toolCallId,name:r.toolName,data:e}])}handleToolEnd(e,t){let r=this.runs[t];delete this.runs[t],r&&this.streamFn([r.ns,"tools",{event:"on_tool_end",toolCallId:r.toolCallId,name:r.toolName,output:e}])}handleToolError(e,t){let r=this.runs[t];delete this.runs[t],r&&this.streamFn([r.ns,"tools",{event:"on_tool_error",toolCallId:r.toolCallId,name:r.toolName,error:e}])}};function F9(e){return JSON.stringify(e,function(t,r){let i=this[t];if(i!=null&&typeof i=="object"&&"toDict"in i&&typeof i.toDict=="function"){let{type:n,data:a}=i.toDict();return{...a,type:n}}return r})}function B9(e){return e instanceof Error?{error:e.name,message:e.message}:{error:"Error",message:JSON.stringify(e)}}function nS(e){return typeof e!="object"||e==null?!1:"configurable"in e&&typeof e.configurable=="object"&&e.configurable!=null}function tS(e){return!nS(e)||!e.configurable.thread_id?null:{thread_id:e.configurable.thread_id,checkpoint_ns:e.configurable.checkpoint_ns||"",checkpoint_id:e.configurable.checkpoint_id||null,checkpoint_map:e.configurable.checkpoint_map||null}}function HR(e){if(nS(e)){let t=Object.fromEntries(Object.entries(e.configurable).filter(([i])=>!i.startsWith("__"))),r={...e,configurable:t};return delete r.callbacks,r}return e}function GR(e){let t={...e,checkpoint:tS(e.config),parent_checkpoint:tS(e.parentConfig),config:HR(e.config),parent_config:HR(e.parentConfig),tasks:e.tasks.map(r=>{if(nS(r.state)){let i=tS(r.state);if(i!=null){let n={...r,checkpoint:i};return delete n.state,n}}return r})};return delete t.parentConfig,t}function KR(e){let t=new TextEncoder;return new ReadableStream({async start(r){let i=n=>{r.enqueue(t.encode(`event: ${n.event}
421
- data: ${F9(n.data)}
420
+ `)].join(""))}var ch=class extends dt{_abortController;_innerReader;constructor(e,t){let r=e.getReader(),i=t??new AbortController;super({start(n){return a();function a(){return r.read().then(({done:o,value:s})=>{if(o){n.close();return}return n.enqueue(s),a()})}}}),this._abortController=i,this._innerReader=r}async cancel(e){this._abortController.abort(e),this._innerReader.releaseLock()}get signal(){return this._abortController.signal}},rS=class extends dt{modes;controller;passthroughFn;_closed=!1;get closed(){return this._closed}constructor(e){let t,r=new Promise(i=>{t=i});super({start:i=>{t(i)}}),r.then(i=>{this.controller=i}),this.passthroughFn=e.passthroughFn,this.modes=e.modes}push(e){this._closed||!this.controller||(this.passthroughFn?.(e),this.controller.enqueue(e))}close(){try{this.controller.close()}catch{}finally{this._closed=!0}}error(e){try{this.controller?.error(e)}finally{this._closed=!0}}},JR=class extends xr{name="StreamToolsHandler";streamFn;runs={};constructor(e){super(),this.streamFn=e}handleToolStart(e,t,r,i,n,a,o,s){if(!a||n&&n.includes("langsmith:hidden"))return;let c=a.langgraph_checkpoint_ns?.split("|")??[],u={ns:c,toolCallId:s,toolName:o??"unknown",input:t};this.runs[r]=u,this.streamFn([c,"tools",{event:"on_tool_start",toolCallId:u.toolCallId,name:u.toolName,input:t}])}handleToolEvent(e,t){let r=this.runs[t];r&&this.streamFn([r.ns,"tools",{event:"on_tool_event",toolCallId:r.toolCallId,name:r.toolName,data:e}])}handleToolEnd(e,t){let r=this.runs[t];delete this.runs[t],r&&this.streamFn([r.ns,"tools",{event:"on_tool_end",toolCallId:r.toolCallId,name:r.toolName,output:e}])}handleToolError(e,t){let r=this.runs[t];delete this.runs[t],r&&this.streamFn([r.ns,"tools",{event:"on_tool_error",toolCallId:r.toolCallId,name:r.toolName,error:e}])}};function V9(e){return JSON.stringify(e,function(t,r){let i=this[t];if(i!=null&&typeof i=="object"&&"toDict"in i&&typeof i.toDict=="function"){let{type:n,data:a}=i.toDict();return{...a,type:n}}return r})}function Z9(e){return e instanceof Error?{error:e.name,message:e.message}:{error:"Error",message:JSON.stringify(e)}}function nS(e){return typeof e!="object"||e==null?!1:"configurable"in e&&typeof e.configurable=="object"&&e.configurable!=null}function tS(e){return!nS(e)||!e.configurable.thread_id?null:{thread_id:e.configurable.thread_id,checkpoint_ns:e.configurable.checkpoint_ns||"",checkpoint_id:e.configurable.checkpoint_id||null,checkpoint_map:e.configurable.checkpoint_map||null}}function HR(e){if(nS(e)){let t=Object.fromEntries(Object.entries(e.configurable).filter(([i])=>!i.startsWith("__"))),r={...e,configurable:t};return delete r.callbacks,r}return e}function GR(e){let t={...e,checkpoint:tS(e.config),parent_checkpoint:tS(e.parentConfig),config:HR(e.config),parent_config:HR(e.parentConfig),tasks:e.tasks.map(r=>{if(nS(r.state)){let i=tS(r.state);if(i!=null){let n={...r,checkpoint:i};return delete n.state,n}}return r})};return delete t.parentConfig,t}function KR(e){let t=new TextEncoder;return new ReadableStream({async start(r){let i=n=>{r.enqueue(t.encode(`event: ${n.event}
421
+ data: ${V9(n.data)}
422
422
 
423
- `))};try{for await(let n of e){let[a,o,s]=n,c=s;if(o==="debug"){let u=s;u.type==="checkpoint"&&(c={...u,payload:GR(u.payload)})}o==="checkpoints"&&(c=GR(s)),i({event:a?.length?`${o}|${a.join("|")}`:o,data:c})}}catch(n){i({event:"error",data:B9(n)})}r.close()}})}function WR(...e){return new rS({passthroughFn:t=>{let r=t[1]==="checkpoints"&&mc(t[2]);for(let i of e)(i.modes.has(t[1])||r)&&i.push(t)},modes:new Set(e.flatMap(t=>Array.from(t.modes)))})}var uh=Symbol.for("INPUT_DONE"),iS=Symbol.for("INPUT_RESUMING"),V9=25,Z9=class extends Lm{cache;queue=Promise.resolve();constructor(e){super(),this.cache=e}async get(e){return this.enqueueOperation("get",e)}async set(e){return this.enqueueOperation("set",e)}async clear(e){return this.enqueueOperation("clear",e)}async stop(){await this.queue}enqueueOperation(e,...t){let r=this.queue.then(()=>this.cache[e](...t));return this.queue=r.then(()=>{},()=>{}),r}},qR=class XR{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=new Set;isNested;_checkpointerChainedPromise=Promise.resolve();_trackCheckpointerPromise(t){let r=t.then(i=>(this.checkpointerPromises.delete(r),i),i=>{throw i});this.checkpointerPromises.add(r)}store;cache;manager;interruptAfter;interruptBefore;toInterrupt=[];debug=!1;triggerToNodes;get isResuming(){let t=!1;if("__start__"in this.checkpoint.channel_versions)t=!0;else for(let s in this.checkpoint.channel_versions)if(Object.prototype.hasOwnProperty.call(this.checkpoint.channel_versions,s)){t=!0;break}let r=this.config.configurable?.__pregel_resuming!==void 0&&this.config.configurable?.__pregel_resuming,i=this.input===null||this.input===void 0,n=yt(this.input)&&this.input.resume!=null,a=this.input===iS,o=!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 t&&(r||i||n||a||o)}constructor(t){this.input=t.input,this.checkpointer=t.checkpointer,this.checkpointer!==void 0?this.checkpointerGetNextVersion=this.checkpointer.getNextVersion.bind(this.checkpointer):this.checkpointerGetNextVersion=DR,this.checkpoint=t.checkpoint,this.checkpointMetadata=t.checkpointMetadata,this.checkpointPreviousVersions=t.checkpointPreviousVersions,this.channels=t.channels,this.checkpointPendingWrites=t.checkpointPendingWrites,this.step=t.step,this.stop=t.stop,this.config=t.config,this.checkpointConfig=t.checkpointConfig,this.isNested=t.isNested,this.manager=t.manager,this.outputKeys=t.outputKeys,this.streamKeys=t.streamKeys,this.nodes=t.nodes,this.skipDoneTasks=t.skipDoneTasks,this.store=t.store,this.cache=t.cache?new Z9(t.cache):void 0,this.stream=t.stream,this.checkpointNamespace=t.checkpointNamespace,this.prevCheckpointConfig=t.prevCheckpointConfig,this.interruptAfter=t.interruptAfter,this.interruptBefore=t.interruptBefore,this.durability=t.durability,this.debug=t.debug,this.triggerToNodes=t.triggerToNodes}static async initialize(t){let{config:r,stream:i}=t;i!==void 0&&r.configurable?.__pregel_stream!==void 0&&(i=WR(i,r.configurable[Ec]));let n=r.configurable?!("checkpoint_id"in r.configurable):!0,a=r.configurable?.[ar];r.configurable&&a&&(a.subgraphCounter>0&&(r=gr(r,{[Rr]:[r.configurable[Rr],a.subgraphCounter.toString()].join("|")})),a.subgraphCounter+=1);let o=Yr in(r.configurable??{});!o&&r.configurable?.checkpoint_ns!==void 0&&r.configurable?.checkpoint_ns!==""&&(r=gr(r,{checkpoint_ns:"",checkpoint_id:void 0}));let s=r;r.configurable?.checkpoint_map!==void 0&&r.configurable?.checkpoint_map?.[r.configurable?.checkpoint_ns]&&(s=gr(r,{checkpoint_id:r.configurable[Mr][r.configurable?.checkpoint_ns]}));let c=r.configurable?.checkpoint_ns?.split("|")??[],u=await t.checkpointer?.getTuple(s)??{config:r,checkpoint:lc(),metadata:{source:"input",step:-2,parents:{}},pendingWrites:[]};s={...r,...u.config,configurable:{checkpoint_ns:"",...r.configurable,...u.config.configurable}};let l=u.parentConfig,d=gn(u.checkpoint),f={...u.metadata},p=u.pendingWrites??[],m=la(t.channelSpecs,d),g=(f.step??0)+1,v=g+(r.recursionLimit??V9)+1,b={...d.channel_versions},w=t.store?new Um(t.store):void 0;return w&&await w.start(),new XR({input:t.input,config:r,checkpointer:t.checkpointer,checkpoint:d,checkpointMetadata:f,checkpointConfig:s,prevCheckpointConfig:l,checkpointNamespace:c,channels:m,isNested:o,manager:t.manager,skipDoneTasks:n,step:g,stop:v,checkpointPreviousVersions:b,checkpointPendingWrites:p,outputKeys:t.outputKeys??[],streamKeys:t.streamKeys??[],nodes:t.nodes,stream:i,store:w,cache:t.cache,interruptAfter:t.interruptAfter,interruptBefore:t.interruptBefore,durability:t.durability,debug:t.debug,triggerToNodes:t.triggerToNodes})}_checkpointerPutAfterPrevious(t){this._checkpointerChainedPromise=this._checkpointerChainedPromise.then(()=>this.checkpointer?.put(t.config,t.checkpoint,t.metadata,t.newVersions)),this._trackCheckpointerPromise(this._checkpointerChainedPromise)}putWrites(t,r){let i=r;if(i.length===0)return;i.every(([c])=>c in hl)&&(i=Array.from(new Map(i.map(c=>[c[0],c])).values()));let n=!1;for(let c in this.channels)if(Object.prototype.hasOwnProperty.call(this.channels,c)&&this.channels[c].lc_graph_name==="UntrackedValue"){n=!0;break}let a=i;n&&(a=i.filter(([c])=>{let u=this.channels[c];return!u||u.lc_graph_name!=="UntrackedValue"}).map(([c,u])=>c==="__pregel_tasks"&&mt(u)?[c,UR(u,this.channels)]:[c,u])),this.checkpointPendingWrites=this.checkpointPendingWrites.filter(c=>c[0]!==t);for(let[c,u]of a)this.checkpointPendingWrites.push([t,c,u]);let o=gr(this.checkpointConfig,{[Rr]:this.config.configurable?.checkpoint_ns??"",[Pl]:this.checkpoint.id});if(this.durability!=="exit"&&this.checkpointer!=null&&this._trackCheckpointerPromise(this.checkpointer.putWrites(o,a,t)),this.tasks&&this._outputWrites(t,i),!r.length||!this.cache||!this.tasks)return;let s=this.tasks[t];s==null||s.cache_key==null||r[0][0]==="__error__"||r[0][0]==="__interrupt__"||this.cache.set([{key:[s.cache_key.ns,s.cache_key.key],value:s.writes,ttl:s.cache_key.ttl}])}_outputWrites(t,r,i=!1){let n=this.tasks[t];if(n!==void 0){if(n.config!==void 0&&(n.config.tags??[]).includes("langsmith:hidden"))return;if(r.length>0)if(r[0][0]==="__interrupt__"){if(n.path?.[0]==="__pregel_push"&&n.path?.[n.path.length-1]===!0)return;let a=r.filter(o=>o[0]===Ue).flatMap(o=>o[1]);this._emit([["updates",{[Ue]:a}],["values",{[Ue]:a}]])}else r[0][0]!=="__error__"&&this._emit(To($i(CR(this.outputKeys,[[n,r]],i),"updates")));i||this._emit(To($i(FR([[n,r]],this.streamKeys),"tasks")))}}async _matchCachedWrites(){if(!this.cache)return[];let t=[],r=([o,s])=>`ns:${o.join(",")}|key:${s}`,i=[],n={};for(let o of Object.values(this.tasks))o.cache_key!=null&&!o.writes.length&&(i.push([o.cache_key.ns,o.cache_key.key]),n[r([o.cache_key.ns,o.cache_key.key])]=o);if(i.length===0)return[];let a=await this.cache.get(i);for(let{key:o,value:s}of a){let c=n[r(o)];c!=null&&(c.writes.push(...s),t.push({task:c,result:s}))}return t}async tick(t){this.store&&!this.store.isRunning&&await this.store?.start();let{inputKeys:r=[]}=t;if(this.status!=="pending")throw new Error(`Cannot tick when status is no longer "pending". Current status: "${this.status}"`);if(![uh,iS].includes(this.input))await this._first(r);else{if(this.toInterrupt.length>0)throw this.status="interrupt_before",new ti;if(Object.values(this.tasks).every(n=>n.writes.length>0)){let n=Object.values(this.tasks).flatMap(o=>o.writes);this.updatedChannels=rr(this.checkpoint,this.channels,Object.values(this.tasks),this.checkpointerGetNextVersion,this.triggerToNodes);let a=await vn($i(ih(this.outputKeys,n,this.channels),"values"));if(this.checkpointPendingWrites=[],await this._putCheckpoint({source:"loop"}),this._emitValuesWithCheckpointMeta(a),$l(this.checkpoint,this.interruptAfter,Object.values(this.tasks)))throw this.status="interrupt_after",new ti;this.config.configurable?.__pregel_resuming!==void 0&&delete this.config.configurable?.[zo]}else return!1}if(this.step>this.stop)return this.status="out_of_steps",!1;if(this.tasks=pa(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 vn($i(BR(this.checkpointConfig,this.channels,this.streamKeys,this.checkpointMetadata,Object.values(this.tasks),this.checkpointPendingWrites,this.prevCheckpointConfig,this.outputKeys),"checkpoints"))),Object.values(this.tasks).length===0)return this.status="done",!1;if(this.skipDoneTasks&&this.checkpointPendingWrites.length>0){for(let[n,a,o]of this.checkpointPendingWrites){if(a==="__error__"||a==="__interrupt__"||a==="__resume__")continue;let s=Object.values(this.tasks).find(c=>c.id===n);s&&s.writes.push([a,o])}for(let n of Object.values(this.tasks))n.writes.length>0&&this._outputWrites(n.id,n.writes,!0)}if(Object.values(this.tasks).every(n=>n.writes.length>0))return this.tick({inputKeys:r});if($l(this.checkpoint,this.interruptBefore,Object.values(this.tasks)))throw this.status="interrupt_before",new ti;let i=await vn($i(Q0(Object.values(this.tasks)),"tasks"));return this._emit(i),!0}async finishAndHandleError(t){this.durability==="exit"&&(!this.isNested||typeof t<"u"||this.checkpointNamespace.every(i=>!i.includes(":")))&&(this._putCheckpoint(this.checkpointMetadata),this._flushPendingWrites());let r=this._suppressInterrupt(t);return(r||t===void 0)&&(this.output=wn(this.channels,this.outputKeys)),r&&(this.tasks!==void 0&&this.checkpointPendingWrites.length>0&&Object.values(this.tasks).some(i=>i.writes.length>0)&&(this.updatedChannels=rr(this.checkpoint,this.channels,Object.values(this.tasks),this.checkpointerGetNextVersion,this.triggerToNodes),this._emitValuesWithCheckpointMeta(To($i(ih(this.outputKeys,Object.values(this.tasks).flatMap(i=>i.writes),this.channels),"values")))),ri(t)&&!t.interrupts.length&&this._emit([["updates",{[Ue]:[]}],["values",{[Ue]:[]}]])),r}async acceptPush(t,r,i){if(this.interruptAfter?.length>0&&$l(this.checkpoint,this.interruptAfter,[t])){this.toInterrupt.push(t);return}let n=oh([jr,t.path??[],r,t.id,i],this.checkpoint,this.checkpointPendingWrites,this.nodes,this.channels,t.config??{},!0,{step:this.step,checkpointer:this.checkpointer,manager:this.manager,store:this.store,stream:this.stream});if(!n)return;if(this.interruptBefore?.length>0&&$l(this.checkpoint,this.interruptBefore,[n])){this.toInterrupt.push(n);return}this._emit(To($i(Q0([n]),"tasks"))),this.debug&&sh(this.step,[n]),this.tasks[n.id]=n,this.skipDoneTasks&&this._matchWrites({[n.id]:n});let a=await this._matchCachedWrites();for(let{task:o}of a)this._outputWrites(o.id,o.writes,!0);return n}_suppressInterrupt(t){return ri(t)&&!this.isNested}async _first(t){let{configurable:r}=this.config,i=r?.[ar];if(i&&i.nullResume!==void 0&&this.putWrites(yr,[[_r,i.nullResume]]),yt(this.input)){let o=this.input.resume!=null;if(this.input.resume!=null&&typeof this.input.resume=="object"&&Object.keys(this.input.resume).every(Qm)&&(this.config.configurable??={},this.config.configurable[Do]=this.input.resume),o&&this.checkpointer==null)throw new Error("Cannot use Command(resume=...) without checkpointer");let s={};for(let[c,u,l]of AR(this.input,this.checkpointPendingWrites))s[c]??=[],s[c].push([u,l]);if(Object.keys(s).length===0)throw new Dl("Received empty Command input");for(let[c,u]of Object.entries(s))this.putWrites(c,u)}let n=(this.checkpointPendingWrites??[]).filter(o=>o[0]===yr).map(o=>o.slice(1));n.length>0&&rr(this.checkpoint,this.channels,[{name:En,writes:n,triggers:[]}],this.checkpointerGetNextVersion,this.triggerToNodes);let a=yt(this.input)&&n.length>0;if(this.isResuming||a){for(let s in this.channels)if(Object.prototype.hasOwnProperty.call(this.channels,s)&&this.checkpoint.channel_versions[s]!==void 0){let c=this.checkpoint.channel_versions[s];this.checkpoint.versions_seen[Ue]={...this.checkpoint.versions_seen[Ue],[s]:c}}let o=await vn($i(ih(this.outputKeys,!0,this.channels),"values"));this.isResuming?this.input=iS:a&&(await this._putCheckpoint({source:"input"}),this.input=uh),this._emitValuesWithCheckpointMeta(o)}else{let o=await vn(nh(t,this.input));if(o.length>0){let s=pa(this.checkpoint,this.checkpointPendingWrites,this.nodes,this.channels,this.config,!0,{step:this.step});this.updatedChannels=rr(this.checkpoint,this.channels,Object.values(s).concat([{name:En,writes:o,triggers:[]}]),this.checkpointerGetNextVersion,this.triggerToNodes),await this._putCheckpoint({source:"input"}),this.input=uh}else if("__pregel_resuming"in(this.config.configurable??{}))this.input=uh;else throw new Dl(`Received no input writes for ${JSON.stringify(t,null,2)}`)}this.isNested||(this.config=gr(this.config,{[zo]:this.isResuming}))}_emit(t){for(let[r,i]of t)if(this.stream.modes.has(r)&&this.stream.push([this.checkpointNamespace,r,i]),(r==="checkpoints"||r==="tasks")&&this.stream.modes.has("debug")){let n=r==="checkpoints"?this.step-1:this.step,a=new Date().toISOString(),o=r==="checkpoints"?"checkpoint":typeof i=="object"&&i!=null&&"result"in i?"task_result":"task";this.stream.push([this.checkpointNamespace,"debug",{step:n,type:o,timestamp:a,payload:i}])}}_currentCheckpointMeta(){if(!this.checkpointMetadata||!this.checkpoint?.id)return;let t=this.prevCheckpointConfig?.configurable?.checkpoint_id;return{checkpoint:{id:this.checkpoint.id,...t?{parent_id:t}:{},step:this.checkpointMetadata.step,source:this.checkpointMetadata.source}}}_emitValuesWithCheckpointMeta(t){let r=this._currentCheckpointMeta();for(let[i,n]of t)i==="values"&&r?.checkpoint!=null&&!this.stream.modes.has("checkpoints")&&this.stream.push([this.checkpointNamespace,"checkpoints",r.checkpoint]),this.stream.modes.has(i)&&this.stream.push([this.checkpointNamespace,i,n])}_putCheckpoint(t){let r=this.checkpointMetadata===t,i=this.checkpointer!=null&&(this.durability!=="exit"||r),n=a=>{this.prevCheckpointConfig=this.checkpointConfig?.configurable?.checkpoint_id?this.checkpointConfig:void 0,this.checkpointConfig=gr(this.checkpointConfig,{[Rr]:this.config.configurable?.checkpoint_ns??""});let o={...this.checkpoint.channel_versions},s=vc(this.checkpointPreviousVersions,o);this.checkpointPreviousVersions=o,this._checkpointerPutAfterPrevious({config:{...this.checkpointConfig},checkpoint:gn(a),metadata:{...this.checkpointMetadata},newVersions:s}),this.checkpointConfig={...this.checkpointConfig,configurable:{...this.checkpointConfig.configurable,checkpoint_id:this.checkpoint.id}}};r||(this.checkpointMetadata={...t,step:this.step,parents:this.config.configurable?.checkpoint_map??{}}),this.checkpoint=_n(this.checkpoint,i?this.channels:void 0,this.step,r?{id:this.checkpoint.id}:void 0),i&&n(this.checkpoint),r||(this.step+=1)}_flushPendingWrites(){if(this.checkpointer==null||this.checkpointPendingWrites.length===0)return;let t=gr(this.checkpointConfig,{[Rr]:this.config.configurable?.checkpoint_ns??"",[Pl]:this.checkpoint.id}),r={};for(let[i,n,a]of this.checkpointPendingWrites)r[i]??=[],r[i].push([n,a]);for(let[i,n]of Object.entries(r))this._trackCheckpointerPromise(this.checkpointer.putWrites(t,n,i))}_matchWrites(t){for(let[r,i,n]of this.checkpointPendingWrites){if(i==="__error__"||i==="__interrupt__"||i==="__resume__")continue;let a=Object.values(t).find(o=>o.id===r);a&&a.writes.push([i,n])}for(let r of Object.values(t))r.writes.length>0&&this._outputWrites(r.id,r.writes,!0)}};function H9(e){return We(e?.message)}function YR(e,t,r){if(!e)return;let i=e.langgraph_checkpoint_ns,n=e.checkpoint_ns,a=i??n;if(a)return[a.split("|"),{tags:t,name:r,...e}]}var QR=class extends xr{name="StreamMessagesHandler";streamFn;metadatas={};seen={};emittedChatModelRunIds={};stableMessageIdMap={};lc_prefer_streaming=!0;constructor(e){super(),this.streamFn=e}_emit(e,t,r,i=!1){if(i&&t.id!==void 0&&this.seen[t.id]!==void 0)return;let n=t.id;r!=null&&(zc(t)?n??=`run-${r}-tool-${t.tool_call_id}`:((n==null||n===`run-${r}`)&&(n=this.stableMessageIdMap[r]??n??`run-${r}`),this.stableMessageIdMap[r]??=n)),n!==t.id&&(t.id=n,t.lc_kwargs.id=n),t.id!=null&&(this.seen[t.id]=t),this.streamFn([e[0],"messages",[t,e[1]]])}handleChatModelStart(e,t,r,i,n,a,o,s){o&&(!a||!a.includes("langsmith:nostream")&&!a.includes("nostream"))&&(this.metadatas[r]=YR(o,a,s))}handleLLMNewToken(e,t,r,i,n,a){let o=a?.chunk;this.emittedChatModelRunIds[r]=!0,this.metadatas[r]!==void 0&&(H9(o)?this._emit(this.metadatas[r],o.message,r):this._emit(this.metadatas[r],new Qe({content:e}),r))}handleLLMEnd(e,t){if(this.metadatas[t]!==void 0){if(!this.emittedChatModelRunIds[t]){let r=e.generations?.[0]?.[0];We(r?.message)&&this._emit(this.metadatas[t],r?.message,t,!0),delete this.emittedChatModelRunIds[t]}delete this.metadatas[t],delete this.stableMessageIdMap[t]}}handleLLMError(e,t){delete this.metadatas[t]}handleChainStart(e,t,r,i,n,a,o,s){if(a!==void 0&&s===a.langgraph_node&&(n===void 0||!n.includes("langsmith:hidden"))&&(this.metadatas[r]=YR(a,n,s),typeof t=="object")){for(let c of Object.values(t))if((We(c)||ai(c))&&c.id!==void 0)this.seen[c.id]=c;else if(Array.isArray(c))for(let u of c)(We(u)||ai(u))&&u.id!==void 0&&(this.seen[u.id]=u)}}handleChainEnd(e,t){let r=this.metadatas[t];if(delete this.metadatas[t],r!==void 0){if(We(e))this._emit(r,e,t,!0);else if(Array.isArray(e))for(let i of e)We(i)&&this._emit(r,i,t,!0);else if(e!=null&&typeof e=="object"){for(let i of Object.values(e))if(We(i))this._emit(r,i,t,!0);else if(Array.isArray(i))for(let n of i)We(n)&&this._emit(r,n,t,!0)}}}handleChainError(e,t){delete this.metadatas[t]}};function eM(e){if("response_metadata"in e&&typeof e.response_metadata=="object"&&e.response_metadata!=null)return e.response_metadata}function tM(e){if("usage_metadata"in e&&typeof e.usage_metadata=="object"&&e.usage_metadata!=null)return e.usage_metadata}function G9(e){switch(e.type){case"text":return{type:"text",text:""};case"reasoning":return{type:"reasoning",reasoning:""};case"tool_call":case"tool_call_chunk":return{type:"tool_call_chunk",...e.id!=null?{id:e.id}:{},...e.name!=null?{name:e.name}:{},args:""};default:return e}}function J9(e){switch(e.type){case"text":{let t=typeof e.text=="string"?e.text:"";return t.length>0?{event:"content-block-delta",index:typeof e.index=="number"?e.index:0,delta:{type:"text-delta",text:t}}:void 0}case"reasoning":{let t=typeof e.reasoning=="string"?e.reasoning:"";return t.length>0?{event:"content-block-delta",index:typeof e.index=="number"?e.index:0,delta:{type:"reasoning-delta",reasoning:t}}:void 0}case"tool_call_chunk":return{event:"content-block-delta",index:typeof e.index=="number"?e.index:0,delta:{type:"block-delta",fields:{...e,type:"tool_call_chunk"}}};default:return}}var rM=class extends xr{name="StreamProtocolMessagesHandler";streamFn;metadatas={};seen={};streamedRunIds=new Set;stableMessageIdMap={};lc_prefer_chat_model_stream_events=!0;constructor(e){super(),this.streamFn=e}normalizeMessageId(e,t){let r=e.id;return t!=null&&(gt.isInstance(e)?r??=`run-${t}-tool-${e.tool_call_id}`:((r==null||r===`run-${t}`)&&(r=this.stableMessageIdMap[t]??r??`run-${t}`),this.stableMessageIdMap[t]??=r)),r!==e.id&&(e.id=r,e.lc_kwargs.id=r),e.id!=null&&(this.seen[e.id]=e),e.id}emit(e,t,r){let i=r!=null?{...e[1],run_id:r}:e[1];this.streamFn([e[0],"messages",[t,i]])}emitFinalMessage(e,t,r,i=!1){let n=t.id??(r!=null?this.stableMessageIdMap[r]:void 0);if(i&&n!=null&&this.seen[n]!==void 0)return;let a=this.normalizeMessageId(t,r),o=t.type==="human"?"human":t.type==="system"?"system":t.type==="tool"?"tool":"ai",s=o==="tool"&&gt.isInstance(t)?t.tool_call_id:void 0;this.emit(e,{event:"message-start",...a!=null?{id:a}:{},...o!=="ai"?{role:o}:{},...typeof s=="string"?{tool_call_id:s}:{}},r),(Array.isArray(t.content)?t.content:typeof t.content=="string"&&t.content.length>0?[{type:"text",text:t.content}]:[]).forEach((c,u)=>{let l=typeof c.index=="number"?c.index:u;this.emit(e,{event:"content-block-start",index:l,content:G9(c)},r);let d=J9({...c,index:l});d!=null&&this.emit(e,d,r),this.emit(e,{event:"content-block-finish",index:l,content:c},r)}),this.emit(e,{event:"message-finish",...tM(t)!=null?{usage:tM(t)}:{},...eM(t)!=null?{responseMetadata:eM(t)}:{}},r)}handleChatModelStart(e,t,r,i,n,a,o,s){o&&(!a||!a.includes("langsmith:nostream")&&!a.includes("nostream"))&&(this.metadatas[r]=[o.langgraph_checkpoint_ns.split("|"),{tags:a,name:s,...o}])}handleLLMNewToken(){}handleChatModelStreamEvent(e,t){let r=this.metadatas[t];if(r===void 0)return;let i=e;if(e.event==="message-start"){this.streamedRunIds.add(t);let n=e.id??`run-${t}`;this.seen[n]=!0,this.stableMessageIdMap[t]??=n,e.id==null&&(i={...e,id:n})}this.emit(r,i,t)}handleLLMEnd(e,t){let r=this.metadatas[t];if(r===void 0)return;let i=e.generations?.[0]?.[0],n=Oe.isInstance(i?.message)?i.message:void 0;if(n!=null)if(this.streamedRunIds.has(t)){let a=this.normalizeMessageId(n,t);a!=null&&(this.seen[a]=n)}else this.emitFinalMessage(r,n,t,!0);this.streamedRunIds.delete(t),delete this.metadatas[t],delete this.stableMessageIdMap[t]}handleLLMError(e,t){this.streamedRunIds.delete(t),delete this.metadatas[t],delete this.stableMessageIdMap[t]}handleChainStart(e,t,r,i,n,a,o,s){if(a!==void 0&&s===a.langgraph_node&&(n===void 0||!n.includes("langsmith:hidden"))&&(this.metadatas[r]=[a.langgraph_checkpoint_ns.split("|"),{tags:n,name:s,...a}],typeof t=="object")){for(let c of Object.values(t))if((Oe.isInstance(c)||bt.isInstance(c))&&c.id!==void 0)this.seen[c.id]=c;else if(Array.isArray(c))for(let u of c)(Oe.isInstance(u)||bt.isInstance(u))&&u.id!==void 0&&(this.seen[u.id]=u)}}handleChainEnd(e,t){let r=this.metadatas[t];if(delete this.metadatas[t],r===void 0)return;let i=n=>{Oe.isInstance(n)&&!gt.isInstance(n)&&this.emitFinalMessage(r,n,t,!0)};if(Oe.isInstance(e))i(e);else if(Array.isArray(e))for(let n of e)i(n);else if(e!=null&&typeof e=="object")for(let n of Object.values(e))if(Array.isArray(n))for(let a of n)i(a);else i(n);delete this.stableMessageIdMap[t]}handleChainError(e,t){delete this.metadatas[t],delete this.stableMessageIdMap[t]}};var K9=[400,401,402,403,404,405,406,407,409],W9=e=>{if(e.message.startsWith("Cancel")||e.message.startsWith("AbortError")||e.name==="AbortError"||e.name==="GraphValueError"||e?.code==="ECONNABORTED")return!1;let t=e?.response?.status??e?.status;return!(t&&K9.includes(+t)||e?.error?.code==="insufficient_quota")};async function aS(e,t,r,i){let n=e.retry_policy??t,a=n!==void 0?n.initialInterval??500:0,o=0,s,c,u=e.config??{};r&&(u=gr(u,r)),u={...u,signal:i};let l=Date.now();for(u.executionInfo!=null&&(u.executionInfo={...u.executionInfo,nodeFirstAttemptTime:l});!i?.aborted;){e.writes.splice(0,e.writes.length),s=void 0;try{c=await e.proc.invoke(e.input,u);break}catch(d){if(s=d,s.pregelTaskId=e.id,_h(s)){let m=u?.configurable?.checkpoint_ns,g=s.command;if(g.graph===m){for(let v of e.writers)await v.invoke(g,u);s=void 0;break}else if(g.graph===ir.PARENT){let v=lR(m);s.command=new ir({...s.command,graph:v})}}if(Ea(s)||n===void 0||(o+=1,o>=(n.maxAttempts??3))||!(n.retryOn??W9)(s))break;a=Math.min(n.maxInterval??128e3,a*(n.backoffFactor??2));let f=n.jitter?Math.floor(a+Math.random()*1e3):a;await new Promise(m=>setTimeout(m,f));let p=s.name??s.constructor.unminifiable_name??s.constructor.name;(n?.logWarning??!0)&&console.log(`Retrying task "${String(e.name)}" after ${a.toFixed(2)}ms (attempt ${o}) after ${p}: ${s}`),u=gr(u,{[zo]:!0}),u.executionInfo!=null&&(u.executionInfo={...u.executionInfo,nodeAttempt:o+1,nodeFirstAttemptTime:l})}}return{task:e,result:c,error:s,signalAborted:i?.aborted}}var oS=Symbol.for("promiseAdded");function q9(){let e={next:()=>{},wait:Promise.resolve(oS)};function t(r){e.next=()=>{e.wait=new Promise(t),r(oS)}}return e.wait=new Promise(t),e}var nM=class{nodeFinished;loop;constructor({loop:e,nodeFinished:t}){this.loop=e,this.nodeFinished=t}async tick(e={}){let{timeout:t,retryPolicy:r,onStepWrite:i,maxConcurrency:n}=e,a=new Set,o,s=new AbortController,c=s.signal,u=t?AbortSignal.timeout(t):void 0,l=Object.values(this.loop.tasks).filter(m=>m.writes.length===0),{signals:d,disposeCombinedSignal:f}=this._initializeAbortSignals({exceptionSignal:c,stepTimeoutSignal:u,signal:e.signal}),p=this._executeTasksWithRetry(l,{signals:d,retryPolicy:r,maxConcurrency:n});for await(let{task:m,error:g,signalAborted:v}of p)this._commit(m,g),ri(g)||Ea(g)&&!ri(o)?o=g:g&&(a.size===0||!v)&&(s.abort(),a.add(g));if(f?.(),i?.(this.loop.step,Object.values(this.loop.tasks).map(m=>m.writes).flat()),a.size===1)throw Array.from(a)[0];if(a.size>1)throw new AggregateError(Array.from(a),`Multiple errors occurred during superstep ${this.loop.step}. See the "errors" field of this exception for more details.`);if(ri(o)||Ea(o)&&this.loop.isNested)throw o}_initializeAbortSignals({exceptionSignal:e,stepTimeoutSignal:t,signal:r}){let i=this.loop.config.configurable?.__pregel_abort_signals??{},n=i.externalAbortSignal??r,a=t??i.timeoutAbortSignal,{signal:o,dispose:s}=bc(n,a,e),c={externalAbortSignal:n,timeoutAbortSignal:a,composedAbortSignal:o};return this.loop.config=gr(this.loop.config,{[xS]:c}),{signals:c,disposeCombinedSignal:s}}async*_executeTasksWithRetry(e,t){let{retryPolicy:r,maxConcurrency:i,signals:n}=t??{},a=q9(),o={},s={executingTasksMap:o,barrier:a,retryPolicy:r,scheduleTask:async(f,p,m)=>this.loop.acceptPush(f,p,m)};if(n?.composedAbortSignal?.aborted)throw new Error("Abort");let c=0,u,l=bc(n?.externalAbortSignal,n?.timeoutAbortSignal),d=l.signal?new Promise((f,p)=>{u=()=>p(new Error("Abort")),l.signal?.addEventListener("abort",u,{once:!0})}):void 0;for(;(c===0||Object.keys(o).length>0)&&e.length;){for(;Object.values(o).length<(i??e.length)&&c<e.length;c+=1){let p=e[c];o[p.id]=aS(p,r,{[jo]:iM?.bind(s,this,p)},n?.composedAbortSignal).catch(m=>({task:p,error:m,signalAborted:n?.composedAbortSignal?.aborted}))}let f=await Promise.race([...Object.values(o),...d?[d]:[],a.wait]);f!==oS&&(yield f,u!=null&&(l.signal?.removeEventListener("abort",u),l.dispose?.()),delete o[f.task.id])}}_commit(e,t){if(t!==void 0)if(ri(t)){if(t.interrupts.length){let r=t.interrupts.map(n=>[Ue,n]),i=e.writes.filter(n=>n[0]===_r);i.length&&r.push(...i),this.loop.putWrites(e.id,r)}}else Ea(t)&&e.writes.length?this.loop.putWrites(e.id,e.writes):this.loop.putWrites(e.id,[[Mo,{message:t.message,name:t.name}]]);else this.nodeFinished&&(e.config?.tags==null||!e.config.tags.includes("langsmith:hidden"))&&this.nodeFinished(String(e.name)),e.writes.length===0&&e.writes.push([Ic,null]),this.loop.putWrites(e.id,e.writes)}};async function iM(e,t,r,i,n,a={}){let o=t.config?.configurable?.[ar];if(!o)throw new Error(`BUG: No scratchpad found on task ${t.name}__${t.id}`);let s=o.callCounter;o.callCounter+=1;let c=new NR({func:r,name:i,input:n,cache:a.cache,retry:a.retry,callbacks:a.callbacks}),u=await this.scheduleTask(t,s,c);if(!u)return;let l=this.executingTasksMap[u.id];if(l!==void 0)return l;if(u.writes.length>0){let d=u.writes.filter(([p])=>p===Ci),f=u.writes.filter(([p])=>p===Mo);if(d.length>0){if(d.length===1)return Promise.resolve(d[0][1]);throw new Error(`BUG: multiple returns found for task ${u.name}__${u.id}`)}if(f.length>0){if(f.length===1){let p=f[0][1],m=p instanceof Error?p:new Error(String(p));return Promise.reject(m)}throw new Error(`BUG: multiple errors found for task ${u.name}__${u.id}`)}return}else{let d=aS(u,a.retry,{[jo]:iM.bind(this,e,u)});return this.executingTasksMap[u.id]=d,this.barrier.next(),d.then(({result:f,error:p})=>p?Promise.reject(p):f)}}var Ei=class extends Error{constructor(e){super(e),this.name="GraphValidationError"}};function aM({nodes:e,channels:t,inputChannels:r,outputChannels:i,streamChannels:n,interruptAfterNodes:a,interruptBeforeNodes:o}){if(!t)throw new Ei("Channels not provided");let s=new Set,c=new Set;for(let[u,l]of Object.entries(e)){if(u==="__interrupt__")throw new Ei(`"Node name ${Ue} is reserved"`);if(l.constructor===bn)l.triggers.forEach(d=>s.add(d));else throw new Ei(`Invalid node type ${typeof l}, expected PregelNode`)}for(let u of s)if(!(u in t))throw new Ei(`Subscribed channel '${String(u)}' not in channels`);if(Array.isArray(r)){if(r.every(u=>!s.has(u)))throw new Ei(`None of the input channels ${r} are subscribed to by any node`)}else if(!s.has(r))throw new Ei(`Input channel ${String(r)} is not subscribed to by any node`);Array.isArray(i)?i.forEach(u=>c.add(u)):c.add(i),n&&!Array.isArray(n)?c.add(n):Array.isArray(n)&&n.forEach(u=>c.add(u));for(let u of c)if(!(u in t))throw new Ei(`Output channel '${String(u)}' not in channels`);if(a&&a!=="*"){for(let u of a)if(!(u in e))throw new Ei(`Node ${String(u)} not in nodes`)}if(o&&o!=="*"){for(let u of o)if(!(u in e))throw new Ei(`Node ${String(u)} not in nodes`)}}function sS(e,t){if(Array.isArray(e)){for(let r of e)if(!(r in t))throw new Error(`Key ${String(r)} not found in channels`)}else if(!(e in t))throw new Error(`Key ${String(e)} not found in channels`)}var cS=class oM extends kt{lc_graph_name="Topic";unique=!1;accumulate=!1;seen;values;constructor(t){super(),this.unique=t?.unique??this.unique,this.accumulate=t?.accumulate??this.accumulate,this.seen=new Set,this.values=[]}fromCheckpoint(t){let r=new oM({unique:this.unique,accumulate:this.accumulate});return typeof t<"u"&&(r.seen=new Set(t[0]),r.values=t[1]),r}update(t){let r=!1;this.accumulate||(r=this.values.length>0,this.values=[]);let i=t.flat();if(i.length>0)if(this.unique)for(let n of i)this.seen.has(n)||(r=!0,this.seen.add(n),this.values.push(n));else r=!0,this.values.push(...i);return r}get(){if(this.values.length===0)throw new Ne;return this.values}checkpoint(){return[[...this.seen],this.values]}isAvailable(){return this.values.length!==0}};function X9(e){let t=new TextEncoder;return new ReadableStream({async start(r){try{for await(let i of e){let n=i.params.namespace,a=n.length?`${i.method}|${n.join("|")}`:i.method;r.enqueue(t.encode(`event: ${a}
423
+ `))};try{for await(let n of e){let[a,o,s]=n,c=s;if(o==="debug"){let u=s;u.type==="checkpoint"&&(c={...u,payload:GR(u.payload)})}o==="checkpoints"&&(c=GR(s)),i({event:a?.length?`${o}|${a.join("|")}`:o,data:c})}}catch(n){i({event:"error",data:Z9(n)})}r.close()}})}function WR(...e){return new rS({passthroughFn:t=>{let r=t[1]==="checkpoints"&&mc(t[2]);for(let i of e)(i.modes.has(t[1])||r)&&i.push(t)},modes:new Set(e.flatMap(t=>Array.from(t.modes)))})}var uh=Symbol.for("INPUT_DONE"),iS=Symbol.for("INPUT_RESUMING"),H9=25,G9=class extends Lm{cache;queue=Promise.resolve();constructor(e){super(),this.cache=e}async get(e){return this.enqueueOperation("get",e)}async set(e){return this.enqueueOperation("set",e)}async clear(e){return this.enqueueOperation("clear",e)}async stop(){await this.queue}enqueueOperation(e,...t){let r=this.queue.then(()=>this.cache[e](...t));return this.queue=r.then(()=>{},()=>{}),r}},qR=class XR{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=new Set;isNested;_checkpointerChainedPromise=Promise.resolve();_trackCheckpointerPromise(t){let r=t.then(i=>(this.checkpointerPromises.delete(r),i),i=>{throw i});this.checkpointerPromises.add(r)}store;cache;manager;interruptAfter;interruptBefore;toInterrupt=[];debug=!1;triggerToNodes;get isResuming(){let t=!1;if("__start__"in this.checkpoint.channel_versions)t=!0;else for(let s in this.checkpoint.channel_versions)if(Object.prototype.hasOwnProperty.call(this.checkpoint.channel_versions,s)){t=!0;break}let r=this.config.configurable?.__pregel_resuming!==void 0&&this.config.configurable?.__pregel_resuming,i=this.input===null||this.input===void 0,n=yt(this.input)&&this.input.resume!=null,a=this.input===iS,o=!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 t&&(r||i||n||a||o)}constructor(t){this.input=t.input,this.checkpointer=t.checkpointer,this.checkpointer!==void 0?this.checkpointerGetNextVersion=this.checkpointer.getNextVersion.bind(this.checkpointer):this.checkpointerGetNextVersion=DR,this.checkpoint=t.checkpoint,this.checkpointMetadata=t.checkpointMetadata,this.checkpointPreviousVersions=t.checkpointPreviousVersions,this.channels=t.channels,this.checkpointPendingWrites=t.checkpointPendingWrites,this.step=t.step,this.stop=t.stop,this.config=t.config,this.checkpointConfig=t.checkpointConfig,this.isNested=t.isNested,this.manager=t.manager,this.outputKeys=t.outputKeys,this.streamKeys=t.streamKeys,this.nodes=t.nodes,this.skipDoneTasks=t.skipDoneTasks,this.store=t.store,this.cache=t.cache?new G9(t.cache):void 0,this.stream=t.stream,this.checkpointNamespace=t.checkpointNamespace,this.prevCheckpointConfig=t.prevCheckpointConfig,this.interruptAfter=t.interruptAfter,this.interruptBefore=t.interruptBefore,this.durability=t.durability,this.debug=t.debug,this.triggerToNodes=t.triggerToNodes}static async initialize(t){let{config:r,stream:i}=t;i!==void 0&&r.configurable?.__pregel_stream!==void 0&&(i=WR(i,r.configurable[Ec]));let n=r.configurable?!("checkpoint_id"in r.configurable):!0,a=r.configurable?.[ar];r.configurable&&a&&(a.subgraphCounter>0&&(r=gr(r,{[Rr]:[r.configurable[Rr],a.subgraphCounter.toString()].join("|")})),a.subgraphCounter+=1);let o=Yr in(r.configurable??{});!o&&r.configurable?.checkpoint_ns!==void 0&&r.configurable?.checkpoint_ns!==""&&(r=gr(r,{checkpoint_ns:"",checkpoint_id:void 0}));let s=r;r.configurable?.checkpoint_map!==void 0&&r.configurable?.checkpoint_map?.[r.configurable?.checkpoint_ns]&&(s=gr(r,{checkpoint_id:r.configurable[Mr][r.configurable?.checkpoint_ns]}));let c=r.configurable?.checkpoint_ns?.split("|")??[],u=await t.checkpointer?.getTuple(s)??{config:r,checkpoint:lc(),metadata:{source:"input",step:-2,parents:{}},pendingWrites:[]};s={...r,...u.config,configurable:{checkpoint_ns:"",...r.configurable,...u.config.configurable}};let l=u.parentConfig,d=gn(u.checkpoint),f={...u.metadata},p=u.pendingWrites??[],m=la(t.channelSpecs,d),g=(f.step??0)+1,v=g+(r.recursionLimit??H9)+1,b={...d.channel_versions},w=t.store?new Um(t.store):void 0;return w&&await w.start(),new XR({input:t.input,config:r,checkpointer:t.checkpointer,checkpoint:d,checkpointMetadata:f,checkpointConfig:s,prevCheckpointConfig:l,checkpointNamespace:c,channels:m,isNested:o,manager:t.manager,skipDoneTasks:n,step:g,stop:v,checkpointPreviousVersions:b,checkpointPendingWrites:p,outputKeys:t.outputKeys??[],streamKeys:t.streamKeys??[],nodes:t.nodes,stream:i,store:w,cache:t.cache,interruptAfter:t.interruptAfter,interruptBefore:t.interruptBefore,durability:t.durability,debug:t.debug,triggerToNodes:t.triggerToNodes})}_checkpointerPutAfterPrevious(t){this._checkpointerChainedPromise=this._checkpointerChainedPromise.then(()=>this.checkpointer?.put(t.config,t.checkpoint,t.metadata,t.newVersions)),this._trackCheckpointerPromise(this._checkpointerChainedPromise)}putWrites(t,r){let i=r;if(i.length===0)return;i.every(([c])=>c in hl)&&(i=Array.from(new Map(i.map(c=>[c[0],c])).values()));let n=!1;for(let c in this.channels)if(Object.prototype.hasOwnProperty.call(this.channels,c)&&this.channels[c].lc_graph_name==="UntrackedValue"){n=!0;break}let a=i;n&&(a=i.filter(([c])=>{let u=this.channels[c];return!u||u.lc_graph_name!=="UntrackedValue"}).map(([c,u])=>c==="__pregel_tasks"&&mt(u)?[c,UR(u,this.channels)]:[c,u])),this.checkpointPendingWrites=this.checkpointPendingWrites.filter(c=>c[0]!==t);for(let[c,u]of a)this.checkpointPendingWrites.push([t,c,u]);let o=gr(this.checkpointConfig,{[Rr]:this.config.configurable?.checkpoint_ns??"",[Pl]:this.checkpoint.id});if(this.durability!=="exit"&&this.checkpointer!=null&&this._trackCheckpointerPromise(this.checkpointer.putWrites(o,a,t)),this.tasks&&this._outputWrites(t,i),!r.length||!this.cache||!this.tasks)return;let s=this.tasks[t];s==null||s.cache_key==null||r[0][0]==="__error__"||r[0][0]==="__interrupt__"||this.cache.set([{key:[s.cache_key.ns,s.cache_key.key],value:s.writes,ttl:s.cache_key.ttl}])}_outputWrites(t,r,i=!1){let n=this.tasks[t];if(n!==void 0){if(n.config!==void 0&&(n.config.tags??[]).includes("langsmith:hidden"))return;if(r.length>0)if(r[0][0]==="__interrupt__"){if(n.path?.[0]==="__pregel_push"&&n.path?.[n.path.length-1]===!0)return;let a=r.filter(o=>o[0]===Ue).flatMap(o=>o[1]);this._emit([["updates",{[Ue]:a}],["values",{[Ue]:a}]])}else r[0][0]!=="__error__"&&this._emit(To($i(CR(this.outputKeys,[[n,r]],i),"updates")));i||this._emit(To($i(FR([[n,r]],this.streamKeys),"tasks")))}}async _matchCachedWrites(){if(!this.cache)return[];let t=[],r=([o,s])=>`ns:${o.join(",")}|key:${s}`,i=[],n={};for(let o of Object.values(this.tasks))o.cache_key!=null&&!o.writes.length&&(i.push([o.cache_key.ns,o.cache_key.key]),n[r([o.cache_key.ns,o.cache_key.key])]=o);if(i.length===0)return[];let a=await this.cache.get(i);for(let{key:o,value:s}of a){let c=n[r(o)];c!=null&&(c.writes.push(...s),t.push({task:c,result:s}))}return t}async tick(t){this.store&&!this.store.isRunning&&await this.store?.start();let{inputKeys:r=[]}=t;if(this.status!=="pending")throw new Error(`Cannot tick when status is no longer "pending". Current status: "${this.status}"`);if(![uh,iS].includes(this.input))await this._first(r);else{if(this.toInterrupt.length>0)throw this.status="interrupt_before",new ti;if(Object.values(this.tasks).every(n=>n.writes.length>0)){let n=Object.values(this.tasks).flatMap(o=>o.writes);this.updatedChannels=rr(this.checkpoint,this.channels,Object.values(this.tasks),this.checkpointerGetNextVersion,this.triggerToNodes);let a=await vn($i(ih(this.outputKeys,n,this.channels),"values"));if(this.checkpointPendingWrites=[],await this._putCheckpoint({source:"loop"}),this._emitValuesWithCheckpointMeta(a),$l(this.checkpoint,this.interruptAfter,Object.values(this.tasks)))throw this.status="interrupt_after",new ti;this.config.configurable?.__pregel_resuming!==void 0&&delete this.config.configurable?.[zo]}else return!1}if(this.step>this.stop)return this.status="out_of_steps",!1;if(this.tasks=pa(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 vn($i(BR(this.checkpointConfig,this.channels,this.streamKeys,this.checkpointMetadata,Object.values(this.tasks),this.checkpointPendingWrites,this.prevCheckpointConfig,this.outputKeys),"checkpoints"))),Object.values(this.tasks).length===0)return this.status="done",!1;if(this.skipDoneTasks&&this.checkpointPendingWrites.length>0){for(let[n,a,o]of this.checkpointPendingWrites){if(a==="__error__"||a==="__interrupt__"||a==="__resume__")continue;let s=Object.values(this.tasks).find(c=>c.id===n);s&&s.writes.push([a,o])}for(let n of Object.values(this.tasks))n.writes.length>0&&this._outputWrites(n.id,n.writes,!0)}if(Object.values(this.tasks).every(n=>n.writes.length>0))return this.tick({inputKeys:r});if($l(this.checkpoint,this.interruptBefore,Object.values(this.tasks)))throw this.status="interrupt_before",new ti;let i=await vn($i(Q0(Object.values(this.tasks)),"tasks"));return this._emit(i),!0}async finishAndHandleError(t){this.durability==="exit"&&(!this.isNested||typeof t<"u"||this.checkpointNamespace.every(i=>!i.includes(":")))&&(this._putCheckpoint(this.checkpointMetadata),this._flushPendingWrites());let r=this._suppressInterrupt(t);return(r||t===void 0)&&(this.output=wn(this.channels,this.outputKeys)),r&&(this.tasks!==void 0&&this.checkpointPendingWrites.length>0&&Object.values(this.tasks).some(i=>i.writes.length>0)&&(this.updatedChannels=rr(this.checkpoint,this.channels,Object.values(this.tasks),this.checkpointerGetNextVersion,this.triggerToNodes),this._emitValuesWithCheckpointMeta(To($i(ih(this.outputKeys,Object.values(this.tasks).flatMap(i=>i.writes),this.channels),"values")))),ri(t)&&!t.interrupts.length&&this._emit([["updates",{[Ue]:[]}],["values",{[Ue]:[]}]])),r}async acceptPush(t,r,i){if(this.interruptAfter?.length>0&&$l(this.checkpoint,this.interruptAfter,[t])){this.toInterrupt.push(t);return}let n=oh([jr,t.path??[],r,t.id,i],this.checkpoint,this.checkpointPendingWrites,this.nodes,this.channels,t.config??{},!0,{step:this.step,checkpointer:this.checkpointer,manager:this.manager,store:this.store,stream:this.stream});if(!n)return;if(this.interruptBefore?.length>0&&$l(this.checkpoint,this.interruptBefore,[n])){this.toInterrupt.push(n);return}this._emit(To($i(Q0([n]),"tasks"))),this.debug&&sh(this.step,[n]),this.tasks[n.id]=n,this.skipDoneTasks&&this._matchWrites({[n.id]:n});let a=await this._matchCachedWrites();for(let{task:o}of a)this._outputWrites(o.id,o.writes,!0);return n}_suppressInterrupt(t){return ri(t)&&!this.isNested}async _first(t){let{configurable:r}=this.config,i=r?.[ar];if(i&&i.nullResume!==void 0&&this.putWrites(yr,[[_r,i.nullResume]]),yt(this.input)){let o=this.input.resume!=null;if(this.input.resume!=null&&typeof this.input.resume=="object"&&Object.keys(this.input.resume).every(Qm)&&(this.config.configurable??={},this.config.configurable[Do]=this.input.resume),o&&this.checkpointer==null)throw new Error("Cannot use Command(resume=...) without checkpointer");let s={};for(let[c,u,l]of AR(this.input,this.checkpointPendingWrites))s[c]??=[],s[c].push([u,l]);if(Object.keys(s).length===0)throw new Dl("Received empty Command input");for(let[c,u]of Object.entries(s))this.putWrites(c,u)}let n=(this.checkpointPendingWrites??[]).filter(o=>o[0]===yr).map(o=>o.slice(1));n.length>0&&rr(this.checkpoint,this.channels,[{name:En,writes:n,triggers:[]}],this.checkpointerGetNextVersion,this.triggerToNodes);let a=yt(this.input)&&n.length>0;if(this.isResuming||a){for(let s in this.channels)if(Object.prototype.hasOwnProperty.call(this.channels,s)&&this.checkpoint.channel_versions[s]!==void 0){let c=this.checkpoint.channel_versions[s];this.checkpoint.versions_seen[Ue]={...this.checkpoint.versions_seen[Ue],[s]:c}}let o=await vn($i(ih(this.outputKeys,!0,this.channels),"values"));this.isResuming?this.input=iS:a&&(await this._putCheckpoint({source:"input"}),this.input=uh),this._emitValuesWithCheckpointMeta(o)}else{let o=await vn(nh(t,this.input));if(o.length>0){let s=pa(this.checkpoint,this.checkpointPendingWrites,this.nodes,this.channels,this.config,!0,{step:this.step});this.updatedChannels=rr(this.checkpoint,this.channels,Object.values(s).concat([{name:En,writes:o,triggers:[]}]),this.checkpointerGetNextVersion,this.triggerToNodes),await this._putCheckpoint({source:"input"}),this.input=uh}else if("__pregel_resuming"in(this.config.configurable??{}))this.input=uh;else throw new Dl(`Received no input writes for ${JSON.stringify(t,null,2)}`)}this.isNested||(this.config=gr(this.config,{[zo]:this.isResuming}))}_emit(t){for(let[r,i]of t)if(this.stream.modes.has(r)&&this.stream.push([this.checkpointNamespace,r,i]),(r==="checkpoints"||r==="tasks")&&this.stream.modes.has("debug")){let n=r==="checkpoints"?this.step-1:this.step,a=new Date().toISOString(),o=r==="checkpoints"?"checkpoint":typeof i=="object"&&i!=null&&"result"in i?"task_result":"task";this.stream.push([this.checkpointNamespace,"debug",{step:n,type:o,timestamp:a,payload:i}])}}_currentCheckpointMeta(){if(!this.checkpointMetadata||!this.checkpoint?.id)return;let t=this.prevCheckpointConfig?.configurable?.checkpoint_id;return{checkpoint:{id:this.checkpoint.id,...t?{parent_id:t}:{},step:this.checkpointMetadata.step,source:this.checkpointMetadata.source}}}_emitValuesWithCheckpointMeta(t){let r=this._currentCheckpointMeta();for(let[i,n]of t)i==="values"&&r?.checkpoint!=null&&!this.stream.modes.has("checkpoints")&&this.stream.push([this.checkpointNamespace,"checkpoints",r.checkpoint]),this.stream.modes.has(i)&&this.stream.push([this.checkpointNamespace,i,n])}_putCheckpoint(t){let r=this.checkpointMetadata===t,i=this.checkpointer!=null&&(this.durability!=="exit"||r),n=a=>{this.prevCheckpointConfig=this.checkpointConfig?.configurable?.checkpoint_id?this.checkpointConfig:void 0,this.checkpointConfig=gr(this.checkpointConfig,{[Rr]:this.config.configurable?.checkpoint_ns??""});let o={...this.checkpoint.channel_versions},s=vc(this.checkpointPreviousVersions,o);this.checkpointPreviousVersions=o,this._checkpointerPutAfterPrevious({config:{...this.checkpointConfig},checkpoint:gn(a),metadata:{...this.checkpointMetadata},newVersions:s}),this.checkpointConfig={...this.checkpointConfig,configurable:{...this.checkpointConfig.configurable,checkpoint_id:this.checkpoint.id}}};r||(this.checkpointMetadata={...t,step:this.step,parents:this.config.configurable?.checkpoint_map??{}}),this.checkpoint=_n(this.checkpoint,i?this.channels:void 0,this.step,r?{id:this.checkpoint.id}:void 0),i&&n(this.checkpoint),r||(this.step+=1)}_flushPendingWrites(){if(this.checkpointer==null||this.checkpointPendingWrites.length===0)return;let t=gr(this.checkpointConfig,{[Rr]:this.config.configurable?.checkpoint_ns??"",[Pl]:this.checkpoint.id}),r={};for(let[i,n,a]of this.checkpointPendingWrites)r[i]??=[],r[i].push([n,a]);for(let[i,n]of Object.entries(r))this._trackCheckpointerPromise(this.checkpointer.putWrites(t,n,i))}_matchWrites(t){for(let[r,i,n]of this.checkpointPendingWrites){if(i==="__error__"||i==="__interrupt__"||i==="__resume__")continue;let a=Object.values(t).find(o=>o.id===r);a&&a.writes.push([i,n])}for(let r of Object.values(t))r.writes.length>0&&this._outputWrites(r.id,r.writes,!0)}};function J9(e){return We(e?.message)}function YR(e,t,r){if(!e)return;let i=e.langgraph_checkpoint_ns,n=e.checkpoint_ns,a=i??n;if(a)return[a.split("|"),{tags:t,name:r,...e}]}var QR=class extends xr{name="StreamMessagesHandler";streamFn;metadatas={};seen={};emittedChatModelRunIds={};stableMessageIdMap={};lc_prefer_streaming=!0;constructor(e){super(),this.streamFn=e}_emit(e,t,r,i=!1){if(i&&t.id!==void 0&&this.seen[t.id]!==void 0)return;let n=t.id;r!=null&&(zc(t)?n??=`run-${r}-tool-${t.tool_call_id}`:((n==null||n===`run-${r}`)&&(n=this.stableMessageIdMap[r]??n??`run-${r}`),this.stableMessageIdMap[r]??=n)),n!==t.id&&(t.id=n,t.lc_kwargs.id=n),t.id!=null&&(this.seen[t.id]=t),this.streamFn([e[0],"messages",[t,e[1]]])}handleChatModelStart(e,t,r,i,n,a,o,s){o&&(!a||!a.includes("langsmith:nostream")&&!a.includes("nostream"))&&(this.metadatas[r]=YR(o,a,s))}handleLLMNewToken(e,t,r,i,n,a){let o=a?.chunk;this.emittedChatModelRunIds[r]=!0,this.metadatas[r]!==void 0&&(J9(o)?this._emit(this.metadatas[r],o.message,r):this._emit(this.metadatas[r],new Qe({content:e}),r))}handleLLMEnd(e,t){if(this.metadatas[t]!==void 0){if(!this.emittedChatModelRunIds[t]){let r=e.generations?.[0]?.[0];We(r?.message)&&this._emit(this.metadatas[t],r?.message,t,!0),delete this.emittedChatModelRunIds[t]}delete this.metadatas[t],delete this.stableMessageIdMap[t]}}handleLLMError(e,t){delete this.metadatas[t]}handleChainStart(e,t,r,i,n,a,o,s){if(a!==void 0&&s===a.langgraph_node&&(n===void 0||!n.includes("langsmith:hidden"))&&(this.metadatas[r]=YR(a,n,s),typeof t=="object")){for(let c of Object.values(t))if((We(c)||ai(c))&&c.id!==void 0)this.seen[c.id]=c;else if(Array.isArray(c))for(let u of c)(We(u)||ai(u))&&u.id!==void 0&&(this.seen[u.id]=u)}}handleChainEnd(e,t){let r=this.metadatas[t];if(delete this.metadatas[t],r!==void 0){if(We(e))this._emit(r,e,t,!0);else if(Array.isArray(e))for(let i of e)We(i)&&this._emit(r,i,t,!0);else if(e!=null&&typeof e=="object"){for(let i of Object.values(e))if(We(i))this._emit(r,i,t,!0);else if(Array.isArray(i))for(let n of i)We(n)&&this._emit(r,n,t,!0)}}}handleChainError(e,t){delete this.metadatas[t]}};function eM(e){if("response_metadata"in e&&typeof e.response_metadata=="object"&&e.response_metadata!=null)return e.response_metadata}function tM(e){if("usage_metadata"in e&&typeof e.usage_metadata=="object"&&e.usage_metadata!=null)return e.usage_metadata}function K9(e){switch(e.type){case"text":return{type:"text",text:""};case"reasoning":return{type:"reasoning",reasoning:""};case"tool_call":case"tool_call_chunk":return{type:"tool_call_chunk",...e.id!=null?{id:e.id}:{},...e.name!=null?{name:e.name}:{},args:""};default:return e}}function W9(e){switch(e.type){case"text":{let t=typeof e.text=="string"?e.text:"";return t.length>0?{event:"content-block-delta",index:typeof e.index=="number"?e.index:0,delta:{type:"text-delta",text:t}}:void 0}case"reasoning":{let t=typeof e.reasoning=="string"?e.reasoning:"";return t.length>0?{event:"content-block-delta",index:typeof e.index=="number"?e.index:0,delta:{type:"reasoning-delta",reasoning:t}}:void 0}case"tool_call_chunk":return{event:"content-block-delta",index:typeof e.index=="number"?e.index:0,delta:{type:"block-delta",fields:{...e,type:"tool_call_chunk"}}};default:return}}var rM=class extends xr{name="StreamProtocolMessagesHandler";streamFn;metadatas={};seen={};streamedRunIds=new Set;stableMessageIdMap={};lc_prefer_chat_model_stream_events=!0;constructor(e){super(),this.streamFn=e}normalizeMessageId(e,t){let r=e.id;return t!=null&&(gt.isInstance(e)?r??=`run-${t}-tool-${e.tool_call_id}`:((r==null||r===`run-${t}`)&&(r=this.stableMessageIdMap[t]??r??`run-${t}`),this.stableMessageIdMap[t]??=r)),r!==e.id&&(e.id=r,e.lc_kwargs.id=r),e.id!=null&&(this.seen[e.id]=e),e.id}emit(e,t,r){let i=r!=null?{...e[1],run_id:r}:e[1];this.streamFn([e[0],"messages",[t,i]])}emitFinalMessage(e,t,r,i=!1){let n=t.id??(r!=null?this.stableMessageIdMap[r]:void 0);if(i&&n!=null&&this.seen[n]!==void 0)return;let a=this.normalizeMessageId(t,r),o=t.type==="human"?"human":t.type==="system"?"system":t.type==="tool"?"tool":"ai",s=o==="tool"&&gt.isInstance(t)?t.tool_call_id:void 0;this.emit(e,{event:"message-start",...a!=null?{id:a}:{},...o!=="ai"?{role:o}:{},...typeof s=="string"?{tool_call_id:s}:{}},r),(Array.isArray(t.content)?t.content:typeof t.content=="string"&&t.content.length>0?[{type:"text",text:t.content}]:[]).forEach((c,u)=>{let l=typeof c.index=="number"?c.index:u;this.emit(e,{event:"content-block-start",index:l,content:K9(c)},r);let d=W9({...c,index:l});d!=null&&this.emit(e,d,r),this.emit(e,{event:"content-block-finish",index:l,content:c},r)}),this.emit(e,{event:"message-finish",...tM(t)!=null?{usage:tM(t)}:{},...eM(t)!=null?{responseMetadata:eM(t)}:{}},r)}handleChatModelStart(e,t,r,i,n,a,o,s){o&&(!a||!a.includes("langsmith:nostream")&&!a.includes("nostream"))&&(this.metadatas[r]=[o.langgraph_checkpoint_ns.split("|"),{tags:a,name:s,...o}])}handleLLMNewToken(){}handleChatModelStreamEvent(e,t){let r=this.metadatas[t];if(r===void 0)return;let i=e;if(e.event==="message-start"){this.streamedRunIds.add(t);let n=e.id??`run-${t}`;this.seen[n]=!0,this.stableMessageIdMap[t]??=n,e.id==null&&(i={...e,id:n})}this.emit(r,i,t)}handleLLMEnd(e,t){let r=this.metadatas[t];if(r===void 0)return;let i=e.generations?.[0]?.[0],n=Oe.isInstance(i?.message)?i.message:void 0;if(n!=null)if(this.streamedRunIds.has(t)){let a=this.normalizeMessageId(n,t);a!=null&&(this.seen[a]=n)}else this.emitFinalMessage(r,n,t,!0);this.streamedRunIds.delete(t),delete this.metadatas[t],delete this.stableMessageIdMap[t]}handleLLMError(e,t){this.streamedRunIds.delete(t),delete this.metadatas[t],delete this.stableMessageIdMap[t]}handleChainStart(e,t,r,i,n,a,o,s){if(a!==void 0&&s===a.langgraph_node&&(n===void 0||!n.includes("langsmith:hidden"))&&(this.metadatas[r]=[a.langgraph_checkpoint_ns.split("|"),{tags:n,name:s,...a}],typeof t=="object")){for(let c of Object.values(t))if((Oe.isInstance(c)||bt.isInstance(c))&&c.id!==void 0)this.seen[c.id]=c;else if(Array.isArray(c))for(let u of c)(Oe.isInstance(u)||bt.isInstance(u))&&u.id!==void 0&&(this.seen[u.id]=u)}}handleChainEnd(e,t){let r=this.metadatas[t];if(delete this.metadatas[t],r===void 0)return;let i=n=>{Oe.isInstance(n)&&!gt.isInstance(n)&&this.emitFinalMessage(r,n,t,!0)};if(Oe.isInstance(e))i(e);else if(Array.isArray(e))for(let n of e)i(n);else if(e!=null&&typeof e=="object")for(let n of Object.values(e))if(Array.isArray(n))for(let a of n)i(a);else i(n);delete this.stableMessageIdMap[t]}handleChainError(e,t){delete this.metadatas[t],delete this.stableMessageIdMap[t]}};var q9=[400,401,402,403,404,405,406,407,409],X9=e=>{if(e.message.startsWith("Cancel")||e.message.startsWith("AbortError")||e.name==="AbortError"||e.name==="GraphValueError"||e?.code==="ECONNABORTED")return!1;let t=e?.response?.status??e?.status;return!(t&&q9.includes(+t)||e?.error?.code==="insufficient_quota")};async function aS(e,t,r,i){let n=e.retry_policy??t,a=n!==void 0?n.initialInterval??500:0,o=0,s,c,u=e.config??{};r&&(u=gr(u,r)),u={...u,signal:i};let l=Date.now();for(u.executionInfo!=null&&(u.executionInfo={...u.executionInfo,nodeFirstAttemptTime:l});!i?.aborted;){e.writes.splice(0,e.writes.length),s=void 0;try{c=await e.proc.invoke(e.input,u);break}catch(d){if(s=d,s.pregelTaskId=e.id,_h(s)){let m=u?.configurable?.checkpoint_ns,g=s.command;if(g.graph===m){for(let v of e.writers)await v.invoke(g,u);s=void 0;break}else if(g.graph===ir.PARENT){let v=lR(m);s.command=new ir({...s.command,graph:v})}}if(Ea(s)||n===void 0||(o+=1,o>=(n.maxAttempts??3))||!(n.retryOn??X9)(s))break;a=Math.min(n.maxInterval??128e3,a*(n.backoffFactor??2));let f=n.jitter?Math.floor(a+Math.random()*1e3):a;await new Promise(m=>setTimeout(m,f));let p=s.name??s.constructor.unminifiable_name??s.constructor.name;(n?.logWarning??!0)&&console.log(`Retrying task "${String(e.name)}" after ${a.toFixed(2)}ms (attempt ${o}) after ${p}: ${s}`),u=gr(u,{[zo]:!0}),u.executionInfo!=null&&(u.executionInfo={...u.executionInfo,nodeAttempt:o+1,nodeFirstAttemptTime:l})}}return{task:e,result:c,error:s,signalAborted:i?.aborted}}var oS=Symbol.for("promiseAdded");function Y9(){let e={next:()=>{},wait:Promise.resolve(oS)};function t(r){e.next=()=>{e.wait=new Promise(t),r(oS)}}return e.wait=new Promise(t),e}var nM=class{nodeFinished;loop;constructor({loop:e,nodeFinished:t}){this.loop=e,this.nodeFinished=t}async tick(e={}){let{timeout:t,retryPolicy:r,onStepWrite:i,maxConcurrency:n}=e,a=new Set,o,s=new AbortController,c=s.signal,u=t?AbortSignal.timeout(t):void 0,l=Object.values(this.loop.tasks).filter(m=>m.writes.length===0),{signals:d,disposeCombinedSignal:f}=this._initializeAbortSignals({exceptionSignal:c,stepTimeoutSignal:u,signal:e.signal}),p=this._executeTasksWithRetry(l,{signals:d,retryPolicy:r,maxConcurrency:n});for await(let{task:m,error:g,signalAborted:v}of p)this._commit(m,g),ri(g)||Ea(g)&&!ri(o)?o=g:g&&(a.size===0||!v)&&(s.abort(),a.add(g));if(f?.(),i?.(this.loop.step,Object.values(this.loop.tasks).map(m=>m.writes).flat()),a.size===1)throw Array.from(a)[0];if(a.size>1)throw new AggregateError(Array.from(a),`Multiple errors occurred during superstep ${this.loop.step}. See the "errors" field of this exception for more details.`);if(ri(o)||Ea(o)&&this.loop.isNested)throw o}_initializeAbortSignals({exceptionSignal:e,stepTimeoutSignal:t,signal:r}){let i=this.loop.config.configurable?.__pregel_abort_signals??{},n=i.externalAbortSignal??r,a=t??i.timeoutAbortSignal,{signal:o,dispose:s}=bc(n,a,e),c={externalAbortSignal:n,timeoutAbortSignal:a,composedAbortSignal:o};return this.loop.config=gr(this.loop.config,{[xS]:c}),{signals:c,disposeCombinedSignal:s}}async*_executeTasksWithRetry(e,t){let{retryPolicy:r,maxConcurrency:i,signals:n}=t??{},a=Y9(),o={},s={executingTasksMap:o,barrier:a,retryPolicy:r,scheduleTask:async(f,p,m)=>this.loop.acceptPush(f,p,m)};if(n?.composedAbortSignal?.aborted)throw new Error("Abort");let c=0,u,l=bc(n?.externalAbortSignal,n?.timeoutAbortSignal),d=l.signal?new Promise((f,p)=>{u=()=>p(new Error("Abort")),l.signal?.addEventListener("abort",u,{once:!0})}):void 0;for(;(c===0||Object.keys(o).length>0)&&e.length;){for(;Object.values(o).length<(i??e.length)&&c<e.length;c+=1){let p=e[c];o[p.id]=aS(p,r,{[jo]:iM?.bind(s,this,p)},n?.composedAbortSignal).catch(m=>({task:p,error:m,signalAborted:n?.composedAbortSignal?.aborted}))}let f=await Promise.race([...Object.values(o),...d?[d]:[],a.wait]);f!==oS&&(yield f,u!=null&&(l.signal?.removeEventListener("abort",u),l.dispose?.()),delete o[f.task.id])}}_commit(e,t){if(t!==void 0)if(ri(t)){if(t.interrupts.length){let r=t.interrupts.map(n=>[Ue,n]),i=e.writes.filter(n=>n[0]===_r);i.length&&r.push(...i),this.loop.putWrites(e.id,r)}}else Ea(t)&&e.writes.length?this.loop.putWrites(e.id,e.writes):this.loop.putWrites(e.id,[[Mo,{message:t.message,name:t.name}]]);else this.nodeFinished&&(e.config?.tags==null||!e.config.tags.includes("langsmith:hidden"))&&this.nodeFinished(String(e.name)),e.writes.length===0&&e.writes.push([Ic,null]),this.loop.putWrites(e.id,e.writes)}};async function iM(e,t,r,i,n,a={}){let o=t.config?.configurable?.[ar];if(!o)throw new Error(`BUG: No scratchpad found on task ${t.name}__${t.id}`);let s=o.callCounter;o.callCounter+=1;let c=new NR({func:r,name:i,input:n,cache:a.cache,retry:a.retry,callbacks:a.callbacks}),u=await this.scheduleTask(t,s,c);if(!u)return;let l=this.executingTasksMap[u.id];if(l!==void 0)return l;if(u.writes.length>0){let d=u.writes.filter(([p])=>p===Ci),f=u.writes.filter(([p])=>p===Mo);if(d.length>0){if(d.length===1)return Promise.resolve(d[0][1]);throw new Error(`BUG: multiple returns found for task ${u.name}__${u.id}`)}if(f.length>0){if(f.length===1){let p=f[0][1],m=p instanceof Error?p:new Error(String(p));return Promise.reject(m)}throw new Error(`BUG: multiple errors found for task ${u.name}__${u.id}`)}return}else{let d=aS(u,a.retry,{[jo]:iM.bind(this,e,u)});return this.executingTasksMap[u.id]=d,this.barrier.next(),d.then(({result:f,error:p})=>p?Promise.reject(p):f)}}var Ei=class extends Error{constructor(e){super(e),this.name="GraphValidationError"}};function aM({nodes:e,channels:t,inputChannels:r,outputChannels:i,streamChannels:n,interruptAfterNodes:a,interruptBeforeNodes:o}){if(!t)throw new Ei("Channels not provided");let s=new Set,c=new Set;for(let[u,l]of Object.entries(e)){if(u==="__interrupt__")throw new Ei(`"Node name ${Ue} is reserved"`);if(l.constructor===bn)l.triggers.forEach(d=>s.add(d));else throw new Ei(`Invalid node type ${typeof l}, expected PregelNode`)}for(let u of s)if(!(u in t))throw new Ei(`Subscribed channel '${String(u)}' not in channels`);if(Array.isArray(r)){if(r.every(u=>!s.has(u)))throw new Ei(`None of the input channels ${r} are subscribed to by any node`)}else if(!s.has(r))throw new Ei(`Input channel ${String(r)} is not subscribed to by any node`);Array.isArray(i)?i.forEach(u=>c.add(u)):c.add(i),n&&!Array.isArray(n)?c.add(n):Array.isArray(n)&&n.forEach(u=>c.add(u));for(let u of c)if(!(u in t))throw new Ei(`Output channel '${String(u)}' not in channels`);if(a&&a!=="*"){for(let u of a)if(!(u in e))throw new Ei(`Node ${String(u)} not in nodes`)}if(o&&o!=="*"){for(let u of o)if(!(u in e))throw new Ei(`Node ${String(u)} not in nodes`)}}function sS(e,t){if(Array.isArray(e)){for(let r of e)if(!(r in t))throw new Error(`Key ${String(r)} not found in channels`)}else if(!(e in t))throw new Error(`Key ${String(e)} not found in channels`)}var cS=class oM extends kt{lc_graph_name="Topic";unique=!1;accumulate=!1;seen;values;constructor(t){super(),this.unique=t?.unique??this.unique,this.accumulate=t?.accumulate??this.accumulate,this.seen=new Set,this.values=[]}fromCheckpoint(t){let r=new oM({unique:this.unique,accumulate:this.accumulate});return typeof t<"u"&&(r.seen=new Set(t[0]),r.values=t[1]),r}update(t){let r=!1;this.accumulate||(r=this.values.length>0,this.values=[]);let i=t.flat();if(i.length>0)if(this.unique)for(let n of i)this.seen.has(n)||(r=!0,this.seen.add(n),this.values.push(n));else r=!0,this.values.push(...i);return r}get(){if(this.values.length===0)throw new Ne;return this.values}checkpoint(){return[[...this.seen],this.values]}isAvailable(){return this.values.length!==0}};function Q9(e){let t=new TextEncoder;return new ReadableStream({async start(r){try{for await(let i of e){let n=i.params.namespace,a=n.length?`${i.method}|${n.join("|")}`:i.method;r.enqueue(t.encode(`event: ${a}
424
424
  data: ${JSON.stringify(i.params.data??{})}
425
425
 
426
426
  `))}}catch(i){r.enqueue(t.encode(`event: error
427
427
  data: ${JSON.stringify({message:String(i)})}
428
428
 
429
- `))}finally{r.close()}}})}var sM=class{static subscribeTo(e,t){let{key:r,tags:i}={key:void 0,tags:void 0,...t??{}};if(Array.isArray(e)&&r!==void 0)throw new Error("Can't specify a key when subscribing to multiple channels");let n;return typeof e=="string"?r?n={[r]:e}:n=[e]:n=Object.fromEntries(e.map(a=>[a,a])),new bn({channels:n,triggers:Array.isArray(e)?e:[e],tags:i})}static writeTo(e,t){let r=[];for(let i of e)r.push({channel:i,value:hr,skipNone:!1});for(let[i,n]of Object.entries(t??{}))ae.isRunnable(n)||typeof n=="function"?r.push({channel:i,value:hr,skipNone:!0,mapper:tt(n)}):r.push({channel:i,value:n,skipNone:!1});return new ot(r)}},Y9=class extends ae{lc_namespace=["langgraph","pregel"];invoke(e,t){throw new Error("Not implemented")}withConfig(e){return super.withConfig(e)}stream(e,t){return super.stream(e,t)}},lh=class extends Y9{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;streamTransformers;triggerToNodes={};constructor(e){super(e);let{streamMode:t}=e;if(t!=null&&!Array.isArray(t)&&(t=[t]),this.nodes=e.nodes,this.channels=e.channels,"__pregel_tasks"in this.channels&&"lc_graph_name"in this.channels.__pregel_tasks&&this.channels.__pregel_tasks.lc_graph_name!=="Topic")throw new Error(`Channel '${In}' is reserved and cannot be used in the graph.`);this.channels[In]=new cS({accumulate:!1}),this.autoValidate=e.autoValidate??this.autoValidate,this.streamMode=t??this.streamMode,this.inputChannels=e.inputChannels,this.outputChannels=e.outputChannels,this.streamChannels=e.streamChannels??this.streamChannels,this.interruptAfter=e.interruptAfter,this.interruptBefore=e.interruptBefore,this.stepTimeout=e.stepTimeout??this.stepTimeout,this.debug=e.debug??this.debug,this.checkpointer=e.checkpointer,this.retryPolicy=e.retryPolicy,this.config=e.config,this.store=e.store,this.cache=e.cache,this.name=e.name,this.triggerToNodes=e.triggerToNodes??this.triggerToNodes,this.userInterrupt=e.userInterrupt,this.streamTransformers=e.streamTransformers??[],this.autoValidate&&this.validate()}withConfig(e){let{streamTransformers:t,...r}=e,i=xt(this.config,r),n=[...this.streamTransformers,...t??[]];return new this.constructor({...this,config:i,streamTransformers:n})}validate(){aM({nodes:this.nodes,channels:this.channels,outputChannels:this.outputChannels,inputChannels:this.inputChannels,streamChannels:this.streamChannels,interruptAfterNodes:this.interruptAfter,interruptBeforeNodes:this.interruptBefore});for(let[e,t]of Object.entries(this.nodes))for(let r of t.triggers)this.triggerToNodes[r]??=[],this.triggerToNodes[r].push(e);return this}get streamChannelsList(){return Array.isArray(this.streamChannels)?this.streamChannels:this.streamChannels?[this.streamChannels]:Object.keys(this.channels)}get streamChannelsAsIs(){return this.streamChannels?this.streamChannels:Object.keys(this.channels)}async getGraphAsync(e){return this.getGraph(e)}*getSubgraphs(e,t){for(let[r,i]of Object.entries(this.nodes)){if(e!==void 0&&!e.startsWith(r))continue;let n=i.subgraphs?.length?i.subgraphs:[i.bound];for(let a of n){let o=rh(a);if(o!==void 0){if(r===e){yield[r,o];return}if(e===void 0&&(yield[r,o]),t){let s=e;e!==void 0&&(s=e.slice(r.length+1));for(let[c,u]of o.getSubgraphs(s,t))yield[`${r}|${c}`,u]}}}}}async*getSubgraphsAsync(e,t){yield*this.getSubgraphs(e,t)}async _prepareStateSnapshot({config:e,saved:t,subgraphCheckpointer:r,applyPendingWrites:i=!1}){if(t===void 0)return{values:{},next:[],config:e,tasks:[]};let n=la(this.channels,t.checkpoint);if(t.pendingWrites?.length){let d=t.pendingWrites.filter(([f,p])=>f===yr).map(([f,p,m])=>[String(p),m]);d.length>0&&rr(t.checkpoint,n,[{name:En,writes:d,triggers:[]}],void 0,this.triggerToNodes)}let a=Object.values(pa(t.checkpoint,t.pendingWrites,this.nodes,n,t.config,!0,{step:(t.metadata?.step??-1)+1,store:this.store})),o=await vn(this.getSubgraphsAsync()),s=t.config.configurable?.checkpoint_ns??"",c={};for(let d of a){let f=o.find(([m])=>m===d.name);if(!f)continue;let p=`${String(d.name)}:${d.id}`;if(s&&(p=`${s}|${p}`),r===void 0){let m={configurable:{thread_id:t.config.configurable?.thread_id,checkpoint_ns:p}};c[d.id]=m}else{let m={configurable:{[Qr]:r,thread_id:t.config.configurable?.thread_id,checkpoint_ns:p}},g=f[1];c[d.id]=await g.getState(m,{subgraphs:!0})}}if(i&&t.pendingWrites?.length){let d=Object.fromEntries(a.map(p=>[p.id,p]));for(let[p,m,g]of t.pendingWrites)["__error__","__interrupt__",Ia].includes(m)||p in d&&d[p].writes.push([String(m),g]);let f=a.filter(p=>p.writes.length>0);f.length>0&&rr(t.checkpoint,n,f,void 0,this.triggerToNodes)}let u=t?.metadata;u&&t?.config?.configurable?.thread_id&&(u={...u,thread_id:t.config.configurable.thread_id});let l=a.filter(d=>d.writes.length===0).map(d=>d.name);return{values:wn(n,this.streamChannelsAsIs),next:l,tasks:eS(a,t?.pendingWrites??[],c,this.streamChannelsAsIs),metadata:u,config:fa(t.config,t.metadata),createdAt:t.checkpoint.ts,parentConfig:t.parentConfig}}async getState(e,t){let r=e.configurable?.__pregel_checkpointer??this.checkpointer;if(!r)throw new $a("No checkpointer set",{lc_error_code:"MISSING_CHECKPOINTER"});let i=e.configurable?.checkpoint_ns??"";if(i!==""&&e.configurable?.__pregel_checkpointer===void 0){let o=Vm(i);for await(let[s,c]of this.getSubgraphsAsync(o,!0))if(s===o)return await c.getState(Ao(e,{[Qr]:r}),{subgraphs:t?.subgraphs})}let n=xt(this.config,e),a=await r.getTuple(e);return await this._prepareStateSnapshot({config:n,saved:a,subgraphCheckpointer:t?.subgraphs?r:void 0,applyPendingWrites:!e.configurable?.checkpoint_id})}async*getStateHistory(e,t){let r=e.configurable?.__pregel_checkpointer??this.checkpointer;if(!r)throw new $a("No checkpointer set",{lc_error_code:"MISSING_CHECKPOINTER"});let i=e.configurable?.checkpoint_ns??"";if(i!==""&&e.configurable?.__pregel_checkpointer===void 0){let a=Vm(i);for await(let[o,s]of this.getSubgraphsAsync(a,!0))if(o===a){yield*s.getStateHistory(Ao(e,{[Qr]:r}),t);return}}let n=xt(this.config,e,{configurable:{checkpoint_ns:i}});for await(let a of r.list(n,t))yield this._prepareStateSnapshot({config:a.config,saved:a})}async bulkUpdateState(e,t){let r=e.configurable?.__pregel_checkpointer??this.checkpointer;if(!r)throw new $a("No checkpointer set",{lc_error_code:"MISSING_CHECKPOINTER"});if(t.length===0)throw new Error("No supersteps provided");if(t.some(o=>o.updates.length===0))throw new Error("No updates provided");let i=e.configurable?.checkpoint_ns??"";if(i!==""&&e.configurable?.__pregel_checkpointer===void 0){let o=Vm(i);for await(let[,s]of this.getSubgraphsAsync(o,!0))return await s.bulkUpdateState(Ao(e,{[Qr]:r}),t);throw new Error(`Subgraph "${o}" not found`)}let n=async(o,s)=>{let c=this.config?xt(this.config,o):o,u=await r.getTuple(c),l=u!==void 0?gn(u.checkpoint):lc(),d={...u?.checkpoint.channel_versions},f=u?.metadata?.step??-1,p=Ao(c,{checkpoint_ns:c.configurable?.checkpoint_ns??""}),m=c.metadata??{};u?.config.configurable&&(p=Ao(c,u.config.configurable),m={...u.metadata,...m});let{values:g,asNode:v}=s[0];if(g==null&&v===void 0){if(s.length>1)throw new be("Cannot create empty checkpoint with multiple updates");return fa(await r.put(p,_n(l,void 0,f),{source:"update",step:f+1,parents:u?.metadata?.parents??{}},{}),u?u.metadata:void 0)}let b=la(this.channels,l);if(g===null&&v==="__end__"){if(s.length>1)throw new be("Cannot apply multiple updates when clearing state");if(u){let C=pa(l,u.pendingWrites||[],this.nodes,b,u.config,!0,{step:(u.metadata?.step??-1)+1,checkpointer:r,store:this.store}),y=(u.pendingWrites||[]).filter(V=>V[0]===yr).map(V=>V.slice(1));y.length>0&&rr(l,b,[{name:En,writes:y,triggers:[]}],r.getNextVersion.bind(r),this.triggerToNodes);for(let[V,B,A]of u.pendingWrites||[])["__error__","__interrupt__",Ia].includes(B)||V in C&&C[V].writes.push([B,A]);rr(l,b,Object.values(C),r.getNextVersion.bind(r),this.triggerToNodes)}return fa(await r.put(p,_n(l,b,f),{...m,source:"update",step:f+1,parents:u?.metadata?.parents??{}},vc(d,l.channel_versions)),u?u.metadata:void 0)}if(v==="__copy__"){if(s.length>1)throw new be("Cannot copy checkpoint with multiple updates");if(u==null)throw new be("Cannot copy a non-existent checkpoint");let C=B=>!Array.isArray(B)||B.length===0?!1:B.every(A=>Array.isArray(A)&&A.length===2),y=_n(l,void 0,f),V=await r.put(u.parentConfig??Ao(u.config,{checkpoint_id:void 0}),y,{source:"fork",step:f+1,parents:u.metadata?.parents??{}},{});if(C(g)){let B=pa(y,u.pendingWrites,this.nodes,b,V,!1,{step:f+2}),A=Object.values(B).reduce((G,{name:Y,id:Ie})=>(G[Y]??=[],G[Y].push({id:Ie}),G),{}),U=g.reduce((G,Y)=>{let[Ie,me]=Y;G[me]??=[];let Sn=G[me].length,Or=A[me]?.[Sn]?.id;return G[me].push({values:Ie,asNode:me,taskId:Or}),G},{});return n(fa(V,u.metadata),Object.values(U).flat())}return fa(V,u.metadata)}if(v==="__input__"){if(s.length>1)throw new be("Cannot apply multiple updates when updating as input");let C=await vn(nh(this.inputChannels,g));if(C.length===0)throw new be(`Received no input writes for ${JSON.stringify(this.inputChannels,null,2)}`);rr(l,b,[{name:En,writes:C,triggers:[]}],r.getNextVersion.bind(this.checkpointer),this.triggerToNodes);let y=u?.metadata?.step!=null?u.metadata.step+1:-1,V=await r.put(p,_n(l,b,y),{source:"input",step:y,parents:u?.metadata?.parents??{}},vc(d,l.channel_versions));return await r.putWrites(V,C,ni(En,l.id)),fa(V,u?u.metadata:void 0)}if(c.configurable?.checkpoint_id===void 0&&u?.pendingWrites!==void 0&&u.pendingWrites.length>0){let C=pa(l,u.pendingWrites,this.nodes,b,u.config,!0,{store:this.store,checkpointer:this.checkpointer,step:(u.metadata?.step??-1)+1}),y=(u.pendingWrites??[]).filter(B=>B[0]===yr).map(B=>B.slice(1));y.length>0&&rr(u.checkpoint,b,[{name:En,writes:y,triggers:[]}],void 0,this.triggerToNodes);for(let[B,A,U]of u.pendingWrites)["__error__","__interrupt__",Ia].includes(A)||C[B]===void 0||C[B].writes.push([A,U]);let V=Object.values(C).filter(B=>B.writes.length>0);V.length>0&&rr(l,b,V,void 0,this.triggerToNodes)}let w=Object.values(l.versions_seen).map(C=>Object.values(C)).flat().find(C=>!!C),S=[];if(s.length===1){let{values:C,asNode:y,taskId:V}=s[0];if(y===void 0&&Object.keys(this.nodes).length===1)[y]=Object.keys(this.nodes);else if(y===void 0&&w===void 0)typeof this.inputChannels=="string"&&this.nodes[this.inputChannels]!==void 0&&(y=this.inputChannels);else if(y===void 0){let B=Object.entries(l.versions_seen).map(([A,U])=>Object.values(U).map(G=>[G,A])).flat().filter(([A,U])=>U!==Ue).sort(([A],[U])=>Dm(A,U));B&&(B.length===1?y=B[0][1]:B[B.length-1][0]!==B[B.length-2][0]&&(y=B[B.length-1][1]))}if(y===void 0)throw new be('Ambiguous update, specify "asNode"');S.push({values:C,asNode:y,taskId:V})}else for(let{asNode:C,values:y,taskId:V}of s){if(C==null)throw new be('"asNode" is required when applying multiple updates');S.push({values:y,asNode:C,taskId:V})}let k=[];for(let{asNode:C,values:y,taskId:V}of S){if(this.nodes[C]===void 0)throw new be(`Node "${C.toString()}" does not exist`);let B=this.nodes[C].getWriters();if(!B.length)throw new be(`No writers found for node "${C.toString()}"`);k.push({name:C,input:y,proc:B.length>1?Ar.from(B,{omitSequenceTags:!0}):B[0],writes:[],triggers:[Ue],id:V??ni("__interrupt__",l.id),writers:[]})}for(let C of k)await C.proc.invoke(C.input,$e({...c,store:c?.store??this.store},{runName:c.runName??`${this.getName()}UpdateState`,configurable:{[Nr]:y=>C.writes.push(...y),[Yr]:(y,V=!1)=>kl(l,b,C,y,V)}}));for(let C of k){let y=C.writes.filter(V=>V[0]!==jr);u!==void 0&&y.length>0&&await r.putWrites(p,y,C.id)}rr(l,b,k,r.getNextVersion.bind(this.checkpointer),this.triggerToNodes);let I=vc(d,l.channel_versions),Z=await r.put(p,_n(l,b,f+1),{source:"update",step:f+1,parents:u?.metadata?.parents??{}},I);for(let C of k){let y=C.writes.filter(V=>V[0]===jr);y.length>0&&await r.putWrites(Z,y,C.id)}return fa(Z,u?u.metadata:void 0)},a=e;for(let{updates:o}of t)a=await n(a,o);return a}async updateState(e,t,r){return this.bulkUpdateState(e,[{updates:[{values:t,asNode:r}]}])}_defaults(e){let{debug:t,streamMode:r,inputKeys:i,outputKeys:n,interruptAfter:a,interruptBefore:o,...s}=e,c=!0,u=t!==void 0?t:this.debug,l=n;l===void 0?l=this.streamChannelsAsIs:sS(l,this.channels);let d=i;d===void 0?d=this.inputChannels:sS(d,this.channels);let f=o??this.interruptBefore??[],p=a??this.interruptAfter??[],m;r!==void 0?(m=Array.isArray(r)?r:[r],c=typeof r=="string"):(e.configurable?.__pregel_task_id!==void 0?m=["values"]:m=this.streamMode,c=!0);let g;if(this.checkpointer===!1)g=void 0;else if(e!==void 0&&e.configurable?.__pregel_checkpointer!==void 0)g=e.configurable[Qr];else{if(this.checkpointer===!0)throw new Error("checkpointer: true cannot be used for root graphs.");g=this.checkpointer}let v=e.store??this.store,b=e.cache??this.cache;if(e.durability!=null&&e.checkpointDuring!=null)throw new Error("Cannot use both `durability` and `checkpointDuring` at the same time.");let w=(()=>{if(e.checkpointDuring!=null)return e.checkpointDuring===!1?"exit":"async"})(),S=e.durability??w??e?.configurable?.__pregel_durability??"async";return[u,m,d,l,s,f,p,g,v,c,b,S]}async stream(e,t){let r=new AbortController,i={recursionLimit:this.config?.recursionLimit,...t,signal:bc(t?.signal,r.signal).signal},n=await super.stream(e,i);return new ch(t?.encoding==="text/event-stream"?KR(n):n,r)}async#e(e,t){let{version:r,encoding:i,transformers:n,...a}=t,o={recursionLimit:this.config?.recursionLimit,...a,configurable:{...this.config?.configurable,...a?.configurable},version:r,streamMode:C0,subgraphs:!0,encoding:void 0},s=this.stream(e,o),c=F0({[Symbol.asyncIterator]:async function*(){let u=await s;for await(let l of u)yield l}},[...this.streamTransformers??[],...n??[]]);if(i==="text/event-stream"){let u=new AbortController;return u.signal.addEventListener("abort",()=>c.abort(u.signal.reason),{once:!0}),new ch(X9(c),u)}return c}streamEvents(e,t,r){if(t.version==="v3")return this.#e(e,t);let i=new AbortController,n={recursionLimit:this.config?.recursionLimit,...t,callbacks:PR(this.config?.callbacks,t?.callbacks),signal:bc(t?.signal,i.signal).signal};return new ch(super.streamEvents(e,n,r),i)}async _validateInput(e){return e}async _validateContext(e){return e}async*_streamIterator(e,t){let r="version"in(t??{})?void 0:t?.encoding??void 0,i=t?.subgraphs,n=t?.version==="v3",a=pc(this.config,t);if(a.recursionLimit===void 0||a.recursionLimit<1)throw new Error('Passed "recursionLimit" must be at least 1.');if(this.checkpointer!==void 0&&this.checkpointer!==!1&&a.configurable===void 0)throw new Error('Checkpointer requires one or more of the following "configurable" keys: "thread_id", "checkpoint_ns", "checkpoint_id"');let o=await this._validateInput(e),{runId:s,...c}=a,[u,l,,d,f,p,m,g,v,b,w,S]=this._defaults(c);f.metadata={ls_integration:"langgraph",...f.metadata},typeof f.context<"u"?f.context=await this._validateContext(f.context):f.configurable=await this._validateContext(f.configurable);let k=new rS({modes:new Set(l)});if(this.checkpointer===!0){f.configurable??={};let U=f.configurable.checkpoint_ns??"";f.configurable[Rr]=U.split("|").map(G=>G.split(":")[0]).join("|")}if(l.includes("messages")){let U=n?new rM(Y=>k.push(Y)):new QR(Y=>k.push(Y)),{callbacks:G}=f;if(G===void 0)f.callbacks=[U];else if(Array.isArray(G))f.callbacks=G.concat(U);else{let Y=G.copy();Y.addHandler(U,!0),f.callbacks=Y}}if(l.includes("tools")){let U=new JR(Y=>k.push(Y)),{callbacks:G}=f;if(G===void 0)f.callbacks=[U];else if(Array.isArray(G))f.callbacks=G.concat(U);else{let Y=G.copy();Y.addHandler(U,!0),f.callbacks=Y}}f.writer??=U=>{if(!l.includes("custom"))return;let G=A0()?.configurable?.[Rr]?.split("|").slice(0,-1);k.push([G??[],"custom",U])},f.interrupt??=this.userInterrupt??H0,f.serverInfo==null&&(f.serverInfo=Q9(f));let I={tracerInheritableMetadata:rV(f)},Z=await(await et._configureSync(f?.callbacks,void 0,f?.tags,void 0,f?.metadata,void 0,I))?.handleChainStart(this.toJSON(),OR(e,"input"),s,void 0,void 0,void 0,f?.runName??this.getName()),C=yl(this.channels),y,V,A=(async()=>{try{y=await qR.initialize({input:o,config:f,checkpointer:g,nodes:this.nodes,channelSpecs:C,outputKeys:d,streamKeys:this.streamChannelsAsIs,store:v,cache:w,stream:k,interruptAfter:m,interruptBefore:p,manager:Z,debug:this.debug,triggerToNodes:this.triggerToNodes,durability:S});let U=new nM({loop:y,nodeFinished:f.configurable?.[wS]});t?.subgraphs&&(y.config.configurable={...y.config.configurable,[Ec]:y.stream}),await this._runLoop({loop:y,runner:U,debug:u,config:f}),S==="sync"&&await Promise.all(y?.checkpointerPromises??[])}catch(U){V=U}finally{try{y&&(await y.store?.stop(),await y.cache?.stop()),await Promise.all(y?.checkpointerPromises??[])}catch(U){V=V??U}V?(await new Promise(U=>{queueMicrotask(U)}),k.error(V)):k.close()}})();try{for await(let U of k){if(U===void 0)throw new Error("Data structure error.");let[G,Y,Ie]=U,me="version"in(t??{});if(l.includes(Y)||Y==="checkpoints"&&mc(Ie)&&(n||me&&i&&l.includes("values"))){if(r==="text/event-stream"){i?yield[G,Y,Ie]:yield[null,Y,Ie];continue}i&&!b?yield[G,Y,Ie]:b?i?yield[G,Ie]:yield Ie:yield[Y,Ie]}}}catch(U){throw await Z?.handleChainError(V),U}finally{await A}await Z?.handleChainEnd(y?.output??{},s,void 0,void 0,void 0)}async invoke(e,t){let r=t?.streamMode??"values",i={...t,outputKeys:t?.outputKeys??this.outputChannels,streamMode:r,encoding:void 0},n=[],a=await this.stream(e,i),o=[],s;for await(let c of a)r==="values"?ka(c)?o.push(c[Ue]):s=c:n.push(c);if(r==="values"){if(o.length>0){let c=o.flat(1);if(s==null)return{[Ue]:c};if(typeof s=="object")return{...s,[Ue]:c}}return s}return n}async _runLoop(e){let{loop:t,runner:r,debug:i,config:n}=e,a;try{for(;await t.tick({inputKeys:this.inputChannels});){for(let{task:o}of await t._matchCachedWrites())t._outputWrites(o.id,o.writes,!0);i&&VR(t.checkpointMetadata.step,t.channels,this.streamChannelsList),i&&sh(t.step,Object.values(t.tasks)),await r.tick({timeout:this.stepTimeout,retryPolicy:this.retryPolicy,onStepWrite:(o,s)=>{i&&ZR(o,s,this.streamChannelsList)},maxConcurrency:n.maxConcurrency,signal:n.signal})}if(t.status==="out_of_steps")throw new gh([`Recursion limit of ${n.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(o){if(a=o,!await t.finishAndHandleError(a))throw o}finally{a===void 0&&await t.finishAndHandleError()}}async clearCache(){await this.cache?.clear([])}};function Q9(e){let t=e.metadata??{},r=e.configurable??{},i=r.assistant_id??t.assistant_id,n=r.graph_id??t.graph_id,a=r.langgraph_auth_user,o;if(a!=null&&typeof a=="object"&&"identity"in a&&(o=a),i!=null||n!=null||o!=null)return{assistantId:i!=null?String(i):"",graphId:n!=null?String(n):"",user:o}}var eV=new Set(["key","token","secret","password","auth"]);function tV(e,t){let r=e.toLowerCase(),i=!1;for(let n of eV)if(r.includes(n)){i=!0;break}return e.startsWith("__")||!(typeof t=="string"||typeof t=="number"||typeof t=="boolean")||i}function rV(e){let t=e.configurable;if(!t)return;let r={};for(let[i,n]of Object.entries(t))tV(i,n)||(r[i]=n);return Object.keys(r).length>0?r:void 0}var xn=class cM extends kt{lc_graph_name="EphemeralValue";guard;value=[];constructor(t=!0){super(),this.guard=t}fromCheckpoint(t){let r=new cM(this.guard);return typeof t<"u"&&(r.value=[t]),r}update(t){if(t.length===0){let r=this.value.length>0;return this.value=[],r}if(t.length!==1&&this.guard)throw new be("EphemeralValue can only receive one value per step.");return this.value=[t[t.length-1]],!0}get(){if(this.value.length===0)throw new Ne;return this.value[0]}checkpoint(){if(this.value.length===0)throw new Ne;return this.value[0]}isAvailable(){return this.value.length!==0}};var uS=class{path;ends;constructor(e){ae.isRunnable(e.path)?this.path=e.path:this.path=tt(e.path),this.ends=Array.isArray(e.pathMap)?e.pathMap.reduce((t,r)=>(t[r]=r,t),{}):e.pathMap}run(e,t){return ot.registerWriter(new Vt({name:"<branch_run>",trace:!1,func:async(r,i)=>{try{return await this._route(r,i,e,t)}catch(n){throw n.name===jl.unminifiable_name&&console.warn(`[WARN]: 'NodeInterrupt' thrown in conditional edge. This is likely a bug in your graph implementation.
429
+ `))}finally{r.close()}}})}var sM=class{static subscribeTo(e,t){let{key:r,tags:i}={key:void 0,tags:void 0,...t??{}};if(Array.isArray(e)&&r!==void 0)throw new Error("Can't specify a key when subscribing to multiple channels");let n;return typeof e=="string"?r?n={[r]:e}:n=[e]:n=Object.fromEntries(e.map(a=>[a,a])),new bn({channels:n,triggers:Array.isArray(e)?e:[e],tags:i})}static writeTo(e,t){let r=[];for(let i of e)r.push({channel:i,value:hr,skipNone:!1});for(let[i,n]of Object.entries(t??{}))ae.isRunnable(n)||typeof n=="function"?r.push({channel:i,value:hr,skipNone:!0,mapper:tt(n)}):r.push({channel:i,value:n,skipNone:!1});return new ot(r)}},eV=class extends ae{lc_namespace=["langgraph","pregel"];invoke(e,t){throw new Error("Not implemented")}withConfig(e){return super.withConfig(e)}stream(e,t){return super.stream(e,t)}},lh=class extends eV{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;streamTransformers;triggerToNodes={};constructor(e){super(e);let{streamMode:t}=e;if(t!=null&&!Array.isArray(t)&&(t=[t]),this.nodes=e.nodes,this.channels=e.channels,"__pregel_tasks"in this.channels&&"lc_graph_name"in this.channels.__pregel_tasks&&this.channels.__pregel_tasks.lc_graph_name!=="Topic")throw new Error(`Channel '${In}' is reserved and cannot be used in the graph.`);this.channels[In]=new cS({accumulate:!1}),this.autoValidate=e.autoValidate??this.autoValidate,this.streamMode=t??this.streamMode,this.inputChannels=e.inputChannels,this.outputChannels=e.outputChannels,this.streamChannels=e.streamChannels??this.streamChannels,this.interruptAfter=e.interruptAfter,this.interruptBefore=e.interruptBefore,this.stepTimeout=e.stepTimeout??this.stepTimeout,this.debug=e.debug??this.debug,this.checkpointer=e.checkpointer,this.retryPolicy=e.retryPolicy,this.config=e.config,this.store=e.store,this.cache=e.cache,this.name=e.name,this.triggerToNodes=e.triggerToNodes??this.triggerToNodes,this.userInterrupt=e.userInterrupt,this.streamTransformers=e.streamTransformers??[],this.autoValidate&&this.validate()}withConfig(e){let{streamTransformers:t,...r}=e,i=xt(this.config,r),n=[...this.streamTransformers,...t??[]];return new this.constructor({...this,config:i,streamTransformers:n})}validate(){aM({nodes:this.nodes,channels:this.channels,outputChannels:this.outputChannels,inputChannels:this.inputChannels,streamChannels:this.streamChannels,interruptAfterNodes:this.interruptAfter,interruptBeforeNodes:this.interruptBefore});for(let[e,t]of Object.entries(this.nodes))for(let r of t.triggers)this.triggerToNodes[r]??=[],this.triggerToNodes[r].push(e);return this}get streamChannelsList(){return Array.isArray(this.streamChannels)?this.streamChannels:this.streamChannels?[this.streamChannels]:Object.keys(this.channels)}get streamChannelsAsIs(){return this.streamChannels?this.streamChannels:Object.keys(this.channels)}async getGraphAsync(e){return this.getGraph(e)}*getSubgraphs(e,t){for(let[r,i]of Object.entries(this.nodes)){if(e!==void 0&&!e.startsWith(r))continue;let n=i.subgraphs?.length?i.subgraphs:[i.bound];for(let a of n){let o=rh(a);if(o!==void 0){if(r===e){yield[r,o];return}if(e===void 0&&(yield[r,o]),t){let s=e;e!==void 0&&(s=e.slice(r.length+1));for(let[c,u]of o.getSubgraphs(s,t))yield[`${r}|${c}`,u]}}}}}async*getSubgraphsAsync(e,t){yield*this.getSubgraphs(e,t)}async _prepareStateSnapshot({config:e,saved:t,subgraphCheckpointer:r,applyPendingWrites:i=!1}){if(t===void 0)return{values:{},next:[],config:e,tasks:[]};let n=la(this.channels,t.checkpoint);if(t.pendingWrites?.length){let d=t.pendingWrites.filter(([f,p])=>f===yr).map(([f,p,m])=>[String(p),m]);d.length>0&&rr(t.checkpoint,n,[{name:En,writes:d,triggers:[]}],void 0,this.triggerToNodes)}let a=Object.values(pa(t.checkpoint,t.pendingWrites,this.nodes,n,t.config,!0,{step:(t.metadata?.step??-1)+1,store:this.store})),o=await vn(this.getSubgraphsAsync()),s=t.config.configurable?.checkpoint_ns??"",c={};for(let d of a){let f=o.find(([m])=>m===d.name);if(!f)continue;let p=`${String(d.name)}:${d.id}`;if(s&&(p=`${s}|${p}`),r===void 0){let m={configurable:{thread_id:t.config.configurable?.thread_id,checkpoint_ns:p}};c[d.id]=m}else{let m={configurable:{[Qr]:r,thread_id:t.config.configurable?.thread_id,checkpoint_ns:p}},g=f[1];c[d.id]=await g.getState(m,{subgraphs:!0})}}if(i&&t.pendingWrites?.length){let d=Object.fromEntries(a.map(p=>[p.id,p]));for(let[p,m,g]of t.pendingWrites)["__error__","__interrupt__",Ia].includes(m)||p in d&&d[p].writes.push([String(m),g]);let f=a.filter(p=>p.writes.length>0);f.length>0&&rr(t.checkpoint,n,f,void 0,this.triggerToNodes)}let u=t?.metadata;u&&t?.config?.configurable?.thread_id&&(u={...u,thread_id:t.config.configurable.thread_id});let l=a.filter(d=>d.writes.length===0).map(d=>d.name);return{values:wn(n,this.streamChannelsAsIs),next:l,tasks:eS(a,t?.pendingWrites??[],c,this.streamChannelsAsIs),metadata:u,config:fa(t.config,t.metadata),createdAt:t.checkpoint.ts,parentConfig:t.parentConfig}}async getState(e,t){let r=e.configurable?.__pregel_checkpointer??this.checkpointer;if(!r)throw new $a("No checkpointer set",{lc_error_code:"MISSING_CHECKPOINTER"});let i=e.configurable?.checkpoint_ns??"";if(i!==""&&e.configurable?.__pregel_checkpointer===void 0){let o=Vm(i);for await(let[s,c]of this.getSubgraphsAsync(o,!0))if(s===o)return await c.getState(Ao(e,{[Qr]:r}),{subgraphs:t?.subgraphs})}let n=xt(this.config,e),a=await r.getTuple(e);return await this._prepareStateSnapshot({config:n,saved:a,subgraphCheckpointer:t?.subgraphs?r:void 0,applyPendingWrites:!e.configurable?.checkpoint_id})}async*getStateHistory(e,t){let r=e.configurable?.__pregel_checkpointer??this.checkpointer;if(!r)throw new $a("No checkpointer set",{lc_error_code:"MISSING_CHECKPOINTER"});let i=e.configurable?.checkpoint_ns??"";if(i!==""&&e.configurable?.__pregel_checkpointer===void 0){let a=Vm(i);for await(let[o,s]of this.getSubgraphsAsync(a,!0))if(o===a){yield*s.getStateHistory(Ao(e,{[Qr]:r}),t);return}}let n=xt(this.config,e,{configurable:{checkpoint_ns:i}});for await(let a of r.list(n,t))yield this._prepareStateSnapshot({config:a.config,saved:a})}async bulkUpdateState(e,t){let r=e.configurable?.__pregel_checkpointer??this.checkpointer;if(!r)throw new $a("No checkpointer set",{lc_error_code:"MISSING_CHECKPOINTER"});if(t.length===0)throw new Error("No supersteps provided");if(t.some(o=>o.updates.length===0))throw new Error("No updates provided");let i=e.configurable?.checkpoint_ns??"";if(i!==""&&e.configurable?.__pregel_checkpointer===void 0){let o=Vm(i);for await(let[,s]of this.getSubgraphsAsync(o,!0))return await s.bulkUpdateState(Ao(e,{[Qr]:r}),t);throw new Error(`Subgraph "${o}" not found`)}let n=async(o,s)=>{let c=this.config?xt(this.config,o):o,u=await r.getTuple(c),l=u!==void 0?gn(u.checkpoint):lc(),d={...u?.checkpoint.channel_versions},f=u?.metadata?.step??-1,p=Ao(c,{checkpoint_ns:c.configurable?.checkpoint_ns??""}),m=c.metadata??{};u?.config.configurable&&(p=Ao(c,u.config.configurable),m={...u.metadata,...m});let{values:g,asNode:v}=s[0];if(g==null&&v===void 0){if(s.length>1)throw new be("Cannot create empty checkpoint with multiple updates");return fa(await r.put(p,_n(l,void 0,f),{source:"update",step:f+1,parents:u?.metadata?.parents??{}},{}),u?u.metadata:void 0)}let b=la(this.channels,l);if(g===null&&v==="__end__"){if(s.length>1)throw new be("Cannot apply multiple updates when clearing state");if(u){let C=pa(l,u.pendingWrites||[],this.nodes,b,u.config,!0,{step:(u.metadata?.step??-1)+1,checkpointer:r,store:this.store}),y=(u.pendingWrites||[]).filter(V=>V[0]===yr).map(V=>V.slice(1));y.length>0&&rr(l,b,[{name:En,writes:y,triggers:[]}],r.getNextVersion.bind(r),this.triggerToNodes);for(let[V,B,A]of u.pendingWrites||[])["__error__","__interrupt__",Ia].includes(B)||V in C&&C[V].writes.push([B,A]);rr(l,b,Object.values(C),r.getNextVersion.bind(r),this.triggerToNodes)}return fa(await r.put(p,_n(l,b,f),{...m,source:"update",step:f+1,parents:u?.metadata?.parents??{}},vc(d,l.channel_versions)),u?u.metadata:void 0)}if(v==="__copy__"){if(s.length>1)throw new be("Cannot copy checkpoint with multiple updates");if(u==null)throw new be("Cannot copy a non-existent checkpoint");let C=B=>!Array.isArray(B)||B.length===0?!1:B.every(A=>Array.isArray(A)&&A.length===2),y=_n(l,void 0,f),V=await r.put(u.parentConfig??Ao(u.config,{checkpoint_id:void 0}),y,{source:"fork",step:f+1,parents:u.metadata?.parents??{}},{});if(C(g)){let B=pa(y,u.pendingWrites,this.nodes,b,V,!1,{step:f+2}),A=Object.values(B).reduce((G,{name:Y,id:Ie})=>(G[Y]??=[],G[Y].push({id:Ie}),G),{}),U=g.reduce((G,Y)=>{let[Ie,me]=Y;G[me]??=[];let Sn=G[me].length,Or=A[me]?.[Sn]?.id;return G[me].push({values:Ie,asNode:me,taskId:Or}),G},{});return n(fa(V,u.metadata),Object.values(U).flat())}return fa(V,u.metadata)}if(v==="__input__"){if(s.length>1)throw new be("Cannot apply multiple updates when updating as input");let C=await vn(nh(this.inputChannels,g));if(C.length===0)throw new be(`Received no input writes for ${JSON.stringify(this.inputChannels,null,2)}`);rr(l,b,[{name:En,writes:C,triggers:[]}],r.getNextVersion.bind(this.checkpointer),this.triggerToNodes);let y=u?.metadata?.step!=null?u.metadata.step+1:-1,V=await r.put(p,_n(l,b,y),{source:"input",step:y,parents:u?.metadata?.parents??{}},vc(d,l.channel_versions));return await r.putWrites(V,C,ni(En,l.id)),fa(V,u?u.metadata:void 0)}if(c.configurable?.checkpoint_id===void 0&&u?.pendingWrites!==void 0&&u.pendingWrites.length>0){let C=pa(l,u.pendingWrites,this.nodes,b,u.config,!0,{store:this.store,checkpointer:this.checkpointer,step:(u.metadata?.step??-1)+1}),y=(u.pendingWrites??[]).filter(B=>B[0]===yr).map(B=>B.slice(1));y.length>0&&rr(u.checkpoint,b,[{name:En,writes:y,triggers:[]}],void 0,this.triggerToNodes);for(let[B,A,U]of u.pendingWrites)["__error__","__interrupt__",Ia].includes(A)||C[B]===void 0||C[B].writes.push([A,U]);let V=Object.values(C).filter(B=>B.writes.length>0);V.length>0&&rr(l,b,V,void 0,this.triggerToNodes)}let w=Object.values(l.versions_seen).map(C=>Object.values(C)).flat().find(C=>!!C),S=[];if(s.length===1){let{values:C,asNode:y,taskId:V}=s[0];if(y===void 0&&Object.keys(this.nodes).length===1)[y]=Object.keys(this.nodes);else if(y===void 0&&w===void 0)typeof this.inputChannels=="string"&&this.nodes[this.inputChannels]!==void 0&&(y=this.inputChannels);else if(y===void 0){let B=Object.entries(l.versions_seen).map(([A,U])=>Object.values(U).map(G=>[G,A])).flat().filter(([A,U])=>U!==Ue).sort(([A],[U])=>Dm(A,U));B&&(B.length===1?y=B[0][1]:B[B.length-1][0]!==B[B.length-2][0]&&(y=B[B.length-1][1]))}if(y===void 0)throw new be('Ambiguous update, specify "asNode"');S.push({values:C,asNode:y,taskId:V})}else for(let{asNode:C,values:y,taskId:V}of s){if(C==null)throw new be('"asNode" is required when applying multiple updates');S.push({values:y,asNode:C,taskId:V})}let k=[];for(let{asNode:C,values:y,taskId:V}of S){if(this.nodes[C]===void 0)throw new be(`Node "${C.toString()}" does not exist`);let B=this.nodes[C].getWriters();if(!B.length)throw new be(`No writers found for node "${C.toString()}"`);k.push({name:C,input:y,proc:B.length>1?Ar.from(B,{omitSequenceTags:!0}):B[0],writes:[],triggers:[Ue],id:V??ni("__interrupt__",l.id),writers:[]})}for(let C of k)await C.proc.invoke(C.input,$e({...c,store:c?.store??this.store},{runName:c.runName??`${this.getName()}UpdateState`,configurable:{[Nr]:y=>C.writes.push(...y),[Yr]:(y,V=!1)=>kl(l,b,C,y,V)}}));for(let C of k){let y=C.writes.filter(V=>V[0]!==jr);u!==void 0&&y.length>0&&await r.putWrites(p,y,C.id)}rr(l,b,k,r.getNextVersion.bind(this.checkpointer),this.triggerToNodes);let I=vc(d,l.channel_versions),Z=await r.put(p,_n(l,b,f+1),{source:"update",step:f+1,parents:u?.metadata?.parents??{}},I);for(let C of k){let y=C.writes.filter(V=>V[0]===jr);y.length>0&&await r.putWrites(Z,y,C.id)}return fa(Z,u?u.metadata:void 0)},a=e;for(let{updates:o}of t)a=await n(a,o);return a}async updateState(e,t,r){return this.bulkUpdateState(e,[{updates:[{values:t,asNode:r}]}])}_defaults(e){let{debug:t,streamMode:r,inputKeys:i,outputKeys:n,interruptAfter:a,interruptBefore:o,...s}=e,c=!0,u=t!==void 0?t:this.debug,l=n;l===void 0?l=this.streamChannelsAsIs:sS(l,this.channels);let d=i;d===void 0?d=this.inputChannels:sS(d,this.channels);let f=o??this.interruptBefore??[],p=a??this.interruptAfter??[],m;r!==void 0?(m=Array.isArray(r)?r:[r],c=typeof r=="string"):(e.configurable?.__pregel_task_id!==void 0?m=["values"]:m=this.streamMode,c=!0);let g;if(this.checkpointer===!1)g=void 0;else if(e!==void 0&&e.configurable?.__pregel_checkpointer!==void 0)g=e.configurable[Qr];else{if(this.checkpointer===!0)throw new Error("checkpointer: true cannot be used for root graphs.");g=this.checkpointer}let v=e.store??this.store,b=e.cache??this.cache;if(e.durability!=null&&e.checkpointDuring!=null)throw new Error("Cannot use both `durability` and `checkpointDuring` at the same time.");let w=(()=>{if(e.checkpointDuring!=null)return e.checkpointDuring===!1?"exit":"async"})(),S=e.durability??w??e?.configurable?.__pregel_durability??"async";return[u,m,d,l,s,f,p,g,v,c,b,S]}async stream(e,t){let r=new AbortController,i={recursionLimit:this.config?.recursionLimit,...t,signal:bc(t?.signal,r.signal).signal},n=await super.stream(e,i);return new ch(t?.encoding==="text/event-stream"?KR(n):n,r)}async#e(e,t){let{version:r,encoding:i,transformers:n,...a}=t,o={recursionLimit:this.config?.recursionLimit,...a,configurable:{...this.config?.configurable,...a?.configurable},version:r,streamMode:C0,subgraphs:!0,encoding:void 0},s=this.stream(e,o),c=F0({[Symbol.asyncIterator]:async function*(){let u=await s;for await(let l of u)yield l}},[...this.streamTransformers??[],...n??[]]);if(i==="text/event-stream"){let u=new AbortController;return u.signal.addEventListener("abort",()=>c.abort(u.signal.reason),{once:!0}),new ch(Q9(c),u)}return c}streamEvents(e,t,r){if(t.version==="v3")return this.#e(e,t);let i=new AbortController,n={recursionLimit:this.config?.recursionLimit,...t,callbacks:PR(this.config?.callbacks,t?.callbacks),signal:bc(t?.signal,i.signal).signal};return new ch(super.streamEvents(e,n,r),i)}async _validateInput(e){return e}async _validateContext(e){return e}async*_streamIterator(e,t){let r="version"in(t??{})?void 0:t?.encoding??void 0,i=t?.subgraphs,n=t?.version==="v3",a=pc(this.config,t);if(a.recursionLimit===void 0||a.recursionLimit<1)throw new Error('Passed "recursionLimit" must be at least 1.');if(this.checkpointer!==void 0&&this.checkpointer!==!1&&a.configurable===void 0)throw new Error('Checkpointer requires one or more of the following "configurable" keys: "thread_id", "checkpoint_ns", "checkpoint_id"');let o=await this._validateInput(e),{runId:s,...c}=a,[u,l,,d,f,p,m,g,v,b,w,S]=this._defaults(c);f.metadata={ls_integration:"langgraph",...f.metadata},typeof f.context<"u"?f.context=await this._validateContext(f.context):f.configurable=await this._validateContext(f.configurable);let k=new rS({modes:new Set(l)});if(this.checkpointer===!0){f.configurable??={};let U=f.configurable.checkpoint_ns??"";f.configurable[Rr]=U.split("|").map(G=>G.split(":")[0]).join("|")}if(l.includes("messages")){let U=n?new rM(Y=>k.push(Y)):new QR(Y=>k.push(Y)),{callbacks:G}=f;if(G===void 0)f.callbacks=[U];else if(Array.isArray(G))f.callbacks=G.concat(U);else{let Y=G.copy();Y.addHandler(U,!0),f.callbacks=Y}}if(l.includes("tools")){let U=new JR(Y=>k.push(Y)),{callbacks:G}=f;if(G===void 0)f.callbacks=[U];else if(Array.isArray(G))f.callbacks=G.concat(U);else{let Y=G.copy();Y.addHandler(U,!0),f.callbacks=Y}}f.writer??=U=>{if(!l.includes("custom"))return;let G=A0()?.configurable?.[Rr]?.split("|").slice(0,-1);k.push([G??[],"custom",U])},f.interrupt??=this.userInterrupt??H0,f.serverInfo==null&&(f.serverInfo=tV(f));let I={tracerInheritableMetadata:iV(f)},Z=await(await et._configureSync(f?.callbacks,void 0,f?.tags,void 0,f?.metadata,void 0,I))?.handleChainStart(this.toJSON(),OR(e,"input"),s,void 0,void 0,void 0,f?.runName??this.getName()),C=yl(this.channels),y,V,A=(async()=>{try{y=await qR.initialize({input:o,config:f,checkpointer:g,nodes:this.nodes,channelSpecs:C,outputKeys:d,streamKeys:this.streamChannelsAsIs,store:v,cache:w,stream:k,interruptAfter:m,interruptBefore:p,manager:Z,debug:this.debug,triggerToNodes:this.triggerToNodes,durability:S});let U=new nM({loop:y,nodeFinished:f.configurable?.[wS]});t?.subgraphs&&(y.config.configurable={...y.config.configurable,[Ec]:y.stream}),await this._runLoop({loop:y,runner:U,debug:u,config:f}),S==="sync"&&await Promise.all(y?.checkpointerPromises??[])}catch(U){V=U}finally{try{y&&(await y.store?.stop(),await y.cache?.stop()),await Promise.all(y?.checkpointerPromises??[])}catch(U){V=V??U}V?(await new Promise(U=>{queueMicrotask(U)}),k.error(V)):k.close()}})();try{for await(let U of k){if(U===void 0)throw new Error("Data structure error.");let[G,Y,Ie]=U,me="version"in(t??{});if(l.includes(Y)||Y==="checkpoints"&&mc(Ie)&&(n||me&&i&&l.includes("values"))){if(r==="text/event-stream"){i?yield[G,Y,Ie]:yield[null,Y,Ie];continue}i&&!b?yield[G,Y,Ie]:b?i?yield[G,Ie]:yield Ie:yield[Y,Ie]}}}catch(U){throw await Z?.handleChainError(V),U}finally{await A}await Z?.handleChainEnd(y?.output??{},s,void 0,void 0,void 0)}async invoke(e,t){let r=t?.streamMode??"values",i={...t,outputKeys:t?.outputKeys??this.outputChannels,streamMode:r,encoding:void 0},n=[],a=await this.stream(e,i),o=[],s;for await(let c of a)r==="values"?ka(c)?o.push(c[Ue]):s=c:n.push(c);if(r==="values"){if(o.length>0){let c=o.flat(1);if(s==null)return{[Ue]:c};if(typeof s=="object")return{...s,[Ue]:c}}return s}return n}async _runLoop(e){let{loop:t,runner:r,debug:i,config:n}=e,a;try{for(;await t.tick({inputKeys:this.inputChannels});){for(let{task:o}of await t._matchCachedWrites())t._outputWrites(o.id,o.writes,!0);i&&VR(t.checkpointMetadata.step,t.channels,this.streamChannelsList),i&&sh(t.step,Object.values(t.tasks)),await r.tick({timeout:this.stepTimeout,retryPolicy:this.retryPolicy,onStepWrite:(o,s)=>{i&&ZR(o,s,this.streamChannelsList)},maxConcurrency:n.maxConcurrency,signal:n.signal})}if(t.status==="out_of_steps")throw new gh([`Recursion limit of ${n.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(o){if(a=o,!await t.finishAndHandleError(a))throw o}finally{a===void 0&&await t.finishAndHandleError()}}async clearCache(){await this.cache?.clear([])}};function tV(e){let t=e.metadata??{},r=e.configurable??{},i=r.assistant_id??t.assistant_id,n=r.graph_id??t.graph_id,a=r.langgraph_auth_user,o;if(a!=null&&typeof a=="object"&&"identity"in a&&(o=a),i!=null||n!=null||o!=null)return{assistantId:i!=null?String(i):"",graphId:n!=null?String(n):"",user:o}}var rV=new Set(["key","token","secret","password","auth"]);function nV(e,t){let r=e.toLowerCase(),i=!1;for(let n of rV)if(r.includes(n)){i=!0;break}return e.startsWith("__")||!(typeof t=="string"||typeof t=="number"||typeof t=="boolean")||i}function iV(e){let t=e.configurable;if(!t)return;let r={};for(let[i,n]of Object.entries(t))nV(i,n)||(r[i]=n);return Object.keys(r).length>0?r:void 0}var xn=class cM extends kt{lc_graph_name="EphemeralValue";guard;value=[];constructor(t=!0){super(),this.guard=t}fromCheckpoint(t){let r=new cM(this.guard);return typeof t<"u"&&(r.value=[t]),r}update(t){if(t.length===0){let r=this.value.length>0;return this.value=[],r}if(t.length!==1&&this.guard)throw new be("EphemeralValue can only receive one value per step.");return this.value=[t[t.length-1]],!0}get(){if(this.value.length===0)throw new Ne;return this.value[0]}checkpoint(){if(this.value.length===0)throw new Ne;return this.value[0]}isAvailable(){return this.value.length!==0}};var uS=class{path;ends;constructor(e){ae.isRunnable(e.path)?this.path=e.path:this.path=tt(e.path),this.ends=Array.isArray(e.pathMap)?e.pathMap.reduce((t,r)=>(t[r]=r,t),{}):e.pathMap}run(e,t){return ot.registerWriter(new Vt({name:"<branch_run>",trace:!1,func:async(r,i)=>{try{return await this._route(r,i,e,t)}catch(n){throw n.name===jl.unminifiable_name&&console.warn(`[WARN]: 'NodeInterrupt' thrown in conditional edge. This is likely a bug in your graph implementation.
430
430
  NodeInterrupt should only be thrown inside a node, not in edge conditions.`),n}}}))}async _route(e,t,r,i){let n=await this.path.invoke(i?i(t):e,t);Array.isArray(n)||(n=[n]);let a;if(this.ends?a=n.map(o=>mt(o)?o:this.ends[o]):a=n,a.some(o=>!o))throw new Error("Branch condition returned unknown or null destination");if(a.filter(mt).some(o=>o.node==="__end__"))throw new be("Cannot send a packet to the END node");return await r(a,t)??e}},lS=class{nodes;edges;branches;entryPoint;compiled=!1;constructor(){this.nodes={},this.edges=new Set,this.branches={}}warnIfCompiled(e){this.compiled&&console.warn(e)}get allEdges(){return this.edges}addNode(...e){function t(i){return i.length>=1&&typeof i[0]!="string"}let r=t(e)?Array.isArray(e[0])?e[0]:Object.entries(e[0]):[[e[0],e[1],e[2]]];if(r.length===0)throw new Error("No nodes provided in `addNode`");for(let[i,n,a]of r){for(let s of["|",":"])if(i.includes(s))throw new Error(`"${s}" 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."),i in this.nodes)throw new Error(`Node \`${i}\` already present.`);if(i==="__end__")throw new Error(`Node \`${i}\` is reserved.`);let o=tt(n);this.nodes[i]={runnable:o,metadata:a?.metadata,subgraphs:Sl(o)?[o]:a?.subgraphs,ends:a?.ends}}return this}addEdge(e,t){if(this.warnIfCompiled("Adding an edge to a graph that has already been compiled. This will not be reflected in the compiled graph."),e==="__end__")throw new Error("END cannot be a start node");if(t==="__start__")throw new Error("START cannot be an end node");if(Array.from(this.edges).some(([r])=>r===e)&&!("channels"in this))throw new Error(`Already found path for ${e}. For multiple edges, use StateGraph.`);return this.edges.add([e,t]),this}addConditionalEdges(e,t,r){let i=typeof e=="object"?e:{source:e,path:t,pathMap:r};this.warnIfCompiled("Adding an edge to a graph that has already been compiled. This will not be reflected in the compiled graph."),ae.isRunnable(i.path)||(i.path=tt(i.path));let n=i.path.getName()==="RunnableLambda"?"condition":i.path.getName();if(this.branches[i.source]&&this.branches[i.source][n])throw new Error(`Condition \`${n}\` already present for node \`${e}\``);return this.branches[i.source]??={},this.branches[i.source][n]=new uS(i),this}setEntryPoint(e){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(He,e)}setFinishPoint(e){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(e,Ye)}compile({checkpointer:e,interruptBefore:t,interruptAfter:r,name:i,transformers:n}={}){this.validate([...Array.isArray(t)?t:[],...Array.isArray(r)?r:[]]);let a=new dS({builder:this,checkpointer:e,interruptAfter:r,interruptBefore:t,autoValidate:!1,nodes:{},channels:{[He]:new xn,[Ye]:new xn},inputChannels:He,outputChannels:Ye,streamChannels:[],streamMode:"values",name:i,streamTransformers:n});for(let[o,s]of Object.entries(this.nodes))a.attachNode(o,s);for(let[o,s]of this.edges)a.attachEdge(o,s);for(let[o,s]of Object.entries(this.branches))for(let[c,u]of Object.entries(s))a.attachBranch(o,c,u);return a.validate()}validate(e){let t=new Set([...this.allEdges].map(([i,n])=>i));for(let[i]of Object.entries(this.branches))t.add(i);for(let i of t)if(i!=="__start__"&&!(i in this.nodes))throw new Error(`Found edge starting at unknown node \`${i}\``);let r=new Set([...this.allEdges].map(([i,n])=>n));for(let[i,n]of Object.entries(this.branches))for(let a of Object.values(n))if(a.ends!=null)for(let o of Object.values(a.ends))r.add(o);else{r.add(Ye);for(let o of Object.keys(this.nodes))o!==i&&r.add(o)}for(let i of Object.values(this.nodes))for(let n of i.ends??[])r.add(n);for(let i of Object.keys(this.nodes))if(!r.has(i))throw new yh([`Node \`${i}\` 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(`
431
- `),{lc_error_code:"UNREACHABLE_NODE"});for(let i of r)if(i!=="__end__"&&!(i in this.nodes))throw new Error(`Found edge ending at unknown node \`${i}\``);if(e){for(let i of e)if(!(i in this.nodes))throw new Error(`Interrupt node \`${i}\` is not present`)}this.compiled=!0}},dS=class extends lh{builder;constructor({builder:e,...t}){super(t),this.builder=e}withConfig(e){return super.withConfig(e)}attachNode(e,t){this.channels[e]=new xn,this.nodes[e]=new bn({channels:[],triggers:[],metadata:t.metadata,subgraphs:t.subgraphs,ends:t.ends}).pipe(t.runnable).pipe(new ot([{channel:e,value:hr}],[lt])),this.streamChannels.push(e)}attachEdge(e,t){if(t==="__end__"){if(e==="__start__")throw new Error("Cannot have an edge from START to END");this.nodes[e].writers.push(new ot([{channel:Ye,value:hr}],[lt]))}else this.nodes[t].triggers.push(e),this.nodes[t].channels.push(e)}attachBranch(e,t,r){e==="__start__"&&!this.nodes.__start__&&(this.nodes[He]=sM.subscribeTo(He,{tags:[lt]})),this.nodes[e].pipe(r.run(n=>new ot(n.map(a=>mt(a)?a:{channel:a==="__end__"?Ye:`branch:${e}:${t}:${a}`,value:hr}),[lt])));let i=r.ends?Object.values(r.ends):Object.keys(this.nodes);for(let n of i)if(n!=="__end__"){let a=`branch:${e}:${t}:${n}`;this.channels[a]=new xn,this.nodes[n].triggers.push(a),this.nodes[n].channels.push(a)}}async getGraphAsync(e){let t=e?.xray,r=new wo,i={[He]:r.addNode({schema:Kr.any()},He)},n={},a={};t&&(a=Object.fromEntries((await vn(this.getSubgraphsAsync())).filter(c=>uM(c[1]))));function o(c,u,l,d=!1){if(u==="__end__"&&n.__end__===void 0&&(n[Ye]=r.addNode({schema:Kr.any()},Ye)),i[c]!==void 0){if(n[u]===void 0)throw new Error(`End node ${u} not found!`);return r.addEdge(i[c],n[u],l!==u?l:void 0,d)}}for(let[c,u]of Object.entries(this.builder.nodes)){let l=Zt(c),d=u.runnable,f=u.metadata??{};if(this.interruptBefore?.includes(c)&&this.interruptAfter?.includes(c)?f.__interrupt="before,after":this.interruptBefore?.includes(c)?f.__interrupt="before":this.interruptAfter?.includes(c)&&(f.__interrupt="after"),t){let p=typeof t=="number"?t-1:t,m=a[c]!==void 0?await a[c].getGraphAsync({...e,xray:p}):d.getGraph(e);if(m.trimFirstNode(),m.trimLastNode(),Object.keys(m.nodes).length>1){let b=function(S){return S?S.lc_runnable:!1},w=function(S,k){if(S!==void 0&&!Uo(S))return S;if(b(k))try{let I=k.getName();return I=I.startsWith("Runnable")?I.slice(8):I,I}catch{return k.getName()}else return k.name??"UnknownSchema"},[g,v]=r.extend(m,l);if(g===void 0)throw new Error(`Could not extend subgraph "${c}" due to missing entrypoint.`);v!==void 0&&(i[l]={name:w(v.id,v.data),...v}),n[l]={name:w(g.id,g.data),...g}}else{let g=r.addNode(d,l,f);i[l]=g,n[l]=g}}else{let p=r.addNode(d,l,f);i[l]=p,n[l]=p}}let s=[...this.builder.allEdges].sort(([c],[u])=>c<u?-1:u>c?1:0);for(let[c,u]of s)o(Zt(c),Zt(u));for(let[c,u]of Object.entries(this.builder.branches)){let l={...Object.fromEntries(Object.keys(this.builder.nodes).filter(d=>d!==c).map(d=>[Zt(d),Zt(d)])),[Ye]:Ye};for(let d of Object.values(u)){let f;d.ends!==void 0?f=d.ends:f=l;for(let[p,m]of Object.entries(f))o(Zt(c),Zt(m),p,!0)}}for(let[c,u]of Object.entries(this.builder.nodes))if(u.ends!==void 0)for(let l of u.ends)o(Zt(c),Zt(l),void 0,!0);return r}getGraph(e){let t=e?.xray,r=new wo,i={[He]:r.addNode({schema:Kr.any()},He)},n={},a={};t&&(a=Object.fromEntries(To(this.getSubgraphs()).filter(c=>uM(c[1]))));function o(c,u,l,d=!1){return u==="__end__"&&n.__end__===void 0&&(n[Ye]=r.addNode({schema:Kr.any()},Ye)),r.addEdge(i[c],n[u],l!==u?l:void 0,d)}for(let[c,u]of Object.entries(this.builder.nodes)){let l=Zt(c),d=u.runnable,f=u.metadata??{};if(this.interruptBefore?.includes(c)&&this.interruptAfter?.includes(c)?f.__interrupt="before,after":this.interruptBefore?.includes(c)?f.__interrupt="before":this.interruptAfter?.includes(c)&&(f.__interrupt="after"),t){let p=typeof t=="number"?t-1:t,m=a[c]!==void 0?a[c].getGraph({...e,xray:p}):d.getGraph(e);if(m.trimFirstNode(),m.trimLastNode(),Object.keys(m.nodes).length>1){let b=function(S){return S?S.lc_runnable:!1},w=function(S,k){if(S!==void 0&&!Uo(S))return S;if(b(k))try{let I=k.getName();return I=I.startsWith("Runnable")?I.slice(8):I,I}catch{return k.getName()}else return k.name??"UnknownSchema"},[g,v]=r.extend(m,l);if(g===void 0)throw new Error(`Could not extend subgraph "${c}" due to missing entrypoint.`);v!==void 0&&(i[l]={name:w(v.id,v.data),...v}),n[l]={name:w(g.id,g.data),...g}}else{let g=r.addNode(d,l,f);i[l]=g,n[l]=g}}else{let p=r.addNode(d,l,f);i[l]=p,n[l]=p}}let s=[...this.builder.allEdges].sort(([c],[u])=>c<u?-1:u>c?1:0);for(let[c,u]of s)o(Zt(c),Zt(u));for(let[c,u]of Object.entries(this.builder.branches)){let l={...Object.fromEntries(Object.keys(this.builder.nodes).filter(d=>d!==c).map(d=>[Zt(d),Zt(d)])),[Ye]:Ye};for(let d of Object.values(u)){let f;d.ends!==void 0?f=d.ends:f=l;for(let[p,m]of Object.entries(f))o(Zt(c),Zt(m),p,!0)}}return r}};function uM(e){return typeof e.attachNode=="function"&&typeof e.attachEdge=="function"}function Zt(e){return e==="subgraph"?`"${e}"`:e}function Ii(e){return typeof e=="object"&&e!==null&&"~standard"in e&&typeof e["~standard"]=="object"&&e["~standard"]!==null&&"validate"in e["~standard"]}function fS(e){return typeof e=="object"&&e!==null&&"~standard"in e&&typeof e["~standard"]=="object"&&e["~standard"]!==null&&"jsonSchema"in e["~standard"]}function nV(e){return Ii(e)&&fS(e)}function ma(e){if(fS(e))try{return e["~standard"].jsonSchema.input({target:"draft-07"})}catch{return}}function ha(e){if(e!=null&&Ii(e))try{let t=e["~standard"].validate(void 0);if(t&&typeof t=="object"&&!("then"in t&&typeof t.then=="function")){let r=t;if(!r.issues){let i=r.value;return()=>i}}}catch{}}var pS=Symbol.for("langgraph.channel.missing"),dh=class lM extends kt{lc_graph_name="UntrackedValue";guard;_value=pS;initialValueFactory;constructor(t){super(),this.guard=t?.guard??!0,this.initialValueFactory=t?.initialValueFactory,this.initialValueFactory&&(this._value=this.initialValueFactory())}fromCheckpoint(t){return new lM({guard:this.guard,initialValueFactory:this.initialValueFactory})}update(t){if(t.length===0)return!1;if(t.length!==1&&this.guard)throw new be("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=t[t.length-1],!0}get(){if(this._value===pS)throw new Ne;return this._value}checkpoint(){}isAvailable(){return this._value!==pS}};var ga=(e,t)=>e.size===t.size&&[...e].every(r=>t.has(r)),mS=class dM extends kt{lc_graph_name="NamedBarrierValue";names;seen;constructor(t){super(),this.names=t,this.seen=new Set}fromCheckpoint(t){let r=new dM(this.names);return typeof t<"u"&&(r.seen=new Set(t)),r}update(t){let r=!1;for(let i of t)if(this.names.has(i))this.seen.has(i)||(this.seen.add(i),r=!0);else throw new be(`Value ${JSON.stringify(i)} not in names ${JSON.stringify(this.names)}`);return r}get(){if(!ga(this.names,this.seen))throw new Ne}checkpoint(){return[...this.seen]}consume(){return this.seen&&this.names&&ga(this.seen,this.names)?(this.seen=new Set,!0):!1}isAvailable(){return!!this.names&&ga(this.names,this.seen)}},hS=class fM extends kt{lc_graph_name="NamedBarrierValueAfterFinish";names;seen;finished;constructor(t){super(),this.names=t,this.seen=new Set,this.finished=!1}fromCheckpoint(t){let r=new fM(this.names);if(typeof t<"u"){let[i,n]=t;r.seen=new Set(i),r.finished=n}return r}update(t){let r=!1;for(let i of t)if(this.names.has(i)&&!this.seen.has(i))this.seen.add(i),r=!0;else if(!this.names.has(i))throw new be(`Value ${JSON.stringify(i)} not in names ${JSON.stringify(this.names)}`);return r}get(){if(!this.finished||!ga(this.names,this.seen))throw new Ne}checkpoint(){return[[...this.seen],this.finished]}consume(){return this.finished&&this.seen&&this.names&&ga(this.seen,this.names)?(this.seen=new Set,this.finished=!1,!0):!1}finish(){return!this.finished&&this.names&&ga(this.names,this.seen)?(this.finished=!0,!0):!1}isAvailable(){return this.finished&&!!this.names&&ga(this.names,this.seen)}};var gS=Symbol.for("langgraph.state.reduced_value"),Ti=class{[gS]=!0;valueSchema;inputSchema;reducer;jsonSchemaExtra;constructor(e,t){this.reducer=t.reducer,this.jsonSchemaExtra=t.jsonSchemaExtra,this.valueSchema=e,this.inputSchema="inputSchema"in t?t.inputSchema:e,this.jsonSchemaExtra=t.jsonSchemaExtra}static isInstance(e){return typeof e=="object"&&e!==null&&gS in e&&e[gS]===!0}};var pM=Symbol.for("langgraph.state.untracked_value"),Oo=class{[pM]=!0;schema;guard;constructor(e,t){this.schema=e,this.guard=t?.guard??!0}static isInstance(e){return typeof e=="object"&&e!==null&&pM in e}};var _S=Symbol.for("langgraph.state.state_schema"),Qn=class{[_S]=!0;constructor(e){this.fields=e}getChannels(){let e={};for(let[t,r]of Object.entries(this.fields))if(Ti.isInstance(r)){let i=ha(r.valueSchema);e[t]=new xi(r.reducer,i)}else if(Oo.isInstance(r)){let i=r.schema?ha(r.schema):void 0;e[t]=new dh({guard:r.guard,initialValueFactory:i})}else if(Ii(r))e[t]=new yn(ha(r));else throw new Error(`Invalid state field "${t}": must be a schema, ReducedValue, UntrackedValue, or ManagedValue`);return e}getJsonSchema(){let e={},t=[];for(let[r,i]of Object.entries(this.fields)){let n;if(Ti.isInstance(i)?(n=ma(i.valueSchema),i.jsonSchemaExtra&&(n={...n??{},...i.jsonSchemaExtra})):Oo.isInstance(i)?n=i.schema?ma(i.schema):void 0:Ii(i)&&(n=ma(i)),n){e[r]=n;let a=!1;Ti.isInstance(i)?a=ha(i.valueSchema)!==void 0:Oo.isInstance(i)?a=i.schema?ha(i.schema)!==void 0:!1:a=ha(i)!==void 0,a||t.push(r)}}return{type:"object",properties:e,required:t.length>0?t:void 0}}getInputJsonSchema(){let e={};for(let[t,r]of Object.entries(this.fields)){let i;Ti.isInstance(r)?(i=ma(r.inputSchema),r.jsonSchemaExtra&&(i={...i??{},...r.jsonSchemaExtra})):Oo.isInstance(r)?i=r.schema?ma(r.schema):void 0:Ii(r)&&(i=ma(r)),i&&(e[t]=i)}return{type:"object",properties:e}}getChannelKeys(){return Object.entries(this.fields).map(([e])=>e)}getAllKeys(){return Object.keys(this.fields)}async validateInput(e){if(e==null||typeof e!="object")return e;let t={};for(let[r,i]of Object.entries(e)){let n=this.fields[r];if(n===void 0){t[r]=i;continue}let a;if(Ti.isInstance(n)?a=n.inputSchema:Oo.isInstance(n)?a=n.schema:Ii(n)&&(a=n),a){let o=await a["~standard"].validate(i);if(o.issues)throw new Error(`Validation failed for field "${r}": ${JSON.stringify(o.issues)}`);t[r]=o.value}else t[r]=i}return t}static isInstance(e){return typeof e=="object"&&e!==null&&_S in e&&e[_S]===!0}};var iV="__remove_all__";function _a(e,t){let r=Array.isArray(e)?e:[e],i=Array.isArray(t)?t:[t],n=r.map(Et),a=i.map(Et);for(let l of n)(l.id===null||l.id===void 0)&&(l.id=Ul(),l.lc_kwargs.id=l.id);let o;for(let l=0;l<a.length;l+=1){let d=a[l];(d.id===null||d.id===void 0)&&(d.id=Ul(),d.lc_kwargs.id=d.id),an.isInstance(d)&&d.id==="__remove_all__"&&(o=l)}if(o!=null)return a.slice(o+1);let s=[...n],c=new Map(s.map((l,d)=>[l.id,d])),u=new Set;for(let l of a){let d=c.get(l.id);if(d!==void 0)an.isInstance(l)?u.add(l.id):(u.delete(l.id),s[d]=l);else{if(an.isInstance(l))throw new Error(`Attempting to delete a message with an ID that doesn't exist ('${l.id}')`);c.set(l.id,s.length),s.push(l)}}return s.filter(l=>!u.has(l.id))}var aV=new Ti(Kr.custom().default(()=>[]),{inputSchema:Kr.custom(),reducer:_a,jsonSchemaExtra:{langgraph_type:"messages",description:"A list of chat messages"}});var oV=class{_map=new Map;_extensionCache=new Map;get(e){return this._map.get(e)}extend(e,t){let r=this.get(e);this._map.set(e,t(r))}remove(e){return this._map.delete(e),this}has(e){return this._map.has(e)}getChannelsForSchema(e){let t={},r=no(e);for(let[i,n]of Object.entries(r)){let a=this.get(n);a?.reducer?t[i]=new xi(a.reducer.fn,a.default):t[i]=new yn(a?.default)}return t}getExtendedChannelSchemas(e,t){if(Object.keys(t).length===0)return e;let r=Object.entries(t).filter(([,a])=>a===!0).sort(([a],[o])=>a.localeCompare(o)).map(([a,o])=>`${a}:${o}`).join("|"),i=this._extensionCache.get(r)??new Map;if(i.has(e))return i.get(e);let n=e;if(t.withReducerSchema||t.withJsonSchemaExtrasAsDescription){let a=Object.entries(no(e)).map(([o,s])=>{let c=this.get(s),u=t.withReducerSchema?c?.reducer?.schema??s:s;if(t.withJsonSchemaExtrasAsDescription&&c?.jsonSchemaExtra){let l=pi(u)??pi(s),d=JSON.stringify({...c.jsonSchemaExtra,description:l});u=u.describe(`lg:${d}`)}return[o,u]});n=sp(e,Object.fromEntries(a)),at(n)&&(n._def.unknownKeys="strip")}return t.asPartial&&(n=js(n)),i.set(e,n),this._extensionCache.set(r,i),n}},Tl=new oV;function mM(e,t){if(t.reducer&&!t.default){let r=cp(e);r!=null&&(t.default=r)}if(t.reducer){let r=Object.assign(e,{lg_reducer_schema:t.reducer?.schema??e});return Tl.extend(r,()=>t),r}else return Tl.extend(e,()=>t),e}function Po(e){return e==null?!1:!!(Qn.isInstance(e)||Yt(e)||typeof e=="object"&&"lc_graph_name"in e&&e.lc_graph_name==="AnnotationRoot"||typeof e=="object"&&!Array.isArray(e)&&Object.keys(e).length>0&&Object.values(e).every(t=>typeof t=="function"||I0(t)))}function hM(e){if(typeof e!="object"||e==null)return!1;let t=e,r="state"in t&&Po(t.state),i="stateSchema"in t&&Po(t.stateSchema),n="input"in t&&Po(t.input);return!(!r&&!i&&!n||"input"in t&&t.input!=null&&!Po(t.input)||"output"in t&&t.output!=null&&!Po(t.output))}var Ai="__root__",fh=Symbol.for("langgraph.state.partial"),yS=class extends lS{channels={};waitingEdges=new Set;_schemaDefinition;_schemaRuntimeDefinition;_inputDefinition;_inputRuntimeDefinition;_outputDefinition;_outputRuntimeDefinition;_schemaDefinitions=new Map;_metaRegistry=Tl;_configSchema;_configRuntimeSchema;_interrupt;_writer;constructor(e,t){super();let r=this._normalizeToStateGraphInit(e,t),i=r.state??r.stateSchema??r.input;if(!i)throw new Tc;let n=this._getChannelsFromSchema(i);this._schemaDefinition=n,Qn.isInstance(i)?this._schemaRuntimeDefinition=i:Yt(i)&&(this._schemaRuntimeDefinition=i),r.input?Qn.isInstance(r.input)?this._inputRuntimeDefinition=r.input:Yt(r.input)?this._inputRuntimeDefinition=r.input:this._inputRuntimeDefinition=fh:this._inputRuntimeDefinition=fh,r.output?Qn.isInstance(r.output)?this._outputRuntimeDefinition=r.output:Yt(r.output)?this._outputRuntimeDefinition=r.output:this._outputRuntimeDefinition=this._schemaRuntimeDefinition:this._outputRuntimeDefinition=this._schemaRuntimeDefinition;let a=r.input?this._getChannelsFromSchema(r.input):n,o=r.output?this._getChannelsFromSchema(r.output):n;this._inputDefinition=a,this._outputDefinition=o,this._addSchema(this._schemaDefinition),this._addSchema(this._inputDefinition),this._addSchema(this._outputDefinition),r.context&&Yt(r.context)&&(this._configRuntimeSchema=r.context),this._interrupt=r.interrupt,this._writer=r.writer}_normalizeToStateGraphInit(e,t){if(hM(e)){if(Yt(t)||Fm.isInstance(t))return{...e,context:t};let r=t;return{...e,input:e.input??r?.input,output:e.output??r?.output,context:e.context??r?.context,interrupt:e.interrupt??r?.interrupt,writer:e.writer??r?.writer,nodes:e.nodes??r?.nodes}}if(Po(e)){if(Yt(t)||Fm.isInstance(t))return{state:e,context:t};let r=t;return{state:e,input:r?.input,output:r?.output,context:r?.context,interrupt:r?.interrupt,writer:r?.writer,nodes:r?.nodes}}if(cV(e))return{state:sV(e.channels)};throw new Tc}_getChannelsFromSchema(e){if(Qn.isInstance(e))return e.getChannels();if(Yt(e))return this._metaRegistry.getChannelsForSchema(e);if(typeof e=="object"&&"lc_graph_name"in e&&e.lc_graph_name==="AnnotationRoot")return e.spec;if(typeof e=="object"&&!Array.isArray(e)&&Object.keys(e).length>0)return e;throw new Tc("Invalid schema type. Expected StateSchema, Zod object, AnnotationRoot, or StateDefinition.")}get allEdges(){return new Set([...this.edges,...Array.from(this.waitingEdges).flatMap(([e,t])=>e.map(r=>[r,t]))])}_addSchema(e){if(!this._schemaDefinitions.has(e)){this._schemaDefinitions.set(e,e);for(let[t,r]of Object.entries(e)){let i;if(typeof r=="function"?i=r():i=r,this.channels[t]!==void 0){if(!this.channels[t].equals(i)&&i.lc_graph_name!=="LastValue")throw new Error(`Channel "${t}" already exists with a different type.`)}else this.channels[t]=i}}}addNode(...e){function t(i){return i.length>=1&&typeof i[0]!="string"}let r=t(e)?Array.isArray(e[0])?e[0]:Object.entries(e[0]).map(([i,n])=>[i,n]):[[e[0],e[1],e[2]]];if(r.length===0)throw new Error("No nodes provided in `addNode`");for(let[i,n,a]of r){if(i in this.channels)throw new Error(`${i} is already being used as a state attribute (a.k.a. a channel), cannot also be used as a node name.`);for(let l of["|",":"])if(i.includes(l))throw new Error(`"${l}" 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."),i in this.nodes)throw new Error(`Node \`${i}\` already present.`);if(i==="__end__"||i==="__start__")throw new Error(`Node \`${i}\` is reserved.`);let o=this._schemaDefinition;a?.input!==void 0&&(o=this._getChannelsFromSchema(a.input)),this._addSchema(o);let s;ae.isRunnable(n)?s=n:typeof n=="function"?s=new Vt({func:n,name:i,trace:!1}):s=tt(n);let c=a?.cachePolicy;typeof c=="boolean"&&(c=c?{}:void 0);let u={runnable:s,retryPolicy:a?.retryPolicy,cachePolicy:c,metadata:a?.metadata,input:o??this._schemaDefinition,subgraphs:Sl(s)?[s]:a?.subgraphs,ends:a?.ends,defer:a?.defer};this.nodes[i]=u}return this}addEdge(e,t){if(typeof e=="string")return super.addEdge(e,t);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 r of e){if(r==="__end__")throw new Error("END cannot be a start node");if(!Object.keys(this.nodes).some(i=>i===r))throw new Error(`Need to add a node named "${r}" first`)}if(t==="__end__")throw new Error("END cannot be an end node");if(!Object.keys(this.nodes).some(r=>r===t))throw new Error(`Need to add a node named "${t}" first`);return this.waitingEdges.add([e,t]),this}addSequence(e){let t=Array.isArray(e)?e:Object.entries(e);if(t.length===0)throw new Error("Sequence requires at least one node.");let r;for(let[i,n,a]of t){if(i in this.nodes)throw new Error(`Node names must be unique: node with the name "${i}" already exists.`);let o=i;this.addNode(o,n,a),r!=null&&this.addEdge(r,o),r=o}return this}compile({checkpointer:e,store:t,cache:r,interruptBefore:i,interruptAfter:n,name:a,description:o,transformers:s}={}){this.validate([...Array.isArray(i)?i:[],...Array.isArray(n)?n:[]]);let c=Object.keys(this._schemaDefinitions.get(this._outputDefinition)),u=c.length===1&&c[0]===Ai?Ai:c,l=Object.keys(this.channels),d=l.length===1&&l[0]===Ai?Ai:l,f=this._interrupt,p=new _M({builder:this,checkpointer:e,interruptAfter:n,interruptBefore:i,autoValidate:!1,nodes:{},channels:{...this.channels,[He]:new xn},inputChannels:He,outputChannels:u,streamChannels:d,streamMode:"updates",store:t,cache:r,name:a,description:o,userInterrupt:f,streamTransformers:s});p.attachNode(He);for(let[m,g]of Object.entries(this.nodes))p.attachNode(m,g);p.attachBranch(He,mh,gM(),{withReader:!1});for(let[m]of Object.entries(this.nodes))p.attachBranch(m,mh,gM(),{withReader:!1});for(let[m,g]of this.edges)p.attachEdge(m,g);for(let[m,g]of this.waitingEdges)p.attachEdge(m,g);for(let[m,g]of Object.entries(this.branches))for(let[v,b]of Object.entries(g))p.attachBranch(m,v,b);return p.validate()}};function sV(e){let t={};for(let[r,i]of Object.entries(e))r===Ai?t[r]=Bm(i):t[r]=Bm(i);return t}var _M=class extends dS{description;_metaRegistry=Tl;constructor({description:e,...t}){super(t),this.description=e}attachNode(e,t){let r;e==="__start__"?r=Object.entries(this.builder._schemaDefinitions.get(this.builder._inputDefinition)).map(([s])=>s):r=Object.keys(this.builder.channels);function i(s){if(yt(s))return s.graph===ir.PARENT?null:s._updateAsTuples();if(Array.isArray(s)&&s.length>0&&s.some(c=>yt(c))){let c=[];for(let u of s)if(yt(u)){if(u.graph===ir.PARENT)continue;c.push(...u._updateAsTuples())}else c.push([Ai,u]);return c}else if(s!=null)return[[Ai,s]];return null}let n=e;function a(s){if(s){if(yt(s))return s.graph===ir.PARENT?null:s._updateAsTuples().filter(([c])=>r.includes(c));if(Array.isArray(s)&&s.length>0&&s.some(yt)){let c=[];for(let u of s)if(yt(u)){if(u.graph===ir.PARENT)continue;c.push(...u._updateAsTuples().filter(([l])=>r.includes(l)))}else{let l=a(u);l&&c.push(...l??[])}return c}else{if(typeof s=="object"&&!Array.isArray(s))return Object.entries(s).filter(([c])=>r.includes(c));{let c=Array.isArray(s)?"array":typeof s;throw new be(`Expected node "${n.toString()}" to return an object or an array containing at least one Command object, received ${c}`,{lc_error_code:"INVALID_GRAPH_NODE_RETURN_VALUE"})}}}else return null}let o=[{value:hr,mapper:new Vt({func:r.length&&r[0]===Ai?i:a,trace:!1,recurse:!1})}];if(e==="__start__")this.nodes[e]=new bn({tags:[lt],triggers:[He],channels:[He],writers:[new ot(o,[lt])]});else{let s=t?.input??this.builder._schemaDefinition,c=Object.fromEntries(Object.keys(this.builder._schemaDefinitions.get(s)).map(d=>[d,d])),u=Object.keys(c).length===1&&Ai in c,l=`branch:to:${e}`;this.channels[l]=t?.defer?new T0:new xn(!1),this.nodes[e]=new bn({triggers:[l],channels:u?Object.keys(c):c,writers:[new ot(o,[lt])],mapper:u?void 0:d=>Object.fromEntries(Object.entries(d).filter(([f])=>f in c)),bound:t?.runnable,metadata:t?.metadata,retryPolicy:t?.retryPolicy,cachePolicy:t?.cachePolicy,subgraphs:t?.subgraphs,ends:t?.ends})}}attachEdge(e,t){if(t!=="__end__"){if(typeof e=="string")this.nodes[e].writers.push(new ot([{channel:`branch:to:${t}`,value:null}],[lt]));else if(Array.isArray(e)){let r=`join:${e.join("+")}:${t}`;this.channels[r]=this.builder.nodes[t].defer?new hS(new Set(e)):new mS(new Set(e)),this.nodes[t].triggers.push(r);for(let i of e)this.nodes[i].writers.push(new ot([{channel:r,value:i}],[lt]))}}}attachBranch(e,t,r,i={withReader:!0}){let n=async(a,o)=>{let s=a.filter(u=>u!==Ye);if(!s.length)return;let c=s.map(u=>mt(u)?u:{channel:u==="__end__"?u:`branch:to:${u}`,value:e});await ot.doWrite({...o,tags:(o.tags??[]).concat([lt])},c)};this.nodes[e].writers.push(r.run(n,i.withReader?a=>IR.doRead(a,this.streamChannels??this.outputChannels,!0):void 0))}async _validateInput(e){if(e==null)return e;let t=this.builder._inputRuntimeDefinition,r=this.builder._schemaRuntimeDefinition;if(Qn.isInstance(t)){if(yt(e)){let n=e;return e.update&&(n.update=await t.validateInput(Array.isArray(e.update)?Object.fromEntries(e.update):e.update)),n}return await t.validateInput(e)}if(t===fh&&Qn.isInstance(r)){if(yt(e)){let n=e;return e.update&&(n.update=await r.validateInput(Array.isArray(e.update)?Object.fromEntries(e.update):e.update)),n}return await r.validateInput(e)}let i=(()=>{let n=a=>{if(a!=null)return this._metaRegistry.getExtendedChannelSchemas(a,{withReducerSchema:!0})};if(Yt(t))return n(t);if(t===fh)return Yt(r)?js(n(r)):void 0})();if(yt(e)){let n=e;if(e.update&&i!=null){let a=Array.isArray(e.update)?Object.fromEntries(e.update):e.update,o=Rs(i,a);n.update=Object.fromEntries(Object.keys(a).map(s=>[s,o[s]]))}return n}return i!=null?Rs(i,e):e}isInterrupted(e){return ka(e)}async _validateContext(e){let t=this.builder._configRuntimeSchema;return Yt(t)&&Rs(t,e),e}};function cV(e){return typeof e=="object"&&e!==null&&e.channels!==void 0}function uV(e){if(mt(e))return[e];let t=[];yt(e)?t.push(e):Array.isArray(e)&&t.push(...e.filter(yt));let r=[];for(let i of t){if(i.graph===ir.PARENT)throw new zl(i);mt(i.goto)||typeof i.goto=="string"?r.push(i.goto):Array.isArray(i.goto)&&r.push(...i.goto)}return r}function gM(){return new uS({path:new Vt({func:uV,tags:[lt],trace:!1,recurse:!1,name:"<control_branch>"})})}var lV=class extends yS{constructor(){super({channels:{__root__:{reducer:_a,default:()=>[]}}})}};function dV(e,t){let{stateKey:r,...i}=t??{},n=pc(i),a=r??"messages";r===null&&(a=void 0);let o=Et(e);if(!o.id)throw new Error("Message ID is required.");let s=(Array.isArray(n.callbacks)?n.callbacks:typeof n.callbacks<"u"?n.callbacks.handlers:[]).find(c=>"name"in c&&c.name==="StreamMessagesHandler");if(s){let c=n.metadata??{},u=(c.langgraph_checkpoint_ns??"").split("|");s._emit([u,c],o,void 0,!1)}return a&&n.configurable?.__pregel_send?.([[a,o]]),o}function fV(e,t){let r=typeof e=="string"?{name:e,retry:void 0,cachePolicy:void 0}:e,{name:i,retry:n}=r;if(G0(t)||J0(t))throw new Error("Generators are disallowed as tasks. For streaming responses, use config.write.");let a=r.cachePolicy??("cache"in r?r.cache:void 0),o;return typeof a=="boolean"?o=a?{}:void 0:o=a,(...s)=>zR({func:t,name:i,retry:n,cache:o},...s)}var yM=function(t,r){let{name:i,checkpointer:n,store:a,cache:o}=typeof t=="string"?{name:t,checkpointer:void 0,store:void 0}:t;if(G0(r)||J0(r))throw new Error("Generators are disallowed as entrypoints. For streaming responses, use config.write.");let s="updates",c=jR(i,r);function u(p){return typeof p=="object"&&p!==null&&"__lg_type"in p&&p.__lg_type==="__pregel_final"}let l=new Vt({name:"pluckReturnValue",func:p=>u(p)?p.value:p}),d=new Vt({name:"pluckSaveValue",func:p=>u(p)?p.save:p}),f=new bn({bound:c,triggers:[He],channels:[He],writers:[new ot([{channel:Ye,value:hr,mapper:l},{channel:Sa,value:hr,mapper:d}],[lt])]});return new lh({name:i,checkpointer:n,nodes:{[i]:f},channels:{[He]:new xn,[Ye]:new yn,[Sa]:new yn},inputChannels:He,outputChannels:Ye,streamChannels:Ye,streamMode:s,store:a,cache:o})};yM.final=function({value:t,save:r}){return{value:t,save:r,__lg_type:"__pregel_final"}};function pV(){return Ae.getRunnableConfig().configurable?.[xa]}var mV=vl.Root({messages:vl({reducer:_a,default:()=>[]})}),vM={reducer:{fn:_a},jsonSchemaExtra:{langgraph_type:"messages"},default:()=>[]},hV=St.object({messages:mM(St.custom(),vM)});function gV(e){let t=Ae.getRunnableConfig();if(!t)throw new Error("Called interrupt() outside the context of a graph.");let r=t.configurable;if(!r)throw new Error("No configurable found in config");return r.writer?.(e)}export{He as a,Ye as b,Ue as c,ph as d,kS as e,wa as f,xM as g,ka as h,ir as i,yt as j,en as k,hh as l,gh as m,$a as n,ti as o,jl as p,zl as q,_h as r,Ea as s,ri as t,Dl as u,Ne as v,be as w,kM as x,yh as y,$M as z,Tc as A,EM as B,JS as C,Ht as D,YM as E,An as F,nk as G,Rc as H,ik as I,gt as J,Go as K,Te as L,Wo as M,Qe as N,nn as O,Aa as P,Oa as Q,Pa as R,oi as S,Xk as T,jt as U,Zi as V,Ha as W,qi as X,Tf as Y,to as Z,Ve as _,at as $,lr as aa,pi as ba,cp as ca,D as da,St as ea,_t as fa,Dt as ga,Tp as ha,iF as ia,Ru as ja,jp as ka,Iw as la,HO as ma,GO as na,uF as oa,lF as pa,Aw as qa,ca as ra,ua as sa,Hw as ta,ec as ua,Yu as va,Kr as wa,gB as xa,kB as ya,lc as za,gn as Aa,zm as Ba,nR as Ca,fc as Da,Um as Ea,oR as Fa,kt as Ga,xi as Ha,vl as Ia,r9 as Ja,n9 as Ka,A0 as La,i9 as Ma,C0 as Na,mc as Oa,O0 as Pa,Wr as Qa,Gm as Ra,M0 as Sa,bl as Ta,wl as Ua,j0 as Va,z0 as Wa,Jm as Xa,L0 as Ya,_R as Za,F0 as _a,H0 as $a,lS as ab,Ii as bb,nV as cb,ma as db,ha as eb,dh as fb,Ti as gb,Oo as hb,Qn as ib,iV as jb,_a as kb,aV as lb,Tl as mb,mM as nb,yS as ob,_M as pb,lV as qb,dV as rb,fV as sb,yM as tb,pV as ub,mV as vb,vM as wb,hV as xb,gV as yb};
431
+ `),{lc_error_code:"UNREACHABLE_NODE"});for(let i of r)if(i!=="__end__"&&!(i in this.nodes))throw new Error(`Found edge ending at unknown node \`${i}\``);if(e){for(let i of e)if(!(i in this.nodes))throw new Error(`Interrupt node \`${i}\` is not present`)}this.compiled=!0}},dS=class extends lh{builder;constructor({builder:e,...t}){super(t),this.builder=e}withConfig(e){return super.withConfig(e)}attachNode(e,t){this.channels[e]=new xn,this.nodes[e]=new bn({channels:[],triggers:[],metadata:t.metadata,subgraphs:t.subgraphs,ends:t.ends}).pipe(t.runnable).pipe(new ot([{channel:e,value:hr}],[lt])),this.streamChannels.push(e)}attachEdge(e,t){if(t==="__end__"){if(e==="__start__")throw new Error("Cannot have an edge from START to END");this.nodes[e].writers.push(new ot([{channel:Ye,value:hr}],[lt]))}else this.nodes[t].triggers.push(e),this.nodes[t].channels.push(e)}attachBranch(e,t,r){e==="__start__"&&!this.nodes.__start__&&(this.nodes[He]=sM.subscribeTo(He,{tags:[lt]})),this.nodes[e].pipe(r.run(n=>new ot(n.map(a=>mt(a)?a:{channel:a==="__end__"?Ye:`branch:${e}:${t}:${a}`,value:hr}),[lt])));let i=r.ends?Object.values(r.ends):Object.keys(this.nodes);for(let n of i)if(n!=="__end__"){let a=`branch:${e}:${t}:${n}`;this.channels[a]=new xn,this.nodes[n].triggers.push(a),this.nodes[n].channels.push(a)}}async getGraphAsync(e){let t=e?.xray,r=new wo,i={[He]:r.addNode({schema:Kr.any()},He)},n={},a={};t&&(a=Object.fromEntries((await vn(this.getSubgraphsAsync())).filter(c=>uM(c[1]))));function o(c,u,l,d=!1){if(u==="__end__"&&n.__end__===void 0&&(n[Ye]=r.addNode({schema:Kr.any()},Ye)),i[c]!==void 0){if(n[u]===void 0)throw new Error(`End node ${u} not found!`);return r.addEdge(i[c],n[u],l!==u?l:void 0,d)}}for(let[c,u]of Object.entries(this.builder.nodes)){let l=Zt(c),d=u.runnable,f=u.metadata??{};if(this.interruptBefore?.includes(c)&&this.interruptAfter?.includes(c)?f.__interrupt="before,after":this.interruptBefore?.includes(c)?f.__interrupt="before":this.interruptAfter?.includes(c)&&(f.__interrupt="after"),t){let p=typeof t=="number"?t-1:t,m=a[c]!==void 0?await a[c].getGraphAsync({...e,xray:p}):d.getGraph(e);if(m.trimFirstNode(),m.trimLastNode(),Object.keys(m.nodes).length>1){let b=function(S){return S?S.lc_runnable:!1},w=function(S,k){if(S!==void 0&&!Uo(S))return S;if(b(k))try{let I=k.getName();return I=I.startsWith("Runnable")?I.slice(8):I,I}catch{return k.getName()}else return k.name??"UnknownSchema"},[g,v]=r.extend(m,l);if(g===void 0)throw new Error(`Could not extend subgraph "${c}" due to missing entrypoint.`);v!==void 0&&(i[l]={name:w(v.id,v.data),...v}),n[l]={name:w(g.id,g.data),...g}}else{let g=r.addNode(d,l,f);i[l]=g,n[l]=g}}else{let p=r.addNode(d,l,f);i[l]=p,n[l]=p}}let s=[...this.builder.allEdges].sort(([c],[u])=>c<u?-1:u>c?1:0);for(let[c,u]of s)o(Zt(c),Zt(u));for(let[c,u]of Object.entries(this.builder.branches)){let l={...Object.fromEntries(Object.keys(this.builder.nodes).filter(d=>d!==c).map(d=>[Zt(d),Zt(d)])),[Ye]:Ye};for(let d of Object.values(u)){let f;d.ends!==void 0?f=d.ends:f=l;for(let[p,m]of Object.entries(f))o(Zt(c),Zt(m),p,!0)}}for(let[c,u]of Object.entries(this.builder.nodes))if(u.ends!==void 0)for(let l of u.ends)o(Zt(c),Zt(l),void 0,!0);return r}getGraph(e){let t=e?.xray,r=new wo,i={[He]:r.addNode({schema:Kr.any()},He)},n={},a={};t&&(a=Object.fromEntries(To(this.getSubgraphs()).filter(c=>uM(c[1]))));function o(c,u,l,d=!1){return u==="__end__"&&n.__end__===void 0&&(n[Ye]=r.addNode({schema:Kr.any()},Ye)),r.addEdge(i[c],n[u],l!==u?l:void 0,d)}for(let[c,u]of Object.entries(this.builder.nodes)){let l=Zt(c),d=u.runnable,f=u.metadata??{};if(this.interruptBefore?.includes(c)&&this.interruptAfter?.includes(c)?f.__interrupt="before,after":this.interruptBefore?.includes(c)?f.__interrupt="before":this.interruptAfter?.includes(c)&&(f.__interrupt="after"),t){let p=typeof t=="number"?t-1:t,m=a[c]!==void 0?a[c].getGraph({...e,xray:p}):d.getGraph(e);if(m.trimFirstNode(),m.trimLastNode(),Object.keys(m.nodes).length>1){let b=function(S){return S?S.lc_runnable:!1},w=function(S,k){if(S!==void 0&&!Uo(S))return S;if(b(k))try{let I=k.getName();return I=I.startsWith("Runnable")?I.slice(8):I,I}catch{return k.getName()}else return k.name??"UnknownSchema"},[g,v]=r.extend(m,l);if(g===void 0)throw new Error(`Could not extend subgraph "${c}" due to missing entrypoint.`);v!==void 0&&(i[l]={name:w(v.id,v.data),...v}),n[l]={name:w(g.id,g.data),...g}}else{let g=r.addNode(d,l,f);i[l]=g,n[l]=g}}else{let p=r.addNode(d,l,f);i[l]=p,n[l]=p}}let s=[...this.builder.allEdges].sort(([c],[u])=>c<u?-1:u>c?1:0);for(let[c,u]of s)o(Zt(c),Zt(u));for(let[c,u]of Object.entries(this.builder.branches)){let l={...Object.fromEntries(Object.keys(this.builder.nodes).filter(d=>d!==c).map(d=>[Zt(d),Zt(d)])),[Ye]:Ye};for(let d of Object.values(u)){let f;d.ends!==void 0?f=d.ends:f=l;for(let[p,m]of Object.entries(f))o(Zt(c),Zt(m),p,!0)}}return r}};function uM(e){return typeof e.attachNode=="function"&&typeof e.attachEdge=="function"}function Zt(e){return e==="subgraph"?`"${e}"`:e}function Ii(e){return typeof e=="object"&&e!==null&&"~standard"in e&&typeof e["~standard"]=="object"&&e["~standard"]!==null&&"validate"in e["~standard"]}function fS(e){return typeof e=="object"&&e!==null&&"~standard"in e&&typeof e["~standard"]=="object"&&e["~standard"]!==null&&"jsonSchema"in e["~standard"]}function aV(e){return Ii(e)&&fS(e)}function ma(e){if(fS(e))try{return e["~standard"].jsonSchema.input({target:"draft-07"})}catch{return}}function ha(e){if(e!=null&&Ii(e))try{let t=e["~standard"].validate(void 0);if(t&&typeof t=="object"&&!("then"in t&&typeof t.then=="function")){let r=t;if(!r.issues){let i=r.value;return()=>i}}}catch{}}var pS=Symbol.for("langgraph.channel.missing"),dh=class lM extends kt{lc_graph_name="UntrackedValue";guard;_value=pS;initialValueFactory;constructor(t){super(),this.guard=t?.guard??!0,this.initialValueFactory=t?.initialValueFactory,this.initialValueFactory&&(this._value=this.initialValueFactory())}fromCheckpoint(t){return new lM({guard:this.guard,initialValueFactory:this.initialValueFactory})}update(t){if(t.length===0)return!1;if(t.length!==1&&this.guard)throw new be("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=t[t.length-1],!0}get(){if(this._value===pS)throw new Ne;return this._value}checkpoint(){}isAvailable(){return this._value!==pS}};var ga=(e,t)=>e.size===t.size&&[...e].every(r=>t.has(r)),mS=class dM extends kt{lc_graph_name="NamedBarrierValue";names;seen;constructor(t){super(),this.names=t,this.seen=new Set}fromCheckpoint(t){let r=new dM(this.names);return typeof t<"u"&&(r.seen=new Set(t)),r}update(t){let r=!1;for(let i of t)if(this.names.has(i))this.seen.has(i)||(this.seen.add(i),r=!0);else throw new be(`Value ${JSON.stringify(i)} not in names ${JSON.stringify(this.names)}`);return r}get(){if(!ga(this.names,this.seen))throw new Ne}checkpoint(){return[...this.seen]}consume(){return this.seen&&this.names&&ga(this.seen,this.names)?(this.seen=new Set,!0):!1}isAvailable(){return!!this.names&&ga(this.names,this.seen)}},hS=class fM extends kt{lc_graph_name="NamedBarrierValueAfterFinish";names;seen;finished;constructor(t){super(),this.names=t,this.seen=new Set,this.finished=!1}fromCheckpoint(t){let r=new fM(this.names);if(typeof t<"u"){let[i,n]=t;r.seen=new Set(i),r.finished=n}return r}update(t){let r=!1;for(let i of t)if(this.names.has(i)&&!this.seen.has(i))this.seen.add(i),r=!0;else if(!this.names.has(i))throw new be(`Value ${JSON.stringify(i)} not in names ${JSON.stringify(this.names)}`);return r}get(){if(!this.finished||!ga(this.names,this.seen))throw new Ne}checkpoint(){return[[...this.seen],this.finished]}consume(){return this.finished&&this.seen&&this.names&&ga(this.seen,this.names)?(this.seen=new Set,this.finished=!1,!0):!1}finish(){return!this.finished&&this.names&&ga(this.names,this.seen)?(this.finished=!0,!0):!1}isAvailable(){return this.finished&&!!this.names&&ga(this.names,this.seen)}};var gS=Symbol.for("langgraph.state.reduced_value"),Ti=class{[gS]=!0;valueSchema;inputSchema;reducer;jsonSchemaExtra;constructor(e,t){this.reducer=t.reducer,this.jsonSchemaExtra=t.jsonSchemaExtra,this.valueSchema=e,this.inputSchema="inputSchema"in t?t.inputSchema:e,this.jsonSchemaExtra=t.jsonSchemaExtra}static isInstance(e){return typeof e=="object"&&e!==null&&gS in e&&e[gS]===!0}};var pM=Symbol.for("langgraph.state.untracked_value"),Oo=class{[pM]=!0;schema;guard;constructor(e,t){this.schema=e,this.guard=t?.guard??!0}static isInstance(e){return typeof e=="object"&&e!==null&&pM in e}};var _S=Symbol.for("langgraph.state.state_schema"),Qn=class{[_S]=!0;constructor(e){this.fields=e}getChannels(){let e={};for(let[t,r]of Object.entries(this.fields))if(Ti.isInstance(r)){let i=ha(r.valueSchema);e[t]=new xi(r.reducer,i)}else if(Oo.isInstance(r)){let i=r.schema?ha(r.schema):void 0;e[t]=new dh({guard:r.guard,initialValueFactory:i})}else if(Ii(r))e[t]=new yn(ha(r));else throw new Error(`Invalid state field "${t}": must be a schema, ReducedValue, UntrackedValue, or ManagedValue`);return e}getJsonSchema(){let e={},t=[];for(let[r,i]of Object.entries(this.fields)){let n;if(Ti.isInstance(i)?(n=ma(i.valueSchema),i.jsonSchemaExtra&&(n={...n??{},...i.jsonSchemaExtra})):Oo.isInstance(i)?n=i.schema?ma(i.schema):void 0:Ii(i)&&(n=ma(i)),n){e[r]=n;let a=!1;Ti.isInstance(i)?a=ha(i.valueSchema)!==void 0:Oo.isInstance(i)?a=i.schema?ha(i.schema)!==void 0:!1:a=ha(i)!==void 0,a||t.push(r)}}return{type:"object",properties:e,required:t.length>0?t:void 0}}getInputJsonSchema(){let e={};for(let[t,r]of Object.entries(this.fields)){let i;Ti.isInstance(r)?(i=ma(r.inputSchema),r.jsonSchemaExtra&&(i={...i??{},...r.jsonSchemaExtra})):Oo.isInstance(r)?i=r.schema?ma(r.schema):void 0:Ii(r)&&(i=ma(r)),i&&(e[t]=i)}return{type:"object",properties:e}}getChannelKeys(){return Object.entries(this.fields).map(([e])=>e)}getAllKeys(){return Object.keys(this.fields)}async validateInput(e){if(e==null||typeof e!="object")return e;let t={};for(let[r,i]of Object.entries(e)){let n=this.fields[r];if(n===void 0){t[r]=i;continue}let a;if(Ti.isInstance(n)?a=n.inputSchema:Oo.isInstance(n)?a=n.schema:Ii(n)&&(a=n),a){let o=await a["~standard"].validate(i);if(o.issues)throw new Error(`Validation failed for field "${r}": ${JSON.stringify(o.issues)}`);t[r]=o.value}else t[r]=i}return t}static isInstance(e){return typeof e=="object"&&e!==null&&_S in e&&e[_S]===!0}};var oV="__remove_all__";function _a(e,t){let r=Array.isArray(e)?e:[e],i=Array.isArray(t)?t:[t],n=r.map(Et),a=i.map(Et);for(let l of n)(l.id===null||l.id===void 0)&&(l.id=Ul(),l.lc_kwargs.id=l.id);let o;for(let l=0;l<a.length;l+=1){let d=a[l];(d.id===null||d.id===void 0)&&(d.id=Ul(),d.lc_kwargs.id=d.id),an.isInstance(d)&&d.id==="__remove_all__"&&(o=l)}if(o!=null)return a.slice(o+1);let s=[...n],c=new Map(s.map((l,d)=>[l.id,d])),u=new Set;for(let l of a){let d=c.get(l.id);if(d!==void 0)an.isInstance(l)?u.add(l.id):(u.delete(l.id),s[d]=l);else{if(an.isInstance(l))throw new Error(`Attempting to delete a message with an ID that doesn't exist ('${l.id}')`);c.set(l.id,s.length),s.push(l)}}return s.filter(l=>!u.has(l.id))}var sV=new Ti(Kr.custom().default(()=>[]),{inputSchema:Kr.custom(),reducer:_a,jsonSchemaExtra:{langgraph_type:"messages",description:"A list of chat messages"}});var cV=class{_map=new Map;_extensionCache=new Map;get(e){return this._map.get(e)}extend(e,t){let r=this.get(e);this._map.set(e,t(r))}remove(e){return this._map.delete(e),this}has(e){return this._map.has(e)}getChannelsForSchema(e){let t={},r=no(e);for(let[i,n]of Object.entries(r)){let a=this.get(n);a?.reducer?t[i]=new xi(a.reducer.fn,a.default):t[i]=new yn(a?.default)}return t}getExtendedChannelSchemas(e,t){if(Object.keys(t).length===0)return e;let r=Object.entries(t).filter(([,a])=>a===!0).sort(([a],[o])=>a.localeCompare(o)).map(([a,o])=>`${a}:${o}`).join("|"),i=this._extensionCache.get(r)??new Map;if(i.has(e))return i.get(e);let n=e;if(t.withReducerSchema||t.withJsonSchemaExtrasAsDescription){let a=Object.entries(no(e)).map(([o,s])=>{let c=this.get(s),u=t.withReducerSchema?c?.reducer?.schema??s:s;if(t.withJsonSchemaExtrasAsDescription&&c?.jsonSchemaExtra){let l=pi(u)??pi(s),d=JSON.stringify({...c.jsonSchemaExtra,description:l});u=u.describe(`lg:${d}`)}return[o,u]});n=sp(e,Object.fromEntries(a)),at(n)&&(n._def.unknownKeys="strip")}return t.asPartial&&(n=js(n)),i.set(e,n),this._extensionCache.set(r,i),n}},Tl=new cV;function mM(e,t){if(t.reducer&&!t.default){let r=cp(e);r!=null&&(t.default=r)}if(t.reducer){let r=Object.assign(e,{lg_reducer_schema:t.reducer?.schema??e});return Tl.extend(r,()=>t),r}else return Tl.extend(e,()=>t),e}function Po(e){return e==null?!1:!!(Qn.isInstance(e)||Yt(e)||typeof e=="object"&&"lc_graph_name"in e&&e.lc_graph_name==="AnnotationRoot"||typeof e=="object"&&!Array.isArray(e)&&Object.keys(e).length>0&&Object.values(e).every(t=>typeof t=="function"||I0(t)))}function hM(e){if(typeof e!="object"||e==null)return!1;let t=e,r="state"in t&&Po(t.state),i="stateSchema"in t&&Po(t.stateSchema),n="input"in t&&Po(t.input);return!(!r&&!i&&!n||"input"in t&&t.input!=null&&!Po(t.input)||"output"in t&&t.output!=null&&!Po(t.output))}var Ai="__root__",fh=Symbol.for("langgraph.state.partial"),yS=class extends lS{channels={};waitingEdges=new Set;_schemaDefinition;_schemaRuntimeDefinition;_inputDefinition;_inputRuntimeDefinition;_outputDefinition;_outputRuntimeDefinition;_schemaDefinitions=new Map;_metaRegistry=Tl;_configSchema;_configRuntimeSchema;_interrupt;_writer;constructor(e,t){super();let r=this._normalizeToStateGraphInit(e,t),i=r.state??r.stateSchema??r.input;if(!i)throw new Tc;let n=this._getChannelsFromSchema(i);this._schemaDefinition=n,Qn.isInstance(i)?this._schemaRuntimeDefinition=i:Yt(i)&&(this._schemaRuntimeDefinition=i),r.input?Qn.isInstance(r.input)?this._inputRuntimeDefinition=r.input:Yt(r.input)?this._inputRuntimeDefinition=r.input:this._inputRuntimeDefinition=fh:this._inputRuntimeDefinition=fh,r.output?Qn.isInstance(r.output)?this._outputRuntimeDefinition=r.output:Yt(r.output)?this._outputRuntimeDefinition=r.output:this._outputRuntimeDefinition=this._schemaRuntimeDefinition:this._outputRuntimeDefinition=this._schemaRuntimeDefinition;let a=r.input?this._getChannelsFromSchema(r.input):n,o=r.output?this._getChannelsFromSchema(r.output):n;this._inputDefinition=a,this._outputDefinition=o,this._addSchema(this._schemaDefinition),this._addSchema(this._inputDefinition),this._addSchema(this._outputDefinition),r.context&&Yt(r.context)&&(this._configRuntimeSchema=r.context),this._interrupt=r.interrupt,this._writer=r.writer}_normalizeToStateGraphInit(e,t){if(hM(e)){if(Yt(t)||Fm.isInstance(t))return{...e,context:t};let r=t;return{...e,input:e.input??r?.input,output:e.output??r?.output,context:e.context??r?.context,interrupt:e.interrupt??r?.interrupt,writer:e.writer??r?.writer,nodes:e.nodes??r?.nodes}}if(Po(e)){if(Yt(t)||Fm.isInstance(t))return{state:e,context:t};let r=t;return{state:e,input:r?.input,output:r?.output,context:r?.context,interrupt:r?.interrupt,writer:r?.writer,nodes:r?.nodes}}if(lV(e))return{state:uV(e.channels)};throw new Tc}_getChannelsFromSchema(e){if(Qn.isInstance(e))return e.getChannels();if(Yt(e))return this._metaRegistry.getChannelsForSchema(e);if(typeof e=="object"&&"lc_graph_name"in e&&e.lc_graph_name==="AnnotationRoot")return e.spec;if(typeof e=="object"&&!Array.isArray(e)&&Object.keys(e).length>0)return e;throw new Tc("Invalid schema type. Expected StateSchema, Zod object, AnnotationRoot, or StateDefinition.")}get allEdges(){return new Set([...this.edges,...Array.from(this.waitingEdges).flatMap(([e,t])=>e.map(r=>[r,t]))])}_addSchema(e){if(!this._schemaDefinitions.has(e)){this._schemaDefinitions.set(e,e);for(let[t,r]of Object.entries(e)){let i;if(typeof r=="function"?i=r():i=r,this.channels[t]!==void 0){if(!this.channels[t].equals(i)&&i.lc_graph_name!=="LastValue")throw new Error(`Channel "${t}" already exists with a different type.`)}else this.channels[t]=i}}}addNode(...e){function t(i){return i.length>=1&&typeof i[0]!="string"}let r=t(e)?Array.isArray(e[0])?e[0]:Object.entries(e[0]).map(([i,n])=>[i,n]):[[e[0],e[1],e[2]]];if(r.length===0)throw new Error("No nodes provided in `addNode`");for(let[i,n,a]of r){if(i in this.channels)throw new Error(`${i} is already being used as a state attribute (a.k.a. a channel), cannot also be used as a node name.`);for(let l of["|",":"])if(i.includes(l))throw new Error(`"${l}" 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."),i in this.nodes)throw new Error(`Node \`${i}\` already present.`);if(i==="__end__"||i==="__start__")throw new Error(`Node \`${i}\` is reserved.`);let o=this._schemaDefinition;a?.input!==void 0&&(o=this._getChannelsFromSchema(a.input)),this._addSchema(o);let s;ae.isRunnable(n)?s=n:typeof n=="function"?s=new Vt({func:n,name:i,trace:!1}):s=tt(n);let c=a?.cachePolicy;typeof c=="boolean"&&(c=c?{}:void 0);let u={runnable:s,retryPolicy:a?.retryPolicy,cachePolicy:c,metadata:a?.metadata,input:o??this._schemaDefinition,subgraphs:Sl(s)?[s]:a?.subgraphs,ends:a?.ends,defer:a?.defer};this.nodes[i]=u}return this}addEdge(e,t){if(typeof e=="string")return super.addEdge(e,t);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 r of e){if(r==="__end__")throw new Error("END cannot be a start node");if(!Object.keys(this.nodes).some(i=>i===r))throw new Error(`Need to add a node named "${r}" first`)}if(t==="__end__")throw new Error("END cannot be an end node");if(!Object.keys(this.nodes).some(r=>r===t))throw new Error(`Need to add a node named "${t}" first`);return this.waitingEdges.add([e,t]),this}addSequence(e){let t=Array.isArray(e)?e:Object.entries(e);if(t.length===0)throw new Error("Sequence requires at least one node.");let r;for(let[i,n,a]of t){if(i in this.nodes)throw new Error(`Node names must be unique: node with the name "${i}" already exists.`);let o=i;this.addNode(o,n,a),r!=null&&this.addEdge(r,o),r=o}return this}compile({checkpointer:e,store:t,cache:r,interruptBefore:i,interruptAfter:n,name:a,description:o,transformers:s}={}){this.validate([...Array.isArray(i)?i:[],...Array.isArray(n)?n:[]]);let c=Object.keys(this._schemaDefinitions.get(this._outputDefinition)),u=c.length===1&&c[0]===Ai?Ai:c,l=Object.keys(this.channels),d=l.length===1&&l[0]===Ai?Ai:l,f=this._interrupt,p=new _M({builder:this,checkpointer:e,interruptAfter:n,interruptBefore:i,autoValidate:!1,nodes:{},channels:{...this.channels,[He]:new xn},inputChannels:He,outputChannels:u,streamChannels:d,streamMode:"updates",store:t,cache:r,name:a,description:o,userInterrupt:f,streamTransformers:s});p.attachNode(He);for(let[m,g]of Object.entries(this.nodes))p.attachNode(m,g);p.attachBranch(He,mh,gM(),{withReader:!1});for(let[m]of Object.entries(this.nodes))p.attachBranch(m,mh,gM(),{withReader:!1});for(let[m,g]of this.edges)p.attachEdge(m,g);for(let[m,g]of this.waitingEdges)p.attachEdge(m,g);for(let[m,g]of Object.entries(this.branches))for(let[v,b]of Object.entries(g))p.attachBranch(m,v,b);return p.validate()}};function uV(e){let t={};for(let[r,i]of Object.entries(e))r===Ai?t[r]=Bm(i):t[r]=Bm(i);return t}var _M=class extends dS{description;_metaRegistry=Tl;constructor({description:e,...t}){super(t),this.description=e}attachNode(e,t){let r;e==="__start__"?r=Object.entries(this.builder._schemaDefinitions.get(this.builder._inputDefinition)).map(([s])=>s):r=Object.keys(this.builder.channels);function i(s){if(yt(s))return s.graph===ir.PARENT?null:s._updateAsTuples();if(Array.isArray(s)&&s.length>0&&s.some(c=>yt(c))){let c=[];for(let u of s)if(yt(u)){if(u.graph===ir.PARENT)continue;c.push(...u._updateAsTuples())}else c.push([Ai,u]);return c}else if(s!=null)return[[Ai,s]];return null}let n=e;function a(s){if(s){if(yt(s))return s.graph===ir.PARENT?null:s._updateAsTuples().filter(([c])=>r.includes(c));if(Array.isArray(s)&&s.length>0&&s.some(yt)){let c=[];for(let u of s)if(yt(u)){if(u.graph===ir.PARENT)continue;c.push(...u._updateAsTuples().filter(([l])=>r.includes(l)))}else{let l=a(u);l&&c.push(...l??[])}return c}else{if(typeof s=="object"&&!Array.isArray(s))return Object.entries(s).filter(([c])=>r.includes(c));{let c=Array.isArray(s)?"array":typeof s;throw new be(`Expected node "${n.toString()}" to return an object or an array containing at least one Command object, received ${c}`,{lc_error_code:"INVALID_GRAPH_NODE_RETURN_VALUE"})}}}else return null}let o=[{value:hr,mapper:new Vt({func:r.length&&r[0]===Ai?i:a,trace:!1,recurse:!1})}];if(e==="__start__")this.nodes[e]=new bn({tags:[lt],triggers:[He],channels:[He],writers:[new ot(o,[lt])]});else{let s=t?.input??this.builder._schemaDefinition,c=Object.fromEntries(Object.keys(this.builder._schemaDefinitions.get(s)).map(d=>[d,d])),u=Object.keys(c).length===1&&Ai in c,l=`branch:to:${e}`;this.channels[l]=t?.defer?new T0:new xn(!1),this.nodes[e]=new bn({triggers:[l],channels:u?Object.keys(c):c,writers:[new ot(o,[lt])],mapper:u?void 0:d=>Object.fromEntries(Object.entries(d).filter(([f])=>f in c)),bound:t?.runnable,metadata:t?.metadata,retryPolicy:t?.retryPolicy,cachePolicy:t?.cachePolicy,subgraphs:t?.subgraphs,ends:t?.ends})}}attachEdge(e,t){if(t!=="__end__"){if(typeof e=="string")this.nodes[e].writers.push(new ot([{channel:`branch:to:${t}`,value:null}],[lt]));else if(Array.isArray(e)){let r=`join:${e.join("+")}:${t}`;this.channels[r]=this.builder.nodes[t].defer?new hS(new Set(e)):new mS(new Set(e)),this.nodes[t].triggers.push(r);for(let i of e)this.nodes[i].writers.push(new ot([{channel:r,value:i}],[lt]))}}}attachBranch(e,t,r,i={withReader:!0}){let n=async(a,o)=>{let s=a.filter(u=>u!==Ye);if(!s.length)return;let c=s.map(u=>mt(u)?u:{channel:u==="__end__"?u:`branch:to:${u}`,value:e});await ot.doWrite({...o,tags:(o.tags??[]).concat([lt])},c)};this.nodes[e].writers.push(r.run(n,i.withReader?a=>IR.doRead(a,this.streamChannels??this.outputChannels,!0):void 0))}async _validateInput(e){if(e==null)return e;let t=this.builder._inputRuntimeDefinition,r=this.builder._schemaRuntimeDefinition;if(Qn.isInstance(t)){if(yt(e)){let n=e;return e.update&&(n.update=await t.validateInput(Array.isArray(e.update)?Object.fromEntries(e.update):e.update)),n}return await t.validateInput(e)}if(t===fh&&Qn.isInstance(r)){if(yt(e)){let n=e;return e.update&&(n.update=await r.validateInput(Array.isArray(e.update)?Object.fromEntries(e.update):e.update)),n}return await r.validateInput(e)}let i=(()=>{let n=a=>{if(a!=null)return this._metaRegistry.getExtendedChannelSchemas(a,{withReducerSchema:!0})};if(Yt(t))return n(t);if(t===fh)return Yt(r)?js(n(r)):void 0})();if(yt(e)){let n=e;if(e.update&&i!=null){let a=Array.isArray(e.update)?Object.fromEntries(e.update):e.update,o=Rs(i,a);n.update=Object.fromEntries(Object.keys(a).map(s=>[s,o[s]]))}return n}return i!=null?Rs(i,e):e}isInterrupted(e){return ka(e)}async _validateContext(e){let t=this.builder._configRuntimeSchema;return Yt(t)&&Rs(t,e),e}};function lV(e){return typeof e=="object"&&e!==null&&e.channels!==void 0}function dV(e){if(mt(e))return[e];let t=[];yt(e)?t.push(e):Array.isArray(e)&&t.push(...e.filter(yt));let r=[];for(let i of t){if(i.graph===ir.PARENT)throw new zl(i);mt(i.goto)||typeof i.goto=="string"?r.push(i.goto):Array.isArray(i.goto)&&r.push(...i.goto)}return r}function gM(){return new uS({path:new Vt({func:dV,tags:[lt],trace:!1,recurse:!1,name:"<control_branch>"})})}var fV=class extends yS{constructor(){super({channels:{__root__:{reducer:_a,default:()=>[]}}})}};function pV(e,t){let{stateKey:r,...i}=t??{},n=pc(i),a=r??"messages";r===null&&(a=void 0);let o=Et(e);if(!o.id)throw new Error("Message ID is required.");let s=(Array.isArray(n.callbacks)?n.callbacks:typeof n.callbacks<"u"?n.callbacks.handlers:[]).find(c=>"name"in c&&c.name==="StreamMessagesHandler");if(s){let c=n.metadata??{},u=(c.langgraph_checkpoint_ns??"").split("|");s._emit([u,c],o,void 0,!1)}return a&&n.configurable?.__pregel_send?.([[a,o]]),o}function mV(e,t){let r=typeof e=="string"?{name:e,retry:void 0,cachePolicy:void 0}:e,{name:i,retry:n}=r;if(G0(t)||J0(t))throw new Error("Generators are disallowed as tasks. For streaming responses, use config.write.");let a=r.cachePolicy??("cache"in r?r.cache:void 0),o;return typeof a=="boolean"?o=a?{}:void 0:o=a,(...s)=>zR({func:t,name:i,retry:n,cache:o},...s)}var yM=function(t,r){let{name:i,checkpointer:n,store:a,cache:o}=typeof t=="string"?{name:t,checkpointer:void 0,store:void 0}:t;if(G0(r)||J0(r))throw new Error("Generators are disallowed as entrypoints. For streaming responses, use config.write.");let s="updates",c=jR(i,r);function u(p){return typeof p=="object"&&p!==null&&"__lg_type"in p&&p.__lg_type==="__pregel_final"}let l=new Vt({name:"pluckReturnValue",func:p=>u(p)?p.value:p}),d=new Vt({name:"pluckSaveValue",func:p=>u(p)?p.save:p}),f=new bn({bound:c,triggers:[He],channels:[He],writers:[new ot([{channel:Ye,value:hr,mapper:l},{channel:Sa,value:hr,mapper:d}],[lt])]});return new lh({name:i,checkpointer:n,nodes:{[i]:f},channels:{[He]:new xn,[Ye]:new yn,[Sa]:new yn},inputChannels:He,outputChannels:Ye,streamChannels:Ye,streamMode:s,store:a,cache:o})};yM.final=function({value:t,save:r}){return{value:t,save:r,__lg_type:"__pregel_final"}};function hV(){return Ae.getRunnableConfig().configurable?.[xa]}var gV=vl.Root({messages:vl({reducer:_a,default:()=>[]})}),vM={reducer:{fn:_a},jsonSchemaExtra:{langgraph_type:"messages"},default:()=>[]},_V=St.object({messages:mM(St.custom(),vM)});function yV(e){let t=Ae.getRunnableConfig();if(!t)throw new Error("Called interrupt() outside the context of a graph.");let r=t.configurable;if(!r)throw new Error("No configurable found in config");return r.writer?.(e)}export{He as a,Ye as b,Ue as c,ph as d,kS as e,wa as f,xM as g,ka as h,ir as i,yt as j,en as k,hh as l,gh as m,$a as n,ti as o,jl as p,zl as q,_h as r,Ea as s,ri as t,Dl as u,Ne as v,be as w,kM as x,yh as y,$M as z,Tc as A,EM as B,JS as C,Ht as D,YM as E,An as F,nk as G,Rc as H,ik as I,gt as J,Go as K,Te as L,Wo as M,Qe as N,nn as O,Aa as P,Oa as Q,Pa as R,oi as S,Xk as T,jt as U,Zi as V,Ha as W,qi as X,Tf as Y,to as Z,Ve as _,at as $,lr as aa,pi as ba,cp as ca,D as da,St as ea,_t as fa,Dt as ga,Tp as ha,iF as ia,Ru as ja,jp as ka,Iw as la,HO as ma,GO as na,uF as oa,lF as pa,Aw as qa,ca as ra,ua as sa,Hw as ta,ec as ua,Yu as va,Kr as wa,gB as xa,kB as ya,lc as za,gn as Aa,zm as Ba,nR as Ca,fc as Da,Um as Ea,oR as Fa,kt as Ga,xi as Ha,vl as Ia,r9 as Ja,n9 as Ka,A0 as La,i9 as Ma,C0 as Na,mc as Oa,O0 as Pa,Wr as Qa,Gm as Ra,M0 as Sa,bl as Ta,wl as Ua,j0 as Va,z0 as Wa,Jm as Xa,L0 as Ya,_R as Za,F0 as _a,H0 as $a,lS as ab,Ii as bb,aV as cb,ma as db,ha as eb,dh as fb,Ti as gb,Oo as hb,Qn as ib,oV as jb,_a as kb,sV as lb,Tl as mb,mM as nb,yS as ob,_M as pb,fV as qb,pV as rb,mV as sb,yM as tb,hV as ub,gV as vb,vM as wb,_V as xb,yV as yb};