zen-code 4.10.2 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/dist/app.js +149 -239
  2. package/dist/{chunk-vbb3m0vz.js → chunk-069q9hkz.js} +1 -1
  3. package/dist/chunk-06trk066.js +1 -0
  4. package/dist/chunk-0kfw8bwn.js +2 -0
  5. package/dist/chunk-0mq8786q.js +281 -0
  6. package/dist/{chunk-mmx0k2yq.js → chunk-0qz8rr2k.js} +1 -1
  7. package/dist/chunk-1d47g6nc.js +2 -0
  8. package/dist/{chunk-nqh1pptf.js → chunk-1gssqf6g.js} +1 -1
  9. package/dist/{chunk-s5cqejr6.js → chunk-1rcc9xzn.js} +1 -1
  10. package/dist/{chunk-tjvhqr94.js → chunk-2bjeg40f.js} +1 -1
  11. package/dist/chunk-2gd8vzrf.js +2 -0
  12. package/dist/{chunk-spx7nn8t.js → chunk-2gprcgep.js} +2 -2
  13. package/dist/chunk-3k3c686f.js +1 -0
  14. package/dist/chunk-43h0n2td.js +1 -0
  15. package/dist/{chunk-8f19qk9r.js → chunk-492hjs9k.js} +1 -1
  16. package/dist/{chunk-pe8mzxwn.js → chunk-4eaqmt3c.js} +11 -11
  17. package/dist/{chunk-y8qhrx11.js → chunk-4fs853nh.js} +1 -1
  18. package/dist/chunk-5fe27s34.js +2 -0
  19. package/dist/{chunk-4wnmk2tj.js → chunk-5hqvapp1.js} +3 -3
  20. package/dist/chunk-6b3vfr39.js +2 -0
  21. package/dist/{chunk-t6440ajd.js → chunk-6j695pam.js} +2 -2
  22. package/dist/{chunk-pzb224c5.js → chunk-6saqxa3z.js} +2 -2
  23. package/dist/{chunk-tjg2e8v3.js → chunk-78ksrp8v.js} +2 -2
  24. package/dist/chunk-7cx9kda0.js +228 -0
  25. package/dist/chunk-7qba2raw.js +2 -0
  26. package/dist/chunk-81b2s97q.js +1 -0
  27. package/dist/chunk-88w3txtb.js +160 -0
  28. package/dist/chunk-8ygdre0g.js +1 -0
  29. package/dist/{chunk-fzh0v6r0.js → chunk-9011y634.js} +2 -2
  30. package/dist/chunk-9zcr1qh6.js +1 -0
  31. package/dist/chunk-a0nr8jva.js +2 -0
  32. package/dist/{chunk-5c3bpcpm.js → chunk-agevsn2e.js} +1 -1
  33. package/dist/{chunk-8tbtavry.js → chunk-akc3s5aw.js} +2 -2
  34. package/dist/{chunk-spa69h7p.js → chunk-b0beqmg2.js} +2 -2
  35. package/dist/{chunk-zg54h6gy.js → chunk-b175s7dm.js} +1 -1
  36. package/dist/chunk-bk32cwxa.js +5 -0
  37. package/dist/{chunk-vrnj0659.js → chunk-bn077sjq.js} +15 -15
  38. package/dist/{chunk-qxebn3jw.js → chunk-c9yrpb3g.js} +3 -3
  39. package/dist/{chunk-hnnwbfqk.js → chunk-cb0f54ar.js} +2 -2
  40. package/dist/chunk-ctqtahz4.js +1 -0
  41. package/dist/{chunk-gt8c6dne.js → chunk-d2sr8fnm.js} +1 -1
  42. package/dist/chunk-d5gzkkgg.js +1 -0
  43. package/dist/{chunk-bzgznka5.js → chunk-dh2f4xyb.js} +1 -1
  44. package/dist/chunk-dr32dt9y.js +1 -0
  45. package/dist/chunk-dv1vt080.js +1 -0
  46. package/dist/{chunk-vfxjbdz4.js → chunk-dz9sqfph.js} +1 -1
  47. package/dist/chunk-e7mbewmw.js +1 -0
  48. package/dist/chunk-em03xqy9.js +1 -0
  49. package/dist/chunk-fkt5b511.js +1 -0
  50. package/dist/{chunk-k4q8j7pg.js → chunk-gphssgy6.js} +1 -1
  51. package/dist/chunk-h2hk7vx4.js +1 -0
  52. package/dist/{chunk-c7kd2qrp.js → chunk-h7ypcqp3.js} +112 -111
  53. package/dist/{chunk-nsw5168d.js → chunk-j8tq0e8m.js} +2 -2
  54. package/dist/{chunk-40ht9pe1.js → chunk-jd1razfg.js} +2 -2
  55. package/dist/chunk-jhxvctg5.js +8 -0
  56. package/dist/chunk-kada5fyh.js +1 -0
  57. package/dist/chunk-kgc6ws03.js +1 -0
  58. package/dist/chunk-mk8ggmt8.js +17 -0
  59. package/dist/{chunk-e8kxa5vj.js → chunk-mv5m8bf4.js} +2 -2
  60. package/dist/chunk-mv8a5svx.js +1 -0
  61. package/dist/chunk-n61yv4t5.js +2 -0
  62. package/dist/chunk-nt2yp4jh.js +1 -0
  63. package/dist/chunk-p7ew4trx.js +1 -0
  64. package/dist/{chunk-s1tbdcs8.js → chunk-pgnhcznr.js} +1 -1
  65. package/dist/chunk-q8cfxky4.js +8 -0
  66. package/dist/{chunk-g2zskge5.js → chunk-q8zsxwd8.js} +2 -2
  67. package/dist/{chunk-nmzx5nmt.js → chunk-qfa5v4n5.js} +1 -1
  68. package/dist/chunk-qhzztj83.js +1 -0
  69. package/dist/chunk-snmkgfbe.js +15 -0
  70. package/dist/chunk-ss4bh5wb.js +2 -0
  71. package/dist/chunk-sv0k2v66.js +1 -0
  72. package/dist/{chunk-wmyc17aa.js → chunk-tbav8trq.js} +1 -1
  73. package/dist/chunk-tmyzfvsy.js +1 -0
  74. package/dist/chunk-ts4jreym.js +7 -0
  75. package/dist/chunk-tws3wcnm.js +2 -0
  76. package/dist/chunk-v0e9bsvt.js +89 -0
  77. package/dist/{chunk-n9rpnke9.js → chunk-vwj4n000.js} +1 -1
  78. package/dist/{chunk-gfhmzpy7.js → chunk-wd6s7gg7.js} +2 -3
  79. package/dist/{chunk-f0m4532p.js → chunk-y524zd2h.js} +5 -5
  80. package/dist/{chunk-hve2a279.js → chunk-yb71zqvt.js} +2 -2
  81. package/dist/{chunk-n7s6my89.js → chunk-yejgw2hm.js} +32 -32
  82. package/dist/{chunk-g974hxbz.js → chunk-yfjs6pf8.js} +1 -1
  83. package/dist/chunk-zhqdp4ak.js +2 -0
  84. package/dist/chunk-zkd3m39v.js +1 -0
  85. package/dist/cli.js +1 -1
  86. package/dist/nonInteractive.js +80 -80
  87. package/dist/zen-core.js +644 -0
  88. package/dist/zen-keyboard.js +1 -1
  89. package/package.json +5 -3
  90. package/dist/chunk-0ddrb30y.js +0 -1
  91. package/dist/chunk-215an3fz.js +0 -1
  92. package/dist/chunk-4z0w0ng1.js +0 -2
  93. package/dist/chunk-57bj89e2.js +0 -1
  94. package/dist/chunk-5a5mepqj.js +0 -1
  95. package/dist/chunk-7kw7ss8d.js +0 -1
  96. package/dist/chunk-86m0rmtc.js +0 -1
  97. package/dist/chunk-9rayxazs.js +0 -8
  98. package/dist/chunk-a9gpb2tx.js +0 -2
  99. package/dist/chunk-a9tw6d68.js +0 -1
  100. package/dist/chunk-anbtppz1.js +0 -294
  101. package/dist/chunk-bca8tkkr.js +0 -1
  102. package/dist/chunk-bdqds8vh.js +0 -1
  103. package/dist/chunk-dvbb3dd1.js +0 -233
  104. package/dist/chunk-ehmmd8qc.js +0 -1
  105. package/dist/chunk-ejfa95sm.js +0 -1
  106. package/dist/chunk-f7cps5x1.js +0 -1
  107. package/dist/chunk-fbemqjck.js +0 -2
  108. package/dist/chunk-feeqtzv5.js +0 -1
  109. package/dist/chunk-g9911ymn.js +0 -1
  110. package/dist/chunk-h8fdexm4.js +0 -2
  111. package/dist/chunk-hp2jzn9x.js +0 -166
  112. package/dist/chunk-js4qp900.js +0 -2
  113. package/dist/chunk-m21hvv91.js +0 -2
  114. package/dist/chunk-mnnyjmgw.js +0 -224
  115. package/dist/chunk-mw7x6xqp.js +0 -1
  116. package/dist/chunk-nk62q95g.js +0 -93
  117. package/dist/chunk-pg1ppq4y.js +0 -1
  118. package/dist/chunk-q1cxrg0x.js +0 -2
  119. package/dist/chunk-swc7se71.js +0 -2
  120. package/dist/chunk-swyc15ym.js +0 -1
  121. package/dist/chunk-t2s3s6af.js +0 -1
  122. package/dist/chunk-vdmq9d9x.js +0 -4
  123. package/dist/chunk-wt3p1w1g.js +0 -1
  124. package/dist/chunk-y5ry5c7v.js +0 -1
  125. package/dist/chunk-yy8p9zph.js +0 -2
  126. package/dist/chunk-z61m3anh.js +0 -1
  127. package/dist/chunk-zr90qp47.js +0 -1
  128. package/dist/chunk-zsa62xr0.js +0 -2
@@ -1,16 +1,16 @@
1
- import{$g as Z1,Dg as b$,Eg as nQ,Gg as j8,Hg as C$,Wg as V0,Xg as fQ,Zg as H1,_g as o$,bh as W8,ch as q1}from"./chunk-hp2jzn9x.js";import{$j as Z$,Bi as V8,Fj as M8,Gj as X$,Ni as F8,Oj as XQ,Pj as F$,Qj as M1,Rj as K8,Uj as x1,Wh as kQ,Xh as a8,Xi as QQ,aj as j1,bi as Y1,bj as DQ,bk as YQ,ck as v$,dj as iQ,fk as Z0,hj as r8,ii as X1,kk as yQ,vi as U8,wj as K1}from"./chunk-nk62q95g.js";import{Hk as L$}from"./chunk-nmzx5nmt.js";import{tl as tQ}from"./chunk-tjg2e8v3.js";import{Cl as D1,wl as J$,xl as Y$}from"./chunk-hve2a279.js";var T="__start__",A="__end__",xQ="__input__",H$="__copy__",p="__error__",k0="__pregel_ns_writes",WQ="__pregel_send",g0="__pregel_call",AQ="__pregel_read",m="__pregel_checkpointer",EQ="__pregel_resuming",Y0="__pregel_task_id",K0="__pregel_stream";var X0="__pregel_resume_map",JQ="__pregel_scratchpad",M0="__pregel_previous",U$="__pregel_durability",w8="checkpoint_id",FQ="checkpoint_ns",V$="__pregel_node_finished",ZQ="checkpoint_map",R8="__pregel_abort_signals",S="__interrupt__",o="__resume__",m0="__no_writes__",jQ="__return__",aQ="__previous__",E="langsmith:hidden",D$="langsmith:nostream",T8="__self__",c="__pregel_tasks",r="__pregel_push",x0="__pregel_pull",n="00000000-0000-0000-0000-000000000000",G$=["langsmith:hidden","__input__","__interrupt__","__resume__","__error__","__no_writes__","__pregel_send","__pregel_read","__pregel_checkpointer","__pregel_durability","__pregel_stream","__pregel_resuming","__pregel_task_id","__pregel_call","__pregel_resume_value","__pregel_scratchpad","__pregel_previous","checkpoint_map","checkpoint_ns","checkpoint_id"],k="|",e=":",f0=Symbol.for("langgraph.command"),h0=class{[f0];constructor(Q){this[f0]=Q}};function u0(Q){let $=Q;return $!==null&&$!==void 0&&typeof $.node==="string"&&$.args!==void 0}var uQ=class{lg_name="Send";node;args;constructor(Q,$){this.node=Q,this.args=G0($)}toJSON(){return{lg_name:this.lg_name,node:this.node,args:this.args}}};function d(Q){return Q instanceof uQ}var j$="__overwrite__";function d0(Q){if(typeof Q==="object"&&Q!==null&&j$ in Q)return[!0,Q[j$]];return[!1,void 0]}function K$(Q){return d0(Q)[0]}function F0(Q){if(!Q||typeof Q!=="object")return!1;if(!("__interrupt__"in Q))return!1;return Array.isArray(Q.__interrupt__)}var a=class extends h0{lg_name="Command";lc_direct_tool_output=!0;graph;update;resume;goto=[];static PARENT="__parent__";constructor(Q){super(Q);if(this.resume=Q.resume,this.graph=Q.graph,this.update=Q.update,Q.goto)this.goto=Array.isArray(Q.goto)?G0(Q.goto):[G0(Q.goto)]}_updateAsTuples(){if(this.update&&typeof this.update==="object"&&!Array.isArray(this.update))return Object.entries(this.update);else if(Array.isArray(this.update)&&this.update.every((Q)=>Array.isArray(Q)&&Q.length===2&&typeof Q[0]==="string"))return this.update;else return[["__root__",this.update]]}toJSON(){let Q;if(typeof this.goto==="string")Q=this.goto;else if(d(this.goto))Q=this.goto.toJSON();else Q=this.goto?.map(($)=>{if(typeof $==="string")return $;else return $.toJSON()});return{lg_name:this.lg_name,update:this.update,resume:this.resume,goto:Q}}};function u(Q){if(typeof Q!=="object")return!1;if(Q===null||Q===void 0)return!1;if("lg_name"in Q&&Q.lg_name==="Command")return!0;return!1}function G0(Q,$=new Map){if(Q!==void 0&&Q!==null&&typeof Q==="object"){if($.has(Q))return $.get(Q);let J;if(Array.isArray(Q))J=[],$.set(Q,J),Q.forEach((Z,q)=>{J[q]=G0(Z,$)});else if(u(Q)&&!(Q instanceof a))J=new a(Q),$.set(Q,J);else if(u0(Q)&&!(Q instanceof uQ))J=new uQ(Q.node,Q.args),$.set(Q,J);else if(u(Q)||d(Q))J=Q,$.set(Q,J);else if("lc_serializable"in Q&&Q.lc_serializable)J=Q,$.set(Q,J);else{J={},$.set(Q,J);for(let[Z,q]of Object.entries(Q))J[Z]=G0(q,$)}return J}return Q}var OQ=class extends Error{lc_error_code;constructor(Q,$){let J=Q??"";if($?.lc_error_code)J=`${J}
1
+ import{Bg as U1,Cg as c$,Dg as q1,Fg as V8,Gg as z1,fg as f$,sg as b$,tg as sQ,vg as D8,yg as V0,zg as kQ}from"./chunk-88w3txtb.js";import{Di as j8,Gh as gQ,Gj as n8,Hh as e8,Nh as X1,Ni as QQ,Pi as H1,Qi as DQ,Rj as q$,Si as rQ,Tj as YQ,Uj as C$,Wi as K1,Xj as Z0,_h as F1,ak as yQ,dj as M8,ej as X$,li as a0,mj as XQ,nj as F$,oj as M1,pj as K8,ri as e0,sj as x1}from"./chunk-v0e9bsvt.js";import{Qk as L$}from"./chunk-qfa5v4n5.js";import{Bl as iQ}from"./chunk-78ksrp8v.js";import{Dl as Z$,El as h8,Jl as N$}from"./chunk-yb71zqvt.js";var T="__start__",A="__end__",xQ="__input__",H$="__copy__",p="__error__",k0="__pregel_ns_writes",WQ="__pregel_send",g0="__pregel_call",AQ="__pregel_read",m="__pregel_checkpointer",EQ="__pregel_resuming",Y0="__pregel_task_id",K0="__pregel_stream";var X0="__pregel_resume_map",JQ="__pregel_scratchpad",M0="__pregel_previous",U$="__pregel_durability",w8="checkpoint_id",FQ="checkpoint_ns",V$="__pregel_node_finished",ZQ="checkpoint_map",R8="__pregel_abort_signals",S="__interrupt__",o="__resume__",m0="__no_writes__",jQ="__return__",aQ="__previous__",E="langsmith:hidden",D$="langsmith:nostream",T8="__self__",c="__pregel_tasks",r="__pregel_push",x0="__pregel_pull",n="00000000-0000-0000-0000-000000000000",G$=["langsmith:hidden","__input__","__interrupt__","__resume__","__error__","__no_writes__","__pregel_send","__pregel_read","__pregel_checkpointer","__pregel_durability","__pregel_stream","__pregel_resuming","__pregel_task_id","__pregel_call","__pregel_resume_value","__pregel_scratchpad","__pregel_previous","checkpoint_map","checkpoint_ns","checkpoint_id"],k="|",e=":",f0=Symbol.for("langgraph.command"),h0=class{[f0];constructor(Q){this[f0]=Q}};function u0(Q){let $=Q;return $!==null&&$!==void 0&&typeof $.node==="string"&&$.args!==void 0}var uQ=class{lg_name="Send";node;args;constructor(Q,$){this.node=Q,this.args=G0($)}toJSON(){return{lg_name:this.lg_name,node:this.node,args:this.args}}};function d(Q){return Q instanceof uQ}var j$="__overwrite__";function d0(Q){if(typeof Q==="object"&&Q!==null&&j$ in Q)return[!0,Q[j$]];return[!1,void 0]}function K$(Q){return d0(Q)[0]}function F0(Q){if(!Q||typeof Q!=="object")return!1;if(!("__interrupt__"in Q))return!1;return Array.isArray(Q.__interrupt__)}var a=class extends h0{lg_name="Command";lc_direct_tool_output=!0;graph;update;resume;goto=[];static PARENT="__parent__";constructor(Q){super(Q);if(this.resume=Q.resume,this.graph=Q.graph,this.update=Q.update,Q.goto)this.goto=Array.isArray(Q.goto)?G0(Q.goto):[G0(Q.goto)]}_updateAsTuples(){if(this.update&&typeof this.update==="object"&&!Array.isArray(this.update))return Object.entries(this.update);else if(Array.isArray(this.update)&&this.update.every((Q)=>Array.isArray(Q)&&Q.length===2&&typeof Q[0]==="string"))return this.update;else return[["__root__",this.update]]}toJSON(){let Q;if(typeof this.goto==="string")Q=this.goto;else if(d(this.goto))Q=this.goto.toJSON();else Q=this.goto?.map(($)=>{if(typeof $==="string")return $;else return $.toJSON()});return{lg_name:this.lg_name,update:this.update,resume:this.resume,goto:Q}}};function u(Q){if(typeof Q!=="object")return!1;if(Q===null||Q===void 0)return!1;if("lg_name"in Q&&Q.lg_name==="Command")return!0;return!1}function G0(Q,$=new Map){if(Q!==void 0&&Q!==null&&typeof Q==="object"){if($.has(Q))return $.get(Q);let J;if(Array.isArray(Q))J=[],$.set(Q,J),Q.forEach((Z,q)=>{J[q]=G0(Z,$)});else if(u(Q)&&!(Q instanceof a))J=new a(Q),$.set(Q,J);else if(u0(Q)&&!(Q instanceof uQ))J=new uQ(Q.node,Q.args),$.set(Q,J);else if(u(Q)||d(Q))J=Q,$.set(Q,J);else if("lc_serializable"in Q&&Q.lc_serializable)J=Q,$.set(Q,J);else{J={},$.set(Q,J);for(let[Z,q]of Object.entries(Q))J[Z]=G0(q,$)}return J}return Q}var OQ=class extends Error{lc_error_code;constructor(Q,$){let J=Q??"";if($?.lc_error_code)J=`${J}
2
2
 
3
3
  Troubleshooting URL: https://docs.langchain.com/oss/javascript/langgraph/${$.lc_error_code}/
4
- `;super(J);this.lc_error_code=$?.lc_error_code}},p0=class extends OQ{get is_bubble_up(){return!0}},l0=class extends OQ{constructor(Q,$){super(Q,$);this.name="GraphRecursionError"}static get unminifiable_name(){return"GraphRecursionError"}},dQ=class extends OQ{constructor(Q,$){super(Q,$);this.name="GraphValueError"}static get unminifiable_name(){return"GraphValueError"}},PQ=class extends p0{interrupts;constructor(Q,$){super(JSON.stringify(Q,null,2),$);this.name="GraphInterrupt",this.interrupts=Q??[]}static get unminifiable_name(){return"GraphInterrupt"}},A0=class extends PQ{constructor(Q,$){super([{value:Q}],$);this.name="NodeInterrupt"}static get unminifiable_name(){return"NodeInterrupt"}},O0=class extends p0{command;constructor(Q){super();this.name="ParentCommand",this.command=Q}static get unminifiable_name(){return"ParentCommand"}};function o0(Q){return Q!==void 0&&Q.name===O0.unminifiable_name}function pQ(Q){return Q!==void 0&&Q.is_bubble_up===!0}function wQ(Q){return Q!==void 0&&[PQ.unminifiable_name,A0.unminifiable_name].includes(Q.name)}var P0=class extends OQ{constructor(Q,$){super(Q,$);this.name="EmptyInputError"}static get unminifiable_name(){return"EmptyInputError"}},v=class extends OQ{constructor(Q,$){super(Q,$);this.name="EmptyChannelError"}static get unminifiable_name(){return"EmptyChannelError"}},w=class extends OQ{constructor(Q,$){super(Q,$);this.name="InvalidUpdateError"}static get unminifiable_name(){return"InvalidUpdateError"}};var c0=class extends OQ{constructor(Q,$){super(Q,$);this.name="UnreachableNodeError"}static get unminifiable_name(){return"UnreachableNodeError"}};var B0=class extends OQ{constructor(Q,$){super(Q,$);this.name="StateGraphInputError",this.message="Invalid StateGraph input. Make sure to pass a valid StateDefinition, Annotation.Root, or Zod schema."}static get unminifiable_name(){return"StateGraphInputError"}};var V=(Q)=>BigInt(Q),C=(Q,$=0)=>new DataView(Q.buffer,Q.byteOffset+$,Q.byteLength-$),O$=V("0x9E3779B1"),P$=V("0x85EBCA77"),_1=V("0xC2B2AE3D"),lQ=V("0x9E3779B185EBCA87"),eQ=V("0xC2B2AE3D27D4EB4F"),w$=V("0x165667B19E3779F9"),_8=V("0x85EBCA77C2B2AE63"),N1=V("0x27D4EB2F165667C5"),I1=V("0x165667919E3779F9"),y1=V("0x9FB21C651E98DF25"),E1=(Q)=>{let $=Q.length;if($%2!==0)throw Error("String should have an even number of characters");let J=$/2,Z=new Uint8Array(J),q=0,z=0;while(z<J){let Y=Q.slice(q,q+=2);Z[z]=Number.parseInt(Y,16),z+=1}return C(Z)},RQ=E1("b8fe6c3923a44bbe7c01812cf721ad1cded46de9839097db7240a4a4b7b3671fcb79e64eccc0e578825ad07dccff7221b8084674f743248ee03590e6813a264c3c2852bb91c300cb88d0658b1b532ea371644897a20df94e3819ef46a9deacd8a8fa763fe39c343ff9dcbbc7c70b4f1d8a51e04bcdb45931c89f7ec9d9787364eac5ac8334d3ebc3c581a0fffa1363eb170ddd51b7f0da49d316552629d4689e2b16be587d47a1fc8ff8b8d17ad031ce45cb3a8f95160428afd7fbcabb4b407e"),L0=(V(1)<<V(128))-V(1),R=(V(1)<<V(64))-V(1),n0=(V(1)<<V(32))-V(1);function W0(Q){if(!Q)throw Error("Assert failed")}function v1(Q){let $=new DataView(new ArrayBuffer(8));return $.setBigUint64(0,Q,!0),$.getBigUint64(0,!1)}function C1(Q){let $=Q;return $=($&V(65535))<<V(16)|($&V(4294901760))>>V(16),$=($&V(16711935))<<V(8)|($&V(4278255360))>>V(8),$}function f1(Q,$){return(Q&n0)*($&n0)&R}function k1(Q,$){return(Q<<$|Q>>V(32)-$)&n0}function R$(Q,$,J){for(let Z=0;Z<8;Z+=1){let q=$.getBigUint64(Z*8,!0),z=q^J.getBigUint64(Z*8,!0);Q[Z^1]+=q,Q[Z]+=f1(z,z>>V(32))}return Q}function M$(Q,$,J,Z){for(let q=0;q<Z;q+=1)R$(Q,C($,q*64),C(J,q*8));return Q}function g1(Q,$){for(let J=0;J<8;J+=1){let Z=$.getBigUint64(J*8,!0),q=Q[J];q=b8(q,V(47)),q^=Z,q*=O$,Q[J]=q&R}return Q}function i0(Q,$){return T$(Q[0]^$.getBigUint64(0,!0),Q[1]^$.getBigUint64(8,!0))}function x$(Q,$,J){let Z=J;return Z+=i0(Q.slice(0),C($,0)),Z+=i0(Q.slice(2),C($,16)),Z+=i0(Q.slice(4),C($,32)),Z+=i0(Q.slice(6),C($,48)),TQ(Z&R)}function m1(Q,$,J,Z,q){let z=Q,Y=Math.floor((J.byteLength-64)/8),X=64*Y,B=Math.floor(($.byteLength-1)/X);for(let F=0;F<B;F+=1)z=M$(z,C($,F*X),J,Y),z=q(z,C(J,J.byteLength-64));{let F=Math.floor(($.byteLength-1-X*B)/64);z=M$(z,C($,B*X),J,F),z=Z(z,C($,$.byteLength-64),C(J,J.byteLength-64-7))}return z}function h1(Q,$){let J=new BigUint64Array([_1,lQ,eQ,w$,_8,P$,N1,O$]);W0(Q.byteLength>128),J=m1(J,Q,$,R$,g1),W0(J.length*8===64);{let Z=x$(J,C($,11),V(Q.byteLength)*lQ&R);return x$(J,C($,$.byteLength-64-11),~(V(Q.byteLength)*eQ)&R)<<V(64)|Z}}function T$(Q,$){let J=Q*$&L0;return J&R^J>>V(64)}function A$(Q,$,J){return T$((Q.getBigUint64(0,!0)^$.getBigUint64(0,!0)+J)&R,(Q.getBigUint64(8,!0)^$.getBigUint64(8,!0)-J)&R)}function r0(Q,$,J,Z,q){let z=Q&R,Y=Q>>V(64)&R;return z+=A$($,Z,q),z^=J.getBigUint64(0,!0)+J.getBigUint64(8,!0),z&=R,Y+=A$(J,C(Z,16),q),Y^=$.getBigUint64(0,!0)+$.getBigUint64(8,!0),Y&=R,Y<<V(64)|z}function TQ(Q){let $=Q;return $^=$>>V(37),$*=I1,$&=R,$^=$>>V(32),$}function s0(Q){let $=Q;return $^=$>>V(33),$*=eQ,$&=R,$^=$>>V(29),$*=w$,$&=R,$^=$>>V(32),$}function u1(Q,$,J){let Z=Q.byteLength;W0(Z>0&&Z<=3);let q=V(Q.getUint8(Z-1))|V(Z<<8)|V(Q.getUint8(0)<<16)|V(Q.getUint8(Z>>1)<<24),z=(q^(V($.getUint32(0,!0))^V($.getUint32(4,!0)))+J)&R,Y=(V($.getUint32(8,!0))^V($.getUint32(12,!0)))-J;return(s0((k1(C1(q),V(13))^Y)&R)&R)<<V(64)|s0(z)}function b8(Q,$){return Q^Q>>$}function d1(Q,$,J){let Z=Q.byteLength;W0(Z>=4&&Z<=8);{let q=Q.getUint32(0,!0),z=Q.getUint32(Z-4,!0),Y=((V(q)|V(z)<<V(32))^($.getBigUint64(16,!0)^$.getBigUint64(24,!0))+J&R)*(lQ+(V(Z)<<V(2)))&L0;return Y+=(Y&R)<<V(65),Y&=L0,Y^=Y>>V(67),b8(b8(Y&R,V(35))*y1&R,V(28))|TQ(Y>>V(64))<<V(64)}}function p1(Q,$,J){let Z=Q.byteLength;W0(Z>=9&&Z<=16);{let q=($.getBigUint64(32,!0)^$.getBigUint64(40,!0))+J&R,z=($.getBigUint64(48,!0)^$.getBigUint64(56,!0))-J&R,Y=Q.getBigUint64(0,!0),X=Q.getBigUint64(Z-8,!0),B=(Y^X^q)*lQ,F=(B&R)+(V(Z-1)<<V(54));B=B&(L0^R)|F,X^=z,B+=X+(X&n0)*(P$-V(1))<<V(64),B&=L0,B^=v1(B>>V(64));let W=(B&R)*eQ;return W+=(B>>V(64))*eQ<<V(64),W&=L0,TQ(W&R)|TQ(W>>V(64))<<V(64)}}function l1(Q,$){let J=Q.byteLength;if(W0(J<=16),J>8)return p1(Q,RQ,$);if(J>=4)return d1(Q,RQ,$);if(J>0)return u1(Q,RQ,$);return s0($^RQ.getBigUint64(64,!0)^RQ.getBigUint64(72,!0))|s0($^RQ.getBigUint64(80,!0)^RQ.getBigUint64(88,!0))<<V(64)}function S8(Q){return~Q+V(1)&R}function o1(Q,$,J){let Z=V(Q.byteLength)*lQ&R,q=V(Q.byteLength-1)/V(32);while(q>=0){let X=Number(q);Z=r0(Z,C(Q,16*X),C(Q,Q.byteLength-16*(X+1)),C($,32*X),J),q-=V(1)}let z=Z+(Z>>V(64))&R;z=TQ(z);let Y=(Z&R)*lQ+(Z>>V(64))*_8+(V(Q.byteLength)-J&R)*eQ;return Y&=R,Y=S8(TQ(Y)),z|Y<<V(64)}function c1(Q,$,J){let Z=V(Q.byteLength)*lQ&R;for(let Y=32;Y<160;Y+=32)Z=r0(Z,C(Q,Y-32),C(Q,Y-16),C($,Y-32),J);Z=TQ(Z&R)|TQ(Z>>V(64))<<V(64);for(let Y=160;Y<=Q.byteLength;Y+=32)Z=r0(Z,C(Q,Y-32),C(Q,Y-16),C($,3+Y-160),J);Z=r0(Z,C(Q,Q.byteLength-16),C(Q,Q.byteLength-32),C($,103),S8(J));let q=Z+(Z>>V(64))&R;q=TQ(q);let z=(Z&R)*lQ+(Z>>V(64))*_8+(V(Q.byteLength)-J&R)*eQ;return z&=R,z=S8(TQ(z)),q|z<<V(64)}function vQ(Q,$=V(0)){let Z=C(typeof Q==="string"?new TextEncoder().encode(Q):Q),q=Z.byteLength,z=(Y)=>Y.toString(16).padStart(32,"0");if(q<=16)return z(l1(Z,$));if(q<=128)return z(o1(Z,RQ,$));if(q<=240)return z(c1(Z,RQ,$));return z(h1(Z,RQ))}function t0(Q){return/^[0-9a-f]{32}$/.test(Q)}function N8(Q){let $=QQ.getRunnableConfig();if(!$)throw Error("Called interrupt() outside the context of a graph.");let J=$.configurable;if(!J)throw Error("No configurable found in config");if(!J[m])throw new dQ("No checkpointer set",{lc_error_code:"MISSING_CHECKPOINTER"});let Z=J[JQ];Z.interruptCounter+=1;let q=Z.interruptCounter;if(Z.resume.length>0&&q<Z.resume.length)return J[WQ]?.([[o,Z.resume]]),Z.resume[q];if(Z.nullResume!==void 0){if(Z.resume.length!==q)throw Error(`Resume length mismatch: ${Z.resume.length} !== ${q}`);let Y=Z.consumeNullResume();return Z.resume.push(Y),J[WQ]?.([[o,Z.resume]]),Y}let z=J[FQ]?.split(k);throw new PQ([{id:z?vQ(z.join(k)):void 0,value:Q}])}var I8=Symbol.for("langgraph.state.reduced_value"),BQ=class{[I8]=!0;valueSchema;inputSchema;reducer;jsonSchemaExtra;constructor(Q,$){this.reducer=$.reducer,this.jsonSchemaExtra=$.jsonSchemaExtra,this.valueSchema=Q,this.inputSchema="inputSchema"in $?$.inputSchema:Q,this.jsonSchemaExtra=$.jsonSchemaExtra}static isInstance(Q){return typeof Q==="object"&&Q!==null&&I8 in Q&&Q[I8]===!0}};function E8(Q){return Q!=null&&Q.lg_is_channel===!0}var l=class{ValueType;UpdateType;lg_is_channel=!0;consume(){return!1}finish(){return!1}isAvailable(){try{return this.get(),!0}catch(Q){if(Q.name===v.unminifiable_name)return!1;throw Q}}equals(Q){return this===Q}},y8=Symbol.for("LG_IS_ONLY_BASE_CHANNEL");function w0(Q){if(Q[y8]===!0)return Q;let $={};for(let J in Q){if(!Object.prototype.hasOwnProperty.call(Q,J))continue;let Z=Q[J];if(E8(Z))$[J]=Z}return Object.assign($,{[y8]:!0}),$}function oQ(Q,$){let J=w0(Q),Z={};for(let q in J){if(!Object.prototype.hasOwnProperty.call(J,q))continue;let z=$.channel_values[q];Z[q]=J[q].fromCheckpoint(z)}return Object.assign(Z,{[y8]:!0}),Z}function HQ(Q,$,J,Z){let q;if($===void 0)q=Q.channel_values;else{q={};for(let z in $){if(!Object.prototype.hasOwnProperty.call($,z))continue;try{q[z]=$[z].checkpoint()}catch(Y){if(Y.name===v.unminifiable_name);else throw Y}}}return{v:4,id:Z?.id??b$(J),ts:new Date().toISOString(),channel_values:q,channel_versions:Q.channel_versions,versions_seen:Q.versions_seen}}var i1=(Q)=>{return Q!=null&&Q.lc_graph_name==="BinaryOperatorAggregate"},bQ=class Q extends l{lc_graph_name="BinaryOperatorAggregate";value;operator;initialValueFactory;constructor($,J){super();this.operator=$,this.initialValueFactory=J,this.value=J?.()}fromCheckpoint($){let J=new Q(this.operator,this.initialValueFactory);if(typeof $<"u")J.value=$;return J}update($){let J=$;if(!J.length)return!1;if(this.value===void 0){let q=J[0],[z,Y]=d0(q);if(z)this.value=Y;else this.value=q;J=J.slice(1)}let Z=!1;for(let q of J)if(K$(q)){if(Z)throw new w("Can receive only one Overwrite value per step.");let[,z]=d0(q);this.value=z,Z=!0;continue}else if(!Z&&this.value!==void 0)this.value=this.operator(this.value,q);return!0}get(){if(this.value===void 0)throw new v;return this.value}checkpoint(){if(this.value===void 0)throw new v;return this.value}isAvailable(){return this.value!==void 0}equals($){if(this===$)return!0;if(!i1($))return!1;return this.operator===$.operator}};var UQ=class Q extends l{lc_graph_name="LastValue";value=[];constructor($){super();if(this.initialValueFactory=$,$)this.value=[$()]}fromCheckpoint($){let J=new Q(this.initialValueFactory);if(typeof $<"u")J.value=[$];return J}update($){if($.length===0)return!1;if($.length!==1)throw new w("LastValue can only receive one value per step.",{lc_error_code:"INVALID_CONCURRENT_GRAPH_UPDATE"});return this.value=[$[$.length-1]],!0}get(){if(this.value.length===0)throw new v;return this.value[0]}checkpoint(){if(this.value.length===0)throw new v;return this.value[0]}isAvailable(){return this.value.length!==0}},v8=class Q extends l{lc_graph_name="LastValueAfterFinish";value=[];finished=!1;fromCheckpoint($){let J=new Q;if(typeof $<"u"){let[Z,q]=$;J.value=[Z],J.finished=q}return J}update($){if($.length===0)return!1;return this.finished=!1,this.value=[$[$.length-1]],!0}get(){if(this.value.length===0||!this.finished)throw new v;return this.value[0]}checkpoint(){if(this.value.length===0)return;return[this.value[0],this.finished]}consume(){if(this.finished)return this.finished=!1,this.value=[],!0;return!1}finish(){if(!this.finished&&this.value.length>0)return this.finished=!0,!0;return!1}isAvailable(){return this.value.length!==0&&this.finished}};function SQ(Q){return typeof Q==="object"&&Q!==null&&"~standard"in Q&&typeof Q["~standard"]==="object"&&Q["~standard"]!==null&&"validate"in Q["~standard"]}function S$(Q){return typeof Q==="object"&&Q!==null&&"~standard"in Q&&typeof Q["~standard"]==="object"&&Q["~standard"]!==null&&"jsonSchema"in Q["~standard"]}function _Q(Q){if(S$(Q))try{return Q["~standard"].jsonSchema.input({target:"draft-07"})}catch{return}}function NQ(Q){if(Q==null)return;if(!SQ(Q))return;try{let $=Q["~standard"].validate(void 0);if($&&typeof $==="object"&&!(("then"in $)&&typeof $.then==="function")){let J=$;if(!J.issues){let Z=J.value;return()=>Z}}}catch{}}var C8=Symbol.for("langgraph.channel.missing"),R0=class Q extends l{lc_graph_name="UntrackedValue";guard;_value=C8;initialValueFactory;constructor($){super();if(this.guard=$?.guard??!0,this.initialValueFactory=$?.initialValueFactory,this.initialValueFactory)this._value=this.initialValueFactory()}fromCheckpoint($){return new Q({guard:this.guard,initialValueFactory:this.initialValueFactory})}update($){if($.length===0)return!1;if($.length!==1&&this.guard)throw new w("UntrackedValue(guard=true) can receive only one value per step. Use guard=false if you want to store any one of multiple values.",{lc_error_code:"INVALID_CONCURRENT_GRAPH_UPDATE"});return this._value=$[$.length-1],!0}get(){if(this._value===C8)throw new v;return this._value}checkpoint(){}isAvailable(){return this._value!==C8}};var f8=class Q extends l{lc_graph_name="Topic";unique=!1;accumulate=!1;seen;values;constructor($){super();this.unique=$?.unique??this.unique,this.accumulate=$?.accumulate??this.accumulate,this.seen=new Set,this.values=[]}fromCheckpoint($){let J=new Q({unique:this.unique,accumulate:this.accumulate});if(typeof $<"u")J.seen=new Set($[0]),J.values=$[1];return J}update($){let J=!1;if(!this.accumulate)J=this.values.length>0,this.values=[];let Z=$.flat();if(Z.length>0)if(this.unique){for(let q of Z)if(!this.seen.has(q))J=!0,this.seen.add(q),this.values.push(q)}else J=!0,this.values.push(...Z);return J}get(){if(this.values.length===0)throw new v;return this.values}checkpoint(){return[[...this.seen],this.values]}isAvailable(){return this.values.length!==0}};var VQ=class Q extends l{lc_graph_name="EphemeralValue";guard;value=[];constructor($=!0){super();this.guard=$}fromCheckpoint($){let J=new Q(this.guard);if(typeof $<"u")J.value=[$];return J}update($){if($.length===0){let J=this.value.length>0;return this.value=[],J}if($.length!==1&&this.guard)throw new w("EphemeralValue can only receive one value per step.");return this.value=[$[$.length-1]],!0}get(){if(this.value.length===0)throw new v;return this.value[0]}checkpoint(){if(this.value.length===0)throw new v;return this.value[0]}isAvailable(){return this.value.length!==0}};var cQ=(Q,$)=>Q.size===$.size&&[...Q].every((J)=>$.has(J)),k8=class Q extends l{lc_graph_name="NamedBarrierValue";names;seen;constructor($){super();this.names=$,this.seen=new Set}fromCheckpoint($){let J=new Q(this.names);if(typeof $<"u")J.seen=new Set($);return J}update($){let J=!1;for(let Z of $)if(this.names.has(Z)){if(!this.seen.has(Z))this.seen.add(Z),J=!0}else throw new w(`Value ${JSON.stringify(Z)} not in names ${JSON.stringify(this.names)}`);return J}get(){if(!cQ(this.names,this.seen))throw new v}checkpoint(){return[...this.seen]}consume(){if(this.seen&&this.names&&cQ(this.seen,this.names))return this.seen=new Set,!0;return!1}isAvailable(){return!!this.names&&cQ(this.names,this.seen)}},g8=class Q extends l{lc_graph_name="NamedBarrierValueAfterFinish";names;seen;finished;constructor($){super();this.names=$,this.seen=new Set,this.finished=!1}fromCheckpoint($){let J=new Q(this.names);if(typeof $<"u"){let[Z,q]=$;J.seen=new Set(Z),J.finished=q}return J}update($){let J=!1;for(let Z of $)if(this.names.has(Z)&&!this.seen.has(Z))this.seen.add(Z),J=!0;else if(!this.names.has(Z))throw new w(`Value ${JSON.stringify(Z)} not in names ${JSON.stringify(this.names)}`);return J}get(){if(!this.finished||!cQ(this.names,this.seen))throw new v}checkpoint(){return[[...this.seen],this.finished]}consume(){if(this.finished&&this.seen&&this.names&&cQ(this.seen,this.names))return this.seen=new Set,this.finished=!1,!0;return!1}finish(){if(!this.finished&&!!this.names&&cQ(this.names,this.seen))return this.finished=!0,!0;return!1}isAvailable(){return this.finished&&!!this.names&&cQ(this.names,this.seen)}};var _$=Symbol.for("langgraph.state.untracked_value"),IQ=class{[_$]=!0;schema;guard;constructor(Q,$){this.schema=Q,this.guard=$?.guard??!0}static isInstance(Q){return typeof Q==="object"&&Q!==null&&_$ in Q}};var m8=Symbol.for("langgraph.state.state_schema"),LQ=class{[m8]=!0;constructor(Q){this.fields=Q}getChannels(){let Q={};for(let[$,J]of Object.entries(this.fields))if(BQ.isInstance(J)){let Z=NQ(J.valueSchema);Q[$]=new bQ(J.reducer,Z)}else if(IQ.isInstance(J)){let Z=J.schema?NQ(J.schema):void 0;Q[$]=new R0({guard:J.guard,initialValueFactory:Z})}else if(SQ(J))Q[$]=new UQ(NQ(J));else throw Error(`Invalid state field "${$}": must be a schema, ReducedValue, UntrackedValue, or ManagedValue`);return Q}getJsonSchema(){let Q={},$=[];for(let[J,Z]of Object.entries(this.fields)){let q;if(BQ.isInstance(Z)){if(q=_Q(Z.valueSchema),Z.jsonSchemaExtra)q={...q??{},...Z.jsonSchemaExtra}}else if(IQ.isInstance(Z))q=Z.schema?_Q(Z.schema):void 0;else if(SQ(Z))q=_Q(Z);if(q){Q[J]=q;let z=!1;if(BQ.isInstance(Z))z=NQ(Z.valueSchema)!==void 0;else if(IQ.isInstance(Z))z=Z.schema?NQ(Z.schema)!==void 0:!1;else z=NQ(Z)!==void 0;if(!z)$.push(J)}}return{type:"object",properties:Q,required:$.length>0?$:void 0}}getInputJsonSchema(){let Q={};for(let[$,J]of Object.entries(this.fields)){let Z;if(BQ.isInstance(J))Z=_Q(J.inputSchema);else if(IQ.isInstance(J))Z=J.schema?_Q(J.schema):void 0;else if(SQ(J))Z=_Q(J);if(Z)Q[$]=Z}return{type:"object",properties:Q}}getChannelKeys(){return Object.entries(this.fields).map(([Q])=>Q)}getAllKeys(){return Object.keys(this.fields)}async validateInput(Q){if(Q==null||typeof Q!=="object")return Q;let $={};for(let[J,Z]of Object.entries(Q)){let q=this.fields[J];if(q===void 0){$[J]=Z;continue}let z;if(BQ.isInstance(q))z=q.inputSchema;else if(IQ.isInstance(q))z=q.schema;else if(SQ(q))z=q;if(z){let Y=await z["~standard"].validate(Z);if(Y.issues)throw Error(`Validation failed for field "${J}": ${JSON.stringify(Y.issues)}`);$[J]=Y.value}else $[J]=Z}return $}static isInstance(Q){return typeof Q==="object"&&Q!==null&&m8 in Q&&Q[m8]===!0}};import{AsyncLocalStorage as r1}from"node:async_hooks";function N$(){QQ.initializeGlobalInstance(new r1)}var T0=class{lc_graph_name="AnnotationRoot";spec;constructor(Q){this.spec=Q}static isInstance(Q){return typeof Q==="object"&&Q!==null&&"lc_graph_name"in Q&&Q.lc_graph_name==="AnnotationRoot"}},Q0=function(Q){if(Q)return a0(Q);else return new UQ};Q0.Root=(Q)=>new T0(Q);function a0(Q){if(typeof Q==="object"&&Q&&"reducer"in Q&&Q.reducer)return new bQ(Q.reducer,Q.default);if(typeof Q==="object"&&Q&&"value"in Q&&Q.value)return new bQ(Q.value,Q.default);return new UQ}var n1=["tags","metadata","callbacks","configurable"],s1=["tags","metadata","callbacks","runName","maxConcurrency","recursionLimit","configurable","runId","outputKeys","streamMode","store","writer","interrupt","context","interruptBefore","interruptAfter","checkpointDuring","durability","signal"],t1=25;function b0(...Q){let $={tags:[],metadata:{},callbacks:void 0,recursionLimit:t1,configurable:{}},J=QQ.getRunnableConfig();if(J!==void 0){for(let[Z,q]of Object.entries(J))if(q!==void 0)if(n1.includes(Z)){let z;if(Array.isArray(q))z=[...q];else if(typeof q==="object")if(Z==="callbacks"&&"copy"in q&&typeof q.copy==="function")z=q.copy();else z={...q};else z=q;$[Z]=z}else $[Z]=q}for(let Z of Q){if(Z===void 0)continue;for(let[q,z]of Object.entries(Z))if(z!==void 0&&s1.includes(q))$[q]=z}for(let[Z,q]of Object.entries($.configurable))if($.metadata=$.metadata??{},!Z.startsWith("__")&&(typeof q==="string"||typeof q==="number"||typeof q==="boolean")&&!(Z in $.metadata))$.metadata[Z]=q;return $}function h8(){return QQ.getRunnableConfig()}function a1(Q){let $=Q??QQ.getRunnableConfig();if($===void 0)throw Error(["Config not retrievable. This is likely because you are running in an environment without support for AsyncLocalStorage.","If you're running `getCurrentTaskInput` in such environment, pass the `config` from the node function directly."].join(`
5
- `));if($.configurable?.[JQ]?.currentTaskInput===void 0)throw Error("BUG: internal scratchpad not initialized.");return $.configurable[JQ].currentTaskInput}function e0(Q){return Q.split(k).filter(($)=>!$.match(/^\d+$/)).map(($)=>$.split(e)[0]).join(k)}function I$(Q){let $=Q.split(k);while($.length>1&&$[$.length-1].match(/^\d+$/))$.pop();return $.slice(0,-1).join(k)}var s=class extends YQ{lc_namespace=["langgraph"];func;tags;config;trace=!0;recurse=!0;constructor(Q){super();this.name=Q.name??Q.func.name,this.func=Q.func,this.config=Q.tags?{tags:Q.tags}:void 0,this.trace=Q.trace??this.trace,this.recurse=Q.recurse??this.recurse}async _tracedInvoke(Q,$,J){return new Promise((Z,q)=>{let z=iQ($,{callbacks:J?.getChild()});QQ.runWithConfig(z,async()=>{try{Z(await this.func(Q,z))}catch(Y){q(Y)}})})}async invoke(Q,$){let J,Z=b0($),q=DQ(this.config,Z);if(this.trace)J=await this._callWithConfig(this._tracedInvoke,Q,q);else J=await QQ.runWithConfig(q,async()=>this.func(Q,q));if(YQ.isRunnable(J)&&this.recurse)return await QQ.runWithConfig(q,async()=>J.invoke(Q,q));return J}};function*CQ(Q,$){if($===void 0)yield*Q;else for(let J of Q)yield[$,J]}async function GQ(Q){let $=[];for await(let J of await Q)$.push(J);return $}function $0(Q){let $=[];for(let J of Q)$.push(J);return $}function J0(Q,$){if(!Q)return{configurable:$};else if(!("configurable"in Q))return{...Q,configurable:$};else return{...Q,configurable:{...Q.configurable,...$}}}function y$(Q){return Q!=null&&typeof Q==="function"&&Q instanceof Object.getPrototypeOf(async function*(){}).constructor}function E$(Q){return Q!=null&&typeof Q==="function"&&Q instanceof Object.getPrototypeOf(function*(){}).constructor}var IZ={[Symbol.for("LG_SKIP_WRITE")]:!0};function e1(Q){return typeof Q==="object"&&Q?.[Symbol.for("LG_SKIP_WRITE")]!==void 0}var qQ={[Symbol.for("LG_PASSTHROUGH")]:!0};function Q8(Q){return typeof Q==="object"&&Q?.[Symbol.for("LG_PASSTHROUGH")]!==void 0}var u8=Symbol("IS_WRITER"),h=class Q extends s{writes;constructor($,J){let Z=`ChannelWrite<${$.map((q)=>{if(d(q))return q.node;else if("channel"in q)return q.channel;return"..."}).join(",")}>`;super({writes:$,name:Z,tags:J,trace:!1,func:async(q,z)=>{return this._write(q,z??{})}});this.writes=$}async _write($,J){let Z=this.writes.map((q)=>{if(d8(q)&&Q8(q.value))return{mapper:q.mapper,value:$};else if($8(q)&&Q8(q.value))return{channel:q.channel,value:$,skipNone:q.skipNone,mapper:q.mapper};else return q});return await Q.doWrite(J,Z),$}static async doWrite($,J){for(let z of J){if($8(z)){if(z.channel===c)throw new w("Cannot write to the reserved channel TASKS");if(Q8(z.value))throw new w("PASSTHROUGH value must be replaced")}if(d8(z)){if(Q8(z.value))throw new w("PASSTHROUGH value must be replaced")}}let Z=[];for(let z of J)if(d(z))Z.push([c,z]);else if(d8(z)){let Y=await z.mapper.invoke(z.value,$);if(Y!=null&&Y.length>0)Z.push(...Y)}else if($8(z)){let Y=z.mapper!==void 0?await z.mapper.invoke(z.value,$):z.value;if(e1(Y))continue;if(z.skipNone&&Y===void 0)continue;Z.push([z.channel,Y])}else throw Error(`Invalid write entry: ${JSON.stringify(z)}`);let q=$.configurable?.[WQ];q(Z)}static isWriter($){return $ instanceof Q||u8 in $&&!!$[u8]}static registerWriter($){return Object.defineProperty($,u8,{value:!0})}};function $8(Q){return Q!==void 0&&typeof Q.channel==="string"}function d8(Q){return Q!==void 0&&!$8(Q)&&YQ.isRunnable(Q.mapper)}var f$=class Q extends s{lc_graph_name="ChannelRead";channel;fresh=!1;mapper;constructor($,J,Z=!1){super({trace:!1,func:(q,z)=>Q.doRead(z,this.channel,this.fresh,this.mapper)});this.fresh=Z,this.mapper=J,this.channel=$,this.name=Array.isArray($)?`ChannelRead<${$.join(",")}>`:`ChannelRead<${$}>`}static doRead($,J,Z,q){let z=$.configurable?.[AQ];if(!z)throw Error("Runnable is not configured with a read function. Make sure to call in the context of a Pregel process");if(q)return q(z(J,Z));else return z(J,Z)}},j0=new C$,KQ=class Q extends v${lc_graph_name="PregelNode";channels;triggers=[];mapper;writers=[];bound=j0;kwargs={};metadata={};tags=[];retryPolicy;cachePolicy;subgraphs;ends;constructor($){let{channels:J,triggers:Z,mapper:q,writers:z,bound:Y,kwargs:X,metadata:B,retryPolicy:F,cachePolicy:W,tags:L,subgraphs:H,ends:j}=$,U=[...$.config?.tags?$.config.tags:[],...L??[]];super({...$,bound:$.bound??j0,config:{...$.config?$.config:{},tags:U}});this.channels=J,this.triggers=Z,this.mapper=q,this.writers=z??this.writers,this.bound=Y??this.bound,this.kwargs=X??this.kwargs,this.metadata=B??this.metadata,this.tags=U,this.retryPolicy=F,this.cachePolicy=W,this.subgraphs=H,this.ends=j}getWriters(){let $=[...this.writers];while($.length>1&&$[$.length-1]instanceof h&&$[$.length-2]instanceof h){let J=$.slice(-2),Z=J[0].writes.concat(J[1].writes);$[$.length-2]=new h(Z,J[0].config?.tags),$.pop()}return $}getNode(){let $=this.getWriters();if(this.bound===j0&&$.length===0)return;else if(this.bound===j0&&$.length===1)return $[0];else if(this.bound===j0)return new Z0({first:$[0],middle:$.slice(1,$.length-1),last:$[$.length-1],omitSequenceTags:!0});else if($.length>0)return new Z0({first:this.bound,middle:$.slice(0,$.length-1),last:$[$.length-1],omitSequenceTags:!0});else return this.bound}join($){if(!Array.isArray($))throw Error("channels must be a list");if(typeof this.channels!=="object")throw Error("all channels must be named when using .join()");return new Q({channels:{...this.channels,...Object.fromEntries($.map((J)=>[J,J]))},triggers:this.triggers,mapper:this.mapper,writers:this.writers,bound:this.bound,kwargs:this.kwargs,config:this.config,retryPolicy:this.retryPolicy,cachePolicy:this.cachePolicy})}pipe($){if(h.isWriter($))return new Q({channels:this.channels,triggers:this.triggers,mapper:this.mapper,writers:[...this.writers,$],bound:this.bound,config:this.config,kwargs:this.kwargs,retryPolicy:this.retryPolicy,cachePolicy:this.cachePolicy});else if(this.bound===j0)return new Q({channels:this.channels,triggers:this.triggers,mapper:this.mapper,writers:this.writers,bound:yQ($),config:this.config,kwargs:this.kwargs,retryPolicy:this.retryPolicy,cachePolicy:this.cachePolicy});else return new Q({channels:this.channels,triggers:this.triggers,mapper:this.mapper,writers:this.writers,bound:this.bound.pipe($),config:this.config,kwargs:this.kwargs,retryPolicy:this.retryPolicy,cachePolicy:this.cachePolicy})}};function Q6(Q){return"steps"in Q&&Array.isArray(Q.steps)}function S0(Q){return"lg_is_pregel"in Q&&Q.lg_is_pregel===!0}function J8(Q){let $=[Q];for(let J of $)if(S0(J))return J;else if(Q6(J))$.push(...J.steps)}function q0(Q,$,J=!0,Z=!1){try{return Q[$].get()}catch(q){if(q.name===v.unminifiable_name){if(Z)return q;else if(J)return null}throw q}}function MQ(Q,$,J=!0){if(Array.isArray($)){let Z={};for(let q of $)try{Z[q]=q0(Q,q,!J)}catch(z){if(z.name===v.unminifiable_name)continue}return Z}else return q0(Q,$)}function*k$(Q,$){if(Q.graph===a.PARENT)throw new w("There is no parent graph.");if(Q.goto){let J;if(Array.isArray(Q.goto))J=Q.goto;else J=[Q.goto];for(let Z of J)if(d(Z))yield[n,c,Z];else if(typeof Z==="string")yield[n,`branch:to:${Z}`,"__start__"];else throw Error(`In Command.send, expected Send or string, got ${typeof Z}`)}if(Q.resume)if(typeof Q.resume==="object"&&Object.keys(Q.resume).length&&Object.keys(Q.resume).every(t0))for(let[J,Z]of Object.entries(Q.resume)){let q=$.filter((z)=>z[0]===J&&z[1]===o).map((z)=>z[2]).slice(0,1)??[];q.push(Z),yield[J,o,q]}else yield[n,o,Q.resume];if(Q.update){if(typeof Q.update!=="object"||!Q.update)throw Error("Expected cmd.update to be a dict mapping channel names to update values");if(Array.isArray(Q.update))for(let[J,Z]of Q.update)yield[n,J,Z];else for(let[J,Z]of Object.entries(Q.update))yield[n,J,Z]}}function*Z8(Q,$){if($!==void 0&&$!==null)if(Array.isArray(Q)&&typeof $==="object"&&!Array.isArray($)){for(let J in $)if(Q.includes(J))yield[J,$[J]]}else if(Array.isArray(Q))throw Error('Input chunk must be an object when "inputChannels" is an array');else yield[Q,$]}function*q8(Q,$,J){if(Array.isArray(Q)){if($===!0||$.find(([Z,q])=>Q.includes(Z)))yield MQ(J,Q)}else if($===!0||$.some(([Z,q])=>Z===Q))yield q0(J,Q)}function*g$(Q,$,J){let Z=$.filter(([X,B])=>{return(X.config===void 0||!X.config.tags?.includes(E))&&B[0][0]!==p&&B[0][0]!==S});if(!Z.length)return;let q;if(Z.some(([X])=>X.writes.some(([B,F])=>B===jQ)))q=Z.flatMap(([X])=>X.writes.filter(([B,F])=>B===jQ).map(([B,F])=>[X.name,F]));else if(!Array.isArray(Q))q=Z.flatMap(([X])=>X.writes.filter(([B,F])=>B===Q).map(([B,F])=>[X.name,F]));else q=Z.flatMap(([X])=>{let{writes:B}=X,F={};for(let[W]of B)if(Q.includes(W))F[W]=(F[W]||0)+1;if(Object.values(F).some((W)=>W>1))return B.filter(([W])=>Q.includes(W)).map(([W,L])=>[X.name,{[W]:L}]);else return[[X.name,Object.fromEntries(B.filter(([W])=>Q.includes(W)))]]});let z={};for(let[X,B]of q){if(!(X in z))z[X]=[];z[X].push(B)}let Y={};for(let X in z)if(z[X].length===1){let[B]=z[X];Y[X]=B}else Y[X]=z[X];if(J)Y.__metadata__={cached:J};yield Y}function z8(Q){let $=typeof Q[T];if($==="number")return 0;if($==="string")return"";for(let J in Q){if(!Object.prototype.hasOwnProperty.call(Q,J))continue;let Z=typeof Q[J];if(Z==="number")return 0;if(Z==="string")return"";break}}function H0(Q,$){if(Object.keys(Q).length>0){let J=z8($);return Object.fromEntries(Object.entries($).filter(([Z,q])=>q>(Q[Z]??J)))}else return $}function m$(Q,$){return Q&&!Array.isArray(Q)&&!(Q instanceof Date)&&typeof Q==="object"?Q:{[$]:Q}}function zQ(Q,$){if(Q===null)return{configurable:$};else if(Q?.configurable===void 0)return{...Q,configurable:$};else return{...Q,configurable:{...Q.configurable,...$}}}function rQ(Q,$){let J=$?.parents??{};if(Object.keys(J).length>0)return zQ(Q,{[ZQ]:{...J,[Q.configurable?.checkpoint_ns??""]:Q.configurable?.checkpoint_id}});else return Q}function U0(...Q){let $=[...new Set(Q.filter(Boolean))];if($.length===0)return{signal:void 0,dispose:void 0};if($.length===1)return{signal:$[0],dispose:void 0};let J=new AbortController,Z=()=>{let z=$.find((Y)=>Y.aborted)?.reason;J.abort(z),$.forEach((Y)=>Y.removeEventListener("abort",Z))};$.forEach((z)=>z.addEventListener("abort",Z,{once:!0}));let q=$.find((z)=>z.aborted);if(q)J.abort(q.reason);return{signal:J.signal,dispose:()=>{$.forEach((z)=>z.removeEventListener("abort",Z))}}}var h$=(Q,$)=>{if(!Q&&!$)return;if(!Q)return $;if(!$)return Q;if(Array.isArray(Q)&&Array.isArray($))return[...Q,...$];if(Array.isArray(Q))return[...Q,$];if(Array.isArray($))return[Q,...$];return[Q,$]};var u$=class{func;name;input;retry;cache;callbacks;__lg_type="call";constructor({func:Q,name:$,input:J,retry:Z,cache:q,callbacks:z}){this.func=Q,this.name=$,this.input=J,this.retry=Z,this.cache=q,this.callbacks=z}};function d$(Q){return typeof Q==="object"&&Q!==null&&"__lg_type"in Q&&Q.__lg_type==="call"}function p$(Q,$){return new Z0({name:Q,first:new s({func:(J)=>$(...J),name:Q,trace:!1,recurse:!1}),last:new h([{channel:jQ,value:qQ}],[E])})}function l$(Q,$){return new s({func:(J,Z)=>{return $(J,Z)},name:Q,trace:!1,recurse:!1})}var c$=(Q)=>{return Q!==void 0?Q+1:1};function $6(Q,$){if($==null)return!1;for(let J of Q)if($[J])return!0;return!1}function J6(Q){let $;for(let J in Q){if(!Object.prototype.hasOwnProperty.call(Q,J))continue;if($==null)$=Q[J];else $=o$($,Q[J])}return $}function N0(Q,$,J){let Z=z8(Q.channel_versions),q=Q.versions_seen[S]??{},z=!1;if((Q.channel_versions[T]??Z)>(q[T]??Z))z=!0;else for(let X in Q.channel_versions){if(!Object.prototype.hasOwnProperty.call(Q.channel_versions,X))continue;if(Q.channel_versions[X]>(q[X]??Z)){z=!0;break}}let Y=J.some((X)=>$==="*"?!X.config?.tags?.includes(E):$.includes(X.name));return z&&Y}function _0(Q,$,J,Z,q=!1){let z=new Set;if(!Array.isArray(Z)){for(let[X]of J.writes)if(X===Z){z=new Set([X]);break}z=z||new Set}else z=new Set(Z.filter((X)=>J.writes.some(([B,F])=>B===X)));let Y;if(q&&z.size>0){let X=Object.fromEntries(Object.entries($).filter(([W,L])=>z.has(W))),B=HQ(Q,X,-1),F=oQ(X,B);$Q(fQ(B),F,[J],void 0,void 0),Y=MQ({...$,...F},Z)}else Y=MQ($,Z);return Y}function p8(Q,$,J){for(let[Z,q]of J)if([r,c].includes(Z)&&q!=null){if(!d(q))throw new w(`Invalid packet type, expected SendProtocol, got ${JSON.stringify(q)}`);if(!(q.node in $))throw new w(`Invalid node name "${q.node}" in Send packet`)}Q(J)}var Z6=new Set([m0,r,o,S,jQ,p]);function $Q(Q,$,J,Z,q){J.sort((H,j)=>{let U=H.path?.slice(0,3)||[],D=j.path?.slice(0,3)||[];for(let M=0;M<Math.min(U.length,D.length);M+=1){if(U[M]<D[M])return-1;if(U[M]>D[M])return 1}return U.length-D.length});let z=J.some((H)=>H.triggers.length>0),Y=w0($);for(let H of J){Q.versions_seen[H.name]??={};for(let j of H.triggers)if(j in Q.channel_versions)Q.versions_seen[H.name][j]=Q.channel_versions[j]}let X=J6(Q.channel_versions),B=new Set(J.flatMap((H)=>H.triggers).filter((H)=>!G$.includes(H))),F=!1;for(let H of B)if(H in Y&&Y[H].consume()){if(Z!==void 0)Q.channel_versions[H]=Z(X),F=!0}let W={};for(let H of J)for(let[j,U]of H.writes)if(Z6.has(j));else if(j in Y)W[j]??=[],W[j].push(U);if(X!=null&&Z!=null)X=F?Z(X):X;let L=new Set;for(let[H,j]of Object.entries(W))if(H in Y){let U=Y[H],D;try{D=U.update(j)}catch(M){if(M.name===w.unminifiable_name){let O=new w(`Invalid update for channel "${H}" with values ${JSON.stringify(j)}: ${M.message}`);throw O.lc_error_code=M.lc_error_code,O}else throw M}if(D&&Z!==void 0){if(Q.channel_versions[H]=Z(X),U.isAvailable())L.add(H)}}if(z)for(let H in Y){if(!Object.prototype.hasOwnProperty.call(Y,H))continue;let j=Y[H];if(j.isAvailable()&&!L.has(H)){if(j.update([])&&Z!==void 0){if(Q.channel_versions[H]=Z(X),j.isAvailable())L.add(H)}}}if(z&&!$6(L,q))for(let H in Y){if(!Object.prototype.hasOwnProperty.call(Y,H))continue;let j=Y[H];if(j.finish()&&Z!==void 0){if(Q.channel_versions[H]=Z(X),j.isAvailable())L.add(H)}}return L}function*q6(Q,$,J){if(J.updatedChannels!=null&&J.triggerToNodes!=null){let Z=new Set;for(let q of J.updatedChannels){let z=J.triggerToNodes[q];for(let Y of z??[])Z.add(Y)}yield*[...Z].sort();return}if((()=>{for(let Z in Q.channel_versions)if(Q.channel_versions[Z]!==null)return!1;return!0})())return;for(let Z in $){if(!Object.prototype.hasOwnProperty.call($,Z))continue;yield Z}}function sQ(Q,$,J,Z,q,z,Y){let X={},B=Z[c];if(B?.isAvailable()){let F=B.get().length;for(let W=0;W<F;W+=1){let L=Y8([r,W],Q,$,J,Z,q,z,Y);if(L!==void 0)X[L.id]=L}}for(let F of q6(Q,J,Y)){let W=Y8([x0,F],Q,$,J,Z,q,z,Y);if(W!==void 0)X[W.id]=W}return X}function Y8(Q,$,J,Z,q,z,Y,X){let{step:B,checkpointer:F,manager:W}=X,L=z.configurable??{},H=L.checkpoint_ns??"";if(Q[0]===r&&d$(Q[Q.length-1])){let j=Q[Q.length-1],U=p$(j.name,j.func),D=[r],M=H===""?j.name:`${H}${k}${j.name}`,O=nQ(JSON.stringify([M,B.toString(),j.name,r,Q[1],Q[2]]),$.id),_=`${M}${e}${O}`,P=[...Q.slice(0,3),!0],I={langgraph_step:B,langgraph_node:j.name,langgraph_triggers:D,langgraph_path:P,langgraph_checkpoint_ns:_};if(Y){let N=[];return{name:j.name,input:j.input,proc:U,writes:N,config:iQ(DQ(z,{metadata:I,store:X.store??z.store}),{runName:j.name,callbacks:W?.getChild(`graph:step:${B}`),configurable:{[Y0]:O,[WQ]:(f)=>p8((K)=>N.push(...K),Z,f),[AQ]:(f,K=!1)=>_0($,q,{name:j.name,writes:N,triggers:D,path:P},f,K),[m]:F??L[m],[ZQ]:{...L[ZQ],[H]:$.id},[JQ]:l8({pendingWrites:J??[],taskId:O,currentTaskInput:j.input,resumeMap:z.configurable?.[X0],namespaceHash:vQ(_)}),[M0]:$.channel_values[aQ],checkpoint_id:void 0,checkpoint_ns:_}}),triggers:D,retry_policy:j.retry,cache_key:j.cache?{key:vQ((j.cache.keyFunc??JSON.stringify)([j.input])),ns:[k0,j.name??"__dynamic__"],ttl:j.cache.ttl}:void 0,id:O,path:P,writers:[]}}else return{id:O,name:j.name,interrupts:[],path:P}}else if(Q[0]===r){let j=typeof Q[1]==="number"?Q[1]:parseInt(Q[1],10);if(!q[c]?.isAvailable())return;let U=q[c].get();if(j<0||j>=U.length)return;let D=u0(U[j])&&!d(U[j])?new uQ(U[j].node,U[j].args):U[j];if(!u0(D)){console.warn(`Ignoring invalid packet ${JSON.stringify(D)} in pending sends.`);return}if(!(D.node in Z)){console.warn(`Ignoring unknown node name ${D.node} in pending sends.`);return}let M=[r],O=H===""?D.node:`${H}${k}${D.node}`,_=nQ(JSON.stringify([O,B.toString(),D.node,r,j.toString()]),$.id),P=`${O}${e}${_}`,I={langgraph_step:B,langgraph_node:D.node,langgraph_triggers:M,langgraph_path:Q.slice(0,3),langgraph_checkpoint_ns:P};if(Y){let N=Z[D.node],f=N.getNode();if(f!==void 0){if(N.metadata!==void 0)I={...I,...N.metadata};let K=[];return{name:D.node,input:D.args,proc:f,subgraphs:N.subgraphs,writes:K,config:iQ(DQ(z,{metadata:I,tags:N.tags,store:X.store??z.store}),{runName:D.node,callbacks:W?.getChild(`graph:step:${B}`),configurable:{[Y0]:_,[WQ]:(x)=>p8((b)=>K.push(...b),Z,x),[AQ]:(x,b=!1)=>_0($,q,{name:D.node,writes:K,triggers:M,path:Q},x,b),[m]:F??L[m],[ZQ]:{...L[ZQ],[H]:$.id},[JQ]:l8({pendingWrites:J??[],taskId:_,currentTaskInput:D.args,resumeMap:z.configurable?.[X0],namespaceHash:vQ(P)}),[M0]:$.channel_values[aQ],checkpoint_id:void 0,checkpoint_ns:P}}),triggers:M,retry_policy:N.retryPolicy,cache_key:N.cachePolicy?{key:vQ((N.cachePolicy.keyFunc??JSON.stringify)([D.args])),ns:[k0,N.name??"__dynamic__",D.node],ttl:N.cachePolicy.ttl}:void 0,id:_,path:Q,writers:N.getWriters()}}}else return{id:_,name:D.node,interrupts:[],path:Q}}else if(Q[0]===x0){let j=Q[1].toString(),U=Z[j];if(U===void 0)return;if(J?.length){let _=H===""?j:`${H}${k}${j}`,P=nQ(JSON.stringify([_,B.toString(),j,x0,j]),$.id);if(J.some((I)=>I[0]===P&&I[1]!==p))return}let D=z8($.channel_versions);if(D===void 0)return;let M=$.versions_seen[j]??{},O=U.triggers.find((_)=>{if(!q[_].isAvailable())return!1;return($.channel_versions[_]??D)>(M[_]??D)});if(O!==void 0){let _=z6(U,q,Y);if(_===void 0)return;let P=H===""?j:`${H}${k}${j}`,I=nQ(JSON.stringify([P,B.toString(),j,x0,[O]]),$.id),N=`${P}${e}${I}`,f={langgraph_step:B,langgraph_node:j,langgraph_triggers:[O],langgraph_path:Q,langgraph_checkpoint_ns:N};if(Y){let K=U.getNode();if(K!==void 0){if(U.metadata!==void 0)f={...f,...U.metadata};let x=[];return{name:j,input:_,proc:K,subgraphs:U.subgraphs,writes:x,config:iQ(DQ(z,{metadata:f,tags:U.tags,store:X.store??z.store}),{runName:j,callbacks:W?.getChild(`graph:step:${B}`),configurable:{[Y0]:I,[WQ]:(b)=>p8((G)=>{x.push(...G)},Z,b),[AQ]:(b,G=!1)=>_0($,q,{name:j,writes:x,triggers:[O],path:Q},b,G),[m]:F??L[m],[ZQ]:{...L[ZQ],[H]:$.id},[JQ]:l8({pendingWrites:J??[],taskId:I,currentTaskInput:_,resumeMap:z.configurable?.[X0],namespaceHash:vQ(N)}),[M0]:$.channel_values[aQ],checkpoint_id:void 0,checkpoint_ns:N}}),triggers:[O],retry_policy:U.retryPolicy,cache_key:U.cachePolicy?{key:vQ((U.cachePolicy.keyFunc??JSON.stringify)([_])),ns:[k0,U.name??"__dynamic__",j],ttl:U.cachePolicy.ttl}:void 0,id:I,path:Q,writers:U.getWriters()}}}else return{id:I,name:j,interrupts:[],path:Q}}}}function z6(Q,$,J){let Z;if(typeof Q.channels==="object"&&!Array.isArray(Q.channels)){Z={};for(let[q,z]of Object.entries(Q.channels))if(Q.triggers.includes(z))try{Z[q]=q0($,z,!1)}catch(Y){if(Y.name===v.unminifiable_name)return;else throw Y}else if(z in $)try{Z[q]=q0($,z,!1)}catch(Y){if(Y.name===v.unminifiable_name)continue;else throw Y}}else if(Array.isArray(Q.channels)){let q=!1;for(let z of Q.channels)try{Z=q0($,z,!1),q=!0;break}catch(Y){if(Y.name===v.unminifiable_name)continue;else throw Y}if(!q)return}else throw Error(`Invalid channels type, expected list or dict, got ${Q.channels}`);if(J&&Q.mapper!==void 0)Z=Q.mapper(Z);return Z}function i$(Q,$){if(typeof Q.args!=="object"||Q.args===null)return Q;let J={};for(let[Z,q]of Object.entries(Q.args)){let z=$[Z];if(!z||z.lc_graph_name!=="UntrackedValue")J[Z]=q}return new uQ(Q.node,J)}function l8({pendingWrites:Q,taskId:$,currentTaskInput:J,resumeMap:Z,namespaceHash:q}){let z=Q.find(([X,B])=>X===n&&B===o)?.[2],Y={callCounter:0,interruptCounter:-1,resume:(()=>{let X=Q.filter(([B,F])=>B===$&&F===o).flatMap(([B,F,W])=>W);if(Z!=null&&q in Z){let B=Z[q];X.push(B)}return X})(),nullResume:z,subgraphCounter:0,currentTaskInput:J,consumeNullResume:()=>{if(Y.nullResume)return delete Y.nullResume,Q.splice(Q.findIndex(([X,B])=>X===n&&B===o),1),z}};return Y}var I0={blue:{start:"\x1B[34m",end:"\x1B[0m"},green:{start:"\x1B[32m",end:"\x1B[0m"},yellow:{start:"\x1B[33;1m",end:"\x1B[0m"}},y0=(Q,$)=>`${Q.start}${$}${Q.end}`;function*o8(Q){for(let{id:$,name:J,input:Z,config:q,triggers:z,writes:Y}of Q){if(q?.tags?.includes(E))continue;yield{id:$,name:J,input:Z,triggers:z,interrupts:Y.filter(([X,B])=>{return X===$&&B===S}).map(([,X])=>{return X})}}}function Y6(Q){if(typeof Q!=="object"||Q===null)return!1;return"$writes"in Q&&Array.isArray(Q.$writes)}function r$(Q){let $={};for(let[J,Z]of Q){let q=String(J);if(q in $){let z=Y6($[q])?$[q].$writes:[$[q]];z.push(Z),$[q]={$writes:z}}else $[q]=Z}return $}function*n$(Q,$){for(let[{id:J,name:Z,config:q},z]of Q){if(q?.tags?.includes(E))continue;yield{id:J,name:Z,result:r$(z.filter(([Y])=>{return Array.isArray($)?$.includes(Y):Y===$})),interrupts:z.filter((Y)=>Y[0]===S).map((Y)=>Y[1])}}}function*s$(Q,$,J,Z,q,z,Y,X){function B(L){let H={};if(L.callbacks!=null)H.callbacks=L.callbacks;if(L.configurable!=null)H.configurable=L.configurable;if(L.maxConcurrency!=null)H.max_concurrency=L.maxConcurrency;if(L.metadata!=null)H.metadata=L.metadata;if(L.recursionLimit!=null)H.recursion_limit=L.recursionLimit;if(L.runId!=null)H.run_id=L.runId;if(L.runName!=null)H.run_name=L.runName;if(L.tags!=null)H.tags=L.tags;return H}let F=Q.configurable?.checkpoint_ns,W={};for(let L of q){if(!((L.subgraphs?.length)?L.subgraphs:[L.proc]).find(J8))continue;let H=`${L.name}:${L.id}`;if(F)H=`${F}|${H}`;W[L.id]={configurable:{thread_id:Q.configurable?.thread_id,checkpoint_ns:H}}}yield{config:B(Q),values:MQ($,J),metadata:Z,next:q.map((L)=>L.name),tasks:c8(q,z,W,X),parentConfig:Y?B(Y):void 0}}function c8(Q,$,J,Z){return Q.map((q)=>{let z=$.find(([F,W])=>F===q.id&&W===p)?.[2],Y=$.filter(([F,W])=>F===q.id&&W===S).map(([,,F])=>F),X=(()=>{if(z||Y.length||!$.length)return;let F=$.findIndex(([W,L])=>W===q.id&&L===jQ);if(F>=0)return $[F][2];if(typeof Z==="string")return $.find(([W,L])=>W===q.id&&L===Z)?.[2];if(Array.isArray(Z)){let W=$.filter(([L,H])=>L===q.id&&Z.includes(H)).map(([,L,H])=>[L,H]);if(!W.length)return;return r$(W)}})();if(z)return{id:q.id,name:q.name,path:q.path,error:z,interrupts:Y,result:X};let B=J?.[q.id];return{id:q.id,name:q.name,path:q.path,interrupts:Y,...B!==void 0?{state:B}:{},result:X}})}function t$(Q,$,J){console.log([`${y0(I0.blue,`[${Q}:checkpoint]`)}`,`\x1B[1m State at the end of step ${Q}:\x1B[0m
6
- `,JSON.stringify(MQ($,J),null,2)].join(""))}function X8(Q,$){let J=$.length;console.log([`${y0(I0.blue,`[${Q}:tasks]`)}`,`\x1B[1m Starting step ${Q} with ${J} task${J===1?"":"s"}:\x1B[0m
4
+ `;super(J);this.lc_error_code=$?.lc_error_code}},p0=class extends OQ{get is_bubble_up(){return!0}},l0=class extends OQ{constructor(Q,$){super(Q,$);this.name="GraphRecursionError"}static get unminifiable_name(){return"GraphRecursionError"}},dQ=class extends OQ{constructor(Q,$){super(Q,$);this.name="GraphValueError"}static get unminifiable_name(){return"GraphValueError"}},PQ=class extends p0{interrupts;constructor(Q,$){super(JSON.stringify(Q,null,2),$);this.name="GraphInterrupt",this.interrupts=Q??[]}static get unminifiable_name(){return"GraphInterrupt"}},A0=class extends PQ{constructor(Q,$){super([{value:Q}],$);this.name="NodeInterrupt"}static get unminifiable_name(){return"NodeInterrupt"}},O0=class extends p0{command;constructor(Q){super();this.name="ParentCommand",this.command=Q}static get unminifiable_name(){return"ParentCommand"}};function o0(Q){return Q!==void 0&&Q.name===O0.unminifiable_name}function pQ(Q){return Q!==void 0&&Q.is_bubble_up===!0}function wQ(Q){return Q!==void 0&&[PQ.unminifiable_name,A0.unminifiable_name].includes(Q.name)}var P0=class extends OQ{constructor(Q,$){super(Q,$);this.name="EmptyInputError"}static get unminifiable_name(){return"EmptyInputError"}},v=class extends OQ{constructor(Q,$){super(Q,$);this.name="EmptyChannelError"}static get unminifiable_name(){return"EmptyChannelError"}},w=class extends OQ{constructor(Q,$){super(Q,$);this.name="InvalidUpdateError"}static get unminifiable_name(){return"InvalidUpdateError"}};var c0=class extends OQ{constructor(Q,$){super(Q,$);this.name="UnreachableNodeError"}static get unminifiable_name(){return"UnreachableNodeError"}};var B0=class extends OQ{constructor(Q,$){super(Q,$);this.name="StateGraphInputError",this.message="Invalid StateGraph input. Make sure to pass a valid StateDefinition, Annotation.Root, or Zod schema."}static get unminifiable_name(){return"StateGraphInputError"}};var V=(Q)=>BigInt(Q),C=(Q,$=0)=>new DataView(Q.buffer,Q.byteOffset+$,Q.byteLength-$),O$=V("0x9E3779B1"),P$=V("0x85EBCA77"),_1=V("0xC2B2AE3D"),lQ=V("0x9E3779B185EBCA87"),eQ=V("0xC2B2AE3D27D4EB4F"),w$=V("0x165667B19E3779F9"),_8=V("0x85EBCA77C2B2AE63"),N1=V("0x27D4EB2F165667C5"),I1=V("0x165667919E3779F9"),y1=V("0x9FB21C651E98DF25"),E1=(Q)=>{let $=Q.length;if($%2!==0)throw Error("String should have an even number of characters");let J=$/2,Z=new Uint8Array(J),q=0,z=0;while(z<J){let Y=Q.slice(q,q+=2);Z[z]=Number.parseInt(Y,16),z+=1}return C(Z)},RQ=E1("b8fe6c3923a44bbe7c01812cf721ad1cded46de9839097db7240a4a4b7b3671fcb79e64eccc0e578825ad07dccff7221b8084674f743248ee03590e6813a264c3c2852bb91c300cb88d0658b1b532ea371644897a20df94e3819ef46a9deacd8a8fa763fe39c343ff9dcbbc7c70b4f1d8a51e04bcdb45931c89f7ec9d9787364eac5ac8334d3ebc3c581a0fffa1363eb170ddd51b7f0da49d316552629d4689e2b16be587d47a1fc8ff8b8d17ad031ce45cb3a8f95160428afd7fbcabb4b407e"),L0=(V(1)<<V(128))-V(1),R=(V(1)<<V(64))-V(1),n0=(V(1)<<V(32))-V(1);function W0(Q){if(!Q)throw Error("Assert failed")}function v1(Q){let $=new DataView(new ArrayBuffer(8));return $.setBigUint64(0,Q,!0),$.getBigUint64(0,!1)}function C1(Q){let $=Q;return $=($&V(65535))<<V(16)|($&V(4294901760))>>V(16),$=($&V(16711935))<<V(8)|($&V(4278255360))>>V(8),$}function f1(Q,$){return(Q&n0)*($&n0)&R}function k1(Q,$){return(Q<<$|Q>>V(32)-$)&n0}function R$(Q,$,J){for(let Z=0;Z<8;Z+=1){let q=$.getBigUint64(Z*8,!0),z=q^J.getBigUint64(Z*8,!0);Q[Z^1]+=q,Q[Z]+=f1(z,z>>V(32))}return Q}function M$(Q,$,J,Z){for(let q=0;q<Z;q+=1)R$(Q,C($,q*64),C(J,q*8));return Q}function g1(Q,$){for(let J=0;J<8;J+=1){let Z=$.getBigUint64(J*8,!0),q=Q[J];q=b8(q,V(47)),q^=Z,q*=O$,Q[J]=q&R}return Q}function i0(Q,$){return T$(Q[0]^$.getBigUint64(0,!0),Q[1]^$.getBigUint64(8,!0))}function x$(Q,$,J){let Z=J;return Z+=i0(Q.slice(0),C($,0)),Z+=i0(Q.slice(2),C($,16)),Z+=i0(Q.slice(4),C($,32)),Z+=i0(Q.slice(6),C($,48)),TQ(Z&R)}function m1(Q,$,J,Z,q){let z=Q,Y=Math.floor((J.byteLength-64)/8),X=64*Y,B=Math.floor(($.byteLength-1)/X);for(let F=0;F<B;F+=1)z=M$(z,C($,F*X),J,Y),z=q(z,C(J,J.byteLength-64));{let F=Math.floor(($.byteLength-1-X*B)/64);z=M$(z,C($,B*X),J,F),z=Z(z,C($,$.byteLength-64),C(J,J.byteLength-64-7))}return z}function h1(Q,$){let J=new BigUint64Array([_1,lQ,eQ,w$,_8,P$,N1,O$]);W0(Q.byteLength>128),J=m1(J,Q,$,R$,g1),W0(J.length*8===64);{let Z=x$(J,C($,11),V(Q.byteLength)*lQ&R);return x$(J,C($,$.byteLength-64-11),~(V(Q.byteLength)*eQ)&R)<<V(64)|Z}}function T$(Q,$){let J=Q*$&L0;return J&R^J>>V(64)}function A$(Q,$,J){return T$((Q.getBigUint64(0,!0)^$.getBigUint64(0,!0)+J)&R,(Q.getBigUint64(8,!0)^$.getBigUint64(8,!0)-J)&R)}function r0(Q,$,J,Z,q){let z=Q&R,Y=Q>>V(64)&R;return z+=A$($,Z,q),z^=J.getBigUint64(0,!0)+J.getBigUint64(8,!0),z&=R,Y+=A$(J,C(Z,16),q),Y^=$.getBigUint64(0,!0)+$.getBigUint64(8,!0),Y&=R,Y<<V(64)|z}function TQ(Q){let $=Q;return $^=$>>V(37),$*=I1,$&=R,$^=$>>V(32),$}function s0(Q){let $=Q;return $^=$>>V(33),$*=eQ,$&=R,$^=$>>V(29),$*=w$,$&=R,$^=$>>V(32),$}function u1(Q,$,J){let Z=Q.byteLength;W0(Z>0&&Z<=3);let q=V(Q.getUint8(Z-1))|V(Z<<8)|V(Q.getUint8(0)<<16)|V(Q.getUint8(Z>>1)<<24),z=(q^(V($.getUint32(0,!0))^V($.getUint32(4,!0)))+J)&R,Y=(V($.getUint32(8,!0))^V($.getUint32(12,!0)))-J;return(s0((k1(C1(q),V(13))^Y)&R)&R)<<V(64)|s0(z)}function b8(Q,$){return Q^Q>>$}function d1(Q,$,J){let Z=Q.byteLength;W0(Z>=4&&Z<=8);{let q=Q.getUint32(0,!0),z=Q.getUint32(Z-4,!0),Y=((V(q)|V(z)<<V(32))^($.getBigUint64(16,!0)^$.getBigUint64(24,!0))+J&R)*(lQ+(V(Z)<<V(2)))&L0;return Y+=(Y&R)<<V(65),Y&=L0,Y^=Y>>V(67),b8(b8(Y&R,V(35))*y1&R,V(28))|TQ(Y>>V(64))<<V(64)}}function p1(Q,$,J){let Z=Q.byteLength;W0(Z>=9&&Z<=16);{let q=($.getBigUint64(32,!0)^$.getBigUint64(40,!0))+J&R,z=($.getBigUint64(48,!0)^$.getBigUint64(56,!0))-J&R,Y=Q.getBigUint64(0,!0),X=Q.getBigUint64(Z-8,!0),B=(Y^X^q)*lQ,F=(B&R)+(V(Z-1)<<V(54));B=B&(L0^R)|F,X^=z,B+=X+(X&n0)*(P$-V(1))<<V(64),B&=L0,B^=v1(B>>V(64));let W=(B&R)*eQ;return W+=(B>>V(64))*eQ<<V(64),W&=L0,TQ(W&R)|TQ(W>>V(64))<<V(64)}}function l1(Q,$){let J=Q.byteLength;if(W0(J<=16),J>8)return p1(Q,RQ,$);if(J>=4)return d1(Q,RQ,$);if(J>0)return u1(Q,RQ,$);return s0($^RQ.getBigUint64(64,!0)^RQ.getBigUint64(72,!0))|s0($^RQ.getBigUint64(80,!0)^RQ.getBigUint64(88,!0))<<V(64)}function S8(Q){return~Q+V(1)&R}function o1(Q,$,J){let Z=V(Q.byteLength)*lQ&R,q=V(Q.byteLength-1)/V(32);while(q>=0){let X=Number(q);Z=r0(Z,C(Q,16*X),C(Q,Q.byteLength-16*(X+1)),C($,32*X),J),q-=V(1)}let z=Z+(Z>>V(64))&R;z=TQ(z);let Y=(Z&R)*lQ+(Z>>V(64))*_8+(V(Q.byteLength)-J&R)*eQ;return Y&=R,Y=S8(TQ(Y)),z|Y<<V(64)}function c1(Q,$,J){let Z=V(Q.byteLength)*lQ&R;for(let Y=32;Y<160;Y+=32)Z=r0(Z,C(Q,Y-32),C(Q,Y-16),C($,Y-32),J);Z=TQ(Z&R)|TQ(Z>>V(64))<<V(64);for(let Y=160;Y<=Q.byteLength;Y+=32)Z=r0(Z,C(Q,Y-32),C(Q,Y-16),C($,3+Y-160),J);Z=r0(Z,C(Q,Q.byteLength-16),C(Q,Q.byteLength-32),C($,103),S8(J));let q=Z+(Z>>V(64))&R;q=TQ(q);let z=(Z&R)*lQ+(Z>>V(64))*_8+(V(Q.byteLength)-J&R)*eQ;return z&=R,z=S8(TQ(z)),q|z<<V(64)}function vQ(Q,$=V(0)){let Z=C(typeof Q==="string"?new TextEncoder().encode(Q):Q),q=Z.byteLength,z=(Y)=>Y.toString(16).padStart(32,"0");if(q<=16)return z(l1(Z,$));if(q<=128)return z(o1(Z,RQ,$));if(q<=240)return z(c1(Z,RQ,$));return z(h1(Z,RQ))}function t0(Q){return/^[0-9a-f]{32}$/.test(Q)}function N8(Q){let $=QQ.getRunnableConfig();if(!$)throw Error("Called interrupt() outside the context of a graph.");let J=$.configurable;if(!J)throw Error("No configurable found in config");if(!J[m])throw new dQ("No checkpointer set",{lc_error_code:"MISSING_CHECKPOINTER"});let Z=J[JQ];Z.interruptCounter+=1;let q=Z.interruptCounter;if(Z.resume.length>0&&q<Z.resume.length)return J[WQ]?.([[o,Z.resume]]),Z.resume[q];if(Z.nullResume!==void 0){if(Z.resume.length!==q)throw Error(`Resume length mismatch: ${Z.resume.length} !== ${q}`);let Y=Z.consumeNullResume();return Z.resume.push(Y),J[WQ]?.([[o,Z.resume]]),Y}let z=J[FQ]?.split(k);throw new PQ([{id:z?vQ(z.join(k)):void 0,value:Q}])}var I8=Symbol.for("langgraph.state.reduced_value"),BQ=class{[I8]=!0;valueSchema;inputSchema;reducer;jsonSchemaExtra;constructor(Q,$){this.reducer=$.reducer,this.jsonSchemaExtra=$.jsonSchemaExtra,this.valueSchema=Q,this.inputSchema="inputSchema"in $?$.inputSchema:Q,this.jsonSchemaExtra=$.jsonSchemaExtra}static isInstance(Q){return typeof Q==="object"&&Q!==null&&I8 in Q&&Q[I8]===!0}};function E8(Q){return Q!=null&&Q.lg_is_channel===!0}var l=class{ValueType;UpdateType;lg_is_channel=!0;consume(){return!1}finish(){return!1}isAvailable(){try{return this.get(),!0}catch(Q){if(Q.name===v.unminifiable_name)return!1;throw Q}}equals(Q){return this===Q}},y8=Symbol.for("LG_IS_ONLY_BASE_CHANNEL");function w0(Q){if(Q[y8]===!0)return Q;let $={};for(let J in Q){if(!Object.prototype.hasOwnProperty.call(Q,J))continue;let Z=Q[J];if(E8(Z))$[J]=Z}return Object.assign($,{[y8]:!0}),$}function oQ(Q,$){let J=w0(Q),Z={};for(let q in J){if(!Object.prototype.hasOwnProperty.call(J,q))continue;let z=$.channel_values[q];Z[q]=J[q].fromCheckpoint(z)}return Object.assign(Z,{[y8]:!0}),Z}function HQ(Q,$,J,Z){let q;if($===void 0)q=Q.channel_values;else{q={};for(let z in $){if(!Object.prototype.hasOwnProperty.call($,z))continue;try{q[z]=$[z].checkpoint()}catch(Y){if(Y.name===v.unminifiable_name);else throw Y}}}return{v:4,id:Z?.id??b$(J),ts:new Date().toISOString(),channel_values:q,channel_versions:Q.channel_versions,versions_seen:Q.versions_seen}}var i1=(Q)=>{return Q!=null&&Q.lc_graph_name==="BinaryOperatorAggregate"},bQ=class Q extends l{lc_graph_name="BinaryOperatorAggregate";value;operator;initialValueFactory;constructor($,J){super();this.operator=$,this.initialValueFactory=J,this.value=J?.()}fromCheckpoint($){let J=new Q(this.operator,this.initialValueFactory);if(typeof $<"u")J.value=$;return J}update($){let J=$;if(!J.length)return!1;if(this.value===void 0){let q=J[0],[z,Y]=d0(q);if(z)this.value=Y;else this.value=q;J=J.slice(1)}let Z=!1;for(let q of J)if(K$(q)){if(Z)throw new w("Can receive only one Overwrite value per step.");let[,z]=d0(q);this.value=z,Z=!0;continue}else if(!Z&&this.value!==void 0)this.value=this.operator(this.value,q);return!0}get(){if(this.value===void 0)throw new v;return this.value}checkpoint(){if(this.value===void 0)throw new v;return this.value}isAvailable(){return this.value!==void 0}equals($){if(this===$)return!0;if(!i1($))return!1;return this.operator===$.operator}};var UQ=class Q extends l{lc_graph_name="LastValue";value=[];constructor($){super();if(this.initialValueFactory=$,$)this.value=[$()]}fromCheckpoint($){let J=new Q(this.initialValueFactory);if(typeof $<"u")J.value=[$];return J}update($){if($.length===0)return!1;if($.length!==1)throw new w("LastValue can only receive one value per step.",{lc_error_code:"INVALID_CONCURRENT_GRAPH_UPDATE"});return this.value=[$[$.length-1]],!0}get(){if(this.value.length===0)throw new v;return this.value[0]}checkpoint(){if(this.value.length===0)throw new v;return this.value[0]}isAvailable(){return this.value.length!==0}},v8=class Q extends l{lc_graph_name="LastValueAfterFinish";value=[];finished=!1;fromCheckpoint($){let J=new Q;if(typeof $<"u"){let[Z,q]=$;J.value=[Z],J.finished=q}return J}update($){if($.length===0)return!1;return this.finished=!1,this.value=[$[$.length-1]],!0}get(){if(this.value.length===0||!this.finished)throw new v;return this.value[0]}checkpoint(){if(this.value.length===0)return;return[this.value[0],this.finished]}consume(){if(this.finished)return this.finished=!1,this.value=[],!0;return!1}finish(){if(!this.finished&&this.value.length>0)return this.finished=!0,!0;return!1}isAvailable(){return this.value.length!==0&&this.finished}};function SQ(Q){return typeof Q==="object"&&Q!==null&&"~standard"in Q&&typeof Q["~standard"]==="object"&&Q["~standard"]!==null&&"validate"in Q["~standard"]}function S$(Q){return typeof Q==="object"&&Q!==null&&"~standard"in Q&&typeof Q["~standard"]==="object"&&Q["~standard"]!==null&&"jsonSchema"in Q["~standard"]}function _Q(Q){if(S$(Q))try{return Q["~standard"].jsonSchema.input({target:"draft-07"})}catch{return}}function NQ(Q){if(Q==null)return;if(!SQ(Q))return;try{let $=Q["~standard"].validate(void 0);if($&&typeof $==="object"&&!(("then"in $)&&typeof $.then==="function")){let J=$;if(!J.issues){let Z=J.value;return()=>Z}}}catch{}}var C8=Symbol.for("langgraph.channel.missing"),R0=class Q extends l{lc_graph_name="UntrackedValue";guard;_value=C8;initialValueFactory;constructor($){super();if(this.guard=$?.guard??!0,this.initialValueFactory=$?.initialValueFactory,this.initialValueFactory)this._value=this.initialValueFactory()}fromCheckpoint($){return new Q({guard:this.guard,initialValueFactory:this.initialValueFactory})}update($){if($.length===0)return!1;if($.length!==1&&this.guard)throw new w("UntrackedValue(guard=true) can receive only one value per step. Use guard=false if you want to store any one of multiple values.",{lc_error_code:"INVALID_CONCURRENT_GRAPH_UPDATE"});return this._value=$[$.length-1],!0}get(){if(this._value===C8)throw new v;return this._value}checkpoint(){}isAvailable(){return this._value!==C8}};var f8=class Q extends l{lc_graph_name="Topic";unique=!1;accumulate=!1;seen;values;constructor($){super();this.unique=$?.unique??this.unique,this.accumulate=$?.accumulate??this.accumulate,this.seen=new Set,this.values=[]}fromCheckpoint($){let J=new Q({unique:this.unique,accumulate:this.accumulate});if(typeof $<"u")J.seen=new Set($[0]),J.values=$[1];return J}update($){let J=!1;if(!this.accumulate)J=this.values.length>0,this.values=[];let Z=$.flat();if(Z.length>0)if(this.unique){for(let q of Z)if(!this.seen.has(q))J=!0,this.seen.add(q),this.values.push(q)}else J=!0,this.values.push(...Z);return J}get(){if(this.values.length===0)throw new v;return this.values}checkpoint(){return[[...this.seen],this.values]}isAvailable(){return this.values.length!==0}};var VQ=class Q extends l{lc_graph_name="EphemeralValue";guard;value=[];constructor($=!0){super();this.guard=$}fromCheckpoint($){let J=new Q(this.guard);if(typeof $<"u")J.value=[$];return J}update($){if($.length===0){let J=this.value.length>0;return this.value=[],J}if($.length!==1&&this.guard)throw new w("EphemeralValue can only receive one value per step.");return this.value=[$[$.length-1]],!0}get(){if(this.value.length===0)throw new v;return this.value[0]}checkpoint(){if(this.value.length===0)throw new v;return this.value[0]}isAvailable(){return this.value.length!==0}};var cQ=(Q,$)=>Q.size===$.size&&[...Q].every((J)=>$.has(J)),k8=class Q extends l{lc_graph_name="NamedBarrierValue";names;seen;constructor($){super();this.names=$,this.seen=new Set}fromCheckpoint($){let J=new Q(this.names);if(typeof $<"u")J.seen=new Set($);return J}update($){let J=!1;for(let Z of $)if(this.names.has(Z)){if(!this.seen.has(Z))this.seen.add(Z),J=!0}else throw new w(`Value ${JSON.stringify(Z)} not in names ${JSON.stringify(this.names)}`);return J}get(){if(!cQ(this.names,this.seen))throw new v}checkpoint(){return[...this.seen]}consume(){if(this.seen&&this.names&&cQ(this.seen,this.names))return this.seen=new Set,!0;return!1}isAvailable(){return!!this.names&&cQ(this.names,this.seen)}},g8=class Q extends l{lc_graph_name="NamedBarrierValueAfterFinish";names;seen;finished;constructor($){super();this.names=$,this.seen=new Set,this.finished=!1}fromCheckpoint($){let J=new Q(this.names);if(typeof $<"u"){let[Z,q]=$;J.seen=new Set(Z),J.finished=q}return J}update($){let J=!1;for(let Z of $)if(this.names.has(Z)&&!this.seen.has(Z))this.seen.add(Z),J=!0;else if(!this.names.has(Z))throw new w(`Value ${JSON.stringify(Z)} not in names ${JSON.stringify(this.names)}`);return J}get(){if(!this.finished||!cQ(this.names,this.seen))throw new v}checkpoint(){return[[...this.seen],this.finished]}consume(){if(this.finished&&this.seen&&this.names&&cQ(this.seen,this.names))return this.seen=new Set,this.finished=!1,!0;return!1}finish(){if(!this.finished&&!!this.names&&cQ(this.names,this.seen))return this.finished=!0,!0;return!1}isAvailable(){return this.finished&&!!this.names&&cQ(this.names,this.seen)}};var _$=Symbol.for("langgraph.state.untracked_value"),IQ=class{[_$]=!0;schema;guard;constructor(Q,$){this.schema=Q,this.guard=$?.guard??!0}static isInstance(Q){return typeof Q==="object"&&Q!==null&&_$ in Q}};var m8=Symbol.for("langgraph.state.state_schema"),LQ=class{[m8]=!0;constructor(Q){this.fields=Q}getChannels(){let Q={};for(let[$,J]of Object.entries(this.fields))if(BQ.isInstance(J)){let Z=NQ(J.valueSchema);Q[$]=new bQ(J.reducer,Z)}else if(IQ.isInstance(J)){let Z=J.schema?NQ(J.schema):void 0;Q[$]=new R0({guard:J.guard,initialValueFactory:Z})}else if(SQ(J))Q[$]=new UQ(NQ(J));else throw Error(`Invalid state field "${$}": must be a schema, ReducedValue, UntrackedValue, or ManagedValue`);return Q}getJsonSchema(){let Q={},$=[];for(let[J,Z]of Object.entries(this.fields)){let q;if(BQ.isInstance(Z)){if(q=_Q(Z.valueSchema),Z.jsonSchemaExtra)q={...q??{},...Z.jsonSchemaExtra}}else if(IQ.isInstance(Z))q=Z.schema?_Q(Z.schema):void 0;else if(SQ(Z))q=_Q(Z);if(q){Q[J]=q;let z=!1;if(BQ.isInstance(Z))z=NQ(Z.valueSchema)!==void 0;else if(IQ.isInstance(Z))z=Z.schema?NQ(Z.schema)!==void 0:!1;else z=NQ(Z)!==void 0;if(!z)$.push(J)}}return{type:"object",properties:Q,required:$.length>0?$:void 0}}getInputJsonSchema(){let Q={};for(let[$,J]of Object.entries(this.fields)){let Z;if(BQ.isInstance(J))Z=_Q(J.inputSchema);else if(IQ.isInstance(J))Z=J.schema?_Q(J.schema):void 0;else if(SQ(J))Z=_Q(J);if(Z)Q[$]=Z}return{type:"object",properties:Q}}getChannelKeys(){return Object.entries(this.fields).map(([Q])=>Q)}getAllKeys(){return Object.keys(this.fields)}async validateInput(Q){if(Q==null||typeof Q!=="object")return Q;let $={};for(let[J,Z]of Object.entries(Q)){let q=this.fields[J];if(q===void 0){$[J]=Z;continue}let z;if(BQ.isInstance(q))z=q.inputSchema;else if(IQ.isInstance(q))z=q.schema;else if(SQ(q))z=q;if(z){let Y=await z["~standard"].validate(Z);if(Y.issues)throw Error(`Validation failed for field "${J}": ${JSON.stringify(Y.issues)}`);$[J]=Y.value}else $[J]=Z}return $}static isInstance(Q){return typeof Q==="object"&&Q!==null&&m8 in Q&&Q[m8]===!0}};N$();var Q8="__remove_all__";function CQ(Q,$){let J=Array.isArray(Q)?Q:[Q],Z=Array.isArray($)?$:[$],q=J.map(e0),z=Z.map(e0);for(let W of q)if(W.id===null||W.id===void 0)W.id=h8(),W.lc_kwargs.id=W.id;let Y;for(let W=0;W<z.length;W+=1){let L=z[W];if(L.id===null||L.id===void 0)L.id=h8(),L.lc_kwargs.id=L.id;if(a0.isInstance(L)&&L.id===Q8)Y=W}if(Y!=null)return z.slice(Y+1);let X=[...q],B=new Map(X.map((W,L)=>[W.id,L])),F=new Set;for(let W of z){let L=B.get(W.id);if(L!==void 0)if(a0.isInstance(W))F.add(W.id);else F.delete(W.id),X[L]=W;else{if(a0.isInstance(W))throw Error(`Attempting to delete a message with an ID that doesn't exist ('${W.id}')`);B.set(W.id,X.length),X.push(W)}}return X.filter((W)=>!F.has(W.id))}var r1=iQ.custom().default(()=>[]),n1=iQ.custom(),$8=new BQ(r1,{inputSchema:n1,reducer:CQ,jsonSchemaExtra:{langgraph_type:"messages",description:"A list of chat messages"}});import{AsyncLocalStorage as s1}from"node:async_hooks";function I$(){QQ.initializeGlobalInstance(new s1)}var T0=class{lc_graph_name="AnnotationRoot";spec;constructor(Q){this.spec=Q}static isInstance(Q){return typeof Q==="object"&&Q!==null&&"lc_graph_name"in Q&&Q.lc_graph_name==="AnnotationRoot"}},Q0=function(Q){if(Q)return J8(Q);else return new UQ};Q0.Root=(Q)=>new T0(Q);function J8(Q){if(typeof Q==="object"&&Q&&"reducer"in Q&&Q.reducer)return new bQ(Q.reducer,Q.default);if(typeof Q==="object"&&Q&&"value"in Q&&Q.value)return new bQ(Q.value,Q.default);return new UQ}var t1=["tags","metadata","callbacks","configurable"],a1=["tags","metadata","callbacks","runName","maxConcurrency","recursionLimit","configurable","runId","outputKeys","streamMode","store","writer","interrupt","context","interruptBefore","interruptAfter","checkpointDuring","durability","signal"],e1=25;function b0(...Q){let $={tags:[],metadata:{},callbacks:void 0,recursionLimit:e1,configurable:{}},J=QQ.getRunnableConfig();if(J!==void 0){for(let[Z,q]of Object.entries(J))if(q!==void 0)if(t1.includes(Z)){let z;if(Array.isArray(q))z=[...q];else if(typeof q==="object")if(Z==="callbacks"&&"copy"in q&&typeof q.copy==="function")z=q.copy();else z={...q};else z=q;$[Z]=z}else $[Z]=q}for(let Z of Q){if(Z===void 0)continue;for(let[q,z]of Object.entries(Z))if(z!==void 0&&a1.includes(q))$[q]=z}for(let[Z,q]of Object.entries($.configurable))if($.metadata=$.metadata??{},!Z.startsWith("__")&&(typeof q==="string"||typeof q==="number"||typeof q==="boolean")&&!(Z in $.metadata))$.metadata[Z]=q;return $}function u8(){return QQ.getRunnableConfig()}function Q6(Q){let $=Q??QQ.getRunnableConfig();if($===void 0)throw Error(["Config not retrievable. This is likely because you are running in an environment without support for AsyncLocalStorage.","If you're running `getCurrentTaskInput` in such environment, pass the `config` from the node function directly."].join(`
5
+ `));if($.configurable?.[JQ]?.currentTaskInput===void 0)throw Error("BUG: internal scratchpad not initialized.");return $.configurable[JQ].currentTaskInput}function Z8(Q){return Q.split(k).filter(($)=>!$.match(/^\d+$/)).map(($)=>$.split(e)[0]).join(k)}function y$(Q){let $=Q.split(k);while($.length>1&&$[$.length-1].match(/^\d+$/))$.pop();return $.slice(0,-1).join(k)}var s=class extends YQ{lc_namespace=["langgraph"];func;tags;config;trace=!0;recurse=!0;constructor(Q){super();this.name=Q.name??Q.func.name,this.func=Q.func,this.config=Q.tags?{tags:Q.tags}:void 0,this.trace=Q.trace??this.trace,this.recurse=Q.recurse??this.recurse}async _tracedInvoke(Q,$,J){return new Promise((Z,q)=>{let z=rQ($,{callbacks:J?.getChild()});QQ.runWithConfig(z,async()=>{try{Z(await this.func(Q,z))}catch(Y){q(Y)}})})}async invoke(Q,$){let J,Z=b0($),q=DQ(this.config,Z);if(this.trace)J=await this._callWithConfig(this._tracedInvoke,Q,q);else J=await QQ.runWithConfig(q,async()=>this.func(Q,q));if(YQ.isRunnable(J)&&this.recurse)return await QQ.runWithConfig(q,async()=>J.invoke(Q,q));return J}};function*fQ(Q,$){if($===void 0)yield*Q;else for(let J of Q)yield[$,J]}async function GQ(Q){let $=[];for await(let J of await Q)$.push(J);return $}function $0(Q){let $=[];for(let J of Q)$.push(J);return $}function J0(Q,$){if(!Q)return{configurable:$};else if(!("configurable"in Q))return{...Q,configurable:$};else return{...Q,configurable:{...Q.configurable,...$}}}function E$(Q){return Q!=null&&typeof Q==="function"&&Q instanceof Object.getPrototypeOf(async function*(){}).constructor}function v$(Q){return Q!=null&&typeof Q==="function"&&Q instanceof Object.getPrototypeOf(function*(){}).constructor}var gZ={[Symbol.for("LG_SKIP_WRITE")]:!0};function $6(Q){return typeof Q==="object"&&Q?.[Symbol.for("LG_SKIP_WRITE")]!==void 0}var qQ={[Symbol.for("LG_PASSTHROUGH")]:!0};function q8(Q){return typeof Q==="object"&&Q?.[Symbol.for("LG_PASSTHROUGH")]!==void 0}var d8=Symbol("IS_WRITER"),h=class Q extends s{writes;constructor($,J){let Z=`ChannelWrite<${$.map((q)=>{if(d(q))return q.node;else if("channel"in q)return q.channel;return"..."}).join(",")}>`;super({writes:$,name:Z,tags:J,trace:!1,func:async(q,z)=>{return this._write(q,z??{})}});this.writes=$}async _write($,J){let Z=this.writes.map((q)=>{if(p8(q)&&q8(q.value))return{mapper:q.mapper,value:$};else if(z8(q)&&q8(q.value))return{channel:q.channel,value:$,skipNone:q.skipNone,mapper:q.mapper};else return q});return await Q.doWrite(J,Z),$}static async doWrite($,J){for(let z of J){if(z8(z)){if(z.channel===c)throw new w("Cannot write to the reserved channel TASKS");if(q8(z.value))throw new w("PASSTHROUGH value must be replaced")}if(p8(z)){if(q8(z.value))throw new w("PASSTHROUGH value must be replaced")}}let Z=[];for(let z of J)if(d(z))Z.push([c,z]);else if(p8(z)){let Y=await z.mapper.invoke(z.value,$);if(Y!=null&&Y.length>0)Z.push(...Y)}else if(z8(z)){let Y=z.mapper!==void 0?await z.mapper.invoke(z.value,$):z.value;if($6(Y))continue;if(z.skipNone&&Y===void 0)continue;Z.push([z.channel,Y])}else throw Error(`Invalid write entry: ${JSON.stringify(z)}`);let q=$.configurable?.[WQ];q(Z)}static isWriter($){return $ instanceof Q||d8 in $&&!!$[d8]}static registerWriter($){return Object.defineProperty($,d8,{value:!0})}};function z8(Q){return Q!==void 0&&typeof Q.channel==="string"}function p8(Q){return Q!==void 0&&!z8(Q)&&YQ.isRunnable(Q.mapper)}var k$=class Q extends s{lc_graph_name="ChannelRead";channel;fresh=!1;mapper;constructor($,J,Z=!1){super({trace:!1,func:(q,z)=>Q.doRead(z,this.channel,this.fresh,this.mapper)});this.fresh=Z,this.mapper=J,this.channel=$,this.name=Array.isArray($)?`ChannelRead<${$.join(",")}>`:`ChannelRead<${$}>`}static doRead($,J,Z,q){let z=$.configurable?.[AQ];if(!z)throw Error("Runnable is not configured with a read function. Make sure to call in the context of a Pregel process");if(q)return q(z(J,Z));else return z(J,Z)}},j0=new f$,KQ=class Q extends C${lc_graph_name="PregelNode";channels;triggers=[];mapper;writers=[];bound=j0;kwargs={};metadata={};tags=[];retryPolicy;cachePolicy;subgraphs;ends;constructor($){let{channels:J,triggers:Z,mapper:q,writers:z,bound:Y,kwargs:X,metadata:B,retryPolicy:F,cachePolicy:W,tags:L,subgraphs:H,ends:j}=$,U=[...$.config?.tags?$.config.tags:[],...L??[]];super({...$,bound:$.bound??j0,config:{...$.config?$.config:{},tags:U}});this.channels=J,this.triggers=Z,this.mapper=q,this.writers=z??this.writers,this.bound=Y??this.bound,this.kwargs=X??this.kwargs,this.metadata=B??this.metadata,this.tags=U,this.retryPolicy=F,this.cachePolicy=W,this.subgraphs=H,this.ends=j}getWriters(){let $=[...this.writers];while($.length>1&&$[$.length-1]instanceof h&&$[$.length-2]instanceof h){let J=$.slice(-2),Z=J[0].writes.concat(J[1].writes);$[$.length-2]=new h(Z,J[0].config?.tags),$.pop()}return $}getNode(){let $=this.getWriters();if(this.bound===j0&&$.length===0)return;else if(this.bound===j0&&$.length===1)return $[0];else if(this.bound===j0)return new Z0({first:$[0],middle:$.slice(1,$.length-1),last:$[$.length-1],omitSequenceTags:!0});else if($.length>0)return new Z0({first:this.bound,middle:$.slice(0,$.length-1),last:$[$.length-1],omitSequenceTags:!0});else return this.bound}join($){if(!Array.isArray($))throw Error("channels must be a list");if(typeof this.channels!=="object")throw Error("all channels must be named when using .join()");return new Q({channels:{...this.channels,...Object.fromEntries($.map((J)=>[J,J]))},triggers:this.triggers,mapper:this.mapper,writers:this.writers,bound:this.bound,kwargs:this.kwargs,config:this.config,retryPolicy:this.retryPolicy,cachePolicy:this.cachePolicy})}pipe($){if(h.isWriter($))return new Q({channels:this.channels,triggers:this.triggers,mapper:this.mapper,writers:[...this.writers,$],bound:this.bound,config:this.config,kwargs:this.kwargs,retryPolicy:this.retryPolicy,cachePolicy:this.cachePolicy});else if(this.bound===j0)return new Q({channels:this.channels,triggers:this.triggers,mapper:this.mapper,writers:this.writers,bound:yQ($),config:this.config,kwargs:this.kwargs,retryPolicy:this.retryPolicy,cachePolicy:this.cachePolicy});else return new Q({channels:this.channels,triggers:this.triggers,mapper:this.mapper,writers:this.writers,bound:this.bound.pipe($),config:this.config,kwargs:this.kwargs,retryPolicy:this.retryPolicy,cachePolicy:this.cachePolicy})}};function J6(Q){return"steps"in Q&&Array.isArray(Q.steps)}function S0(Q){return"lg_is_pregel"in Q&&Q.lg_is_pregel===!0}function Y8(Q){let $=[Q];for(let J of $)if(S0(J))return J;else if(J6(J))$.push(...J.steps)}function q0(Q,$,J=!0,Z=!1){try{return Q[$].get()}catch(q){if(q.name===v.unminifiable_name){if(Z)return q;else if(J)return null}throw q}}function MQ(Q,$,J=!0){if(Array.isArray($)){let Z={};for(let q of $)try{Z[q]=q0(Q,q,!J)}catch(z){if(z.name===v.unminifiable_name)continue}return Z}else return q0(Q,$)}function*g$(Q,$){if(Q.graph===a.PARENT)throw new w("There is no parent graph.");if(Q.goto){let J;if(Array.isArray(Q.goto))J=Q.goto;else J=[Q.goto];for(let Z of J)if(d(Z))yield[n,c,Z];else if(typeof Z==="string")yield[n,`branch:to:${Z}`,"__start__"];else throw Error(`In Command.send, expected Send or string, got ${typeof Z}`)}if(Q.resume)if(typeof Q.resume==="object"&&Object.keys(Q.resume).length&&Object.keys(Q.resume).every(t0))for(let[J,Z]of Object.entries(Q.resume)){let q=$.filter((z)=>z[0]===J&&z[1]===o).map((z)=>z[2]).slice(0,1)??[];q.push(Z),yield[J,o,q]}else yield[n,o,Q.resume];if(Q.update){if(typeof Q.update!=="object"||!Q.update)throw Error("Expected cmd.update to be a dict mapping channel names to update values");if(Array.isArray(Q.update))for(let[J,Z]of Q.update)yield[n,J,Z];else for(let[J,Z]of Object.entries(Q.update))yield[n,J,Z]}}function*X8(Q,$){if($!==void 0&&$!==null)if(Array.isArray(Q)&&typeof $==="object"&&!Array.isArray($)){for(let J in $)if(Q.includes(J))yield[J,$[J]]}else if(Array.isArray(Q))throw Error('Input chunk must be an object when "inputChannels" is an array');else yield[Q,$]}function*F8(Q,$,J){if(Array.isArray(Q)){if($===!0||$.find(([Z,q])=>Q.includes(Z)))yield MQ(J,Q)}else if($===!0||$.some(([Z,q])=>Z===Q))yield q0(J,Q)}function*m$(Q,$,J){let Z=$.filter(([X,B])=>{return(X.config===void 0||!X.config.tags?.includes(E))&&B[0][0]!==p&&B[0][0]!==S});if(!Z.length)return;let q;if(Z.some(([X])=>X.writes.some(([B,F])=>B===jQ)))q=Z.flatMap(([X])=>X.writes.filter(([B,F])=>B===jQ).map(([B,F])=>[X.name,F]));else if(!Array.isArray(Q))q=Z.flatMap(([X])=>X.writes.filter(([B,F])=>B===Q).map(([B,F])=>[X.name,F]));else q=Z.flatMap(([X])=>{let{writes:B}=X,F={};for(let[W]of B)if(Q.includes(W))F[W]=(F[W]||0)+1;if(Object.values(F).some((W)=>W>1))return B.filter(([W])=>Q.includes(W)).map(([W,L])=>[X.name,{[W]:L}]);else return[[X.name,Object.fromEntries(B.filter(([W])=>Q.includes(W)))]]});let z={};for(let[X,B]of q){if(!(X in z))z[X]=[];z[X].push(B)}let Y={};for(let X in z)if(z[X].length===1){let[B]=z[X];Y[X]=B}else Y[X]=z[X];if(J)Y.__metadata__={cached:J};yield Y}function B8(Q){let $=typeof Q[T];if($==="number")return 0;if($==="string")return"";for(let J in Q){if(!Object.prototype.hasOwnProperty.call(Q,J))continue;let Z=typeof Q[J];if(Z==="number")return 0;if(Z==="string")return"";break}}function H0(Q,$){if(Object.keys(Q).length>0){let J=B8($);return Object.fromEntries(Object.entries($).filter(([Z,q])=>q>(Q[Z]??J)))}else return $}function h$(Q,$){return Q&&!Array.isArray(Q)&&!(Q instanceof Date)&&typeof Q==="object"?Q:{[$]:Q}}function zQ(Q,$){if(Q===null)return{configurable:$};else if(Q?.configurable===void 0)return{...Q,configurable:$};else return{...Q,configurable:{...Q.configurable,...$}}}function nQ(Q,$){let J=$?.parents??{};if(Object.keys(J).length>0)return zQ(Q,{[ZQ]:{...J,[Q.configurable?.checkpoint_ns??""]:Q.configurable?.checkpoint_id}});else return Q}function U0(...Q){let $=[...new Set(Q.filter(Boolean))];if($.length===0)return{signal:void 0,dispose:void 0};if($.length===1)return{signal:$[0],dispose:void 0};let J=new AbortController,Z=()=>{let z=$.find((Y)=>Y.aborted)?.reason;J.abort(z),$.forEach((Y)=>Y.removeEventListener("abort",Z))};$.forEach((z)=>z.addEventListener("abort",Z,{once:!0}));let q=$.find((z)=>z.aborted);if(q)J.abort(q.reason);return{signal:J.signal,dispose:()=>{$.forEach((z)=>z.removeEventListener("abort",Z))}}}var u$=(Q,$)=>{if(!Q&&!$)return;if(!Q)return $;if(!$)return Q;if(Array.isArray(Q)&&Array.isArray($))return[...Q,...$];if(Array.isArray(Q))return[...Q,$];if(Array.isArray($))return[Q,...$];return[Q,$]};var d$=class{func;name;input;retry;cache;callbacks;__lg_type="call";constructor({func:Q,name:$,input:J,retry:Z,cache:q,callbacks:z}){this.func=Q,this.name=$,this.input=J,this.retry=Z,this.cache=q,this.callbacks=z}};function p$(Q){return typeof Q==="object"&&Q!==null&&"__lg_type"in Q&&Q.__lg_type==="call"}function l$(Q,$){return new Z0({name:Q,first:new s({func:(J)=>$(...J),name:Q,trace:!1,recurse:!1}),last:new h([{channel:jQ,value:qQ}],[E])})}function o$(Q,$){return new s({func:(J,Z)=>{return $(J,Z)},name:Q,trace:!1,recurse:!1})}var i$=(Q)=>{return Q!==void 0?Q+1:1};function Z6(Q,$){if($==null)return!1;for(let J of Q)if($[J])return!0;return!1}function q6(Q){let $;for(let J in Q){if(!Object.prototype.hasOwnProperty.call(Q,J))continue;if($==null)$=Q[J];else $=c$($,Q[J])}return $}function N0(Q,$,J){let Z=B8(Q.channel_versions),q=Q.versions_seen[S]??{},z=!1;if((Q.channel_versions[T]??Z)>(q[T]??Z))z=!0;else for(let X in Q.channel_versions){if(!Object.prototype.hasOwnProperty.call(Q.channel_versions,X))continue;if(Q.channel_versions[X]>(q[X]??Z)){z=!0;break}}let Y=J.some((X)=>$==="*"?!X.config?.tags?.includes(E):$.includes(X.name));return z&&Y}function _0(Q,$,J,Z,q=!1){let z=new Set;if(!Array.isArray(Z)){for(let[X]of J.writes)if(X===Z){z=new Set([X]);break}z=z||new Set}else z=new Set(Z.filter((X)=>J.writes.some(([B,F])=>B===X)));let Y;if(q&&z.size>0){let X=Object.fromEntries(Object.entries($).filter(([W,L])=>z.has(W))),B=HQ(Q,X,-1),F=oQ(X,B);$Q(kQ(B),F,[J],void 0,void 0),Y=MQ({...$,...F},Z)}else Y=MQ($,Z);return Y}function l8(Q,$,J){for(let[Z,q]of J)if([r,c].includes(Z)&&q!=null){if(!d(q))throw new w(`Invalid packet type, expected SendProtocol, got ${JSON.stringify(q)}`);if(!(q.node in $))throw new w(`Invalid node name "${q.node}" in Send packet`)}Q(J)}var z6=new Set([m0,r,o,S,jQ,p]);function $Q(Q,$,J,Z,q){J.sort((H,j)=>{let U=H.path?.slice(0,3)||[],D=j.path?.slice(0,3)||[];for(let M=0;M<Math.min(U.length,D.length);M+=1){if(U[M]<D[M])return-1;if(U[M]>D[M])return 1}return U.length-D.length});let z=J.some((H)=>H.triggers.length>0),Y=w0($);for(let H of J){Q.versions_seen[H.name]??={};for(let j of H.triggers)if(j in Q.channel_versions)Q.versions_seen[H.name][j]=Q.channel_versions[j]}let X=q6(Q.channel_versions),B=new Set(J.flatMap((H)=>H.triggers).filter((H)=>!G$.includes(H))),F=!1;for(let H of B)if(H in Y&&Y[H].consume()){if(Z!==void 0)Q.channel_versions[H]=Z(X),F=!0}let W={};for(let H of J)for(let[j,U]of H.writes)if(z6.has(j));else if(j in Y)W[j]??=[],W[j].push(U);if(X!=null&&Z!=null)X=F?Z(X):X;let L=new Set;for(let[H,j]of Object.entries(W))if(H in Y){let U=Y[H],D;try{D=U.update(j)}catch(M){if(M.name===w.unminifiable_name){let O=new w(`Invalid update for channel "${H}" with values ${JSON.stringify(j)}: ${M.message}`);throw O.lc_error_code=M.lc_error_code,O}else throw M}if(D&&Z!==void 0){if(Q.channel_versions[H]=Z(X),U.isAvailable())L.add(H)}}if(z)for(let H in Y){if(!Object.prototype.hasOwnProperty.call(Y,H))continue;let j=Y[H];if(j.isAvailable()&&!L.has(H)){if(j.update([])&&Z!==void 0){if(Q.channel_versions[H]=Z(X),j.isAvailable())L.add(H)}}}if(z&&!Z6(L,q))for(let H in Y){if(!Object.prototype.hasOwnProperty.call(Y,H))continue;let j=Y[H];if(j.finish()&&Z!==void 0){if(Q.channel_versions[H]=Z(X),j.isAvailable())L.add(H)}}return L}function*Y6(Q,$,J){if(J.updatedChannels!=null&&J.triggerToNodes!=null){let Z=new Set;for(let q of J.updatedChannels){let z=J.triggerToNodes[q];for(let Y of z??[])Z.add(Y)}yield*[...Z].sort();return}if((()=>{for(let Z in Q.channel_versions)if(Q.channel_versions[Z]!==null)return!1;return!0})())return;for(let Z in $){if(!Object.prototype.hasOwnProperty.call($,Z))continue;yield Z}}function tQ(Q,$,J,Z,q,z,Y){let X={},B=Z[c];if(B?.isAvailable()){let F=B.get().length;for(let W=0;W<F;W+=1){let L=L8([r,W],Q,$,J,Z,q,z,Y);if(L!==void 0)X[L.id]=L}}for(let F of Y6(Q,J,Y)){let W=L8([x0,F],Q,$,J,Z,q,z,Y);if(W!==void 0)X[W.id]=W}return X}function L8(Q,$,J,Z,q,z,Y,X){let{step:B,checkpointer:F,manager:W}=X,L=z.configurable??{},H=L.checkpoint_ns??"";if(Q[0]===r&&p$(Q[Q.length-1])){let j=Q[Q.length-1],U=l$(j.name,j.func),D=[r],M=H===""?j.name:`${H}${k}${j.name}`,O=sQ(JSON.stringify([M,B.toString(),j.name,r,Q[1],Q[2]]),$.id),_=`${M}${e}${O}`,P=[...Q.slice(0,3),!0],I={langgraph_step:B,langgraph_node:j.name,langgraph_triggers:D,langgraph_path:P,langgraph_checkpoint_ns:_};if(Y){let N=[];return{name:j.name,input:j.input,proc:U,writes:N,config:rQ(DQ(z,{metadata:I,store:X.store??z.store}),{runName:j.name,callbacks:W?.getChild(`graph:step:${B}`),configurable:{[Y0]:O,[WQ]:(f)=>l8((K)=>N.push(...K),Z,f),[AQ]:(f,K=!1)=>_0($,q,{name:j.name,writes:N,triggers:D,path:P},f,K),[m]:F??L[m],[ZQ]:{...L[ZQ],[H]:$.id},[JQ]:o8({pendingWrites:J??[],taskId:O,currentTaskInput:j.input,resumeMap:z.configurable?.[X0],namespaceHash:vQ(_)}),[M0]:$.channel_values[aQ],checkpoint_id:void 0,checkpoint_ns:_}}),triggers:D,retry_policy:j.retry,cache_key:j.cache?{key:vQ((j.cache.keyFunc??JSON.stringify)([j.input])),ns:[k0,j.name??"__dynamic__"],ttl:j.cache.ttl}:void 0,id:O,path:P,writers:[]}}else return{id:O,name:j.name,interrupts:[],path:P}}else if(Q[0]===r){let j=typeof Q[1]==="number"?Q[1]:parseInt(Q[1],10);if(!q[c]?.isAvailable())return;let U=q[c].get();if(j<0||j>=U.length)return;let D=u0(U[j])&&!d(U[j])?new uQ(U[j].node,U[j].args):U[j];if(!u0(D)){console.warn(`Ignoring invalid packet ${JSON.stringify(D)} in pending sends.`);return}if(!(D.node in Z)){console.warn(`Ignoring unknown node name ${D.node} in pending sends.`);return}let M=[r],O=H===""?D.node:`${H}${k}${D.node}`,_=sQ(JSON.stringify([O,B.toString(),D.node,r,j.toString()]),$.id),P=`${O}${e}${_}`,I={langgraph_step:B,langgraph_node:D.node,langgraph_triggers:M,langgraph_path:Q.slice(0,3),langgraph_checkpoint_ns:P};if(Y){let N=Z[D.node],f=N.getNode();if(f!==void 0){if(N.metadata!==void 0)I={...I,...N.metadata};let K=[];return{name:D.node,input:D.args,proc:f,subgraphs:N.subgraphs,writes:K,config:rQ(DQ(z,{metadata:I,tags:N.tags,store:X.store??z.store}),{runName:D.node,callbacks:W?.getChild(`graph:step:${B}`),configurable:{[Y0]:_,[WQ]:(x)=>l8((b)=>K.push(...b),Z,x),[AQ]:(x,b=!1)=>_0($,q,{name:D.node,writes:K,triggers:M,path:Q},x,b),[m]:F??L[m],[ZQ]:{...L[ZQ],[H]:$.id},[JQ]:o8({pendingWrites:J??[],taskId:_,currentTaskInput:D.args,resumeMap:z.configurable?.[X0],namespaceHash:vQ(P)}),[M0]:$.channel_values[aQ],checkpoint_id:void 0,checkpoint_ns:P}}),triggers:M,retry_policy:N.retryPolicy,cache_key:N.cachePolicy?{key:vQ((N.cachePolicy.keyFunc??JSON.stringify)([D.args])),ns:[k0,N.name??"__dynamic__",D.node],ttl:N.cachePolicy.ttl}:void 0,id:_,path:Q,writers:N.getWriters()}}}else return{id:_,name:D.node,interrupts:[],path:Q}}else if(Q[0]===x0){let j=Q[1].toString(),U=Z[j];if(U===void 0)return;if(J?.length){let _=H===""?j:`${H}${k}${j}`,P=sQ(JSON.stringify([_,B.toString(),j,x0,j]),$.id);if(J.some((I)=>I[0]===P&&I[1]!==p))return}let D=B8($.channel_versions);if(D===void 0)return;let M=$.versions_seen[j]??{},O=U.triggers.find((_)=>{if(!q[_].isAvailable())return!1;return($.channel_versions[_]??D)>(M[_]??D)});if(O!==void 0){let _=X6(U,q,Y);if(_===void 0)return;let P=H===""?j:`${H}${k}${j}`,I=sQ(JSON.stringify([P,B.toString(),j,x0,[O]]),$.id),N=`${P}${e}${I}`,f={langgraph_step:B,langgraph_node:j,langgraph_triggers:[O],langgraph_path:Q,langgraph_checkpoint_ns:N};if(Y){let K=U.getNode();if(K!==void 0){if(U.metadata!==void 0)f={...f,...U.metadata};let x=[];return{name:j,input:_,proc:K,subgraphs:U.subgraphs,writes:x,config:rQ(DQ(z,{metadata:f,tags:U.tags,store:X.store??z.store}),{runName:j,callbacks:W?.getChild(`graph:step:${B}`),configurable:{[Y0]:I,[WQ]:(b)=>l8((G)=>{x.push(...G)},Z,b),[AQ]:(b,G=!1)=>_0($,q,{name:j,writes:x,triggers:[O],path:Q},b,G),[m]:F??L[m],[ZQ]:{...L[ZQ],[H]:$.id},[JQ]:o8({pendingWrites:J??[],taskId:I,currentTaskInput:_,resumeMap:z.configurable?.[X0],namespaceHash:vQ(N)}),[M0]:$.channel_values[aQ],checkpoint_id:void 0,checkpoint_ns:N}}),triggers:[O],retry_policy:U.retryPolicy,cache_key:U.cachePolicy?{key:vQ((U.cachePolicy.keyFunc??JSON.stringify)([_])),ns:[k0,U.name??"__dynamic__",j],ttl:U.cachePolicy.ttl}:void 0,id:I,path:Q,writers:U.getWriters()}}}else return{id:I,name:j,interrupts:[],path:Q}}}}function X6(Q,$,J){let Z;if(typeof Q.channels==="object"&&!Array.isArray(Q.channels)){Z={};for(let[q,z]of Object.entries(Q.channels))if(Q.triggers.includes(z))try{Z[q]=q0($,z,!1)}catch(Y){if(Y.name===v.unminifiable_name)return;else throw Y}else if(z in $)try{Z[q]=q0($,z,!1)}catch(Y){if(Y.name===v.unminifiable_name)continue;else throw Y}}else if(Array.isArray(Q.channels)){let q=!1;for(let z of Q.channels)try{Z=q0($,z,!1),q=!0;break}catch(Y){if(Y.name===v.unminifiable_name)continue;else throw Y}if(!q)return}else throw Error(`Invalid channels type, expected list or dict, got ${Q.channels}`);if(J&&Q.mapper!==void 0)Z=Q.mapper(Z);return Z}function r$(Q,$){if(typeof Q.args!=="object"||Q.args===null)return Q;let J={};for(let[Z,q]of Object.entries(Q.args)){let z=$[Z];if(!z||z.lc_graph_name!=="UntrackedValue")J[Z]=q}return new uQ(Q.node,J)}function o8({pendingWrites:Q,taskId:$,currentTaskInput:J,resumeMap:Z,namespaceHash:q}){let z=Q.find(([X,B])=>X===n&&B===o)?.[2],Y={callCounter:0,interruptCounter:-1,resume:(()=>{let X=Q.filter(([B,F])=>B===$&&F===o).flatMap(([B,F,W])=>W);if(Z!=null&&q in Z){let B=Z[q];X.push(B)}return X})(),nullResume:z,subgraphCounter:0,currentTaskInput:J,consumeNullResume:()=>{if(Y.nullResume)return delete Y.nullResume,Q.splice(Q.findIndex(([X,B])=>X===n&&B===o),1),z}};return Y}var I0={blue:{start:"\x1B[34m",end:"\x1B[0m"},green:{start:"\x1B[32m",end:"\x1B[0m"},yellow:{start:"\x1B[33;1m",end:"\x1B[0m"}},y0=(Q,$)=>`${Q.start}${$}${Q.end}`;function*c8(Q){for(let{id:$,name:J,input:Z,config:q,triggers:z,writes:Y}of Q){if(q?.tags?.includes(E))continue;yield{id:$,name:J,input:Z,triggers:z,interrupts:Y.filter(([X,B])=>{return X===$&&B===S}).map(([,X])=>{return X})}}}function F6(Q){if(typeof Q!=="object"||Q===null)return!1;return"$writes"in Q&&Array.isArray(Q.$writes)}function n$(Q){let $={};for(let[J,Z]of Q){let q=String(J);if(q in $){let z=F6($[q])?$[q].$writes:[$[q]];z.push(Z),$[q]={$writes:z}}else $[q]=Z}return $}function*s$(Q,$){for(let[{id:J,name:Z,config:q},z]of Q){if(q?.tags?.includes(E))continue;yield{id:J,name:Z,result:n$(z.filter(([Y])=>{return Array.isArray($)?$.includes(Y):Y===$})),interrupts:z.filter((Y)=>Y[0]===S).map((Y)=>Y[1])}}}function*t$(Q,$,J,Z,q,z,Y,X){function B(L){let H={};if(L.callbacks!=null)H.callbacks=L.callbacks;if(L.configurable!=null)H.configurable=L.configurable;if(L.maxConcurrency!=null)H.max_concurrency=L.maxConcurrency;if(L.metadata!=null)H.metadata=L.metadata;if(L.recursionLimit!=null)H.recursion_limit=L.recursionLimit;if(L.runId!=null)H.run_id=L.runId;if(L.runName!=null)H.run_name=L.runName;if(L.tags!=null)H.tags=L.tags;return H}let F=Q.configurable?.checkpoint_ns,W={};for(let L of q){if(!((L.subgraphs?.length)?L.subgraphs:[L.proc]).find(Y8))continue;let H=`${L.name}:${L.id}`;if(F)H=`${F}|${H}`;W[L.id]={configurable:{thread_id:Q.configurable?.thread_id,checkpoint_ns:H}}}yield{config:B(Q),values:MQ($,J),metadata:Z,next:q.map((L)=>L.name),tasks:i8(q,z,W,X),parentConfig:Y?B(Y):void 0}}function i8(Q,$,J,Z){return Q.map((q)=>{let z=$.find(([F,W])=>F===q.id&&W===p)?.[2],Y=$.filter(([F,W])=>F===q.id&&W===S).map(([,,F])=>F),X=(()=>{if(z||Y.length||!$.length)return;let F=$.findIndex(([W,L])=>W===q.id&&L===jQ);if(F>=0)return $[F][2];if(typeof Z==="string")return $.find(([W,L])=>W===q.id&&L===Z)?.[2];if(Array.isArray(Z)){let W=$.filter(([L,H])=>L===q.id&&Z.includes(H)).map(([,L,H])=>[L,H]);if(!W.length)return;return n$(W)}})();if(z)return{id:q.id,name:q.name,path:q.path,error:z,interrupts:Y,result:X};let B=J?.[q.id];return{id:q.id,name:q.name,path:q.path,interrupts:Y,...B!==void 0?{state:B}:{},result:X}})}function a$(Q,$,J){console.log([`${y0(I0.blue,`[${Q}:checkpoint]`)}`,`\x1B[1m State at the end of step ${Q}:\x1B[0m
6
+ `,JSON.stringify(MQ($,J),null,2)].join(""))}function W8(Q,$){let J=$.length;console.log([`${y0(I0.blue,`[${Q}:tasks]`)}`,`\x1B[1m Starting step ${Q} with ${J} task${J===1?"":"s"}:\x1B[0m
7
7
  `,$.map((Z)=>`- ${y0(I0.green,String(Z.name))} -> ${JSON.stringify(Z.input,null,2)}`).join(`
8
- `)].join(""))}function a$(Q,$,J){let Z={};for(let[q,z]of $)if(J.includes(q)){if(!Z[q])Z[q]=[];Z[q].push(z)}console.log([`${y0(I0.blue,`[${Q}:writes]`)}`,`\x1B[1m Finished step ${Q} with writes to ${Object.keys(Z).length} channel${Object.keys(Z).length!==1?"s":""}:\x1B[0m
8
+ `)].join(""))}function e$(Q,$,J){let Z={};for(let[q,z]of $)if(J.includes(q)){if(!Z[q])Z[q]=[];Z[q].push(z)}console.log([`${y0(I0.blue,`[${Q}:writes]`)}`,`\x1B[1m Finished step ${Q} with writes to ${Object.keys(Z).length} channel${Object.keys(Z).length!==1?"s":""}:\x1B[0m
9
9
  `,Object.entries(Z).map(([q,z])=>`- ${y0(I0.yellow,q)} -> ${z.map((Y)=>JSON.stringify(Y)).join(", ")}`).join(`
10
- `)].join(""))}var n8=class extends r8{_abortController;_innerReader;constructor(Q,$){let J=Q.getReader(),Z=$??new AbortController;super({start(q){return z();function z(){return J.read().then(({done:Y,value:X})=>{if(Y){q.close();return}return q.enqueue(X),z()})}}});this._abortController=Z,this._innerReader=J}async cancel(Q){this._abortController.abort(Q),this._innerReader.releaseLock()}get signal(){return this._abortController.signal}},B8=class extends r8{modes;controller;passthroughFn;_closed=!1;get closed(){return this._closed}constructor(Q){let $,J=new Promise((Z)=>{$=Z});super({start:(Z)=>{$(Z)}});J.then((Z)=>{this.controller=Z}),this.passthroughFn=Q.passthroughFn,this.modes=Q.modes}push(Q){this.passthroughFn?.(Q),this.controller.enqueue(Q)}close(){try{this.controller.close()}catch(Q){}finally{this._closed=!0}}error(Q){this.controller.error(Q)}},$1=class extends F8{name="StreamToolsHandler";streamFn;runs={};constructor(Q){super();this.streamFn=Q}handleToolStart(Q,$,J,Z,q,z,Y,X){if(!z||q&&q.includes(E))return;let B=z.langgraph_checkpoint_ns?.split("|")??[],F={ns:B,toolCallId:X,toolName:Y??"unknown",input:$};this.runs[J]=F,this.streamFn([B,"tools",{event:"on_tool_start",toolCallId:F.toolCallId,name:F.toolName,input:$}])}handleToolEvent(Q,$){let J=this.runs[$];if(!J)return;this.streamFn([J.ns,"tools",{event:"on_tool_event",toolCallId:J.toolCallId,name:J.toolName,data:Q}])}handleToolEnd(Q,$){let J=this.runs[$];if(delete this.runs[$],!J)return;this.streamFn([J.ns,"tools",{event:"on_tool_end",toolCallId:J.toolCallId,name:J.toolName,output:Q}])}handleToolError(Q,$){let J=this.runs[$];if(delete this.runs[$],!J)return;this.streamFn([J.ns,"tools",{event:"on_tool_error",toolCallId:J.toolCallId,name:J.toolName,error:Q}])}};function X6(Q){return JSON.stringify(Q,function($,J){let Z=this[$];if(Z!=null&&typeof Z==="object"&&"toDict"in Z&&typeof Z.toDict==="function"){let{type:q,data:z}=Z.toDict();return{...z,type:q}}return J})}function F6(Q){if(Q instanceof Error)return{error:Q.name,message:Q.message};return{error:"Error",message:JSON.stringify(Q)}}function s8(Q){if(typeof Q!=="object"||Q==null)return!1;return"configurable"in Q&&typeof Q.configurable==="object"&&Q.configurable!=null}function i8(Q){if(!s8(Q)||!Q.configurable.thread_id)return null;return{thread_id:Q.configurable.thread_id,checkpoint_ns:Q.configurable.checkpoint_ns||"",checkpoint_id:Q.configurable.checkpoint_id||null,checkpoint_map:Q.configurable.checkpoint_map||null}}function e$(Q){if(s8(Q)){let $=Object.fromEntries(Object.entries(Q.configurable).filter(([Z])=>!Z.startsWith("__"))),J={...Q,configurable:$};return delete J.callbacks,J}return Q}function Q1(Q){let $={...Q,checkpoint:i8(Q.config),parent_checkpoint:i8(Q.parentConfig),config:e$(Q.config),parent_config:e$(Q.parentConfig),tasks:Q.tasks.map((J)=>{if(s8(J.state)){let Z=i8(J.state);if(Z!=null){let q={...J,checkpoint:Z};return delete q.state,q}}return J})};return delete $.parentConfig,$}function J1(Q){let $=new TextEncoder;return new ReadableStream({async start(J){let Z=(q)=>{J.enqueue($.encode(`event: ${q.event}
11
- data: ${X6(q.data)}
10
+ `)].join(""))}var s8=class extends n8{_abortController;_innerReader;constructor(Q,$){let J=Q.getReader(),Z=$??new AbortController;super({start(q){return z();function z(){return J.read().then(({done:Y,value:X})=>{if(Y){q.close();return}return q.enqueue(X),z()})}}});this._abortController=Z,this._innerReader=J}async cancel(Q){this._abortController.abort(Q),this._innerReader.releaseLock()}get signal(){return this._abortController.signal}},H8=class extends n8{modes;controller;passthroughFn;_closed=!1;get closed(){return this._closed}constructor(Q){let $,J=new Promise((Z)=>{$=Z});super({start:(Z)=>{$(Z)}});J.then((Z)=>{this.controller=Z}),this.passthroughFn=Q.passthroughFn,this.modes=Q.modes}push(Q){this.passthroughFn?.(Q),this.controller.enqueue(Q)}close(){try{this.controller.close()}catch(Q){}finally{this._closed=!0}}error(Q){this.controller.error(Q)}},J1=class extends j8{name="StreamToolsHandler";streamFn;runs={};constructor(Q){super();this.streamFn=Q}handleToolStart(Q,$,J,Z,q,z,Y,X){if(!z||q&&q.includes(E))return;let B=z.langgraph_checkpoint_ns?.split("|")??[],F={ns:B,toolCallId:X,toolName:Y??"unknown",input:$};this.runs[J]=F,this.streamFn([B,"tools",{event:"on_tool_start",toolCallId:F.toolCallId,name:F.toolName,input:$}])}handleToolEvent(Q,$){let J=this.runs[$];if(!J)return;this.streamFn([J.ns,"tools",{event:"on_tool_event",toolCallId:J.toolCallId,name:J.toolName,data:Q}])}handleToolEnd(Q,$){let J=this.runs[$];if(delete this.runs[$],!J)return;this.streamFn([J.ns,"tools",{event:"on_tool_end",toolCallId:J.toolCallId,name:J.toolName,output:Q}])}handleToolError(Q,$){let J=this.runs[$];if(delete this.runs[$],!J)return;this.streamFn([J.ns,"tools",{event:"on_tool_error",toolCallId:J.toolCallId,name:J.toolName,error:Q}])}};function B6(Q){return JSON.stringify(Q,function($,J){let Z=this[$];if(Z!=null&&typeof Z==="object"&&"toDict"in Z&&typeof Z.toDict==="function"){let{type:q,data:z}=Z.toDict();return{...z,type:q}}return J})}function L6(Q){if(Q instanceof Error)return{error:Q.name,message:Q.message};return{error:"Error",message:JSON.stringify(Q)}}function t8(Q){if(typeof Q!=="object"||Q==null)return!1;return"configurable"in Q&&typeof Q.configurable==="object"&&Q.configurable!=null}function r8(Q){if(!t8(Q)||!Q.configurable.thread_id)return null;return{thread_id:Q.configurable.thread_id,checkpoint_ns:Q.configurable.checkpoint_ns||"",checkpoint_id:Q.configurable.checkpoint_id||null,checkpoint_map:Q.configurable.checkpoint_map||null}}function Q1(Q){if(t8(Q)){let $=Object.fromEntries(Object.entries(Q.configurable).filter(([Z])=>!Z.startsWith("__"))),J={...Q,configurable:$};return delete J.callbacks,J}return Q}function $1(Q){let $={...Q,checkpoint:r8(Q.config),parent_checkpoint:r8(Q.parentConfig),config:Q1(Q.config),parent_config:Q1(Q.parentConfig),tasks:Q.tasks.map((J)=>{if(t8(J.state)){let Z=r8(J.state);if(Z!=null){let q={...J,checkpoint:Z};return delete q.state,q}}return J})};return delete $.parentConfig,$}function Z1(Q){let $=new TextEncoder;return new ReadableStream({async start(J){let Z=(q)=>{J.enqueue($.encode(`event: ${q.event}
11
+ data: ${B6(q.data)}
12
12
 
13
- `))};try{for await(let q of Q){let[z,Y,X]=q,B=X;if(Y==="debug"){let F=X;if(F.type==="checkpoint")B={...F,payload:Q1(F.payload)}}if(Y==="checkpoints")B=Q1(X);Z({event:z?.length?`${Y}|${z.join("|")}`:Y,data:B})}}catch(q){Z({event:"error",data:F6(q)})}J.close()}})}var L8=Symbol.for("INPUT_DONE"),t8=Symbol.for("INPUT_RESUMING"),B6=25;function L6(...Q){return new B8({passthroughFn:($)=>{for(let J of Q)if(J.modes.has($[1]))J.push($)},modes:new Set(Q.flatMap(($)=>Array.from($.modes)))})}var W6=class extends q1{cache;queue=Promise.resolve();constructor(Q){super();this.cache=Q}async get(Q){return this.enqueueOperation("get",Q)}async set(Q){return this.enqueueOperation("set",Q)}async clear(Q){return this.enqueueOperation("clear",Q)}async stop(){await this.queue}enqueueOperation(Q,...$){let J=this.queue.then(()=>{return this.cache[Q](...$)});return this.queue=J.then(()=>{return},()=>{return}),J}},z1=class Q{input;output;config;checkpointer;checkpointerGetNextVersion;channels;checkpoint;checkpointIdSaved;checkpointConfig;checkpointMetadata;checkpointNamespace;checkpointPendingWrites=[];checkpointPreviousVersions;step;stop;durability;outputKeys;streamKeys;nodes;skipDoneTasks;prevCheckpointConfig;updatedChannels;status="pending";tasks={};stream;checkpointerPromises=[];isNested;_checkpointerChainedPromise=Promise.resolve();store;cache;manager;interruptAfter;interruptBefore;toInterrupt=[];debug=!1;triggerToNodes;get isResuming(){let $=!1;if(T in this.checkpoint.channel_versions)$=!0;else for(let X in this.checkpoint.channel_versions)if(Object.prototype.hasOwnProperty.call(this.checkpoint.channel_versions,X)){$=!0;break}let J=this.config.configurable?.[EQ]!==void 0&&this.config.configurable?.[EQ],Z=this.input===null||this.input===void 0,q=u(this.input)&&this.input.resume!=null,z=this.input===t8,Y=!this.isNested&&this.config.metadata?.run_id!==void 0&&this.checkpointMetadata?.run_id!==void 0&&this.config.metadata.run_id===this.checkpointMetadata?.run_id;return $&&(J||Z||q||z||Y)}constructor($){if(this.input=$.input,this.checkpointer=$.checkpointer,this.checkpointer!==void 0)this.checkpointerGetNextVersion=this.checkpointer.getNextVersion.bind(this.checkpointer);else this.checkpointerGetNextVersion=c$;this.checkpoint=$.checkpoint,this.checkpointMetadata=$.checkpointMetadata,this.checkpointPreviousVersions=$.checkpointPreviousVersions,this.channels=$.channels,this.checkpointPendingWrites=$.checkpointPendingWrites,this.step=$.step,this.stop=$.stop,this.config=$.config,this.checkpointConfig=$.checkpointConfig,this.isNested=$.isNested,this.manager=$.manager,this.outputKeys=$.outputKeys,this.streamKeys=$.streamKeys,this.nodes=$.nodes,this.skipDoneTasks=$.skipDoneTasks,this.store=$.store,this.cache=$.cache?new W6($.cache):void 0,this.stream=$.stream,this.checkpointNamespace=$.checkpointNamespace,this.prevCheckpointConfig=$.prevCheckpointConfig,this.interruptAfter=$.interruptAfter,this.interruptBefore=$.interruptBefore,this.durability=$.durability,this.debug=$.debug,this.triggerToNodes=$.triggerToNodes}static async initialize($){let{config:J,stream:Z}=$;if(Z!==void 0&&J.configurable?.[K0]!==void 0)Z=L6(Z,J.configurable[K0]);let q=J.configurable?!("checkpoint_id"in J.configurable):!0,z=J.configurable?.[JQ];if(J.configurable&&z){if(z.subgraphCounter>0)J=zQ(J,{[FQ]:[J.configurable[FQ],z.subgraphCounter.toString()].join(k)});z.subgraphCounter+=1}let Y=AQ in(J.configurable??{});if(!Y&&J.configurable?.checkpoint_ns!==void 0&&J.configurable?.checkpoint_ns!=="")J=zQ(J,{checkpoint_ns:"",checkpoint_id:void 0});let X=J;if(J.configurable?.[ZQ]!==void 0&&J.configurable?.[ZQ]?.[J.configurable?.checkpoint_ns])X=zQ(J,{checkpoint_id:J.configurable[ZQ][J.configurable?.checkpoint_ns]});let B=J.configurable?.checkpoint_ns?.split(k)??[],F=await $.checkpointer?.getTuple(X)??{config:J,checkpoint:V0(),metadata:{source:"input",step:-2,parents:{}},pendingWrites:[]};X={...J,...F.config,configurable:{checkpoint_ns:"",...J.configurable,...F.config.configurable}};let W=F.parentConfig,L=fQ(F.checkpoint),H={...F.metadata},j=F.pendingWrites??[],U=oQ($.channelSpecs,L),D=(H.step??0)+1,M=D+(J.recursionLimit??B6)+1,O={...L.channel_versions},_=$.store?new W8($.store):void 0;if(_)await _.start();return new Q({input:$.input,config:J,checkpointer:$.checkpointer,checkpoint:L,checkpointMetadata:H,checkpointConfig:X,prevCheckpointConfig:W,checkpointNamespace:B,channels:U,isNested:Y,manager:$.manager,skipDoneTasks:q,step:D,stop:M,checkpointPreviousVersions:O,checkpointPendingWrites:j,outputKeys:$.outputKeys??[],streamKeys:$.streamKeys??[],nodes:$.nodes,stream:Z,store:_,cache:$.cache,interruptAfter:$.interruptAfter,interruptBefore:$.interruptBefore,durability:$.durability,debug:$.debug,triggerToNodes:$.triggerToNodes})}_checkpointerPutAfterPrevious($){this._checkpointerChainedPromise=this._checkpointerChainedPromise.then(()=>{return this.checkpointer?.put($.config,$.checkpoint,$.metadata,$.newVersions)}),this.checkpointerPromises.push(this._checkpointerChainedPromise)}putWrites($,J){let Z=J;if(Z.length===0)return;if(Z.every(([B])=>(B in Z1)))Z=Array.from(new Map(Z.map((B)=>[B[0],B])).values());let q=!1;for(let B in this.channels)if(Object.prototype.hasOwnProperty.call(this.channels,B)){if(this.channels[B].lc_graph_name==="UntrackedValue"){q=!0;break}}let z=Z;if(q)z=Z.filter(([B])=>{let F=this.channels[B];return!F||F.lc_graph_name!=="UntrackedValue"}).map(([B,F])=>{if(B===c&&d(F))return[B,i$(F,this.channels)];return[B,F]});this.checkpointPendingWrites=this.checkpointPendingWrites.filter((B)=>B[0]!==$);for(let[B,F]of z)this.checkpointPendingWrites.push([$,B,F]);let Y=zQ(this.checkpointConfig,{[FQ]:this.config.configurable?.checkpoint_ns??"",[w8]:this.checkpoint.id});if(this.durability!=="exit"&&this.checkpointer!=null)this.checkpointerPromises.push(this.checkpointer.putWrites(Y,z,$));if(this.tasks)this._outputWrites($,Z);if(!J.length||!this.cache||!this.tasks)return;let X=this.tasks[$];if(X==null||X.cache_key==null)return;if(J[0][0]===p||J[0][0]===S)return;this.cache.set([{key:[X.cache_key.ns,X.cache_key.key],value:X.writes,ttl:X.cache_key.ttl}])}_outputWrites($,J,Z=!1){let q=this.tasks[$];if(q!==void 0){if(q.config!==void 0&&(q.config.tags??[]).includes(E))return;if(J.length>0){if(J[0][0]===S){if(q.path?.[0]===r&&q.path?.[q.path.length-1]===!0)return;let z=J.filter((Y)=>Y[0]===S).flatMap((Y)=>Y[1]);this._emit([["updates",{[S]:z}],["values",{[S]:z}]])}else if(J[0][0]!==p)this._emit($0(CQ(g$(this.outputKeys,[[q,J]],Z),"updates")))}if(!Z)this._emit($0(CQ(n$([[q,J]],this.streamKeys),"tasks")))}}async _matchCachedWrites(){if(!this.cache)return[];let $=[],J=([Y,X])=>{return`ns:${Y.join(",")}|key:${X}`},Z=[],q={};for(let Y of Object.values(this.tasks))if(Y.cache_key!=null&&!Y.writes.length)Z.push([Y.cache_key.ns,Y.cache_key.key]),q[J([Y.cache_key.ns,Y.cache_key.key])]=Y;if(Z.length===0)return[];let z=await this.cache.get(Z);for(let{key:Y,value:X}of z){let B=q[J(Y)];if(B!=null)B.writes.push(...X),$.push({task:B,result:X})}return $}async tick($){if(this.store&&!this.store.isRunning)await this.store?.start();let{inputKeys:J=[]}=$;if(this.status!=="pending")throw Error(`Cannot tick when status is no longer "pending". Current status: "${this.status}"`);if(![L8,t8].includes(this.input))await this._first(J);else if(this.toInterrupt.length>0)throw this.status="interrupt_before",new PQ;else if(Object.values(this.tasks).every((q)=>q.writes.length>0)){let q=Object.values(this.tasks).flatMap((Y)=>Y.writes);this.updatedChannels=$Q(this.checkpoint,this.channels,Object.values(this.tasks),this.checkpointerGetNextVersion,this.triggerToNodes);let z=await GQ(CQ(q8(this.outputKeys,q,this.channels),"values"));if(this._emit(z),this.checkpointPendingWrites=[],await this._putCheckpoint({source:"loop"}),N0(this.checkpoint,this.interruptAfter,Object.values(this.tasks)))throw this.status="interrupt_after",new PQ;if(this.config.configurable?.[EQ]!==void 0)delete this.config.configurable?.[EQ]}else return!1;if(this.step>this.stop)return this.status="out_of_steps",!1;if(this.tasks=sQ(this.checkpoint,this.checkpointPendingWrites,this.nodes,this.channels,this.config,!0,{step:this.step,checkpointer:this.checkpointer,isResuming:this.isResuming,manager:this.manager,store:this.store,stream:this.stream,triggerToNodes:this.triggerToNodes,updatedChannels:this.updatedChannels}),this.checkpointer)this._emit(await GQ(CQ(s$(this.checkpointConfig,this.channels,this.streamKeys,this.checkpointMetadata,Object.values(this.tasks),this.checkpointPendingWrites,this.prevCheckpointConfig,this.outputKeys),"checkpoints")));if(Object.values(this.tasks).length===0)return this.status="done",!1;if(this.skipDoneTasks&&this.checkpointPendingWrites.length>0){for(let[q,z,Y]of this.checkpointPendingWrites){if(z===p||z===S||z===o)continue;let X=Object.values(this.tasks).find((B)=>B.id===q);if(X)X.writes.push([z,Y])}for(let q of Object.values(this.tasks))if(q.writes.length>0)this._outputWrites(q.id,q.writes,!0)}if(Object.values(this.tasks).every((q)=>q.writes.length>0))return this.tick({inputKeys:J});if(N0(this.checkpoint,this.interruptBefore,Object.values(this.tasks)))throw this.status="interrupt_before",new PQ;let Z=await GQ(CQ(o8(Object.values(this.tasks)),"tasks"));return this._emit(Z),!0}async finishAndHandleError($){if(this.durability==="exit"&&(!this.isNested||typeof $<"u"||this.checkpointNamespace.every((Z)=>!Z.includes(e))))this._putCheckpoint(this.checkpointMetadata),this._flushPendingWrites();let J=this._suppressInterrupt($);if(J||$===void 0)this.output=MQ(this.channels,this.outputKeys);if(J){if(this.tasks!==void 0&&this.checkpointPendingWrites.length>0&&Object.values(this.tasks).some((Z)=>Z.writes.length>0))this.updatedChannels=$Q(this.checkpoint,this.channels,Object.values(this.tasks),this.checkpointerGetNextVersion,this.triggerToNodes),this._emit($0(CQ(q8(this.outputKeys,Object.values(this.tasks).flatMap((Z)=>Z.writes),this.channels),"values")));if(wQ($)&&!$.interrupts.length)this._emit([["updates",{[S]:[]}],["values",{[S]:[]}]])}return J}async acceptPush($,J,Z){if(this.interruptAfter?.length>0&&N0(this.checkpoint,this.interruptAfter,[$])){this.toInterrupt.push($);return}let q=Y8([r,$.path??[],J,$.id,Z],this.checkpoint,this.checkpointPendingWrites,this.nodes,this.channels,$.config??{},!0,{step:this.step,checkpointer:this.checkpointer,manager:this.manager,store:this.store,stream:this.stream});if(!q)return;if(this.interruptBefore?.length>0&&N0(this.checkpoint,this.interruptBefore,[q])){this.toInterrupt.push(q);return}if(this._emit($0(CQ(o8([q]),"tasks"))),this.debug)X8(this.step,[q]);if(this.tasks[q.id]=q,this.skipDoneTasks)this._matchWrites({[q.id]:q});let z=await this._matchCachedWrites();for(let{task:Y}of z)this._outputWrites(Y.id,Y.writes,!0);return q}_suppressInterrupt($){return wQ($)&&!this.isNested}async _first($){let{configurable:J}=this.config,Z=J?.[JQ];if(Z&&Z.nullResume!==void 0)this.putWrites(n,[[o,Z.nullResume]]);if(u(this.input)){let Y=this.input.resume!=null;if(this.input.resume!=null&&typeof this.input.resume==="object"&&Object.keys(this.input.resume).every(t0))this.config.configurable??={},this.config.configurable[X0]=this.input.resume;if(Y&&this.checkpointer==null)throw Error("Cannot use Command(resume=...) without checkpointer");let X={};for(let[B,F,W]of k$(this.input,this.checkpointPendingWrites))X[B]??=[],X[B].push([F,W]);if(Object.keys(X).length===0)throw new P0("Received empty Command input");for(let[B,F]of Object.entries(X))this.putWrites(B,F)}let q=(this.checkpointPendingWrites??[]).filter((Y)=>Y[0]===n).map((Y)=>Y.slice(1));if(q.length>0)$Q(this.checkpoint,this.channels,[{name:xQ,writes:q,triggers:[]}],this.checkpointerGetNextVersion,this.triggerToNodes);let z=u(this.input)&&q.length>0;if(this.isResuming||z){for(let X in this.channels){if(!Object.prototype.hasOwnProperty.call(this.channels,X))continue;if(this.checkpoint.channel_versions[X]!==void 0){let B=this.checkpoint.channel_versions[X];this.checkpoint.versions_seen[S]={...this.checkpoint.versions_seen[S],[X]:B}}}let Y=await GQ(CQ(q8(this.outputKeys,!0,this.channels),"values"));this._emit(Y)}if(this.isResuming)this.input=t8;else if(z)await this._putCheckpoint({source:"input"}),this.input=L8;else{let Y=await GQ(Z8($,this.input));if(Y.length>0){let X=sQ(this.checkpoint,this.checkpointPendingWrites,this.nodes,this.channels,this.config,!0,{step:this.step});this.updatedChannels=$Q(this.checkpoint,this.channels,Object.values(X).concat([{name:xQ,writes:Y,triggers:[]}]),this.checkpointerGetNextVersion,this.triggerToNodes),await this._putCheckpoint({source:"input"}),this.input=L8}else if(!(EQ in(this.config.configurable??{})))throw new P0(`Received no input writes for ${JSON.stringify($,null,2)}`);else this.input=L8}if(!this.isNested)this.config=zQ(this.config,{[EQ]:this.isResuming})}_emit($){for(let[J,Z]of $){if(this.stream.modes.has(J))this.stream.push([this.checkpointNamespace,J,Z]);if((J==="checkpoints"||J==="tasks")&&this.stream.modes.has("debug")){let q=J==="checkpoints"?this.step-1:this.step,z=new Date().toISOString(),Y=(()=>{if(J==="checkpoints")return"checkpoint";else if(typeof Z==="object"&&Z!=null&&"result"in Z)return"task_result";else return"task"})();this.stream.push([this.checkpointNamespace,"debug",{step:q,type:Y,timestamp:z,payload:Z}])}}}_putCheckpoint($){let J=this.checkpointMetadata===$,Z=this.checkpointer!=null&&(this.durability!=="exit"||J),q=(z)=>{this.prevCheckpointConfig=this.checkpointConfig?.configurable?.checkpoint_id?this.checkpointConfig:void 0,this.checkpointConfig=zQ(this.checkpointConfig,{[FQ]:this.config.configurable?.checkpoint_ns??""});let Y={...this.checkpoint.channel_versions},X=H0(this.checkpointPreviousVersions,Y);this.checkpointPreviousVersions=Y,this._checkpointerPutAfterPrevious({config:{...this.checkpointConfig},checkpoint:fQ(z),metadata:{...this.checkpointMetadata},newVersions:X}),this.checkpointConfig={...this.checkpointConfig,configurable:{...this.checkpointConfig.configurable,checkpoint_id:this.checkpoint.id}}};if(!J)this.checkpointMetadata={...$,step:this.step,parents:this.config.configurable?.[ZQ]??{}};if(this.checkpoint=HQ(this.checkpoint,Z?this.channels:void 0,this.step,J?{id:this.checkpoint.id}:void 0),Z)q(this.checkpoint);if(!J)this.step+=1}_flushPendingWrites(){if(this.checkpointer==null)return;if(this.checkpointPendingWrites.length===0)return;let $=zQ(this.checkpointConfig,{[FQ]:this.config.configurable?.checkpoint_ns??"",[w8]:this.checkpoint.id}),J={};for(let[Z,q,z]of this.checkpointPendingWrites)J[Z]??=[],J[Z].push([q,z]);for(let[Z,q]of Object.entries(J))this.checkpointerPromises.push(this.checkpointer.putWrites($,q,Z))}_matchWrites($){for(let[J,Z,q]of this.checkpointPendingWrites){if(Z===p||Z===S||Z===o)continue;let z=Object.values($).find((Y)=>Y.id===J);if(z)z.writes.push([Z,q])}for(let J of Object.values($))if(J.writes.length>0)this._outputWrites(J.id,J.writes,!0)}};function j6(Q){return kQ(Q?.message)}var F1=class extends F8{name="StreamMessagesHandler";streamFn;metadatas={};seen={};emittedChatModelRunIds={};stableMessageIdMap={};lc_prefer_streaming=!0;constructor(Q){super();this.streamFn=Q}_emit(Q,$,J,Z=!1){if(Z&&$.id!==void 0&&this.seen[$.id]!==void 0)return;let q=$.id;if(J!=null)if(Y1($))q??=`run-${J}-tool-${$.tool_call_id}`;else{if(q==null||q===`run-${J}`)q=this.stableMessageIdMap[J]??q??`run-${J}`;this.stableMessageIdMap[J]??=q}if(q!==$.id)$.id=q,$.lc_kwargs.id=q;if($.id!=null)this.seen[$.id]=$;this.streamFn([Q[0],"messages",[$,Q[1]]])}handleChatModelStart(Q,$,J,Z,q,z,Y,X){if(Y&&(!z||!z.includes(D$)&&!z.includes("nostream")))this.metadatas[J]=[Y.langgraph_checkpoint_ns.split("|"),{tags:z,name:X,...Y}]}handleLLMNewToken(Q,$,J,Z,q,z){let Y=z?.chunk;if(this.emittedChatModelRunIds[J]=!0,this.metadatas[J]!==void 0)if(j6(Y))this._emit(this.metadatas[J],Y.message,J);else this._emit(this.metadatas[J],new X1({content:Q}),J)}handleLLMEnd(Q,$){if(this.metadatas[$]===void 0)return;if(!this.emittedChatModelRunIds[$]){let J=Q.generations?.[0]?.[0];if(kQ(J?.message))this._emit(this.metadatas[$],J?.message,$,!0);delete this.emittedChatModelRunIds[$]}delete this.metadatas[$],delete this.stableMessageIdMap[$]}handleLLMError(Q,$){delete this.metadatas[$]}handleChainStart(Q,$,J,Z,q,z,Y,X){if(z!==void 0&&X===z.langgraph_node&&(q===void 0||!q.includes(E))){if(this.metadatas[J]=[z.langgraph_checkpoint_ns.split("|"),{tags:q,name:X,...z}],typeof $==="object"){for(let B of Object.values($))if((kQ(B)||a8(B))&&B.id!==void 0)this.seen[B.id]=B;else if(Array.isArray(B)){for(let F of B)if((kQ(F)||a8(F))&&F.id!==void 0)this.seen[F.id]=F}}}}handleChainEnd(Q,$){let J=this.metadatas[$];if(delete this.metadatas[$],J!==void 0){if(kQ(Q))this._emit(J,Q,$,!0);else if(Array.isArray(Q)){for(let Z of Q)if(kQ(Z))this._emit(J,Z,$,!0)}else if(Q!=null&&typeof Q==="object"){for(let Z of Object.values(Q))if(kQ(Z))this._emit(J,Z,$,!0);else if(Array.isArray(Z)){for(let q of Z)if(kQ(q))this._emit(J,q,$,!0)}}}}handleChainError(Q,$){delete this.metadatas[$]}};var H6=500,U6=2,V6=128000,D6=3,G6=[400,401,402,403,404,405,406,407,409],K6=(Q)=>{if(Q.message.startsWith("Cancel")||Q.message.startsWith("AbortError")||Q.name==="AbortError")return!1;if(Q.name==="GraphValueError")return!1;if(Q?.code==="ECONNABORTED")return!1;let $=Q?.response?.status??Q?.status;if($&&G6.includes(+$))return!1;if(Q?.error?.code==="insufficient_quota")return!1;return!0};async function e8(Q,$,J,Z){let q=Q.retry_policy??$,z=q!==void 0?q.initialInterval??H6:0,Y=0,X,B,{config:F}=Q;if(J)F=zQ(F,J);F={...F,signal:Z};while(!0){if(Z?.aborted)break;Q.writes.splice(0,Q.writes.length),X=void 0;try{B=await Q.proc.invoke(Q.input,F);break}catch(W){if(X=W,X.pregelTaskId=Q.id,o0(X)){let j=F?.configurable?.checkpoint_ns,U=X.command;if(U.graph===j){for(let D of Q.writers)await D.invoke(U,F);X=void 0;break}else if(U.graph===a.PARENT){let D=I$(j);X.command=new a({...X.command,graph:D})}}if(pQ(X))break;if(q===void 0)break;if(Y+=1,Y>=(q.maxAttempts??D6))break;if(!(q.retryOn??K6)(X))break;z=Math.min(q.maxInterval??V6,z*(q.backoffFactor??U6));let L=q.jitter?Math.floor(z+Math.random()*1000):z;await new Promise((j)=>setTimeout(j,L));let H=X.name??X.constructor.unminifiable_name??X.constructor.name;if(q?.logWarning??!0)console.log(`Retrying task "${String(Q.name)}" after ${z.toFixed(2)}ms (attempt ${Y}) after ${H}: ${X}`);F=zQ(F,{[EQ]:!0})}}return{task:Q,result:B,error:X,signalAborted:Z?.aborted}}var Q$=Symbol.for("promiseAdded");function M6(){let Q={next:()=>{return},wait:Promise.resolve(Q$)};function $(J){Q.next=()=>{Q.wait=new Promise($),J(Q$)}}return Q.wait=new Promise($),Q}var B1=class{nodeFinished;loop;constructor({loop:Q,nodeFinished:$}){this.loop=Q,this.nodeFinished=$}async tick(Q={}){let{timeout:$,retryPolicy:J,onStepWrite:Z,maxConcurrency:q}=Q,z=new Set,Y,X=new AbortController,B=X.signal,F=$?AbortSignal.timeout($):void 0,W=Object.values(this.loop.tasks).filter((U)=>U.writes.length===0),{signals:L,disposeCombinedSignal:H}=this._initializeAbortSignals({exceptionSignal:B,stepTimeoutSignal:F,signal:Q.signal}),j=this._executeTasksWithRetry(W,{signals:L,retryPolicy:J,maxConcurrency:q});for await(let{task:U,error:D,signalAborted:M}of j)if(this._commit(U,D),wQ(D))Y=D;else if(pQ(D)&&!wQ(Y))Y=D;else if(D&&(z.size===0||!M))X.abort(),z.add(D);if(H?.(),Z?.(this.loop.step,Object.values(this.loop.tasks).map((U)=>U.writes).flat()),z.size===1)throw Array.from(z)[0];else if(z.size>1)throw AggregateError(Array.from(z),`Multiple errors occurred during superstep ${this.loop.step}. See the "errors" field of this exception for more details.`);if(wQ(Y))throw Y;if(pQ(Y)&&this.loop.isNested)throw Y}_initializeAbortSignals({exceptionSignal:Q,stepTimeoutSignal:$,signal:J}){let Z=this.loop.config.configurable?.[R8]??{},q=Z.externalAbortSignal??J,z=$??Z.timeoutAbortSignal,{signal:Y,dispose:X}=U0(q,z,Q),B={externalAbortSignal:q,timeoutAbortSignal:z,composedAbortSignal:Y};return this.loop.config=zQ(this.loop.config,{[R8]:B}),{signals:B,disposeCombinedSignal:X}}async*_executeTasksWithRetry(Q,$){let{retryPolicy:J,maxConcurrency:Z,signals:q}=$??{},z=M6(),Y={},X={executingTasksMap:Y,barrier:z,retryPolicy:J,scheduleTask:async(H,j,U)=>this.loop.acceptPush(H,j,U)};if(q?.composedAbortSignal?.aborted)throw Error("Abort");let B=0,F,W=U0(q?.externalAbortSignal,q?.timeoutAbortSignal),L=W.signal?new Promise((H,j)=>{F=()=>j(Error("Abort")),W.signal?.addEventListener("abort",F,{once:!0})}):void 0;while((B===0||Object.keys(Y).length>0)&&Q.length){for(;Object.values(Y).length<(Z??Q.length)&&B<Q.length;B+=1){let j=Q[B];Y[j.id]=e8(j,J,{[g0]:L1?.bind(X,this,j)},q?.composedAbortSignal).catch((U)=>{return{task:j,error:U,signalAborted:q?.composedAbortSignal?.aborted}})}let H=await Promise.race([...Object.values(Y),...L?[L]:[],z.wait]);if(H===Q$)continue;if(yield H,F!=null)W.signal?.removeEventListener("abort",F),W.dispose?.();delete Y[H.task.id]}}_commit(Q,$){if($!==void 0)if(wQ($)){if($.interrupts.length){let J=$.interrupts.map((q)=>[S,q]),Z=Q.writes.filter((q)=>q[0]===o);if(Z.length)J.push(...Z);this.loop.putWrites(Q.id,J)}}else if(pQ($)&&Q.writes.length)this.loop.putWrites(Q.id,Q.writes);else this.loop.putWrites(Q.id,[[p,{message:$.message,name:$.name}]]);else{if(this.nodeFinished&&(Q.config?.tags==null||!Q.config.tags.includes(E)))this.nodeFinished(String(Q.name));if(Q.writes.length===0)Q.writes.push([m0,null]);this.loop.putWrites(Q.id,Q.writes)}}};async function L1(Q,$,J,Z,q,z={}){let Y=$.config?.configurable?.[JQ];if(!Y)throw Error(`BUG: No scratchpad found on task ${$.name}__${$.id}`);let X=Y.callCounter;Y.callCounter+=1;let B=new u$({func:J,name:Z,input:q,cache:z.cache,retry:z.retry,callbacks:z.callbacks}),F=await this.scheduleTask($,X,B);if(!F)return;let W=this.executingTasksMap[F.id];if(W!==void 0)return W;if(F.writes.length>0){let L=F.writes.filter(([j])=>j===jQ),H=F.writes.filter(([j])=>j===p);if(L.length>0){if(L.length===1)return Promise.resolve(L[0][1]);throw Error(`BUG: multiple returns found for task ${F.name}__${F.id}`)}if(H.length>0){if(H.length===1){let j=H[0][1],U=j instanceof Error?j:Error(String(j));return Promise.reject(U)}throw Error(`BUG: multiple errors found for task ${F.name}__${F.id}`)}return}else{let L=e8(F,z.retry,{[g0]:L1.bind(this,Q,F)});return this.executingTasksMap[F.id]=L,this.barrier.next(),L.then(({result:H,error:j})=>{if(j)return Promise.reject(j);return H})}}var gQ=class extends Error{constructor(Q){super(Q);this.name="GraphValidationError"}};function W1({nodes:Q,channels:$,inputChannels:J,outputChannels:Z,streamChannels:q,interruptAfterNodes:z,interruptBeforeNodes:Y}){if(!$)throw new gQ("Channels not provided");let X=new Set,B=new Set;for(let[F,W]of Object.entries(Q)){if(F===S)throw new gQ(`"Node name ${S} is reserved"`);if(W.constructor===KQ)W.triggers.forEach((L)=>X.add(L));else throw new gQ(`Invalid node type ${typeof W}, expected PregelNode`)}for(let F of X)if(!(F in $))throw new gQ(`Subscribed channel '${String(F)}' not in channels`);if(!Array.isArray(J)){if(!X.has(J))throw new gQ(`Input channel ${String(J)} is not subscribed to by any node`)}else if(J.every((F)=>!X.has(F)))throw new gQ(`None of the input channels ${J} are subscribed to by any node`);if(!Array.isArray(Z))B.add(Z);else Z.forEach((F)=>B.add(F));if(q&&!Array.isArray(q))B.add(q);else if(Array.isArray(q))q.forEach((F)=>B.add(F));for(let F of B)if(!(F in $))throw new gQ(`Output channel '${String(F)}' not in channels`);if(z&&z!=="*"){for(let F of z)if(!(F in Q))throw new gQ(`Node ${String(F)} not in nodes`)}if(Y&&Y!=="*"){for(let F of Y)if(!(F in Q))throw new gQ(`Node ${String(F)} not in nodes`)}}function $$(Q,$){if(Array.isArray(Q)){for(let J of Q)if(!(J in $))throw Error(`Key ${String(J)} not found in channels`)}else if(!(Q in $))throw Error(`Key ${String(Q)} not found in channels`)}var U1=class{static subscribeTo(Q,$){let{key:J,tags:Z}={key:void 0,tags:void 0,...$??{}};if(Array.isArray(Q)&&J!==void 0)throw Error("Can't specify a key when subscribing to multiple channels");let q;if(typeof Q==="string")if(J)q={[J]:Q};else q=[Q];else q=Object.fromEntries(Q.map((z)=>[z,z]));return new KQ({channels:q,triggers:Array.isArray(Q)?Q:[Q],tags:Z})}static writeTo(Q,$){let J=[];for(let Z of Q)J.push({channel:Z,value:qQ,skipNone:!1});for(let[Z,q]of Object.entries($??{}))if(YQ.isRunnable(q)||typeof q==="function")J.push({channel:Z,value:qQ,skipNone:!0,mapper:yQ(q)});else J.push({channel:Z,value:q,skipNone:!1});return new h(J)}},x6=class extends YQ{lc_namespace=["langgraph","pregel"];invoke(Q,$){throw Error("Not implemented")}withConfig(Q){return super.withConfig(Q)}stream(Q,$){return super.stream(Q,$)}},H8=class extends x6{static lc_name(){return"LangGraph"}lc_namespace=["langgraph","pregel"];lg_is_pregel=!0;nodes;channels;inputChannels;outputChannels;autoValidate=!0;streamMode=["values"];streamChannels;interruptAfter;interruptBefore;stepTimeout;debug=!1;checkpointer;retryPolicy;config;store;cache;userInterrupt;triggerToNodes={};constructor(Q){super(Q);let{streamMode:$}=Q;if($!=null&&!Array.isArray($))$=[$];if(this.nodes=Q.nodes,this.channels=Q.channels,c in this.channels&&"lc_graph_name"in this.channels[c]&&this.channels[c].lc_graph_name!=="Topic")throw Error(`Channel '${c}' is reserved and cannot be used in the graph.`);else this.channels[c]=new f8({accumulate:!1});if(this.autoValidate=Q.autoValidate??this.autoValidate,this.streamMode=$??this.streamMode,this.inputChannels=Q.inputChannels,this.outputChannels=Q.outputChannels,this.streamChannels=Q.streamChannels??this.streamChannels,this.interruptAfter=Q.interruptAfter,this.interruptBefore=Q.interruptBefore,this.stepTimeout=Q.stepTimeout??this.stepTimeout,this.debug=Q.debug??this.debug,this.checkpointer=Q.checkpointer,this.retryPolicy=Q.retryPolicy,this.config=Q.config,this.store=Q.store,this.cache=Q.cache,this.name=Q.name,this.triggerToNodes=Q.triggerToNodes??this.triggerToNodes,this.userInterrupt=Q.userInterrupt,this.autoValidate)this.validate()}withConfig(Q){let $=DQ(this.config,Q);return new this.constructor({...this,config:$})}validate(){W1({nodes:this.nodes,channels:this.channels,outputChannels:this.outputChannels,inputChannels:this.inputChannels,streamChannels:this.streamChannels,interruptAfterNodes:this.interruptAfter,interruptBeforeNodes:this.interruptBefore});for(let[Q,$]of Object.entries(this.nodes))for(let J of $.triggers)this.triggerToNodes[J]??=[],this.triggerToNodes[J].push(Q);return this}get streamChannelsList(){if(Array.isArray(this.streamChannels))return this.streamChannels;else if(this.streamChannels)return[this.streamChannels];else return Object.keys(this.channels)}get streamChannelsAsIs(){if(this.streamChannels)return this.streamChannels;else return Object.keys(this.channels)}async getGraphAsync(Q){return this.getGraph(Q)}*getSubgraphs(Q,$){for(let[J,Z]of Object.entries(this.nodes)){if(Q!==void 0){if(!Q.startsWith(J))continue}let q=Z.subgraphs?.length?Z.subgraphs:[Z.bound];for(let z of q){let Y=J8(z);if(Y!==void 0){if(J===Q){yield[J,Y];return}if(Q===void 0)yield[J,Y];if($){let X=Q;if(Q!==void 0)X=Q.slice(J.length+1);for(let[B,F]of Y.getSubgraphs(X,$))yield[`${J}${k}${B}`,F]}}}}}async*getSubgraphsAsync(Q,$){yield*this.getSubgraphs(Q,$)}async _prepareStateSnapshot({config:Q,saved:$,subgraphCheckpointer:J,applyPendingWrites:Z=!1}){if($===void 0)return{values:{},next:[],config:Q,tasks:[]};let q=oQ(this.channels,$.checkpoint);if($.pendingWrites?.length){let L=$.pendingWrites.filter(([H,j])=>H===n).map(([H,j,U])=>[String(j),U]);if(L.length>0)$Q($.checkpoint,q,[{name:xQ,writes:L,triggers:[]}],void 0,this.triggerToNodes)}let z=Object.values(sQ($.checkpoint,$.pendingWrites,this.nodes,q,$.config,!0,{step:($.metadata?.step??-1)+1,store:this.store})),Y=await GQ(this.getSubgraphsAsync()),X=$.config.configurable?.checkpoint_ns??"",B={};for(let L of z){let H=Y.find(([U])=>U===L.name);if(!H)continue;let j=`${String(L.name)}${e}${L.id}`;if(X)j=`${X}${k}${j}`;if(J===void 0){let U={configurable:{thread_id:$.config.configurable?.thread_id,checkpoint_ns:j}};B[L.id]=U}else{let U={configurable:{[m]:J,thread_id:$.config.configurable?.thread_id,checkpoint_ns:j}},D=H[1];B[L.id]=await D.getState(U,{subgraphs:!0})}}if(Z&&$.pendingWrites?.length){let L=Object.fromEntries(z.map((j)=>[j.id,j]));for(let[j,U,D]of $.pendingWrites){if([p,S,j8].includes(U))continue;if(!(j in L))continue;L[j].writes.push([String(U),D])}let H=z.filter((j)=>j.writes.length>0);if(H.length>0)$Q($.checkpoint,q,H,void 0,this.triggerToNodes)}let F=$?.metadata;if(F&&$?.config?.configurable?.thread_id)F={...F,thread_id:$.config.configurable.thread_id};let W=z.filter((L)=>L.writes.length===0).map((L)=>L.name);return{values:MQ(q,this.streamChannelsAsIs),next:W,tasks:c8(z,$?.pendingWrites??[],B,this.streamChannelsAsIs),metadata:F,config:rQ($.config,$.metadata),createdAt:$.checkpoint.ts,parentConfig:$.parentConfig}}async getState(Q,$){let J=Q.configurable?.[m]??this.checkpointer;if(!J)throw new dQ("No checkpointer set",{lc_error_code:"MISSING_CHECKPOINTER"});let Z=Q.configurable?.checkpoint_ns??"";if(Z!==""&&Q.configurable?.[m]===void 0){let Y=e0(Z);for await(let[X,B]of this.getSubgraphsAsync(Y,!0))if(X===Y)return await B.getState(J0(Q,{[m]:J}),{subgraphs:$?.subgraphs});throw Error(`Subgraph with namespace "${Y}" not found.`)}let q=DQ(this.config,Q),z=await J.getTuple(Q);return await this._prepareStateSnapshot({config:q,saved:z,subgraphCheckpointer:$?.subgraphs?J:void 0,applyPendingWrites:!Q.configurable?.checkpoint_id})}async*getStateHistory(Q,$){let J=Q.configurable?.[m]??this.checkpointer;if(!J)throw new dQ("No checkpointer set",{lc_error_code:"MISSING_CHECKPOINTER"});let Z=Q.configurable?.checkpoint_ns??"";if(Z!==""&&Q.configurable?.[m]===void 0){let z=e0(Z);for await(let[Y,X]of this.getSubgraphsAsync(z,!0))if(Y===z){yield*X.getStateHistory(J0(Q,{[m]:J}),$);return}throw Error(`Subgraph with namespace "${z}" not found.`)}let q=DQ(this.config,Q,{configurable:{checkpoint_ns:Z}});for await(let z of J.list(q,$))yield this._prepareStateSnapshot({config:z.config,saved:z})}async bulkUpdateState(Q,$){let J=Q.configurable?.[m]??this.checkpointer;if(!J)throw new dQ("No checkpointer set",{lc_error_code:"MISSING_CHECKPOINTER"});if($.length===0)throw Error("No supersteps provided");if($.some((Y)=>Y.updates.length===0))throw Error("No updates provided");let Z=Q.configurable?.checkpoint_ns??"";if(Z!==""&&Q.configurable?.[m]===void 0){let Y=e0(Z);for await(let[,X]of this.getSubgraphsAsync(Y,!0))return await X.bulkUpdateState(J0(Q,{[m]:J}),$);throw Error(`Subgraph "${Y}" not found`)}let q=async(Y,X)=>{let B=this.config?DQ(this.config,Y):Y,F=await J.getTuple(B),W=F!==void 0?fQ(F.checkpoint):V0(),L={...F?.checkpoint.channel_versions},H=F?.metadata?.step??-1,j=J0(B,{checkpoint_ns:B.configurable?.checkpoint_ns??""}),U=B.metadata??{};if(F?.config.configurable)j=J0(B,F.config.configurable),U={...F.metadata,...U};let{values:D,asNode:M}=X[0];if(D==null&&M===void 0){if(X.length>1)throw new w("Cannot create empty checkpoint with multiple updates");return rQ(await J.put(j,HQ(W,void 0,H),{source:"update",step:H+1,parents:F?.metadata?.parents??{}},{}),F?F.metadata:void 0)}let O=oQ(this.channels,W);if(D===null&&M===A){if(X.length>1)throw new w("Cannot apply multiple updates when clearing state");if(F){let K=sQ(W,F.pendingWrites||[],this.nodes,O,F.config,!0,{step:(F.metadata?.step??-1)+1,checkpointer:J,store:this.store}),x=(F.pendingWrites||[]).filter((b)=>b[0]===n).map((b)=>b.slice(1));if(x.length>0)$Q(W,O,[{name:xQ,writes:x,triggers:[]}],J.getNextVersion.bind(J),this.triggerToNodes);for(let[b,G,y]of F.pendingWrites||[]){if([p,S,j8].includes(G))continue;if(!(b in K))continue;K[b].writes.push([G,y])}$Q(W,O,Object.values(K),J.getNextVersion.bind(J),this.triggerToNodes)}return rQ(await J.put(j,HQ(W,O,H),{...U,source:"update",step:H+1,parents:F?.metadata?.parents??{}},H0(L,W.channel_versions)),F?F.metadata:void 0)}if(M===H$){if(X.length>1)throw new w("Cannot copy checkpoint with multiple updates");if(F==null)throw new w("Cannot copy a non-existent checkpoint");let K=(G)=>{if(!Array.isArray(G))return!1;if(G.length===0)return!1;return G.every((y)=>Array.isArray(y)&&y.length===2)},x=HQ(W,void 0,H),b=await J.put(F.parentConfig??J0(F.config,{checkpoint_id:void 0}),x,{source:"fork",step:H+1,parents:F.metadata?.parents??{}},{});if(K(D)){let G=sQ(x,F.pendingWrites,this.nodes,O,b,!1,{step:H+2}),y=Object.values(G).reduce((i,{name:C0,id:P8})=>{return i[C0]??=[],i[C0].push({id:P8}),i},{}),g=D.reduce((i,C0)=>{let[P8,D0]=C0;i[D0]??=[];let b1=i[D0].length,S1=y[D0]?.[b1]?.id;return i[D0].push({values:P8,asNode:D0,taskId:S1}),i},{});return q(rQ(b,F.metadata),Object.values(g).flat())}return rQ(b,F.metadata)}if(M===xQ){if(X.length>1)throw new w("Cannot apply multiple updates when updating as input");let K=await GQ(Z8(this.inputChannels,D));if(K.length===0)throw new w(`Received no input writes for ${JSON.stringify(this.inputChannels,null,2)}`);$Q(W,O,[{name:xQ,writes:K,triggers:[]}],J.getNextVersion.bind(this.checkpointer),this.triggerToNodes);let x=F?.metadata?.step!=null?F.metadata.step+1:-1,b=await J.put(j,HQ(W,O,x),{source:"input",step:x,parents:F?.metadata?.parents??{}},H0(L,W.channel_versions));return await J.putWrites(b,K,nQ(xQ,W.id)),rQ(b,F?F.metadata:void 0)}if(B.configurable?.checkpoint_id===void 0&&F?.pendingWrites!==void 0&&F.pendingWrites.length>0){let K=sQ(W,F.pendingWrites,this.nodes,O,F.config,!0,{store:this.store,checkpointer:this.checkpointer,step:(F.metadata?.step??-1)+1}),x=(F.pendingWrites??[]).filter((G)=>G[0]===n).map((G)=>G.slice(1));if(x.length>0)$Q(F.checkpoint,O,[{name:xQ,writes:x,triggers:[]}],void 0,this.triggerToNodes);for(let[G,y,g]of F.pendingWrites){if([p,S,j8].includes(y)||K[G]===void 0)continue;K[G].writes.push([y,g])}let b=Object.values(K).filter((G)=>{return G.writes.length>0});if(b.length>0)$Q(W,O,b,void 0,this.triggerToNodes)}let _=Object.values(W.versions_seen).map((K)=>{return Object.values(K)}).flat().find((K)=>!!K),P=[];if(X.length===1){let{values:K,asNode:x,taskId:b}=X[0];if(x===void 0&&Object.keys(this.nodes).length===1)[x]=Object.keys(this.nodes);else if(x===void 0&&_===void 0){if(typeof this.inputChannels==="string"&&this.nodes[this.inputChannels]!==void 0)x=this.inputChannels}else if(x===void 0){let G=Object.entries(W.versions_seen).map(([y,g])=>{return Object.values(g).map((i)=>{return[i,y]})}).flat().filter(([y,g])=>g!==S).sort(([y],[g])=>H1(y,g));if(G){if(G.length===1)x=G[0][1];else if(G[G.length-1][0]!==G[G.length-2][0])x=G[G.length-1][1]}}if(x===void 0)throw new w('Ambiguous update, specify "asNode"');P.push({values:K,asNode:x,taskId:b})}else for(let{asNode:K,values:x,taskId:b}of X){if(K==null)throw new w('"asNode" is required when applying multiple updates');P.push({values:x,asNode:K,taskId:b})}let I=[];for(let{asNode:K,values:x,taskId:b}of P){if(this.nodes[K]===void 0)throw new w(`Node "${K.toString()}" does not exist`);let G=this.nodes[K].getWriters();if(!G.length)throw new w(`No writers found for node "${K.toString()}"`);I.push({name:K,input:x,proc:G.length>1?Z0.from(G,{omitSequenceTags:!0}):G[0],writes:[],triggers:[S],id:b??nQ(S,W.id),writers:[]})}for(let K of I)await K.proc.invoke(K.input,iQ({...B,store:B?.store??this.store},{runName:B.runName??`${this.getName()}UpdateState`,configurable:{[WQ]:(x)=>K.writes.push(...x),[AQ]:(x,b=!1)=>_0(W,O,K,x,b)}}));for(let K of I){let x=K.writes.filter((b)=>b[0]!==r);if(F!==void 0&&x.length>0)await J.putWrites(j,x,K.id)}$Q(W,O,I,J.getNextVersion.bind(this.checkpointer),this.triggerToNodes);let N=H0(L,W.channel_versions),f=await J.put(j,HQ(W,O,H+1),{source:"update",step:H+1,parents:F?.metadata?.parents??{}},N);for(let K of I){let x=K.writes.filter((b)=>b[0]===r);if(x.length>0)await J.putWrites(f,x,K.id)}return rQ(f,F?F.metadata:void 0)},z=Q;for(let{updates:Y}of $)z=await q(z,Y);return z}async updateState(Q,$,J){return this.bulkUpdateState(Q,[{updates:[{values:$,asNode:J}]}])}_defaults(Q){let{debug:$,streamMode:J,inputKeys:Z,outputKeys:q,interruptAfter:z,interruptBefore:Y,...X}=Q,B=!0,F=$!==void 0?$:this.debug,W=q;if(W===void 0)W=this.streamChannelsAsIs;else $$(W,this.channels);let L=Z;if(L===void 0)L=this.inputChannels;else $$(L,this.channels);let H=Y??this.interruptBefore??[],j=z??this.interruptAfter??[],U;if(J!==void 0)U=Array.isArray(J)?J:[J],B=typeof J==="string";else{if(Q.configurable?.[Y0]!==void 0)U=["values"];else U=this.streamMode;B=!0}let D;if(this.checkpointer===!1)D=void 0;else if(Q!==void 0&&Q.configurable?.[m]!==void 0)D=Q.configurable[m];else if(this.checkpointer===!0)throw Error("checkpointer: true cannot be used for root graphs.");else D=this.checkpointer;let M=Q.store??this.store,O=Q.cache??this.cache;if(Q.durability!=null&&Q.checkpointDuring!=null)throw Error("Cannot use both `durability` and `checkpointDuring` at the same time.");let _=(()=>{if(Q.checkpointDuring==null)return;if(Q.checkpointDuring===!1)return"exit";return"async"})(),P=Q.durability??_??Q?.configurable?.[U$]??"async";return[F,U,L,W,X,H,j,D,M,B,O,P]}async stream(Q,$){let J=new AbortController,Z={recursionLimit:this.config?.recursionLimit,...$,signal:U0($?.signal,J.signal).signal},q=await super.stream(Q,Z);return new n8($?.encoding==="text/event-stream"?J1(q):q,J)}streamEvents(Q,$,J){let Z=new AbortController,q={recursionLimit:this.config?.recursionLimit,...$,callbacks:h$(this.config?.callbacks,$?.callbacks),signal:U0($?.signal,Z.signal).signal};return new n8(super.streamEvents(Q,q,J),Z)}async _validateInput(Q){return Q}async _validateContext(Q){return Q}async*_streamIterator(Q,$){let J="version"in($??{})?void 0:$?.encoding??void 0,Z=$?.subgraphs,q=b0(this.config,$);if(q.recursionLimit===void 0||q.recursionLimit<1)throw Error('Passed "recursionLimit" must be at least 1.');if(this.checkpointer!==void 0&&this.checkpointer!==!1&&q.configurable===void 0)throw Error('Checkpointer requires one or more of the following "configurable" keys: "thread_id", "checkpoint_ns", "checkpoint_id"');let z=await this._validateInput(Q),{runId:Y,...X}=q,[B,F,,W,L,H,j,U,D,M,O,_]=this._defaults(X);if(typeof L.context<"u")L.context=await this._validateContext(L.context);else L.configurable=await this._validateContext(L.configurable);let P=new B8({modes:new Set(F)});if(this.checkpointer===!0){L.configurable??={};let G=L.configurable[FQ]??"";L.configurable[FQ]=G.split(k).map((y)=>y.split(e)[0]).join(k)}if(F.includes("messages")){let G=new F1((g)=>P.push(g)),{callbacks:y}=L;if(y===void 0)L.callbacks=[G];else if(Array.isArray(y))L.callbacks=y.concat(G);else{let g=y.copy();g.addHandler(G,!0),L.callbacks=g}}if(F.includes("tools")){let G=new $1((g)=>P.push(g)),{callbacks:y}=L;if(y===void 0)L.callbacks=[G];else if(Array.isArray(y))L.callbacks=y.concat(G);else{let g=y.copy();g.addHandler(G,!0),L.callbacks=g}}L.writer??=(G)=>{if(!F.includes("custom"))return;let y=h8()?.configurable?.[FQ]?.split(k).slice(0,-1);P.push([y??[],"custom",G])},L.interrupt??=this.userInterrupt??N8;let I=await(await j1(L))?.handleChainStart(this.toJSON(),m$(Q,"input"),Y,void 0,void 0,void 0,L?.runName??this.getName()),N=w0(this.channels),f,K,b=(async()=>{try{f=await z1.initialize({input:z,config:L,checkpointer:U,nodes:this.nodes,channelSpecs:N,outputKeys:W,streamKeys:this.streamChannelsAsIs,store:D,cache:O,stream:P,interruptAfter:j,interruptBefore:H,manager:I,debug:this.debug,triggerToNodes:this.triggerToNodes,durability:_});let G=new B1({loop:f,nodeFinished:L.configurable?.[V$]});if($?.subgraphs)f.config.configurable={...f.config.configurable,[K0]:f.stream};if(await this._runLoop({loop:f,runner:G,debug:B,config:L}),_==="sync")await Promise.all(f?.checkpointerPromises??[])}catch(G){K=G}finally{try{if(f)await f.store?.stop(),await f.cache?.stop();await Promise.all(f?.checkpointerPromises??[])}catch(G){K=K??G}if(K)P.error(K);else P.close()}})();try{for await(let G of P){if(G===void 0)throw Error("Data structure error.");let[y,g,i]=G;if(F.includes(g)){if(J==="text/event-stream"){if(Z)yield[y,g,i];else yield[null,g,i];continue}if(Z&&!M)yield[y,g,i];else if(!M)yield[g,i];else if(Z)yield[y,i];else yield i}}}catch(G){throw await I?.handleChainError(K),G}finally{await b}await I?.handleChainEnd(f?.output??{},Y,void 0,void 0,void 0)}async invoke(Q,$){let J=$?.streamMode??"values",Z={...$,outputKeys:$?.outputKeys??this.outputChannels,streamMode:J,encoding:void 0},q=[],z=await this.stream(Q,Z),Y=[],X;for await(let B of z)if(J==="values")if(F0(B))Y.push(B[S]);else X=B;else q.push(B);if(J==="values"){if(Y.length>0){let B=Y.flat(1);if(X==null)return{[S]:B};if(typeof X==="object")return{...X,[S]:B}}return X}return q}async _runLoop(Q){let{loop:$,runner:J,debug:Z,config:q}=Q,z;try{while(await $.tick({inputKeys:this.inputChannels})){for(let{task:Y}of await $._matchCachedWrites())$._outputWrites(Y.id,Y.writes,!0);if(Z)t$($.checkpointMetadata.step,$.channels,this.streamChannelsList);if(Z)X8($.step,Object.values($.tasks));await J.tick({timeout:this.stepTimeout,retryPolicy:this.retryPolicy,onStepWrite:(Y,X)=>{if(Z)a$(Y,X,this.streamChannelsList)},maxConcurrency:q.maxConcurrency,signal:q.signal})}if($.status==="out_of_steps")throw new l0([`Recursion limit of ${q.recursionLimit} reached`,"without hitting a stop condition. You can increase the",'limit by setting the "recursionLimit" config key.'].join(" "),{lc_error_code:"GRAPH_RECURSION_LIMIT"})}catch(Y){if(z=Y,!await $.finishAndHandleError(z))throw Y}finally{if(z===void 0)await $.finishAndHandleError()}}async clearCache(){await this.cache?.clear([])}};D1();var q$=class{path;ends;constructor(Q){if(YQ.isRunnable(Q.path))this.path=Q.path;else this.path=yQ(Q.path);this.ends=Array.isArray(Q.pathMap)?Q.pathMap.reduce(($,J)=>{return $[J]=J,$},{}):Q.pathMap}run(Q,$){return h.registerWriter(new s({name:"<branch_run>",trace:!1,func:async(J,Z)=>{try{return await this._route(J,Z,Q,$)}catch(q){if(q.name===A0.unminifiable_name)console.warn(`[WARN]: 'NodeInterrupt' thrown in conditional edge. This is likely a bug in your graph implementation.
14
- NodeInterrupt should only be thrown inside a node, not in edge conditions.`);throw q}}}))}async _route(Q,$,J,Z){let q=await this.path.invoke(Z?Z($):Q,$);if(!Array.isArray(q))q=[q];let z;if(this.ends)z=q.map((Y)=>d(Y)?Y:this.ends[Y]);else z=q;if(z.some((Y)=>!Y))throw Error("Branch condition returned unknown or null destination");if(z.filter(d).some((Y)=>Y.node===A))throw new w("Cannot send a packet to the END node");return await J(z,$)??Q}},E0=class{nodes;edges;branches;entryPoint;compiled=!1;constructor(){this.nodes={},this.edges=new Set,this.branches={}}warnIfCompiled(Q){if(this.compiled)console.warn(Q)}get allEdges(){return this.edges}addNode(...Q){function $(Z){return Z.length>=1&&typeof Z[0]!=="string"}let J=$(Q)?Array.isArray(Q[0])?Q[0]:Object.entries(Q[0]):[[Q[0],Q[1],Q[2]]];if(J.length===0)throw Error("No nodes provided in `addNode`");for(let[Z,q,z]of J){for(let X of[k,e])if(Z.includes(X))throw Error(`"${X}" is a reserved character and is not allowed in node names.`);if(this.warnIfCompiled("Adding a node to a graph that has already been compiled. This will not be reflected in the compiled graph."),Z in this.nodes)throw Error(`Node \`${Z}\` already present.`);if(Z===A)throw Error(`Node \`${Z}\` is reserved.`);let Y=yQ(q);this.nodes[Z]={runnable:Y,metadata:z?.metadata,subgraphs:S0(Y)?[Y]:z?.subgraphs,ends:z?.ends}}return this}addEdge(Q,$){if(this.warnIfCompiled("Adding an edge to a graph that has already been compiled. This will not be reflected in the compiled graph."),Q===A)throw Error("END cannot be a start node");if($===T)throw Error("START cannot be an end node");if(Array.from(this.edges).some(([J])=>J===Q)&&!("channels"in this))throw Error(`Already found path for ${Q}. For multiple edges, use StateGraph.`);return this.edges.add([Q,$]),this}addConditionalEdges(Q,$,J){let Z=typeof Q==="object"?Q:{source:Q,path:$,pathMap:J};if(this.warnIfCompiled("Adding an edge to a graph that has already been compiled. This will not be reflected in the compiled graph."),!YQ.isRunnable(Z.path))Z.path=yQ(Z.path);let q=Z.path.getName()==="RunnableLambda"?"condition":Z.path.getName();if(this.branches[Z.source]&&this.branches[Z.source][q])throw Error(`Condition \`${q}\` already present for node \`${Q}\``);return this.branches[Z.source]??={},this.branches[Z.source][q]=new q$(Z),this}setEntryPoint(Q){return this.warnIfCompiled("Setting the entry point of a graph that has already been compiled. This will not be reflected in the compiled graph."),this.addEdge(T,Q)}setFinishPoint(Q){return this.warnIfCompiled("Setting a finish point of a graph that has already been compiled. This will not be reflected in the compiled graph."),this.addEdge(Q,A)}compile({checkpointer:Q,interruptBefore:$,interruptAfter:J,name:Z}={}){this.validate([...Array.isArray($)?$:[],...Array.isArray(J)?J:[]]);let q=new z$({builder:this,checkpointer:Q,interruptAfter:J,interruptBefore:$,autoValidate:!1,nodes:{},channels:{[T]:new VQ,[A]:new VQ},inputChannels:T,outputChannels:A,streamChannels:[],streamMode:"values",name:Z});for(let[z,Y]of Object.entries(this.nodes))q.attachNode(z,Y);for(let[z,Y]of this.edges)q.attachEdge(z,Y);for(let[z,Y]of Object.entries(this.branches))for(let[X,B]of Object.entries(Y))q.attachBranch(z,X,B);return q.validate()}validate(Q){let $=new Set([...this.allEdges].map(([Z,q])=>Z));for(let[Z]of Object.entries(this.branches))$.add(Z);for(let Z of $)if(Z!==T&&!(Z in this.nodes))throw Error(`Found edge starting at unknown node \`${Z}\``);let J=new Set([...this.allEdges].map(([Z,q])=>q));for(let[Z,q]of Object.entries(this.branches))for(let z of Object.values(q))if(z.ends!=null)for(let Y of Object.values(z.ends))J.add(Y);else{J.add(A);for(let Y of Object.keys(this.nodes))if(Y!==Z)J.add(Y)}for(let Z of Object.values(this.nodes))for(let q of Z.ends??[])J.add(q);for(let Z of Object.keys(this.nodes))if(!J.has(Z))throw new c0([`Node \`${Z}\` is not reachable.`,"","If you are returning Command objects from your node,",'make sure you are passing names of potential destination nodes as an "ends" array','into ".addNode(..., { ends: ["node1", "node2"] })".'].join(`
15
- `),{lc_error_code:"UNREACHABLE_NODE"});for(let Z of J)if(Z!==A&&!(Z in this.nodes))throw Error(`Found edge ending at unknown node \`${Z}\``);if(Q){for(let Z of Q)if(!(Z in this.nodes))throw Error(`Interrupt node \`${Z}\` is not present`)}this.compiled=!0}},z$=class extends H8{builder;constructor({builder:Q,...$}){super($);this.builder=Q}attachNode(Q,$){this.channels[Q]=new VQ,this.nodes[Q]=new KQ({channels:[],triggers:[],metadata:$.metadata,subgraphs:$.subgraphs,ends:$.ends}).pipe($.runnable).pipe(new h([{channel:Q,value:qQ}],[E])),this.streamChannels.push(Q)}attachEdge(Q,$){if($===A){if(Q===T)throw Error("Cannot have an edge from START to END");this.nodes[Q].writers.push(new h([{channel:A,value:qQ}],[E]))}else this.nodes[$].triggers.push(Q),this.nodes[$].channels.push(Q)}attachBranch(Q,$,J){if(Q===T&&!this.nodes[T])this.nodes[T]=U1.subscribeTo(T,{tags:[E]});this.nodes[Q].pipe(J.run((q)=>{return new h(q.map((z)=>{if(d(z))return z;return{channel:z===A?A:`branch:${Q}:${$}:${z}`,value:qQ}}),[E])}));let Z=J.ends?Object.values(J.ends):Object.keys(this.nodes);for(let q of Z)if(q!==A){let z=`branch:${Q}:${$}:${q}`;this.channels[z]=new VQ,this.nodes[q].triggers.push(z),this.nodes[q].channels.push(z)}}async getGraphAsync(Q){let $=Q?.xray,J=new Z$,Z={[T]:J.addNode({schema:tQ.any()},T)},q={},z={};if($)z=Object.fromEntries((await GQ(this.getSubgraphsAsync())).filter((B)=>V1(B[1])));function Y(B,F,W,L=!1){if(F===A&&q[A]===void 0)q[A]=J.addNode({schema:tQ.any()},A);if(Z[B]===void 0)return;if(q[F]===void 0)throw Error(`End node ${F} not found!`);return J.addEdge(Z[B],q[F],W!==F?W:void 0,L)}for(let[B,F]of Object.entries(this.builder.nodes)){let W=t(B),L=F.runnable,H=F.metadata??{};if(this.interruptBefore?.includes(B)&&this.interruptAfter?.includes(B))H.__interrupt="before,after";else if(this.interruptBefore?.includes(B))H.__interrupt="before";else if(this.interruptAfter?.includes(B))H.__interrupt="after";if($){let j=typeof $==="number"?$-1:$,U=z[B]!==void 0?await z[B].getGraphAsync({...Q,xray:j}):L.getGraph(Q);if(U.trimFirstNode(),U.trimLastNode(),Object.keys(U.nodes).length>1){let O=function(P){return P?P.lc_runnable:!1},_=function(P,I){if(P!==void 0&&!J$(P))return P;else if(O(I))try{let N=I.getName();return N=N.startsWith("Runnable")?N.slice(8):N,N}catch(N){return I.getName()}else return I.name??"UnknownSchema"},[D,M]=J.extend(U,W);if(D===void 0)throw Error(`Could not extend subgraph "${B}" due to missing entrypoint.`);if(M!==void 0)Z[W]={name:_(M.id,M.data),...M};q[W]={name:_(D.id,D.data),...D}}else{let D=J.addNode(L,W,H);Z[W]=D,q[W]=D}}else{let j=J.addNode(L,W,H);Z[W]=j,q[W]=j}}let X=[...this.builder.allEdges].sort(([B],[F])=>{if(B<F)return-1;else if(F>B)return 1;else return 0});for(let[B,F]of X)Y(t(B),t(F));for(let[B,F]of Object.entries(this.builder.branches)){let W={...Object.fromEntries(Object.keys(this.builder.nodes).filter((L)=>L!==B).map((L)=>[t(L),t(L)])),[A]:A};for(let L of Object.values(F)){let H;if(L.ends!==void 0)H=L.ends;else H=W;for(let[j,U]of Object.entries(H))Y(t(B),t(U),j,!0)}}for(let[B,F]of Object.entries(this.builder.nodes))if(F.ends!==void 0)for(let W of F.ends)Y(t(B),t(W),void 0,!0);return J}getGraph(Q){let $=Q?.xray,J=new Z$,Z={[T]:J.addNode({schema:tQ.any()},T)},q={},z={};if($)z=Object.fromEntries($0(this.getSubgraphs()).filter((B)=>V1(B[1])));function Y(B,F,W,L=!1){if(F===A&&q[A]===void 0)q[A]=J.addNode({schema:tQ.any()},A);return J.addEdge(Z[B],q[F],W!==F?W:void 0,L)}for(let[B,F]of Object.entries(this.builder.nodes)){let W=t(B),L=F.runnable,H=F.metadata??{};if(this.interruptBefore?.includes(B)&&this.interruptAfter?.includes(B))H.__interrupt="before,after";else if(this.interruptBefore?.includes(B))H.__interrupt="before";else if(this.interruptAfter?.includes(B))H.__interrupt="after";if($){let j=typeof $==="number"?$-1:$,U=z[B]!==void 0?z[B].getGraph({...Q,xray:j}):L.getGraph(Q);if(U.trimFirstNode(),U.trimLastNode(),Object.keys(U.nodes).length>1){let O=function(P){return P?P.lc_runnable:!1},_=function(P,I){if(P!==void 0&&!J$(P))return P;else if(O(I))try{let N=I.getName();return N=N.startsWith("Runnable")?N.slice(8):N,N}catch(N){return I.getName()}else return I.name??"UnknownSchema"},[D,M]=J.extend(U,W);if(D===void 0)throw Error(`Could not extend subgraph "${B}" due to missing entrypoint.`);if(M!==void 0)Z[W]={name:_(M.id,M.data),...M};q[W]={name:_(D.id,D.data),...D}}else{let D=J.addNode(L,W,H);Z[W]=D,q[W]=D}}else{let j=J.addNode(L,W,H);Z[W]=j,q[W]=j}}let X=[...this.builder.allEdges].sort(([B],[F])=>{if(B<F)return-1;else if(F>B)return 1;else return 0});for(let[B,F]of X)Y(t(B),t(F));for(let[B,F]of Object.entries(this.builder.branches)){let W={...Object.fromEntries(Object.keys(this.builder.nodes).filter((L)=>L!==B).map((L)=>[t(L),t(L)])),[A]:A};for(let L of Object.values(F)){let H;if(L.ends!==void 0)H=L.ends;else H=W;for(let[j,U]of Object.entries(H))Y(t(B),t(U),j,!0)}}return J}};function V1(Q){return typeof Q.attachNode==="function"&&typeof Q.attachEdge==="function"}function t(Q){if(Q==="subgraph")return`"${Q}"`;return Q}D1();var D8="__remove_all__";function mQ(Q,$){let J=Array.isArray(Q)?Q:[Q],Z=Array.isArray($)?$:[$],q=J.map(V8),z=Z.map(V8);for(let W of q)if(W.id===null||W.id===void 0)W.id=Y$(),W.lc_kwargs.id=W.id;let Y;for(let W=0;W<z.length;W+=1){let L=z[W];if(L.id===null||L.id===void 0)L.id=Y$(),L.lc_kwargs.id=L.id;if(U8.isInstance(L)&&L.id===D8)Y=W}if(Y!=null)return z.slice(Y+1);let X=[...q],B=new Map(X.map((W,L)=>[W.id,L])),F=new Set;for(let W of z){let L=B.get(W.id);if(L!==void 0)if(U8.isInstance(W))F.add(W.id);else F.delete(W.id),X[L]=W;else{if(U8.isInstance(W))throw Error(`Attempting to delete a message with an ID that doesn't exist ('${W.id}')`);B.set(W.id,X.length),X.push(W)}}return X.filter((W)=>!F.has(W.id))}var A6=tQ.custom().default(()=>[]),O6=tQ.custom(),G8=new BQ(A6,{inputSchema:O6,reducer:mQ,jsonSchemaExtra:{langgraph_type:"messages",description:"A list of chat messages"}});var P6="lg:",w6=class{_map=new Map;_extensionCache=new Map;get(Q){return this._map.get(Q)}extend(Q,$){let J=this.get(Q);this._map.set(Q,$(J))}remove(Q){return this._map.delete(Q),this}has(Q){return this._map.has(Q)}getChannelsForSchema(Q){let $={},J=F$(Q);for(let[Z,q]of Object.entries(J)){let z=this.get(q);if(z?.reducer)$[Z]=new bQ(z.reducer.fn,z.default);else $[Z]=new UQ(z?.default)}return $}getExtendedChannelSchemas(Q,$){if(Object.keys($).length===0)return Q;let J=Object.entries($).filter(([,z])=>z===!0).sort(([z],[Y])=>z.localeCompare(Y)).map(([z,Y])=>`${z}:${Y}`).join("|"),Z=this._extensionCache.get(J)??new Map;if(Z.has(Q))return Z.get(Q);let q=Q;if($.withReducerSchema||$.withJsonSchemaExtrasAsDescription){let z=Object.entries(F$(Q)).map(([Y,X])=>{let B=this.get(X),F=$.withReducerSchema?B?.reducer?.schema??X:X;if($.withJsonSchemaExtrasAsDescription&&B?.jsonSchemaExtra){let W=X$(F)??X$(X),L=JSON.stringify({...B.jsonSchemaExtra,description:W});F=F.describe(`${P6}${L}`)}return[Y,F]});if(q=M1(Q,Object.fromEntries(z)),K1(q))q._def.unknownKeys="strip"}if($.asPartial)q=K8(q);return Z.set(Q,q),this._extensionCache.set(J,Z),q}},v0=new w6;function A1(Q,$){if($.reducer&&!$.default){let J=x1(Q);if(J!=null)$.default=J}if($.reducer){let J=Object.assign(Q,{lg_reducer_schema:$.reducer?.schema??Q});return v0.extend(J,()=>$),J}else return v0.extend(Q,()=>$),Q}function z0(Q){if(Q==null)return!1;if(LQ.isInstance(Q))return!0;if(XQ(Q))return!0;if(typeof Q==="object"&&"lc_graph_name"in Q&&Q.lc_graph_name==="AnnotationRoot")return!0;if(typeof Q==="object"&&!Array.isArray(Q)&&Object.keys(Q).length>0&&Object.values(Q).every(($)=>typeof $==="function"||E8($)))return!0;return!1}function O1(Q){if(typeof Q!=="object"||Q==null)return!1;let $=Q,J="state"in $&&z0($.state),Z="stateSchema"in $&&z0($.stateSchema),q="input"in $&&z0($.input);if(!J&&!Z&&!q)return!1;if("input"in $&&$.input!=null&&!z0($.input))return!1;if("output"in $&&$.output!=null&&!z0($.output))return!1;return!0}var hQ="__root__",x8=Symbol.for("langgraph.state.partial"),A8=class extends E0{channels={};waitingEdges=new Set;_schemaDefinition;_schemaRuntimeDefinition;_inputDefinition;_inputRuntimeDefinition;_outputDefinition;_outputRuntimeDefinition;_schemaDefinitions=new Map;_metaRegistry=v0;_configSchema;_configRuntimeSchema;_interrupt;_writer;constructor(Q,$){super();let J=this._normalizeToStateGraphInit(Q,$),Z=J.state??J.stateSchema??J.input;if(!Z)throw new B0;let q=this._getChannelsFromSchema(Z);if(this._schemaDefinition=q,LQ.isInstance(Z))this._schemaRuntimeDefinition=Z;else if(XQ(Z))this._schemaRuntimeDefinition=Z;if(J.input)if(LQ.isInstance(J.input))this._inputRuntimeDefinition=J.input;else if(XQ(J.input))this._inputRuntimeDefinition=J.input;else this._inputRuntimeDefinition=x8;else this._inputRuntimeDefinition=x8;if(J.output)if(LQ.isInstance(J.output))this._outputRuntimeDefinition=J.output;else if(XQ(J.output))this._outputRuntimeDefinition=J.output;else this._outputRuntimeDefinition=this._schemaRuntimeDefinition;else this._outputRuntimeDefinition=this._schemaRuntimeDefinition;let z=J.input?this._getChannelsFromSchema(J.input):q,Y=J.output?this._getChannelsFromSchema(J.output):q;if(this._inputDefinition=z,this._outputDefinition=Y,this._addSchema(this._schemaDefinition),this._addSchema(this._inputDefinition),this._addSchema(this._outputDefinition),J.context){if(XQ(J.context))this._configRuntimeSchema=J.context}this._interrupt=J.interrupt,this._writer=J.writer}_normalizeToStateGraphInit(Q,$){if(O1(Q)){if(XQ($)||T0.isInstance($))return{...Q,context:$};let J=$;return{...Q,input:Q.input??J?.input,output:Q.output??J?.output,context:Q.context??J?.context,interrupt:Q.interrupt??J?.interrupt,writer:Q.writer??J?.writer,nodes:Q.nodes??J?.nodes}}if(z0(Q)){if(XQ($)||T0.isInstance($))return{state:Q,context:$};let J=$;return{state:Q,input:J?.input,output:J?.output,context:J?.context,interrupt:J?.interrupt,writer:J?.writer,nodes:J?.nodes}}if(T6(Q))return{state:R6(Q.channels)};throw new B0}_getChannelsFromSchema(Q){if(LQ.isInstance(Q))return Q.getChannels();if(XQ(Q))return this._metaRegistry.getChannelsForSchema(Q);if(typeof Q==="object"&&"lc_graph_name"in Q&&Q.lc_graph_name==="AnnotationRoot")return Q.spec;if(typeof Q==="object"&&!Array.isArray(Q)&&Object.keys(Q).length>0)return Q;throw new B0("Invalid schema type. Expected StateSchema, Zod object, AnnotationRoot, or StateDefinition.")}get allEdges(){return new Set([...this.edges,...Array.from(this.waitingEdges).flatMap(([Q,$])=>Q.map((J)=>[J,$]))])}_addSchema(Q){if(this._schemaDefinitions.has(Q))return;this._schemaDefinitions.set(Q,Q);for(let[$,J]of Object.entries(Q)){let Z;if(typeof J==="function")Z=J();else Z=J;if(this.channels[$]!==void 0){if(!this.channels[$].equals(Z)){if(Z.lc_graph_name!=="LastValue")throw Error(`Channel "${$}" already exists with a different type.`)}}else this.channels[$]=Z}}addNode(...Q){function $(Z){return Z.length>=1&&typeof Z[0]!=="string"}let J=$(Q)?Array.isArray(Q[0])?Q[0]:Object.entries(Q[0]).map(([Z,q])=>[Z,q]):[[Q[0],Q[1],Q[2]]];if(J.length===0)throw Error("No nodes provided in `addNode`");for(let[Z,q,z]of J){if(Z in this.channels)throw Error(`${Z} is already being used as a state attribute (a.k.a. a channel), cannot also be used as a node name.`);for(let W of[k,e])if(Z.includes(W))throw Error(`"${W}" is a reserved character and is not allowed in node names.`);if(this.warnIfCompiled("Adding a node to a graph that has already been compiled. This will not be reflected in the compiled graph."),Z in this.nodes)throw Error(`Node \`${Z}\` already present.`);if(Z===A||Z===T)throw Error(`Node \`${Z}\` is reserved.`);let Y=this._schemaDefinition;if(z?.input!==void 0)Y=this._getChannelsFromSchema(z.input);this._addSchema(Y);let X;if(YQ.isRunnable(q))X=q;else if(typeof q==="function")X=new s({func:q,name:Z,trace:!1});else X=yQ(q);let B=z?.cachePolicy;if(typeof B==="boolean")B=B?{}:void 0;let F={runnable:X,retryPolicy:z?.retryPolicy,cachePolicy:B,metadata:z?.metadata,input:Y??this._schemaDefinition,subgraphs:S0(X)?[X]:z?.subgraphs,ends:z?.ends,defer:z?.defer};this.nodes[Z]=F}return this}addEdge(Q,$){if(typeof Q==="string")return super.addEdge(Q,$);if(this.compiled)console.warn("Adding an edge to a graph that has already been compiled. This will not be reflected in the compiled graph.");for(let J of Q){if(J===A)throw Error("END cannot be a start node");if(!Object.keys(this.nodes).some((Z)=>Z===J))throw Error(`Need to add a node named "${J}" first`)}if($===A)throw Error("END cannot be an end node");if(!Object.keys(this.nodes).some((J)=>J===$))throw Error(`Need to add a node named "${$}" first`);return this.waitingEdges.add([Q,$]),this}addSequence(Q){let $=Array.isArray(Q)?Q:Object.entries(Q);if($.length===0)throw Error("Sequence requires at least one node.");let J;for(let[Z,q,z]of $){if(Z in this.nodes)throw Error(`Node names must be unique: node with the name "${Z}" already exists.`);let Y=Z;if(this.addNode(Y,q,z),J!=null)this.addEdge(J,Y);J=Y}return this}compile({checkpointer:Q,store:$,cache:J,interruptBefore:Z,interruptAfter:q,name:z,description:Y}={}){this.validate([...Array.isArray(Z)?Z:[],...Array.isArray(q)?q:[]]);let X=Object.keys(this._schemaDefinitions.get(this._outputDefinition)),B=X.length===1&&X[0]===hQ?hQ:X,F=Object.keys(this.channels),W=F.length===1&&F[0]===hQ?hQ:F,L=this._interrupt,H=new O8({builder:this,checkpointer:Q,interruptAfter:q,interruptBefore:Z,autoValidate:!1,nodes:{},channels:{...this.channels,[T]:new VQ},inputChannels:T,outputChannels:B,streamChannels:W,streamMode:"updates",store:$,cache:J,name:z,description:Y,userInterrupt:L});H.attachNode(T);for(let[j,U]of Object.entries(this.nodes))H.attachNode(j,U);H.attachBranch(T,T8,P1(),{withReader:!1});for(let[j]of Object.entries(this.nodes))H.attachBranch(j,T8,P1(),{withReader:!1});for(let[j,U]of this.edges)H.attachEdge(j,U);for(let[j,U]of this.waitingEdges)H.attachEdge(j,U);for(let[j,U]of Object.entries(this.branches))for(let[D,M]of Object.entries(U))H.attachBranch(j,D,M);return H.validate()}};function R6(Q){let $={};for(let[J,Z]of Object.entries(Q))if(J===hQ)$[J]=a0(Z);else $[J]=a0(Z);return $}var O8=class extends z${description;_metaRegistry=v0;constructor({description:Q,...$}){super($);this.description=Q}attachNode(Q,$){let J;if(Q===T)J=Object.entries(this.builder._schemaDefinitions.get(this.builder._inputDefinition)).map(([X])=>X);else J=Object.keys(this.builder.channels);function Z(X){if(u(X)){if(X.graph===a.PARENT)return null;return X._updateAsTuples()}else if(Array.isArray(X)&&X.length>0&&X.some((B)=>u(B))){let B=[];for(let F of X)if(u(F)){if(F.graph===a.PARENT)continue;B.push(...F._updateAsTuples())}else B.push([hQ,F]);return B}else if(X!=null)return[[hQ,X]];return null}let q=Q;function z(X){if(!X)return null;else if(u(X)){if(X.graph===a.PARENT)return null;return X._updateAsTuples().filter(([B])=>J.includes(B))}else if(Array.isArray(X)&&X.length>0&&X.some(u)){let B=[];for(let F of X)if(u(F)){if(F.graph===a.PARENT)continue;B.push(...F._updateAsTuples().filter(([W])=>J.includes(W)))}else{let W=z(F);if(W)B.push(...W??[])}return B}else if(typeof X==="object"&&!Array.isArray(X))return Object.entries(X).filter(([B])=>J.includes(B));else{let B=Array.isArray(X)?"array":typeof X;throw new w(`Expected node "${q.toString()}" to return an object or an array containing at least one Command object, received ${B}`,{lc_error_code:"INVALID_GRAPH_NODE_RETURN_VALUE"})}}let Y=[{value:qQ,mapper:new s({func:J.length&&J[0]===hQ?Z:z,trace:!1,recurse:!1})}];if(Q===T)this.nodes[Q]=new KQ({tags:[E],triggers:[T],channels:[T],writers:[new h(Y,[E])]});else{let X=$?.input??this.builder._schemaDefinition,B=Object.fromEntries(Object.keys(this.builder._schemaDefinitions.get(X)).map((L)=>[L,L])),F=Object.keys(B).length===1&&hQ in B,W=`branch:to:${Q}`;this.channels[W]=$?.defer?new v8:new VQ(!1),this.nodes[Q]=new KQ({triggers:[W],channels:F?Object.keys(B):B,writers:[new h(Y,[E])],mapper:F?void 0:(L)=>{return Object.fromEntries(Object.entries(L).filter(([H])=>(H in B)))},bound:$?.runnable,metadata:$?.metadata,retryPolicy:$?.retryPolicy,cachePolicy:$?.cachePolicy,subgraphs:$?.subgraphs,ends:$?.ends})}}attachEdge(Q,$){if($===A)return;if(typeof Q==="string")this.nodes[Q].writers.push(new h([{channel:`branch:to:${$}`,value:null}],[E]));else if(Array.isArray(Q)){let J=`join:${Q.join("+")}:${$}`;this.channels[J]=this.builder.nodes[$].defer?new g8(new Set(Q)):new k8(new Set(Q)),this.nodes[$].triggers.push(J);for(let Z of Q)this.nodes[Z].writers.push(new h([{channel:J,value:Z}],[E]))}}attachBranch(Q,$,J,Z={withReader:!0}){let q=async(z,Y)=>{let X=z.filter((F)=>F!==A);if(!X.length)return;let B=X.map((F)=>{if(d(F))return F;return{channel:F===A?F:`branch:to:${F}`,value:Q}});await h.doWrite({...Y,tags:(Y.tags??[]).concat([E])},B)};this.nodes[Q].writers.push(J.run(q,Z.withReader?(z)=>f$.doRead(z,this.streamChannels??this.outputChannels,!0):void 0))}async _validateInput(Q){if(Q==null)return Q;let $=this.builder._inputRuntimeDefinition,J=this.builder._schemaRuntimeDefinition;if(LQ.isInstance($)){if(u(Q)){let q=Q;if(Q.update)q.update=await $.validateInput(Array.isArray(Q.update)?Object.fromEntries(Q.update):Q.update);return q}return await $.validateInput(Q)}if($===x8&&LQ.isInstance(J)){if(u(Q)){let q=Q;if(Q.update)q.update=await J.validateInput(Array.isArray(Q.update)?Object.fromEntries(Q.update):Q.update);return q}return await J.validateInput(Q)}let Z=(()=>{let q=(z)=>{if(z==null)return;return this._metaRegistry.getExtendedChannelSchemas(z,{withReducerSchema:!0})};if(XQ($))return q($);if($===x8){if(XQ(J))return K8(q(J));return}})();if(u(Q)){let q=Q;if(Q.update&&Z!=null)q.update=M8(Z,Q.update);return q}if(Z!=null)return M8(Z,Q);return Q}isInterrupted(Q){return F0(Q)}async _validateContext(Q){let $=this.builder._configRuntimeSchema;if(XQ($))M8($,Q);return Q}};function T6(Q){return typeof Q==="object"&&Q!==null&&Q.channels!==void 0}function b6(Q){if(d(Q))return[Q];let $=[];if(u(Q))$.push(Q);else if(Array.isArray(Q))$.push(...Q.filter(u));let J=[];for(let Z of $){if(Z.graph===a.PARENT)throw new O0(Z);if(d(Z.goto))J.push(Z.goto);else if(typeof Z.goto==="string")J.push(Z.goto);else if(Array.isArray(Z.goto))J.push(...Z.goto)}return J}function P1(){return new q$({path:new s({func:b6,tags:[E],trace:!1,recurse:!1,name:"<control_branch>"})})}var B$=function($,J){let{name:Z,checkpointer:q,store:z,cache:Y}=typeof $==="string"?{name:$,checkpointer:void 0,store:void 0}:$;if(y$(J)||E$(J))throw Error("Generators are disallowed as entrypoints. For streaming responses, use config.write.");let X="updates",B=l$(Z,J);function F(j){return typeof j==="object"&&j!==null&&"__lg_type"in j&&j.__lg_type==="__pregel_final"}let W=new s({name:"pluckReturnValue",func:(j)=>{return F(j)?j.value:j}}),L=new s({name:"pluckSaveValue",func:(j)=>{return F(j)?j.save:j}}),H=new KQ({bound:B,triggers:[T],channels:[T],writers:[new h([{channel:A,value:qQ,mapper:W},{channel:aQ,value:qQ,mapper:L}],[E])]});return new H8({name:Z,checkpointer:q,nodes:{[Z]:H},channels:{[T]:new VQ,[A]:new UQ,[aQ]:new UQ},inputChannels:T,outputChannels:A,streamChannels:A,streamMode:X,store:z,cache:Y})};B$.final=function({value:$,save:J}){return{value:$,save:J,__lg_type:"__pregel_final"}};var w1=Q0.Root({messages:Q0({reducer:mQ,default:()=>[]})}),W$={reducer:{fn:mQ},jsonSchemaExtra:{langgraph_type:"messages"},default:()=>[]},R1=L$.object({messages:A1(L$.custom(),W$)});N$();
16
- export{T as jg,A as kg,uQ as lg,a as mg,u as ng,pQ as og,wQ as pg,Q0 as qg,a1 as rg,N8 as sg,BQ as tg,IQ as ug,LQ as vg,G8 as wg,v0 as xg,A1 as yg,A8 as zg,w1 as Ag,W$ as Bg};
13
+ `))};try{for await(let q of Q){let[z,Y,X]=q,B=X;if(Y==="debug"){let F=X;if(F.type==="checkpoint")B={...F,payload:$1(F.payload)}}if(Y==="checkpoints")B=$1(X);Z({event:z?.length?`${Y}|${z.join("|")}`:Y,data:B})}}catch(q){Z({event:"error",data:L6(q)})}J.close()}})}var U8=Symbol.for("INPUT_DONE"),a8=Symbol.for("INPUT_RESUMING"),W6=25;function j6(...Q){return new H8({passthroughFn:($)=>{for(let J of Q)if(J.modes.has($[1]))J.push($)},modes:new Set(Q.flatMap(($)=>Array.from($.modes)))})}var H6=class extends z1{cache;queue=Promise.resolve();constructor(Q){super();this.cache=Q}async get(Q){return this.enqueueOperation("get",Q)}async set(Q){return this.enqueueOperation("set",Q)}async clear(Q){return this.enqueueOperation("clear",Q)}async stop(){await this.queue}enqueueOperation(Q,...$){let J=this.queue.then(()=>{return this.cache[Q](...$)});return this.queue=J.then(()=>{return},()=>{return}),J}},Y1=class Q{input;output;config;checkpointer;checkpointerGetNextVersion;channels;checkpoint;checkpointIdSaved;checkpointConfig;checkpointMetadata;checkpointNamespace;checkpointPendingWrites=[];checkpointPreviousVersions;step;stop;durability;outputKeys;streamKeys;nodes;skipDoneTasks;prevCheckpointConfig;updatedChannels;status="pending";tasks={};stream;checkpointerPromises=[];isNested;_checkpointerChainedPromise=Promise.resolve();store;cache;manager;interruptAfter;interruptBefore;toInterrupt=[];debug=!1;triggerToNodes;get isResuming(){let $=!1;if(T in this.checkpoint.channel_versions)$=!0;else for(let X in this.checkpoint.channel_versions)if(Object.prototype.hasOwnProperty.call(this.checkpoint.channel_versions,X)){$=!0;break}let J=this.config.configurable?.[EQ]!==void 0&&this.config.configurable?.[EQ],Z=this.input===null||this.input===void 0,q=u(this.input)&&this.input.resume!=null,z=this.input===a8,Y=!this.isNested&&this.config.metadata?.run_id!==void 0&&this.checkpointMetadata?.run_id!==void 0&&this.config.metadata.run_id===this.checkpointMetadata?.run_id;return $&&(J||Z||q||z||Y)}constructor($){if(this.input=$.input,this.checkpointer=$.checkpointer,this.checkpointer!==void 0)this.checkpointerGetNextVersion=this.checkpointer.getNextVersion.bind(this.checkpointer);else this.checkpointerGetNextVersion=i$;this.checkpoint=$.checkpoint,this.checkpointMetadata=$.checkpointMetadata,this.checkpointPreviousVersions=$.checkpointPreviousVersions,this.channels=$.channels,this.checkpointPendingWrites=$.checkpointPendingWrites,this.step=$.step,this.stop=$.stop,this.config=$.config,this.checkpointConfig=$.checkpointConfig,this.isNested=$.isNested,this.manager=$.manager,this.outputKeys=$.outputKeys,this.streamKeys=$.streamKeys,this.nodes=$.nodes,this.skipDoneTasks=$.skipDoneTasks,this.store=$.store,this.cache=$.cache?new H6($.cache):void 0,this.stream=$.stream,this.checkpointNamespace=$.checkpointNamespace,this.prevCheckpointConfig=$.prevCheckpointConfig,this.interruptAfter=$.interruptAfter,this.interruptBefore=$.interruptBefore,this.durability=$.durability,this.debug=$.debug,this.triggerToNodes=$.triggerToNodes}static async initialize($){let{config:J,stream:Z}=$;if(Z!==void 0&&J.configurable?.[K0]!==void 0)Z=j6(Z,J.configurable[K0]);let q=J.configurable?!("checkpoint_id"in J.configurable):!0,z=J.configurable?.[JQ];if(J.configurable&&z){if(z.subgraphCounter>0)J=zQ(J,{[FQ]:[J.configurable[FQ],z.subgraphCounter.toString()].join(k)});z.subgraphCounter+=1}let Y=AQ in(J.configurable??{});if(!Y&&J.configurable?.checkpoint_ns!==void 0&&J.configurable?.checkpoint_ns!=="")J=zQ(J,{checkpoint_ns:"",checkpoint_id:void 0});let X=J;if(J.configurable?.[ZQ]!==void 0&&J.configurable?.[ZQ]?.[J.configurable?.checkpoint_ns])X=zQ(J,{checkpoint_id:J.configurable[ZQ][J.configurable?.checkpoint_ns]});let B=J.configurable?.checkpoint_ns?.split(k)??[],F=await $.checkpointer?.getTuple(X)??{config:J,checkpoint:V0(),metadata:{source:"input",step:-2,parents:{}},pendingWrites:[]};X={...J,...F.config,configurable:{checkpoint_ns:"",...J.configurable,...F.config.configurable}};let W=F.parentConfig,L=kQ(F.checkpoint),H={...F.metadata},j=F.pendingWrites??[],U=oQ($.channelSpecs,L),D=(H.step??0)+1,M=D+(J.recursionLimit??W6)+1,O={...L.channel_versions},_=$.store?new V8($.store):void 0;if(_)await _.start();return new Q({input:$.input,config:J,checkpointer:$.checkpointer,checkpoint:L,checkpointMetadata:H,checkpointConfig:X,prevCheckpointConfig:W,checkpointNamespace:B,channels:U,isNested:Y,manager:$.manager,skipDoneTasks:q,step:D,stop:M,checkpointPreviousVersions:O,checkpointPendingWrites:j,outputKeys:$.outputKeys??[],streamKeys:$.streamKeys??[],nodes:$.nodes,stream:Z,store:_,cache:$.cache,interruptAfter:$.interruptAfter,interruptBefore:$.interruptBefore,durability:$.durability,debug:$.debug,triggerToNodes:$.triggerToNodes})}_checkpointerPutAfterPrevious($){this._checkpointerChainedPromise=this._checkpointerChainedPromise.then(()=>{return this.checkpointer?.put($.config,$.checkpoint,$.metadata,$.newVersions)}),this.checkpointerPromises.push(this._checkpointerChainedPromise)}putWrites($,J){let Z=J;if(Z.length===0)return;if(Z.every(([B])=>(B in q1)))Z=Array.from(new Map(Z.map((B)=>[B[0],B])).values());let q=!1;for(let B in this.channels)if(Object.prototype.hasOwnProperty.call(this.channels,B)){if(this.channels[B].lc_graph_name==="UntrackedValue"){q=!0;break}}let z=Z;if(q)z=Z.filter(([B])=>{let F=this.channels[B];return!F||F.lc_graph_name!=="UntrackedValue"}).map(([B,F])=>{if(B===c&&d(F))return[B,r$(F,this.channels)];return[B,F]});this.checkpointPendingWrites=this.checkpointPendingWrites.filter((B)=>B[0]!==$);for(let[B,F]of z)this.checkpointPendingWrites.push([$,B,F]);let Y=zQ(this.checkpointConfig,{[FQ]:this.config.configurable?.checkpoint_ns??"",[w8]:this.checkpoint.id});if(this.durability!=="exit"&&this.checkpointer!=null)this.checkpointerPromises.push(this.checkpointer.putWrites(Y,z,$));if(this.tasks)this._outputWrites($,Z);if(!J.length||!this.cache||!this.tasks)return;let X=this.tasks[$];if(X==null||X.cache_key==null)return;if(J[0][0]===p||J[0][0]===S)return;this.cache.set([{key:[X.cache_key.ns,X.cache_key.key],value:X.writes,ttl:X.cache_key.ttl}])}_outputWrites($,J,Z=!1){let q=this.tasks[$];if(q!==void 0){if(q.config!==void 0&&(q.config.tags??[]).includes(E))return;if(J.length>0){if(J[0][0]===S){if(q.path?.[0]===r&&q.path?.[q.path.length-1]===!0)return;let z=J.filter((Y)=>Y[0]===S).flatMap((Y)=>Y[1]);this._emit([["updates",{[S]:z}],["values",{[S]:z}]])}else if(J[0][0]!==p)this._emit($0(fQ(m$(this.outputKeys,[[q,J]],Z),"updates")))}if(!Z)this._emit($0(fQ(s$([[q,J]],this.streamKeys),"tasks")))}}async _matchCachedWrites(){if(!this.cache)return[];let $=[],J=([Y,X])=>{return`ns:${Y.join(",")}|key:${X}`},Z=[],q={};for(let Y of Object.values(this.tasks))if(Y.cache_key!=null&&!Y.writes.length)Z.push([Y.cache_key.ns,Y.cache_key.key]),q[J([Y.cache_key.ns,Y.cache_key.key])]=Y;if(Z.length===0)return[];let z=await this.cache.get(Z);for(let{key:Y,value:X}of z){let B=q[J(Y)];if(B!=null)B.writes.push(...X),$.push({task:B,result:X})}return $}async tick($){if(this.store&&!this.store.isRunning)await this.store?.start();let{inputKeys:J=[]}=$;if(this.status!=="pending")throw Error(`Cannot tick when status is no longer "pending". Current status: "${this.status}"`);if(![U8,a8].includes(this.input))await this._first(J);else if(this.toInterrupt.length>0)throw this.status="interrupt_before",new PQ;else if(Object.values(this.tasks).every((q)=>q.writes.length>0)){let q=Object.values(this.tasks).flatMap((Y)=>Y.writes);this.updatedChannels=$Q(this.checkpoint,this.channels,Object.values(this.tasks),this.checkpointerGetNextVersion,this.triggerToNodes);let z=await GQ(fQ(F8(this.outputKeys,q,this.channels),"values"));if(this._emit(z),this.checkpointPendingWrites=[],await this._putCheckpoint({source:"loop"}),N0(this.checkpoint,this.interruptAfter,Object.values(this.tasks)))throw this.status="interrupt_after",new PQ;if(this.config.configurable?.[EQ]!==void 0)delete this.config.configurable?.[EQ]}else return!1;if(this.step>this.stop)return this.status="out_of_steps",!1;if(this.tasks=tQ(this.checkpoint,this.checkpointPendingWrites,this.nodes,this.channels,this.config,!0,{step:this.step,checkpointer:this.checkpointer,isResuming:this.isResuming,manager:this.manager,store:this.store,stream:this.stream,triggerToNodes:this.triggerToNodes,updatedChannels:this.updatedChannels}),this.checkpointer)this._emit(await GQ(fQ(t$(this.checkpointConfig,this.channels,this.streamKeys,this.checkpointMetadata,Object.values(this.tasks),this.checkpointPendingWrites,this.prevCheckpointConfig,this.outputKeys),"checkpoints")));if(Object.values(this.tasks).length===0)return this.status="done",!1;if(this.skipDoneTasks&&this.checkpointPendingWrites.length>0){for(let[q,z,Y]of this.checkpointPendingWrites){if(z===p||z===S||z===o)continue;let X=Object.values(this.tasks).find((B)=>B.id===q);if(X)X.writes.push([z,Y])}for(let q of Object.values(this.tasks))if(q.writes.length>0)this._outputWrites(q.id,q.writes,!0)}if(Object.values(this.tasks).every((q)=>q.writes.length>0))return this.tick({inputKeys:J});if(N0(this.checkpoint,this.interruptBefore,Object.values(this.tasks)))throw this.status="interrupt_before",new PQ;let Z=await GQ(fQ(c8(Object.values(this.tasks)),"tasks"));return this._emit(Z),!0}async finishAndHandleError($){if(this.durability==="exit"&&(!this.isNested||typeof $<"u"||this.checkpointNamespace.every((Z)=>!Z.includes(e))))this._putCheckpoint(this.checkpointMetadata),this._flushPendingWrites();let J=this._suppressInterrupt($);if(J||$===void 0)this.output=MQ(this.channels,this.outputKeys);if(J){if(this.tasks!==void 0&&this.checkpointPendingWrites.length>0&&Object.values(this.tasks).some((Z)=>Z.writes.length>0))this.updatedChannels=$Q(this.checkpoint,this.channels,Object.values(this.tasks),this.checkpointerGetNextVersion,this.triggerToNodes),this._emit($0(fQ(F8(this.outputKeys,Object.values(this.tasks).flatMap((Z)=>Z.writes),this.channels),"values")));if(wQ($)&&!$.interrupts.length)this._emit([["updates",{[S]:[]}],["values",{[S]:[]}]])}return J}async acceptPush($,J,Z){if(this.interruptAfter?.length>0&&N0(this.checkpoint,this.interruptAfter,[$])){this.toInterrupt.push($);return}let q=L8([r,$.path??[],J,$.id,Z],this.checkpoint,this.checkpointPendingWrites,this.nodes,this.channels,$.config??{},!0,{step:this.step,checkpointer:this.checkpointer,manager:this.manager,store:this.store,stream:this.stream});if(!q)return;if(this.interruptBefore?.length>0&&N0(this.checkpoint,this.interruptBefore,[q])){this.toInterrupt.push(q);return}if(this._emit($0(fQ(c8([q]),"tasks"))),this.debug)W8(this.step,[q]);if(this.tasks[q.id]=q,this.skipDoneTasks)this._matchWrites({[q.id]:q});let z=await this._matchCachedWrites();for(let{task:Y}of z)this._outputWrites(Y.id,Y.writes,!0);return q}_suppressInterrupt($){return wQ($)&&!this.isNested}async _first($){let{configurable:J}=this.config,Z=J?.[JQ];if(Z&&Z.nullResume!==void 0)this.putWrites(n,[[o,Z.nullResume]]);if(u(this.input)){let Y=this.input.resume!=null;if(this.input.resume!=null&&typeof this.input.resume==="object"&&Object.keys(this.input.resume).every(t0))this.config.configurable??={},this.config.configurable[X0]=this.input.resume;if(Y&&this.checkpointer==null)throw Error("Cannot use Command(resume=...) without checkpointer");let X={};for(let[B,F,W]of g$(this.input,this.checkpointPendingWrites))X[B]??=[],X[B].push([F,W]);if(Object.keys(X).length===0)throw new P0("Received empty Command input");for(let[B,F]of Object.entries(X))this.putWrites(B,F)}let q=(this.checkpointPendingWrites??[]).filter((Y)=>Y[0]===n).map((Y)=>Y.slice(1));if(q.length>0)$Q(this.checkpoint,this.channels,[{name:xQ,writes:q,triggers:[]}],this.checkpointerGetNextVersion,this.triggerToNodes);let z=u(this.input)&&q.length>0;if(this.isResuming||z){for(let X in this.channels){if(!Object.prototype.hasOwnProperty.call(this.channels,X))continue;if(this.checkpoint.channel_versions[X]!==void 0){let B=this.checkpoint.channel_versions[X];this.checkpoint.versions_seen[S]={...this.checkpoint.versions_seen[S],[X]:B}}}let Y=await GQ(fQ(F8(this.outputKeys,!0,this.channels),"values"));this._emit(Y)}if(this.isResuming)this.input=a8;else if(z)await this._putCheckpoint({source:"input"}),this.input=U8;else{let Y=await GQ(X8($,this.input));if(Y.length>0){let X=tQ(this.checkpoint,this.checkpointPendingWrites,this.nodes,this.channels,this.config,!0,{step:this.step});this.updatedChannels=$Q(this.checkpoint,this.channels,Object.values(X).concat([{name:xQ,writes:Y,triggers:[]}]),this.checkpointerGetNextVersion,this.triggerToNodes),await this._putCheckpoint({source:"input"}),this.input=U8}else if(!(EQ in(this.config.configurable??{})))throw new P0(`Received no input writes for ${JSON.stringify($,null,2)}`);else this.input=U8}if(!this.isNested)this.config=zQ(this.config,{[EQ]:this.isResuming})}_emit($){for(let[J,Z]of $){if(this.stream.modes.has(J))this.stream.push([this.checkpointNamespace,J,Z]);if((J==="checkpoints"||J==="tasks")&&this.stream.modes.has("debug")){let q=J==="checkpoints"?this.step-1:this.step,z=new Date().toISOString(),Y=(()=>{if(J==="checkpoints")return"checkpoint";else if(typeof Z==="object"&&Z!=null&&"result"in Z)return"task_result";else return"task"})();this.stream.push([this.checkpointNamespace,"debug",{step:q,type:Y,timestamp:z,payload:Z}])}}}_putCheckpoint($){let J=this.checkpointMetadata===$,Z=this.checkpointer!=null&&(this.durability!=="exit"||J),q=(z)=>{this.prevCheckpointConfig=this.checkpointConfig?.configurable?.checkpoint_id?this.checkpointConfig:void 0,this.checkpointConfig=zQ(this.checkpointConfig,{[FQ]:this.config.configurable?.checkpoint_ns??""});let Y={...this.checkpoint.channel_versions},X=H0(this.checkpointPreviousVersions,Y);this.checkpointPreviousVersions=Y,this._checkpointerPutAfterPrevious({config:{...this.checkpointConfig},checkpoint:kQ(z),metadata:{...this.checkpointMetadata},newVersions:X}),this.checkpointConfig={...this.checkpointConfig,configurable:{...this.checkpointConfig.configurable,checkpoint_id:this.checkpoint.id}}};if(!J)this.checkpointMetadata={...$,step:this.step,parents:this.config.configurable?.[ZQ]??{}};if(this.checkpoint=HQ(this.checkpoint,Z?this.channels:void 0,this.step,J?{id:this.checkpoint.id}:void 0),Z)q(this.checkpoint);if(!J)this.step+=1}_flushPendingWrites(){if(this.checkpointer==null)return;if(this.checkpointPendingWrites.length===0)return;let $=zQ(this.checkpointConfig,{[FQ]:this.config.configurable?.checkpoint_ns??"",[w8]:this.checkpoint.id}),J={};for(let[Z,q,z]of this.checkpointPendingWrites)J[Z]??=[],J[Z].push([q,z]);for(let[Z,q]of Object.entries(J))this.checkpointerPromises.push(this.checkpointer.putWrites($,q,Z))}_matchWrites($){for(let[J,Z,q]of this.checkpointPendingWrites){if(Z===p||Z===S||Z===o)continue;let z=Object.values($).find((Y)=>Y.id===J);if(z)z.writes.push([Z,q])}for(let J of Object.values($))if(J.writes.length>0)this._outputWrites(J.id,J.writes,!0)}};function U6(Q){return gQ(Q?.message)}var B1=class extends j8{name="StreamMessagesHandler";streamFn;metadatas={};seen={};emittedChatModelRunIds={};stableMessageIdMap={};lc_prefer_streaming=!0;constructor(Q){super();this.streamFn=Q}_emit(Q,$,J,Z=!1){if(Z&&$.id!==void 0&&this.seen[$.id]!==void 0)return;let q=$.id;if(J!=null)if(X1($))q??=`run-${J}-tool-${$.tool_call_id}`;else{if(q==null||q===`run-${J}`)q=this.stableMessageIdMap[J]??q??`run-${J}`;this.stableMessageIdMap[J]??=q}if(q!==$.id)$.id=q,$.lc_kwargs.id=q;if($.id!=null)this.seen[$.id]=$;this.streamFn([Q[0],"messages",[$,Q[1]]])}handleChatModelStart(Q,$,J,Z,q,z,Y,X){if(Y&&(!z||!z.includes(D$)&&!z.includes("nostream")))this.metadatas[J]=[Y.langgraph_checkpoint_ns.split("|"),{tags:z,name:X,...Y}]}handleLLMNewToken(Q,$,J,Z,q,z){let Y=z?.chunk;if(this.emittedChatModelRunIds[J]=!0,this.metadatas[J]!==void 0)if(U6(Y))this._emit(this.metadatas[J],Y.message,J);else this._emit(this.metadatas[J],new F1({content:Q}),J)}handleLLMEnd(Q,$){if(this.metadatas[$]===void 0)return;if(!this.emittedChatModelRunIds[$]){let J=Q.generations?.[0]?.[0];if(gQ(J?.message))this._emit(this.metadatas[$],J?.message,$,!0);delete this.emittedChatModelRunIds[$]}delete this.metadatas[$],delete this.stableMessageIdMap[$]}handleLLMError(Q,$){delete this.metadatas[$]}handleChainStart(Q,$,J,Z,q,z,Y,X){if(z!==void 0&&X===z.langgraph_node&&(q===void 0||!q.includes(E))){if(this.metadatas[J]=[z.langgraph_checkpoint_ns.split("|"),{tags:q,name:X,...z}],typeof $==="object"){for(let B of Object.values($))if((gQ(B)||e8(B))&&B.id!==void 0)this.seen[B.id]=B;else if(Array.isArray(B)){for(let F of B)if((gQ(F)||e8(F))&&F.id!==void 0)this.seen[F.id]=F}}}}handleChainEnd(Q,$){let J=this.metadatas[$];if(delete this.metadatas[$],J!==void 0){if(gQ(Q))this._emit(J,Q,$,!0);else if(Array.isArray(Q)){for(let Z of Q)if(gQ(Z))this._emit(J,Z,$,!0)}else if(Q!=null&&typeof Q==="object"){for(let Z of Object.values(Q))if(gQ(Z))this._emit(J,Z,$,!0);else if(Array.isArray(Z)){for(let q of Z)if(gQ(q))this._emit(J,q,$,!0)}}}}handleChainError(Q,$){delete this.metadatas[$]}};var V6=500,D6=2,G6=128000,K6=3,M6=[400,401,402,403,404,405,406,407,409],x6=(Q)=>{if(Q.message.startsWith("Cancel")||Q.message.startsWith("AbortError")||Q.name==="AbortError")return!1;if(Q.name==="GraphValueError")return!1;if(Q?.code==="ECONNABORTED")return!1;let $=Q?.response?.status??Q?.status;if($&&M6.includes(+$))return!1;if(Q?.error?.code==="insufficient_quota")return!1;return!0};async function Q$(Q,$,J,Z){let q=Q.retry_policy??$,z=q!==void 0?q.initialInterval??V6:0,Y=0,X,B,{config:F}=Q;if(J)F=zQ(F,J);F={...F,signal:Z};while(!0){if(Z?.aborted)break;Q.writes.splice(0,Q.writes.length),X=void 0;try{B=await Q.proc.invoke(Q.input,F);break}catch(W){if(X=W,X.pregelTaskId=Q.id,o0(X)){let j=F?.configurable?.checkpoint_ns,U=X.command;if(U.graph===j){for(let D of Q.writers)await D.invoke(U,F);X=void 0;break}else if(U.graph===a.PARENT){let D=y$(j);X.command=new a({...X.command,graph:D})}}if(pQ(X))break;if(q===void 0)break;if(Y+=1,Y>=(q.maxAttempts??K6))break;if(!(q.retryOn??x6)(X))break;z=Math.min(q.maxInterval??G6,z*(q.backoffFactor??D6));let L=q.jitter?Math.floor(z+Math.random()*1000):z;await new Promise((j)=>setTimeout(j,L));let H=X.name??X.constructor.unminifiable_name??X.constructor.name;if(q?.logWarning??!0)console.log(`Retrying task "${String(Q.name)}" after ${z.toFixed(2)}ms (attempt ${Y}) after ${H}: ${X}`);F=zQ(F,{[EQ]:!0})}}return{task:Q,result:B,error:X,signalAborted:Z?.aborted}}var $$=Symbol.for("promiseAdded");function A6(){let Q={next:()=>{return},wait:Promise.resolve($$)};function $(J){Q.next=()=>{Q.wait=new Promise($),J($$)}}return Q.wait=new Promise($),Q}var L1=class{nodeFinished;loop;constructor({loop:Q,nodeFinished:$}){this.loop=Q,this.nodeFinished=$}async tick(Q={}){let{timeout:$,retryPolicy:J,onStepWrite:Z,maxConcurrency:q}=Q,z=new Set,Y,X=new AbortController,B=X.signal,F=$?AbortSignal.timeout($):void 0,W=Object.values(this.loop.tasks).filter((U)=>U.writes.length===0),{signals:L,disposeCombinedSignal:H}=this._initializeAbortSignals({exceptionSignal:B,stepTimeoutSignal:F,signal:Q.signal}),j=this._executeTasksWithRetry(W,{signals:L,retryPolicy:J,maxConcurrency:q});for await(let{task:U,error:D,signalAborted:M}of j)if(this._commit(U,D),wQ(D))Y=D;else if(pQ(D)&&!wQ(Y))Y=D;else if(D&&(z.size===0||!M))X.abort(),z.add(D);if(H?.(),Z?.(this.loop.step,Object.values(this.loop.tasks).map((U)=>U.writes).flat()),z.size===1)throw Array.from(z)[0];else if(z.size>1)throw AggregateError(Array.from(z),`Multiple errors occurred during superstep ${this.loop.step}. See the "errors" field of this exception for more details.`);if(wQ(Y))throw Y;if(pQ(Y)&&this.loop.isNested)throw Y}_initializeAbortSignals({exceptionSignal:Q,stepTimeoutSignal:$,signal:J}){let Z=this.loop.config.configurable?.[R8]??{},q=Z.externalAbortSignal??J,z=$??Z.timeoutAbortSignal,{signal:Y,dispose:X}=U0(q,z,Q),B={externalAbortSignal:q,timeoutAbortSignal:z,composedAbortSignal:Y};return this.loop.config=zQ(this.loop.config,{[R8]:B}),{signals:B,disposeCombinedSignal:X}}async*_executeTasksWithRetry(Q,$){let{retryPolicy:J,maxConcurrency:Z,signals:q}=$??{},z=A6(),Y={},X={executingTasksMap:Y,barrier:z,retryPolicy:J,scheduleTask:async(H,j,U)=>this.loop.acceptPush(H,j,U)};if(q?.composedAbortSignal?.aborted)throw Error("Abort");let B=0,F,W=U0(q?.externalAbortSignal,q?.timeoutAbortSignal),L=W.signal?new Promise((H,j)=>{F=()=>j(Error("Abort")),W.signal?.addEventListener("abort",F,{once:!0})}):void 0;while((B===0||Object.keys(Y).length>0)&&Q.length){for(;Object.values(Y).length<(Z??Q.length)&&B<Q.length;B+=1){let j=Q[B];Y[j.id]=Q$(j,J,{[g0]:W1?.bind(X,this,j)},q?.composedAbortSignal).catch((U)=>{return{task:j,error:U,signalAborted:q?.composedAbortSignal?.aborted}})}let H=await Promise.race([...Object.values(Y),...L?[L]:[],z.wait]);if(H===$$)continue;if(yield H,F!=null)W.signal?.removeEventListener("abort",F),W.dispose?.();delete Y[H.task.id]}}_commit(Q,$){if($!==void 0)if(wQ($)){if($.interrupts.length){let J=$.interrupts.map((q)=>[S,q]),Z=Q.writes.filter((q)=>q[0]===o);if(Z.length)J.push(...Z);this.loop.putWrites(Q.id,J)}}else if(pQ($)&&Q.writes.length)this.loop.putWrites(Q.id,Q.writes);else this.loop.putWrites(Q.id,[[p,{message:$.message,name:$.name}]]);else{if(this.nodeFinished&&(Q.config?.tags==null||!Q.config.tags.includes(E)))this.nodeFinished(String(Q.name));if(Q.writes.length===0)Q.writes.push([m0,null]);this.loop.putWrites(Q.id,Q.writes)}}};async function W1(Q,$,J,Z,q,z={}){let Y=$.config?.configurable?.[JQ];if(!Y)throw Error(`BUG: No scratchpad found on task ${$.name}__${$.id}`);let X=Y.callCounter;Y.callCounter+=1;let B=new d$({func:J,name:Z,input:q,cache:z.cache,retry:z.retry,callbacks:z.callbacks}),F=await this.scheduleTask($,X,B);if(!F)return;let W=this.executingTasksMap[F.id];if(W!==void 0)return W;if(F.writes.length>0){let L=F.writes.filter(([j])=>j===jQ),H=F.writes.filter(([j])=>j===p);if(L.length>0){if(L.length===1)return Promise.resolve(L[0][1]);throw Error(`BUG: multiple returns found for task ${F.name}__${F.id}`)}if(H.length>0){if(H.length===1){let j=H[0][1],U=j instanceof Error?j:Error(String(j));return Promise.reject(U)}throw Error(`BUG: multiple errors found for task ${F.name}__${F.id}`)}return}else{let L=Q$(F,z.retry,{[g0]:W1.bind(this,Q,F)});return this.executingTasksMap[F.id]=L,this.barrier.next(),L.then(({result:H,error:j})=>{if(j)return Promise.reject(j);return H})}}var mQ=class extends Error{constructor(Q){super(Q);this.name="GraphValidationError"}};function j1({nodes:Q,channels:$,inputChannels:J,outputChannels:Z,streamChannels:q,interruptAfterNodes:z,interruptBeforeNodes:Y}){if(!$)throw new mQ("Channels not provided");let X=new Set,B=new Set;for(let[F,W]of Object.entries(Q)){if(F===S)throw new mQ(`"Node name ${S} is reserved"`);if(W.constructor===KQ)W.triggers.forEach((L)=>X.add(L));else throw new mQ(`Invalid node type ${typeof W}, expected PregelNode`)}for(let F of X)if(!(F in $))throw new mQ(`Subscribed channel '${String(F)}' not in channels`);if(!Array.isArray(J)){if(!X.has(J))throw new mQ(`Input channel ${String(J)} is not subscribed to by any node`)}else if(J.every((F)=>!X.has(F)))throw new mQ(`None of the input channels ${J} are subscribed to by any node`);if(!Array.isArray(Z))B.add(Z);else Z.forEach((F)=>B.add(F));if(q&&!Array.isArray(q))B.add(q);else if(Array.isArray(q))q.forEach((F)=>B.add(F));for(let F of B)if(!(F in $))throw new mQ(`Output channel '${String(F)}' not in channels`);if(z&&z!=="*"){for(let F of z)if(!(F in Q))throw new mQ(`Node ${String(F)} not in nodes`)}if(Y&&Y!=="*"){for(let F of Y)if(!(F in Q))throw new mQ(`Node ${String(F)} not in nodes`)}}function J$(Q,$){if(Array.isArray(Q)){for(let J of Q)if(!(J in $))throw Error(`Key ${String(J)} not found in channels`)}else if(!(Q in $))throw Error(`Key ${String(Q)} not found in channels`)}var V1=class{static subscribeTo(Q,$){let{key:J,tags:Z}={key:void 0,tags:void 0,...$??{}};if(Array.isArray(Q)&&J!==void 0)throw Error("Can't specify a key when subscribing to multiple channels");let q;if(typeof Q==="string")if(J)q={[J]:Q};else q=[Q];else q=Object.fromEntries(Q.map((z)=>[z,z]));return new KQ({channels:q,triggers:Array.isArray(Q)?Q:[Q],tags:Z})}static writeTo(Q,$){let J=[];for(let Z of Q)J.push({channel:Z,value:qQ,skipNone:!1});for(let[Z,q]of Object.entries($??{}))if(YQ.isRunnable(q)||typeof q==="function")J.push({channel:Z,value:qQ,skipNone:!0,mapper:yQ(q)});else J.push({channel:Z,value:q,skipNone:!1});return new h(J)}},O6=class extends YQ{lc_namespace=["langgraph","pregel"];invoke(Q,$){throw Error("Not implemented")}withConfig(Q){return super.withConfig(Q)}stream(Q,$){return super.stream(Q,$)}},G8=class extends O6{static lc_name(){return"LangGraph"}lc_namespace=["langgraph","pregel"];lg_is_pregel=!0;nodes;channels;inputChannels;outputChannels;autoValidate=!0;streamMode=["values"];streamChannels;interruptAfter;interruptBefore;stepTimeout;debug=!1;checkpointer;retryPolicy;config;store;cache;userInterrupt;triggerToNodes={};constructor(Q){super(Q);let{streamMode:$}=Q;if($!=null&&!Array.isArray($))$=[$];if(this.nodes=Q.nodes,this.channels=Q.channels,c in this.channels&&"lc_graph_name"in this.channels[c]&&this.channels[c].lc_graph_name!=="Topic")throw Error(`Channel '${c}' is reserved and cannot be used in the graph.`);else this.channels[c]=new f8({accumulate:!1});if(this.autoValidate=Q.autoValidate??this.autoValidate,this.streamMode=$??this.streamMode,this.inputChannels=Q.inputChannels,this.outputChannels=Q.outputChannels,this.streamChannels=Q.streamChannels??this.streamChannels,this.interruptAfter=Q.interruptAfter,this.interruptBefore=Q.interruptBefore,this.stepTimeout=Q.stepTimeout??this.stepTimeout,this.debug=Q.debug??this.debug,this.checkpointer=Q.checkpointer,this.retryPolicy=Q.retryPolicy,this.config=Q.config,this.store=Q.store,this.cache=Q.cache,this.name=Q.name,this.triggerToNodes=Q.triggerToNodes??this.triggerToNodes,this.userInterrupt=Q.userInterrupt,this.autoValidate)this.validate()}withConfig(Q){let $=DQ(this.config,Q);return new this.constructor({...this,config:$})}validate(){j1({nodes:this.nodes,channels:this.channels,outputChannels:this.outputChannels,inputChannels:this.inputChannels,streamChannels:this.streamChannels,interruptAfterNodes:this.interruptAfter,interruptBeforeNodes:this.interruptBefore});for(let[Q,$]of Object.entries(this.nodes))for(let J of $.triggers)this.triggerToNodes[J]??=[],this.triggerToNodes[J].push(Q);return this}get streamChannelsList(){if(Array.isArray(this.streamChannels))return this.streamChannels;else if(this.streamChannels)return[this.streamChannels];else return Object.keys(this.channels)}get streamChannelsAsIs(){if(this.streamChannels)return this.streamChannels;else return Object.keys(this.channels)}async getGraphAsync(Q){return this.getGraph(Q)}*getSubgraphs(Q,$){for(let[J,Z]of Object.entries(this.nodes)){if(Q!==void 0){if(!Q.startsWith(J))continue}let q=Z.subgraphs?.length?Z.subgraphs:[Z.bound];for(let z of q){let Y=Y8(z);if(Y!==void 0){if(J===Q){yield[J,Y];return}if(Q===void 0)yield[J,Y];if($){let X=Q;if(Q!==void 0)X=Q.slice(J.length+1);for(let[B,F]of Y.getSubgraphs(X,$))yield[`${J}${k}${B}`,F]}}}}}async*getSubgraphsAsync(Q,$){yield*this.getSubgraphs(Q,$)}async _prepareStateSnapshot({config:Q,saved:$,subgraphCheckpointer:J,applyPendingWrites:Z=!1}){if($===void 0)return{values:{},next:[],config:Q,tasks:[]};let q=oQ(this.channels,$.checkpoint);if($.pendingWrites?.length){let L=$.pendingWrites.filter(([H,j])=>H===n).map(([H,j,U])=>[String(j),U]);if(L.length>0)$Q($.checkpoint,q,[{name:xQ,writes:L,triggers:[]}],void 0,this.triggerToNodes)}let z=Object.values(tQ($.checkpoint,$.pendingWrites,this.nodes,q,$.config,!0,{step:($.metadata?.step??-1)+1,store:this.store})),Y=await GQ(this.getSubgraphsAsync()),X=$.config.configurable?.checkpoint_ns??"",B={};for(let L of z){let H=Y.find(([U])=>U===L.name);if(!H)continue;let j=`${String(L.name)}${e}${L.id}`;if(X)j=`${X}${k}${j}`;if(J===void 0){let U={configurable:{thread_id:$.config.configurable?.thread_id,checkpoint_ns:j}};B[L.id]=U}else{let U={configurable:{[m]:J,thread_id:$.config.configurable?.thread_id,checkpoint_ns:j}},D=H[1];B[L.id]=await D.getState(U,{subgraphs:!0})}}if(Z&&$.pendingWrites?.length){let L=Object.fromEntries(z.map((j)=>[j.id,j]));for(let[j,U,D]of $.pendingWrites){if([p,S,D8].includes(U))continue;if(!(j in L))continue;L[j].writes.push([String(U),D])}let H=z.filter((j)=>j.writes.length>0);if(H.length>0)$Q($.checkpoint,q,H,void 0,this.triggerToNodes)}let F=$?.metadata;if(F&&$?.config?.configurable?.thread_id)F={...F,thread_id:$.config.configurable.thread_id};let W=z.filter((L)=>L.writes.length===0).map((L)=>L.name);return{values:MQ(q,this.streamChannelsAsIs),next:W,tasks:i8(z,$?.pendingWrites??[],B,this.streamChannelsAsIs),metadata:F,config:nQ($.config,$.metadata),createdAt:$.checkpoint.ts,parentConfig:$.parentConfig}}async getState(Q,$){let J=Q.configurable?.[m]??this.checkpointer;if(!J)throw new dQ("No checkpointer set",{lc_error_code:"MISSING_CHECKPOINTER"});let Z=Q.configurable?.checkpoint_ns??"";if(Z!==""&&Q.configurable?.[m]===void 0){let Y=Z8(Z);for await(let[X,B]of this.getSubgraphsAsync(Y,!0))if(X===Y)return await B.getState(J0(Q,{[m]:J}),{subgraphs:$?.subgraphs});throw Error(`Subgraph with namespace "${Y}" not found.`)}let q=DQ(this.config,Q),z=await J.getTuple(Q);return await this._prepareStateSnapshot({config:q,saved:z,subgraphCheckpointer:$?.subgraphs?J:void 0,applyPendingWrites:!Q.configurable?.checkpoint_id})}async*getStateHistory(Q,$){let J=Q.configurable?.[m]??this.checkpointer;if(!J)throw new dQ("No checkpointer set",{lc_error_code:"MISSING_CHECKPOINTER"});let Z=Q.configurable?.checkpoint_ns??"";if(Z!==""&&Q.configurable?.[m]===void 0){let z=Z8(Z);for await(let[Y,X]of this.getSubgraphsAsync(z,!0))if(Y===z){yield*X.getStateHistory(J0(Q,{[m]:J}),$);return}throw Error(`Subgraph with namespace "${z}" not found.`)}let q=DQ(this.config,Q,{configurable:{checkpoint_ns:Z}});for await(let z of J.list(q,$))yield this._prepareStateSnapshot({config:z.config,saved:z})}async bulkUpdateState(Q,$){let J=Q.configurable?.[m]??this.checkpointer;if(!J)throw new dQ("No checkpointer set",{lc_error_code:"MISSING_CHECKPOINTER"});if($.length===0)throw Error("No supersteps provided");if($.some((Y)=>Y.updates.length===0))throw Error("No updates provided");let Z=Q.configurable?.checkpoint_ns??"";if(Z!==""&&Q.configurable?.[m]===void 0){let Y=Z8(Z);for await(let[,X]of this.getSubgraphsAsync(Y,!0))return await X.bulkUpdateState(J0(Q,{[m]:J}),$);throw Error(`Subgraph "${Y}" not found`)}let q=async(Y,X)=>{let B=this.config?DQ(this.config,Y):Y,F=await J.getTuple(B),W=F!==void 0?kQ(F.checkpoint):V0(),L={...F?.checkpoint.channel_versions},H=F?.metadata?.step??-1,j=J0(B,{checkpoint_ns:B.configurable?.checkpoint_ns??""}),U=B.metadata??{};if(F?.config.configurable)j=J0(B,F.config.configurable),U={...F.metadata,...U};let{values:D,asNode:M}=X[0];if(D==null&&M===void 0){if(X.length>1)throw new w("Cannot create empty checkpoint with multiple updates");return nQ(await J.put(j,HQ(W,void 0,H),{source:"update",step:H+1,parents:F?.metadata?.parents??{}},{}),F?F.metadata:void 0)}let O=oQ(this.channels,W);if(D===null&&M===A){if(X.length>1)throw new w("Cannot apply multiple updates when clearing state");if(F){let K=tQ(W,F.pendingWrites||[],this.nodes,O,F.config,!0,{step:(F.metadata?.step??-1)+1,checkpointer:J,store:this.store}),x=(F.pendingWrites||[]).filter((b)=>b[0]===n).map((b)=>b.slice(1));if(x.length>0)$Q(W,O,[{name:xQ,writes:x,triggers:[]}],J.getNextVersion.bind(J),this.triggerToNodes);for(let[b,G,y]of F.pendingWrites||[]){if([p,S,D8].includes(G))continue;if(!(b in K))continue;K[b].writes.push([G,y])}$Q(W,O,Object.values(K),J.getNextVersion.bind(J),this.triggerToNodes)}return nQ(await J.put(j,HQ(W,O,H),{...U,source:"update",step:H+1,parents:F?.metadata?.parents??{}},H0(L,W.channel_versions)),F?F.metadata:void 0)}if(M===H$){if(X.length>1)throw new w("Cannot copy checkpoint with multiple updates");if(F==null)throw new w("Cannot copy a non-existent checkpoint");let K=(G)=>{if(!Array.isArray(G))return!1;if(G.length===0)return!1;return G.every((y)=>Array.isArray(y)&&y.length===2)},x=HQ(W,void 0,H),b=await J.put(F.parentConfig??J0(F.config,{checkpoint_id:void 0}),x,{source:"fork",step:H+1,parents:F.metadata?.parents??{}},{});if(K(D)){let G=tQ(x,F.pendingWrites,this.nodes,O,b,!1,{step:H+2}),y=Object.values(G).reduce((i,{name:C0,id:P8})=>{return i[C0]??=[],i[C0].push({id:P8}),i},{}),g=D.reduce((i,C0)=>{let[P8,D0]=C0;i[D0]??=[];let b1=i[D0].length,S1=y[D0]?.[b1]?.id;return i[D0].push({values:P8,asNode:D0,taskId:S1}),i},{});return q(nQ(b,F.metadata),Object.values(g).flat())}return nQ(b,F.metadata)}if(M===xQ){if(X.length>1)throw new w("Cannot apply multiple updates when updating as input");let K=await GQ(X8(this.inputChannels,D));if(K.length===0)throw new w(`Received no input writes for ${JSON.stringify(this.inputChannels,null,2)}`);$Q(W,O,[{name:xQ,writes:K,triggers:[]}],J.getNextVersion.bind(this.checkpointer),this.triggerToNodes);let x=F?.metadata?.step!=null?F.metadata.step+1:-1,b=await J.put(j,HQ(W,O,x),{source:"input",step:x,parents:F?.metadata?.parents??{}},H0(L,W.channel_versions));return await J.putWrites(b,K,sQ(xQ,W.id)),nQ(b,F?F.metadata:void 0)}if(B.configurable?.checkpoint_id===void 0&&F?.pendingWrites!==void 0&&F.pendingWrites.length>0){let K=tQ(W,F.pendingWrites,this.nodes,O,F.config,!0,{store:this.store,checkpointer:this.checkpointer,step:(F.metadata?.step??-1)+1}),x=(F.pendingWrites??[]).filter((G)=>G[0]===n).map((G)=>G.slice(1));if(x.length>0)$Q(F.checkpoint,O,[{name:xQ,writes:x,triggers:[]}],void 0,this.triggerToNodes);for(let[G,y,g]of F.pendingWrites){if([p,S,D8].includes(y)||K[G]===void 0)continue;K[G].writes.push([y,g])}let b=Object.values(K).filter((G)=>{return G.writes.length>0});if(b.length>0)$Q(W,O,b,void 0,this.triggerToNodes)}let _=Object.values(W.versions_seen).map((K)=>{return Object.values(K)}).flat().find((K)=>!!K),P=[];if(X.length===1){let{values:K,asNode:x,taskId:b}=X[0];if(x===void 0&&Object.keys(this.nodes).length===1)[x]=Object.keys(this.nodes);else if(x===void 0&&_===void 0){if(typeof this.inputChannels==="string"&&this.nodes[this.inputChannels]!==void 0)x=this.inputChannels}else if(x===void 0){let G=Object.entries(W.versions_seen).map(([y,g])=>{return Object.values(g).map((i)=>{return[i,y]})}).flat().filter(([y,g])=>g!==S).sort(([y],[g])=>U1(y,g));if(G){if(G.length===1)x=G[0][1];else if(G[G.length-1][0]!==G[G.length-2][0])x=G[G.length-1][1]}}if(x===void 0)throw new w('Ambiguous update, specify "asNode"');P.push({values:K,asNode:x,taskId:b})}else for(let{asNode:K,values:x,taskId:b}of X){if(K==null)throw new w('"asNode" is required when applying multiple updates');P.push({values:x,asNode:K,taskId:b})}let I=[];for(let{asNode:K,values:x,taskId:b}of P){if(this.nodes[K]===void 0)throw new w(`Node "${K.toString()}" does not exist`);let G=this.nodes[K].getWriters();if(!G.length)throw new w(`No writers found for node "${K.toString()}"`);I.push({name:K,input:x,proc:G.length>1?Z0.from(G,{omitSequenceTags:!0}):G[0],writes:[],triggers:[S],id:b??sQ(S,W.id),writers:[]})}for(let K of I)await K.proc.invoke(K.input,rQ({...B,store:B?.store??this.store},{runName:B.runName??`${this.getName()}UpdateState`,configurable:{[WQ]:(x)=>K.writes.push(...x),[AQ]:(x,b=!1)=>_0(W,O,K,x,b)}}));for(let K of I){let x=K.writes.filter((b)=>b[0]!==r);if(F!==void 0&&x.length>0)await J.putWrites(j,x,K.id)}$Q(W,O,I,J.getNextVersion.bind(this.checkpointer),this.triggerToNodes);let N=H0(L,W.channel_versions),f=await J.put(j,HQ(W,O,H+1),{source:"update",step:H+1,parents:F?.metadata?.parents??{}},N);for(let K of I){let x=K.writes.filter((b)=>b[0]===r);if(x.length>0)await J.putWrites(f,x,K.id)}return nQ(f,F?F.metadata:void 0)},z=Q;for(let{updates:Y}of $)z=await q(z,Y);return z}async updateState(Q,$,J){return this.bulkUpdateState(Q,[{updates:[{values:$,asNode:J}]}])}_defaults(Q){let{debug:$,streamMode:J,inputKeys:Z,outputKeys:q,interruptAfter:z,interruptBefore:Y,...X}=Q,B=!0,F=$!==void 0?$:this.debug,W=q;if(W===void 0)W=this.streamChannelsAsIs;else J$(W,this.channels);let L=Z;if(L===void 0)L=this.inputChannels;else J$(L,this.channels);let H=Y??this.interruptBefore??[],j=z??this.interruptAfter??[],U;if(J!==void 0)U=Array.isArray(J)?J:[J],B=typeof J==="string";else{if(Q.configurable?.[Y0]!==void 0)U=["values"];else U=this.streamMode;B=!0}let D;if(this.checkpointer===!1)D=void 0;else if(Q!==void 0&&Q.configurable?.[m]!==void 0)D=Q.configurable[m];else if(this.checkpointer===!0)throw Error("checkpointer: true cannot be used for root graphs.");else D=this.checkpointer;let M=Q.store??this.store,O=Q.cache??this.cache;if(Q.durability!=null&&Q.checkpointDuring!=null)throw Error("Cannot use both `durability` and `checkpointDuring` at the same time.");let _=(()=>{if(Q.checkpointDuring==null)return;if(Q.checkpointDuring===!1)return"exit";return"async"})(),P=Q.durability??_??Q?.configurable?.[U$]??"async";return[F,U,L,W,X,H,j,D,M,B,O,P]}async stream(Q,$){let J=new AbortController,Z={recursionLimit:this.config?.recursionLimit,...$,signal:U0($?.signal,J.signal).signal},q=await super.stream(Q,Z);return new s8($?.encoding==="text/event-stream"?Z1(q):q,J)}streamEvents(Q,$,J){let Z=new AbortController,q={recursionLimit:this.config?.recursionLimit,...$,callbacks:u$(this.config?.callbacks,$?.callbacks),signal:U0($?.signal,Z.signal).signal};return new s8(super.streamEvents(Q,q,J),Z)}async _validateInput(Q){return Q}async _validateContext(Q){return Q}async*_streamIterator(Q,$){let J="version"in($??{})?void 0:$?.encoding??void 0,Z=$?.subgraphs,q=b0(this.config,$);if(q.recursionLimit===void 0||q.recursionLimit<1)throw Error('Passed "recursionLimit" must be at least 1.');if(this.checkpointer!==void 0&&this.checkpointer!==!1&&q.configurable===void 0)throw Error('Checkpointer requires one or more of the following "configurable" keys: "thread_id", "checkpoint_ns", "checkpoint_id"');let z=await this._validateInput(Q),{runId:Y,...X}=q,[B,F,,W,L,H,j,U,D,M,O,_]=this._defaults(X);if(typeof L.context<"u")L.context=await this._validateContext(L.context);else L.configurable=await this._validateContext(L.configurable);let P=new H8({modes:new Set(F)});if(this.checkpointer===!0){L.configurable??={};let G=L.configurable[FQ]??"";L.configurable[FQ]=G.split(k).map((y)=>y.split(e)[0]).join(k)}if(F.includes("messages")){let G=new B1((g)=>P.push(g)),{callbacks:y}=L;if(y===void 0)L.callbacks=[G];else if(Array.isArray(y))L.callbacks=y.concat(G);else{let g=y.copy();g.addHandler(G,!0),L.callbacks=g}}if(F.includes("tools")){let G=new J1((g)=>P.push(g)),{callbacks:y}=L;if(y===void 0)L.callbacks=[G];else if(Array.isArray(y))L.callbacks=y.concat(G);else{let g=y.copy();g.addHandler(G,!0),L.callbacks=g}}L.writer??=(G)=>{if(!F.includes("custom"))return;let y=u8()?.configurable?.[FQ]?.split(k).slice(0,-1);P.push([y??[],"custom",G])},L.interrupt??=this.userInterrupt??N8;let I=await(await H1(L))?.handleChainStart(this.toJSON(),h$(Q,"input"),Y,void 0,void 0,void 0,L?.runName??this.getName()),N=w0(this.channels),f,K,b=(async()=>{try{f=await Y1.initialize({input:z,config:L,checkpointer:U,nodes:this.nodes,channelSpecs:N,outputKeys:W,streamKeys:this.streamChannelsAsIs,store:D,cache:O,stream:P,interruptAfter:j,interruptBefore:H,manager:I,debug:this.debug,triggerToNodes:this.triggerToNodes,durability:_});let G=new L1({loop:f,nodeFinished:L.configurable?.[V$]});if($?.subgraphs)f.config.configurable={...f.config.configurable,[K0]:f.stream};if(await this._runLoop({loop:f,runner:G,debug:B,config:L}),_==="sync")await Promise.all(f?.checkpointerPromises??[])}catch(G){K=G}finally{try{if(f)await f.store?.stop(),await f.cache?.stop();await Promise.all(f?.checkpointerPromises??[])}catch(G){K=K??G}if(K)P.error(K);else P.close()}})();try{for await(let G of P){if(G===void 0)throw Error("Data structure error.");let[y,g,i]=G;if(F.includes(g)){if(J==="text/event-stream"){if(Z)yield[y,g,i];else yield[null,g,i];continue}if(Z&&!M)yield[y,g,i];else if(!M)yield[g,i];else if(Z)yield[y,i];else yield i}}}catch(G){throw await I?.handleChainError(K),G}finally{await b}await I?.handleChainEnd(f?.output??{},Y,void 0,void 0,void 0)}async invoke(Q,$){let J=$?.streamMode??"values",Z={...$,outputKeys:$?.outputKeys??this.outputChannels,streamMode:J,encoding:void 0},q=[],z=await this.stream(Q,Z),Y=[],X;for await(let B of z)if(J==="values")if(F0(B))Y.push(B[S]);else X=B;else q.push(B);if(J==="values"){if(Y.length>0){let B=Y.flat(1);if(X==null)return{[S]:B};if(typeof X==="object")return{...X,[S]:B}}return X}return q}async _runLoop(Q){let{loop:$,runner:J,debug:Z,config:q}=Q,z;try{while(await $.tick({inputKeys:this.inputChannels})){for(let{task:Y}of await $._matchCachedWrites())$._outputWrites(Y.id,Y.writes,!0);if(Z)a$($.checkpointMetadata.step,$.channels,this.streamChannelsList);if(Z)W8($.step,Object.values($.tasks));await J.tick({timeout:this.stepTimeout,retryPolicy:this.retryPolicy,onStepWrite:(Y,X)=>{if(Z)e$(Y,X,this.streamChannelsList)},maxConcurrency:q.maxConcurrency,signal:q.signal})}if($.status==="out_of_steps")throw new l0([`Recursion limit of ${q.recursionLimit} reached`,"without hitting a stop condition. You can increase the",'limit by setting the "recursionLimit" config key.'].join(" "),{lc_error_code:"GRAPH_RECURSION_LIMIT"})}catch(Y){if(z=Y,!await $.finishAndHandleError(z))throw Y}finally{if(z===void 0)await $.finishAndHandleError()}}async clearCache(){await this.cache?.clear([])}};N$();var z$=class{path;ends;constructor(Q){if(YQ.isRunnable(Q.path))this.path=Q.path;else this.path=yQ(Q.path);this.ends=Array.isArray(Q.pathMap)?Q.pathMap.reduce(($,J)=>{return $[J]=J,$},{}):Q.pathMap}run(Q,$){return h.registerWriter(new s({name:"<branch_run>",trace:!1,func:async(J,Z)=>{try{return await this._route(J,Z,Q,$)}catch(q){if(q.name===A0.unminifiable_name)console.warn(`[WARN]: 'NodeInterrupt' thrown in conditional edge. This is likely a bug in your graph implementation.
14
+ NodeInterrupt should only be thrown inside a node, not in edge conditions.`);throw q}}}))}async _route(Q,$,J,Z){let q=await this.path.invoke(Z?Z($):Q,$);if(!Array.isArray(q))q=[q];let z;if(this.ends)z=q.map((Y)=>d(Y)?Y:this.ends[Y]);else z=q;if(z.some((Y)=>!Y))throw Error("Branch condition returned unknown or null destination");if(z.filter(d).some((Y)=>Y.node===A))throw new w("Cannot send a packet to the END node");return await J(z,$)??Q}},E0=class{nodes;edges;branches;entryPoint;compiled=!1;constructor(){this.nodes={},this.edges=new Set,this.branches={}}warnIfCompiled(Q){if(this.compiled)console.warn(Q)}get allEdges(){return this.edges}addNode(...Q){function $(Z){return Z.length>=1&&typeof Z[0]!=="string"}let J=$(Q)?Array.isArray(Q[0])?Q[0]:Object.entries(Q[0]):[[Q[0],Q[1],Q[2]]];if(J.length===0)throw Error("No nodes provided in `addNode`");for(let[Z,q,z]of J){for(let X of[k,e])if(Z.includes(X))throw Error(`"${X}" is a reserved character and is not allowed in node names.`);if(this.warnIfCompiled("Adding a node to a graph that has already been compiled. This will not be reflected in the compiled graph."),Z in this.nodes)throw Error(`Node \`${Z}\` already present.`);if(Z===A)throw Error(`Node \`${Z}\` is reserved.`);let Y=yQ(q);this.nodes[Z]={runnable:Y,metadata:z?.metadata,subgraphs:S0(Y)?[Y]:z?.subgraphs,ends:z?.ends}}return this}addEdge(Q,$){if(this.warnIfCompiled("Adding an edge to a graph that has already been compiled. This will not be reflected in the compiled graph."),Q===A)throw Error("END cannot be a start node");if($===T)throw Error("START cannot be an end node");if(Array.from(this.edges).some(([J])=>J===Q)&&!("channels"in this))throw Error(`Already found path for ${Q}. For multiple edges, use StateGraph.`);return this.edges.add([Q,$]),this}addConditionalEdges(Q,$,J){let Z=typeof Q==="object"?Q:{source:Q,path:$,pathMap:J};if(this.warnIfCompiled("Adding an edge to a graph that has already been compiled. This will not be reflected in the compiled graph."),!YQ.isRunnable(Z.path))Z.path=yQ(Z.path);let q=Z.path.getName()==="RunnableLambda"?"condition":Z.path.getName();if(this.branches[Z.source]&&this.branches[Z.source][q])throw Error(`Condition \`${q}\` already present for node \`${Q}\``);return this.branches[Z.source]??={},this.branches[Z.source][q]=new z$(Z),this}setEntryPoint(Q){return this.warnIfCompiled("Setting the entry point of a graph that has already been compiled. This will not be reflected in the compiled graph."),this.addEdge(T,Q)}setFinishPoint(Q){return this.warnIfCompiled("Setting a finish point of a graph that has already been compiled. This will not be reflected in the compiled graph."),this.addEdge(Q,A)}compile({checkpointer:Q,interruptBefore:$,interruptAfter:J,name:Z}={}){this.validate([...Array.isArray($)?$:[],...Array.isArray(J)?J:[]]);let q=new Y$({builder:this,checkpointer:Q,interruptAfter:J,interruptBefore:$,autoValidate:!1,nodes:{},channels:{[T]:new VQ,[A]:new VQ},inputChannels:T,outputChannels:A,streamChannels:[],streamMode:"values",name:Z});for(let[z,Y]of Object.entries(this.nodes))q.attachNode(z,Y);for(let[z,Y]of this.edges)q.attachEdge(z,Y);for(let[z,Y]of Object.entries(this.branches))for(let[X,B]of Object.entries(Y))q.attachBranch(z,X,B);return q.validate()}validate(Q){let $=new Set([...this.allEdges].map(([Z,q])=>Z));for(let[Z]of Object.entries(this.branches))$.add(Z);for(let Z of $)if(Z!==T&&!(Z in this.nodes))throw Error(`Found edge starting at unknown node \`${Z}\``);let J=new Set([...this.allEdges].map(([Z,q])=>q));for(let[Z,q]of Object.entries(this.branches))for(let z of Object.values(q))if(z.ends!=null)for(let Y of Object.values(z.ends))J.add(Y);else{J.add(A);for(let Y of Object.keys(this.nodes))if(Y!==Z)J.add(Y)}for(let Z of Object.values(this.nodes))for(let q of Z.ends??[])J.add(q);for(let Z of Object.keys(this.nodes))if(!J.has(Z))throw new c0([`Node \`${Z}\` is not reachable.`,"","If you are returning Command objects from your node,",'make sure you are passing names of potential destination nodes as an "ends" array','into ".addNode(..., { ends: ["node1", "node2"] })".'].join(`
15
+ `),{lc_error_code:"UNREACHABLE_NODE"});for(let Z of J)if(Z!==A&&!(Z in this.nodes))throw Error(`Found edge ending at unknown node \`${Z}\``);if(Q){for(let Z of Q)if(!(Z in this.nodes))throw Error(`Interrupt node \`${Z}\` is not present`)}this.compiled=!0}},Y$=class extends G8{builder;constructor({builder:Q,...$}){super($);this.builder=Q}attachNode(Q,$){this.channels[Q]=new VQ,this.nodes[Q]=new KQ({channels:[],triggers:[],metadata:$.metadata,subgraphs:$.subgraphs,ends:$.ends}).pipe($.runnable).pipe(new h([{channel:Q,value:qQ}],[E])),this.streamChannels.push(Q)}attachEdge(Q,$){if($===A){if(Q===T)throw Error("Cannot have an edge from START to END");this.nodes[Q].writers.push(new h([{channel:A,value:qQ}],[E]))}else this.nodes[$].triggers.push(Q),this.nodes[$].channels.push(Q)}attachBranch(Q,$,J){if(Q===T&&!this.nodes[T])this.nodes[T]=V1.subscribeTo(T,{tags:[E]});this.nodes[Q].pipe(J.run((q)=>{return new h(q.map((z)=>{if(d(z))return z;return{channel:z===A?A:`branch:${Q}:${$}:${z}`,value:qQ}}),[E])}));let Z=J.ends?Object.values(J.ends):Object.keys(this.nodes);for(let q of Z)if(q!==A){let z=`branch:${Q}:${$}:${q}`;this.channels[z]=new VQ,this.nodes[q].triggers.push(z),this.nodes[q].channels.push(z)}}async getGraphAsync(Q){let $=Q?.xray,J=new q$,Z={[T]:J.addNode({schema:iQ.any()},T)},q={},z={};if($)z=Object.fromEntries((await GQ(this.getSubgraphsAsync())).filter((B)=>D1(B[1])));function Y(B,F,W,L=!1){if(F===A&&q[A]===void 0)q[A]=J.addNode({schema:iQ.any()},A);if(Z[B]===void 0)return;if(q[F]===void 0)throw Error(`End node ${F} not found!`);return J.addEdge(Z[B],q[F],W!==F?W:void 0,L)}for(let[B,F]of Object.entries(this.builder.nodes)){let W=t(B),L=F.runnable,H=F.metadata??{};if(this.interruptBefore?.includes(B)&&this.interruptAfter?.includes(B))H.__interrupt="before,after";else if(this.interruptBefore?.includes(B))H.__interrupt="before";else if(this.interruptAfter?.includes(B))H.__interrupt="after";if($){let j=typeof $==="number"?$-1:$,U=z[B]!==void 0?await z[B].getGraphAsync({...Q,xray:j}):L.getGraph(Q);if(U.trimFirstNode(),U.trimLastNode(),Object.keys(U.nodes).length>1){let O=function(P){return P?P.lc_runnable:!1},_=function(P,I){if(P!==void 0&&!Z$(P))return P;else if(O(I))try{let N=I.getName();return N=N.startsWith("Runnable")?N.slice(8):N,N}catch(N){return I.getName()}else return I.name??"UnknownSchema"},[D,M]=J.extend(U,W);if(D===void 0)throw Error(`Could not extend subgraph "${B}" due to missing entrypoint.`);if(M!==void 0)Z[W]={name:_(M.id,M.data),...M};q[W]={name:_(D.id,D.data),...D}}else{let D=J.addNode(L,W,H);Z[W]=D,q[W]=D}}else{let j=J.addNode(L,W,H);Z[W]=j,q[W]=j}}let X=[...this.builder.allEdges].sort(([B],[F])=>{if(B<F)return-1;else if(F>B)return 1;else return 0});for(let[B,F]of X)Y(t(B),t(F));for(let[B,F]of Object.entries(this.builder.branches)){let W={...Object.fromEntries(Object.keys(this.builder.nodes).filter((L)=>L!==B).map((L)=>[t(L),t(L)])),[A]:A};for(let L of Object.values(F)){let H;if(L.ends!==void 0)H=L.ends;else H=W;for(let[j,U]of Object.entries(H))Y(t(B),t(U),j,!0)}}for(let[B,F]of Object.entries(this.builder.nodes))if(F.ends!==void 0)for(let W of F.ends)Y(t(B),t(W),void 0,!0);return J}getGraph(Q){let $=Q?.xray,J=new q$,Z={[T]:J.addNode({schema:iQ.any()},T)},q={},z={};if($)z=Object.fromEntries($0(this.getSubgraphs()).filter((B)=>D1(B[1])));function Y(B,F,W,L=!1){if(F===A&&q[A]===void 0)q[A]=J.addNode({schema:iQ.any()},A);return J.addEdge(Z[B],q[F],W!==F?W:void 0,L)}for(let[B,F]of Object.entries(this.builder.nodes)){let W=t(B),L=F.runnable,H=F.metadata??{};if(this.interruptBefore?.includes(B)&&this.interruptAfter?.includes(B))H.__interrupt="before,after";else if(this.interruptBefore?.includes(B))H.__interrupt="before";else if(this.interruptAfter?.includes(B))H.__interrupt="after";if($){let j=typeof $==="number"?$-1:$,U=z[B]!==void 0?z[B].getGraph({...Q,xray:j}):L.getGraph(Q);if(U.trimFirstNode(),U.trimLastNode(),Object.keys(U.nodes).length>1){let O=function(P){return P?P.lc_runnable:!1},_=function(P,I){if(P!==void 0&&!Z$(P))return P;else if(O(I))try{let N=I.getName();return N=N.startsWith("Runnable")?N.slice(8):N,N}catch(N){return I.getName()}else return I.name??"UnknownSchema"},[D,M]=J.extend(U,W);if(D===void 0)throw Error(`Could not extend subgraph "${B}" due to missing entrypoint.`);if(M!==void 0)Z[W]={name:_(M.id,M.data),...M};q[W]={name:_(D.id,D.data),...D}}else{let D=J.addNode(L,W,H);Z[W]=D,q[W]=D}}else{let j=J.addNode(L,W,H);Z[W]=j,q[W]=j}}let X=[...this.builder.allEdges].sort(([B],[F])=>{if(B<F)return-1;else if(F>B)return 1;else return 0});for(let[B,F]of X)Y(t(B),t(F));for(let[B,F]of Object.entries(this.builder.branches)){let W={...Object.fromEntries(Object.keys(this.builder.nodes).filter((L)=>L!==B).map((L)=>[t(L),t(L)])),[A]:A};for(let L of Object.values(F)){let H;if(L.ends!==void 0)H=L.ends;else H=W;for(let[j,U]of Object.entries(H))Y(t(B),t(U),j,!0)}}return J}};function D1(Q){return typeof Q.attachNode==="function"&&typeof Q.attachEdge==="function"}function t(Q){if(Q==="subgraph")return`"${Q}"`;return Q}var P6="lg:",w6=class{_map=new Map;_extensionCache=new Map;get(Q){return this._map.get(Q)}extend(Q,$){let J=this.get(Q);this._map.set(Q,$(J))}remove(Q){return this._map.delete(Q),this}has(Q){return this._map.has(Q)}getChannelsForSchema(Q){let $={},J=F$(Q);for(let[Z,q]of Object.entries(J)){let z=this.get(q);if(z?.reducer)$[Z]=new bQ(z.reducer.fn,z.default);else $[Z]=new UQ(z?.default)}return $}getExtendedChannelSchemas(Q,$){if(Object.keys($).length===0)return Q;let J=Object.entries($).filter(([,z])=>z===!0).sort(([z],[Y])=>z.localeCompare(Y)).map(([z,Y])=>`${z}:${Y}`).join("|"),Z=this._extensionCache.get(J)??new Map;if(Z.has(Q))return Z.get(Q);let q=Q;if($.withReducerSchema||$.withJsonSchemaExtrasAsDescription){let z=Object.entries(F$(Q)).map(([Y,X])=>{let B=this.get(X),F=$.withReducerSchema?B?.reducer?.schema??X:X;if($.withJsonSchemaExtrasAsDescription&&B?.jsonSchemaExtra){let W=X$(F)??X$(X),L=JSON.stringify({...B.jsonSchemaExtra,description:W});F=F.describe(`${P6}${L}`)}return[Y,F]});if(q=M1(Q,Object.fromEntries(z)),K1(q))q._def.unknownKeys="strip"}if($.asPartial)q=K8(q);return Z.set(Q,q),this._extensionCache.set(J,Z),q}},v0=new w6;function A1(Q,$){if($.reducer&&!$.default){let J=x1(Q);if(J!=null)$.default=J}if($.reducer){let J=Object.assign(Q,{lg_reducer_schema:$.reducer?.schema??Q});return v0.extend(J,()=>$),J}else return v0.extend(Q,()=>$),Q}function z0(Q){if(Q==null)return!1;if(LQ.isInstance(Q))return!0;if(XQ(Q))return!0;if(typeof Q==="object"&&"lc_graph_name"in Q&&Q.lc_graph_name==="AnnotationRoot")return!0;if(typeof Q==="object"&&!Array.isArray(Q)&&Object.keys(Q).length>0&&Object.values(Q).every(($)=>typeof $==="function"||E8($)))return!0;return!1}function O1(Q){if(typeof Q!=="object"||Q==null)return!1;let $=Q,J="state"in $&&z0($.state),Z="stateSchema"in $&&z0($.stateSchema),q="input"in $&&z0($.input);if(!J&&!Z&&!q)return!1;if("input"in $&&$.input!=null&&!z0($.input))return!1;if("output"in $&&$.output!=null&&!z0($.output))return!1;return!0}var hQ="__root__",x8=Symbol.for("langgraph.state.partial"),A8=class extends E0{channels={};waitingEdges=new Set;_schemaDefinition;_schemaRuntimeDefinition;_inputDefinition;_inputRuntimeDefinition;_outputDefinition;_outputRuntimeDefinition;_schemaDefinitions=new Map;_metaRegistry=v0;_configSchema;_configRuntimeSchema;_interrupt;_writer;constructor(Q,$){super();let J=this._normalizeToStateGraphInit(Q,$),Z=J.state??J.stateSchema??J.input;if(!Z)throw new B0;let q=this._getChannelsFromSchema(Z);if(this._schemaDefinition=q,LQ.isInstance(Z))this._schemaRuntimeDefinition=Z;else if(XQ(Z))this._schemaRuntimeDefinition=Z;if(J.input)if(LQ.isInstance(J.input))this._inputRuntimeDefinition=J.input;else if(XQ(J.input))this._inputRuntimeDefinition=J.input;else this._inputRuntimeDefinition=x8;else this._inputRuntimeDefinition=x8;if(J.output)if(LQ.isInstance(J.output))this._outputRuntimeDefinition=J.output;else if(XQ(J.output))this._outputRuntimeDefinition=J.output;else this._outputRuntimeDefinition=this._schemaRuntimeDefinition;else this._outputRuntimeDefinition=this._schemaRuntimeDefinition;let z=J.input?this._getChannelsFromSchema(J.input):q,Y=J.output?this._getChannelsFromSchema(J.output):q;if(this._inputDefinition=z,this._outputDefinition=Y,this._addSchema(this._schemaDefinition),this._addSchema(this._inputDefinition),this._addSchema(this._outputDefinition),J.context){if(XQ(J.context))this._configRuntimeSchema=J.context}this._interrupt=J.interrupt,this._writer=J.writer}_normalizeToStateGraphInit(Q,$){if(O1(Q)){if(XQ($)||T0.isInstance($))return{...Q,context:$};let J=$;return{...Q,input:Q.input??J?.input,output:Q.output??J?.output,context:Q.context??J?.context,interrupt:Q.interrupt??J?.interrupt,writer:Q.writer??J?.writer,nodes:Q.nodes??J?.nodes}}if(z0(Q)){if(XQ($)||T0.isInstance($))return{state:Q,context:$};let J=$;return{state:Q,input:J?.input,output:J?.output,context:J?.context,interrupt:J?.interrupt,writer:J?.writer,nodes:J?.nodes}}if(T6(Q))return{state:R6(Q.channels)};throw new B0}_getChannelsFromSchema(Q){if(LQ.isInstance(Q))return Q.getChannels();if(XQ(Q))return this._metaRegistry.getChannelsForSchema(Q);if(typeof Q==="object"&&"lc_graph_name"in Q&&Q.lc_graph_name==="AnnotationRoot")return Q.spec;if(typeof Q==="object"&&!Array.isArray(Q)&&Object.keys(Q).length>0)return Q;throw new B0("Invalid schema type. Expected StateSchema, Zod object, AnnotationRoot, or StateDefinition.")}get allEdges(){return new Set([...this.edges,...Array.from(this.waitingEdges).flatMap(([Q,$])=>Q.map((J)=>[J,$]))])}_addSchema(Q){if(this._schemaDefinitions.has(Q))return;this._schemaDefinitions.set(Q,Q);for(let[$,J]of Object.entries(Q)){let Z;if(typeof J==="function")Z=J();else Z=J;if(this.channels[$]!==void 0){if(!this.channels[$].equals(Z)){if(Z.lc_graph_name!=="LastValue")throw Error(`Channel "${$}" already exists with a different type.`)}}else this.channels[$]=Z}}addNode(...Q){function $(Z){return Z.length>=1&&typeof Z[0]!=="string"}let J=$(Q)?Array.isArray(Q[0])?Q[0]:Object.entries(Q[0]).map(([Z,q])=>[Z,q]):[[Q[0],Q[1],Q[2]]];if(J.length===0)throw Error("No nodes provided in `addNode`");for(let[Z,q,z]of J){if(Z in this.channels)throw Error(`${Z} is already being used as a state attribute (a.k.a. a channel), cannot also be used as a node name.`);for(let W of[k,e])if(Z.includes(W))throw Error(`"${W}" is a reserved character and is not allowed in node names.`);if(this.warnIfCompiled("Adding a node to a graph that has already been compiled. This will not be reflected in the compiled graph."),Z in this.nodes)throw Error(`Node \`${Z}\` already present.`);if(Z===A||Z===T)throw Error(`Node \`${Z}\` is reserved.`);let Y=this._schemaDefinition;if(z?.input!==void 0)Y=this._getChannelsFromSchema(z.input);this._addSchema(Y);let X;if(YQ.isRunnable(q))X=q;else if(typeof q==="function")X=new s({func:q,name:Z,trace:!1});else X=yQ(q);let B=z?.cachePolicy;if(typeof B==="boolean")B=B?{}:void 0;let F={runnable:X,retryPolicy:z?.retryPolicy,cachePolicy:B,metadata:z?.metadata,input:Y??this._schemaDefinition,subgraphs:S0(X)?[X]:z?.subgraphs,ends:z?.ends,defer:z?.defer};this.nodes[Z]=F}return this}addEdge(Q,$){if(typeof Q==="string")return super.addEdge(Q,$);if(this.compiled)console.warn("Adding an edge to a graph that has already been compiled. This will not be reflected in the compiled graph.");for(let J of Q){if(J===A)throw Error("END cannot be a start node");if(!Object.keys(this.nodes).some((Z)=>Z===J))throw Error(`Need to add a node named "${J}" first`)}if($===A)throw Error("END cannot be an end node");if(!Object.keys(this.nodes).some((J)=>J===$))throw Error(`Need to add a node named "${$}" first`);return this.waitingEdges.add([Q,$]),this}addSequence(Q){let $=Array.isArray(Q)?Q:Object.entries(Q);if($.length===0)throw Error("Sequence requires at least one node.");let J;for(let[Z,q,z]of $){if(Z in this.nodes)throw Error(`Node names must be unique: node with the name "${Z}" already exists.`);let Y=Z;if(this.addNode(Y,q,z),J!=null)this.addEdge(J,Y);J=Y}return this}compile({checkpointer:Q,store:$,cache:J,interruptBefore:Z,interruptAfter:q,name:z,description:Y}={}){this.validate([...Array.isArray(Z)?Z:[],...Array.isArray(q)?q:[]]);let X=Object.keys(this._schemaDefinitions.get(this._outputDefinition)),B=X.length===1&&X[0]===hQ?hQ:X,F=Object.keys(this.channels),W=F.length===1&&F[0]===hQ?hQ:F,L=this._interrupt,H=new O8({builder:this,checkpointer:Q,interruptAfter:q,interruptBefore:Z,autoValidate:!1,nodes:{},channels:{...this.channels,[T]:new VQ},inputChannels:T,outputChannels:B,streamChannels:W,streamMode:"updates",store:$,cache:J,name:z,description:Y,userInterrupt:L});H.attachNode(T);for(let[j,U]of Object.entries(this.nodes))H.attachNode(j,U);H.attachBranch(T,T8,P1(),{withReader:!1});for(let[j]of Object.entries(this.nodes))H.attachBranch(j,T8,P1(),{withReader:!1});for(let[j,U]of this.edges)H.attachEdge(j,U);for(let[j,U]of this.waitingEdges)H.attachEdge(j,U);for(let[j,U]of Object.entries(this.branches))for(let[D,M]of Object.entries(U))H.attachBranch(j,D,M);return H.validate()}};function R6(Q){let $={};for(let[J,Z]of Object.entries(Q))if(J===hQ)$[J]=J8(Z);else $[J]=J8(Z);return $}var O8=class extends Y${description;_metaRegistry=v0;constructor({description:Q,...$}){super($);this.description=Q}attachNode(Q,$){let J;if(Q===T)J=Object.entries(this.builder._schemaDefinitions.get(this.builder._inputDefinition)).map(([X])=>X);else J=Object.keys(this.builder.channels);function Z(X){if(u(X)){if(X.graph===a.PARENT)return null;return X._updateAsTuples()}else if(Array.isArray(X)&&X.length>0&&X.some((B)=>u(B))){let B=[];for(let F of X)if(u(F)){if(F.graph===a.PARENT)continue;B.push(...F._updateAsTuples())}else B.push([hQ,F]);return B}else if(X!=null)return[[hQ,X]];return null}let q=Q;function z(X){if(!X)return null;else if(u(X)){if(X.graph===a.PARENT)return null;return X._updateAsTuples().filter(([B])=>J.includes(B))}else if(Array.isArray(X)&&X.length>0&&X.some(u)){let B=[];for(let F of X)if(u(F)){if(F.graph===a.PARENT)continue;B.push(...F._updateAsTuples().filter(([W])=>J.includes(W)))}else{let W=z(F);if(W)B.push(...W??[])}return B}else if(typeof X==="object"&&!Array.isArray(X))return Object.entries(X).filter(([B])=>J.includes(B));else{let B=Array.isArray(X)?"array":typeof X;throw new w(`Expected node "${q.toString()}" to return an object or an array containing at least one Command object, received ${B}`,{lc_error_code:"INVALID_GRAPH_NODE_RETURN_VALUE"})}}let Y=[{value:qQ,mapper:new s({func:J.length&&J[0]===hQ?Z:z,trace:!1,recurse:!1})}];if(Q===T)this.nodes[Q]=new KQ({tags:[E],triggers:[T],channels:[T],writers:[new h(Y,[E])]});else{let X=$?.input??this.builder._schemaDefinition,B=Object.fromEntries(Object.keys(this.builder._schemaDefinitions.get(X)).map((L)=>[L,L])),F=Object.keys(B).length===1&&hQ in B,W=`branch:to:${Q}`;this.channels[W]=$?.defer?new v8:new VQ(!1),this.nodes[Q]=new KQ({triggers:[W],channels:F?Object.keys(B):B,writers:[new h(Y,[E])],mapper:F?void 0:(L)=>{return Object.fromEntries(Object.entries(L).filter(([H])=>(H in B)))},bound:$?.runnable,metadata:$?.metadata,retryPolicy:$?.retryPolicy,cachePolicy:$?.cachePolicy,subgraphs:$?.subgraphs,ends:$?.ends})}}attachEdge(Q,$){if($===A)return;if(typeof Q==="string")this.nodes[Q].writers.push(new h([{channel:`branch:to:${$}`,value:null}],[E]));else if(Array.isArray(Q)){let J=`join:${Q.join("+")}:${$}`;this.channels[J]=this.builder.nodes[$].defer?new g8(new Set(Q)):new k8(new Set(Q)),this.nodes[$].triggers.push(J);for(let Z of Q)this.nodes[Z].writers.push(new h([{channel:J,value:Z}],[E]))}}attachBranch(Q,$,J,Z={withReader:!0}){let q=async(z,Y)=>{let X=z.filter((F)=>F!==A);if(!X.length)return;let B=X.map((F)=>{if(d(F))return F;return{channel:F===A?F:`branch:to:${F}`,value:Q}});await h.doWrite({...Y,tags:(Y.tags??[]).concat([E])},B)};this.nodes[Q].writers.push(J.run(q,Z.withReader?(z)=>k$.doRead(z,this.streamChannels??this.outputChannels,!0):void 0))}async _validateInput(Q){if(Q==null)return Q;let $=this.builder._inputRuntimeDefinition,J=this.builder._schemaRuntimeDefinition;if(LQ.isInstance($)){if(u(Q)){let q=Q;if(Q.update)q.update=await $.validateInput(Array.isArray(Q.update)?Object.fromEntries(Q.update):Q.update);return q}return await $.validateInput(Q)}if($===x8&&LQ.isInstance(J)){if(u(Q)){let q=Q;if(Q.update)q.update=await J.validateInput(Array.isArray(Q.update)?Object.fromEntries(Q.update):Q.update);return q}return await J.validateInput(Q)}let Z=(()=>{let q=(z)=>{if(z==null)return;return this._metaRegistry.getExtendedChannelSchemas(z,{withReducerSchema:!0})};if(XQ($))return q($);if($===x8){if(XQ(J))return K8(q(J));return}})();if(u(Q)){let q=Q;if(Q.update&&Z!=null)q.update=M8(Z,Q.update);return q}if(Z!=null)return M8(Z,Q);return Q}isInterrupted(Q){return F0(Q)}async _validateContext(Q){let $=this.builder._configRuntimeSchema;if(XQ($))M8($,Q);return Q}};function T6(Q){return typeof Q==="object"&&Q!==null&&Q.channels!==void 0}function b6(Q){if(d(Q))return[Q];let $=[];if(u(Q))$.push(Q);else if(Array.isArray(Q))$.push(...Q.filter(u));let J=[];for(let Z of $){if(Z.graph===a.PARENT)throw new O0(Z);if(d(Z.goto))J.push(Z.goto);else if(typeof Z.goto==="string")J.push(Z.goto);else if(Array.isArray(Z.goto))J.push(...Z.goto)}return J}function P1(){return new z$({path:new s({func:b6,tags:[E],trace:!1,recurse:!1,name:"<control_branch>"})})}var B$=function($,J){let{name:Z,checkpointer:q,store:z,cache:Y}=typeof $==="string"?{name:$,checkpointer:void 0,store:void 0}:$;if(E$(J)||v$(J))throw Error("Generators are disallowed as entrypoints. For streaming responses, use config.write.");let X="updates",B=o$(Z,J);function F(j){return typeof j==="object"&&j!==null&&"__lg_type"in j&&j.__lg_type==="__pregel_final"}let W=new s({name:"pluckReturnValue",func:(j)=>{return F(j)?j.value:j}}),L=new s({name:"pluckSaveValue",func:(j)=>{return F(j)?j.save:j}}),H=new KQ({bound:B,triggers:[T],channels:[T],writers:[new h([{channel:A,value:qQ,mapper:W},{channel:aQ,value:qQ,mapper:L}],[E])]});return new G8({name:Z,checkpointer:q,nodes:{[Z]:H},channels:{[T]:new VQ,[A]:new UQ,[aQ]:new UQ},inputChannels:T,outputChannels:A,streamChannels:A,streamMode:X,store:z,cache:Y})};B$.final=function({value:$,save:J}){return{value:$,save:J,__lg_type:"__pregel_final"}};var w1=Q0.Root({messages:Q0({reducer:CQ,default:()=>[]})}),W$={reducer:{fn:CQ},jsonSchemaExtra:{langgraph_type:"messages"},default:()=>[]},R1=L$.object({messages:A1(L$.custom(),W$)});I$();
16
+ export{T as Of,A as Pf,uQ as Qf,a as Rf,u as Sf,pQ as Tf,wQ as Uf,Q0 as Vf,Q6 as Wf,N8 as Xf,BQ as Yf,IQ as Zf,LQ as _f,$8 as $f,v0 as ag,A1 as bg,A8 as cg,w1 as dg,W$ as eg};