zen-code 4.9.2 → 4.10.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.
- package/dist/app.js +94 -128
- package/dist/chunk-075hks9v.js +1 -0
- package/dist/chunk-0fj768k4.js +112 -0
- package/dist/chunk-19mf2aa7.js +1 -0
- package/dist/chunk-1mq2jmfy.js +2 -0
- package/dist/chunk-1v863afn.js +278 -0
- package/dist/chunk-1vn8d8b8.js +1 -0
- package/dist/{chunk-hfypkhky.js → chunk-1w19w1bm.js} +1 -1
- package/dist/chunk-3dnayvgx.js +224 -0
- package/dist/chunk-4hg13vwj.js +1 -0
- package/dist/chunk-4scrkcqv.js +1 -0
- package/dist/chunk-54cdhhqm.js +1 -0
- package/dist/chunk-5m4yb9av.js +91 -0
- package/dist/chunk-5yd4ntp6.js +8 -0
- package/dist/{chunk-dxec2q4t.js → chunk-6scjjkn3.js} +1 -1
- package/dist/{chunk-hmemx3cw.js → chunk-7jatn15w.js} +2 -2
- package/dist/{chunk-0pss3s5r.js → chunk-7w9y11hj.js} +1 -1
- package/dist/chunk-7yzv6385.js +1 -0
- package/dist/{chunk-ce53j63y.js → chunk-875hayaj.js} +3 -3
- package/dist/chunk-8bs8r50r.js +1 -0
- package/dist/{chunk-x552nspp.js → chunk-8waww0j9.js} +2 -2
- package/dist/chunk-8ysg0rga.js +1 -0
- package/dist/chunk-9czhw5k6.js +4 -0
- package/dist/chunk-9tgp14v7.js +16 -0
- package/dist/{chunk-yndex7hs.js → chunk-a239dn0b.js} +1 -1
- package/dist/chunk-arv4h3h1.js +2 -0
- package/dist/chunk-b2551zfb.js +2 -0
- package/dist/chunk-b9emn03n.js +1 -0
- package/dist/chunk-bm7578sn.js +1 -0
- package/dist/{chunk-62zh99t6.js → chunk-bytq4kd1.js} +3 -125
- package/dist/chunk-c2wfgbj6.js +1 -0
- package/dist/{chunk-0zk0m93z.js → chunk-cef4vbtb.js} +1 -1
- package/dist/{chunk-hsev32dg.js → chunk-cnzhxgn5.js} +2 -2
- package/dist/chunk-d2770b2z.js +1 -0
- package/dist/chunk-d72063sm.js +2 -0
- package/dist/{chunk-6nfpdtn6.js → chunk-d988tv30.js} +1 -1
- package/dist/{chunk-55nx49pj.js → chunk-dx9k6sdd.js} +3 -3
- package/dist/chunk-e6ggkg36.js +2 -0
- package/dist/{chunk-x90r4sje.js → chunk-fjqtrakn.js} +1 -1
- package/dist/chunk-gbfpab0j.js +1 -0
- package/dist/chunk-gkvx829z.js +1 -0
- package/dist/{chunk-94jawhw7.js → chunk-gwf8b14k.js} +1 -1
- package/dist/chunk-gz7fz9fg.js +1 -0
- package/dist/{chunk-48vkm1yn.js → chunk-h0q3dvnv.js} +2 -2
- package/dist/chunk-h0qb9jk1.js +1 -0
- package/dist/chunk-h9y136h8.js +1 -0
- package/dist/chunk-hrcxdj3c.js +54 -0
- package/dist/chunk-hz9yw7cs.js +166 -0
- package/dist/{chunk-98wjxsna.js → chunk-j4y5rjne.js} +1 -1
- package/dist/chunk-k12y05c3.js +3 -0
- package/dist/{chunk-fkrydbn4.js → chunk-k6fxqssr.js} +3 -3
- package/dist/{chunk-vfwbx331.js → chunk-kmxdq21k.js} +2 -2
- package/dist/chunk-mcb8rewr.js +213 -0
- package/dist/{chunk-9k64296h.js → chunk-mm9w91rj.js} +1 -1
- package/dist/chunk-mv0xzmq8.js +2 -0
- package/dist/{chunk-rztre6k0.js → chunk-n849zsd3.js} +1 -1
- package/dist/chunk-nm253hhf.js +81 -0
- package/dist/{chunk-gyhxdxb4.js → chunk-prg6489q.js} +1 -1
- package/dist/{chunk-pwrscdkf.js → chunk-pxdgy0vr.js} +1 -1
- package/dist/{chunk-frhhpxxy.js → chunk-qhzm2qw9.js} +2 -2
- package/dist/{chunk-8f2zh5h6.js → chunk-qmxtys9q.js} +2 -2
- package/dist/chunk-r0cfe5c1.js +294 -0
- package/dist/chunk-rtjytfhh.js +1 -0
- package/dist/chunk-s7ttf0pm.js +2 -0
- package/dist/{chunk-k38fjqj7.js → chunk-t01t72t2.js} +2 -2
- package/dist/{chunk-fw3nrwpf.js → chunk-t0f66x64.js} +1 -1
- package/dist/chunk-tn356gwf.js +93 -0
- package/dist/chunk-vd8kwzra.js +41 -0
- package/dist/chunk-vhn13anh.js +233 -0
- package/dist/chunk-vnewbtjy.js +1 -0
- package/dist/{chunk-hfegb4pr.js → chunk-wbm7rn9w.js} +2 -2
- package/dist/chunk-wd3gkd45.js +3 -0
- package/dist/chunk-whdf0vbb.js +1 -0
- package/dist/{chunk-r019959h.js → chunk-ws232ksq.js} +2 -2
- package/dist/{chunk-rt5mpgbg.js → chunk-yerf10k7.js} +2 -2
- package/dist/{chunk-pndhbee8.js → chunk-yzv3n8mw.js} +2 -2
- package/dist/chunk-z3e4c424.js +2 -0
- package/dist/{chunk-jb4yt88g.js → chunk-znw7fpep.js} +2 -2
- package/dist/chunk-zq2g4rfd.js +1 -0
- package/dist/cli.js +1 -1
- package/dist/nonInteractive.js +314 -4
- package/dist/zen-keyboard.js +1 -1
- package/package.json +37 -37
- package/dist/chunk-0sxrk9sx.js +0 -1
- package/dist/chunk-178yjjsx.js +0 -1
- package/dist/chunk-1p9xzvpt.js +0 -3
- package/dist/chunk-2eh0sv3s.js +0 -2
- package/dist/chunk-43xrz4wp.js +0 -2
- package/dist/chunk-48ce2wt0.js +0 -1
- package/dist/chunk-578m1dhj.js +0 -2
- package/dist/chunk-5dsevrtz.js +0 -91
- package/dist/chunk-66890qd3.js +0 -2
- package/dist/chunk-738m8242.js +0 -53
- package/dist/chunk-8ty2zfve.js +0 -3
- package/dist/chunk-9b7nj74j.js +0 -1
- package/dist/chunk-9x562s6p.js +0 -1
- package/dist/chunk-a90fm6gz.js +0 -278
- package/dist/chunk-ac5t2ywn.js +0 -100
- package/dist/chunk-ad2hbq42.js +0 -1
- package/dist/chunk-afhxxkmv.js +0 -16
- package/dist/chunk-b4vvgbav.js +0 -1
- package/dist/chunk-b9pcntkv.js +0 -253
- package/dist/chunk-c7y5efa0.js +0 -1
- package/dist/chunk-cbjnwrt7.js +0 -2
- package/dist/chunk-dcs1r9as.js +0 -2
- package/dist/chunk-dcwnpdtk.js +0 -9
- package/dist/chunk-e3tyc24s.js +0 -310
- package/dist/chunk-e8hp8d68.js +0 -81
- package/dist/chunk-h1enhch1.js +0 -2
- package/dist/chunk-hcnx1j2z.js +0 -1
- package/dist/chunk-hra0748z.js +0 -2
- package/dist/chunk-hyf24r36.js +0 -2
- package/dist/chunk-jjcmm167.js +0 -1
- package/dist/chunk-jrepjpft.js +0 -2
- package/dist/chunk-kym9tb01.js +0 -1
- package/dist/chunk-mt1g6g89.js +0 -1
- package/dist/chunk-p0vzbr7s.js +0 -585
- package/dist/chunk-r10bn684.js +0 -1
- package/dist/chunk-r3pe49q4.js +0 -8
- package/dist/chunk-r4tq44hr.js +0 -1
- package/dist/chunk-rjrnaka2.js +0 -1
- package/dist/chunk-s77qbhtz.js +0 -3
- package/dist/chunk-t7rwtc17.js +0 -1
- package/dist/chunk-v8g52kan.js +0 -1
- package/dist/chunk-vd6c87cm.js +0 -2
- package/dist/chunk-vh9zd1v3.js +0 -5
- package/dist/chunk-w2hbsa9j.js +0 -86
- package/dist/chunk-wabmqprd.js +0 -184
- package/dist/chunk-wpy5r9ma.js +0 -40
- package/dist/chunk-yqwxbcc7.js +0 -31
- package/dist/chunk-z8n7y37k.js +0 -1
- package/dist/chunk-zr7sx9hd.js +0 -1
- package/dist/chunk-zxqmghzf.js +0 -1
package/dist/chunk-afhxxkmv.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import{$g as I$,bh as F$,ch as rQ,eh as F8,rh as U0,sh as fQ,uh as X1,vh as m$,wh as s$,yh as X8,zh as t$}from"./chunk-ac5t2ywn.js";import{ri as sQ}from"./chunk-cbjnwrt7.js";import{$i as kQ,$j as $1,Bj as W8,Bk as H1,Hj as L8,Kk as U8,Lk as Z$,Rj as Q1,Tk as XQ,Uk as q$,Vj as J$,Vk as V1,Wk as V8,Yj as i8,Zk as U1,aj as d8,ij as e$,jk as QQ,lk as Y1,mk as UQ,nl as r8,ok as cQ,pl as YQ,ql as S$,tk as g8,tl as Z0,yl as SQ}from"./chunk-w2hbsa9j.js";import{El as Y$}from"./chunk-rztre6k0.js";var xQ=class extends Error{lc_error_code;constructor(Q,$){let J=Q??"";if($?.lc_error_code)J=`${J}
|
|
2
|
-
|
|
3
|
-
Troubleshooting URL: https://docs.langchain.com/oss/javascript/langgraph/${$.lc_error_code}/
|
|
4
|
-
`;super(J);this.lc_error_code=$?.lc_error_code}},f0=class extends xQ{get is_bubble_up(){return!0}},k0=class extends xQ{constructor(Q,$){super(Q,$);this.name="GraphRecursionError"}static get unminifiable_name(){return"GraphRecursionError"}},uQ=class extends xQ{constructor(Q,$){super(Q,$);this.name="GraphValueError"}static get unminifiable_name(){return"GraphValueError"}},AQ=class extends f0{interrupts;constructor(Q,$){super(JSON.stringify(Q,null,2),$);this.name="GraphInterrupt",this.interrupts=Q??[]}static get unminifiable_name(){return"GraphInterrupt"}},D0=class extends AQ{constructor(Q,$){super([{value:Q}],$);this.name="NodeInterrupt"}static get unminifiable_name(){return"NodeInterrupt"}},K0=class extends f0{command;constructor(Q){super();this.name="ParentCommand",this.command=Q}static get unminifiable_name(){return"ParentCommand"}};function g0(Q){return Q!==void 0&&Q.name===K0.unminifiable_name}function dQ(Q){return Q!==void 0&&Q.is_bubble_up===!0}function OQ(Q){return Q!==void 0&&[AQ.unminifiable_name,D0.unminifiable_name].includes(Q.name)}var M0=class extends xQ{constructor(Q,$){super(Q,$);this.name="EmptyInputError"}static get unminifiable_name(){return"EmptyInputError"}},E=class extends xQ{constructor(Q,$){super(Q,$);this.name="EmptyChannelError"}static get unminifiable_name(){return"EmptyChannelError"}},b=class extends xQ{constructor(Q,$){super(Q,$);this.name="InvalidUpdateError"}static get unminifiable_name(){return"InvalidUpdateError"}};var m0=class extends xQ{constructor(Q,$){super(Q,$);this.name="UnreachableNodeError"}static get unminifiable_name(){return"UnreachableNodeError"}};var Y0=class extends xQ{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"}};function A8(Q){return Q!=null&&Q.lg_is_channel===!0}var p=class{ValueType;UpdateType;lg_is_channel=!0;consume(){return!1}finish(){return!1}isAvailable(){try{return this.get(),!0}catch(Q){if(Q.name===E.unminifiable_name)return!1;throw Q}}equals(Q){return this===Q}},x8=Symbol.for("LG_IS_ONLY_BASE_CHANNEL");function x0(Q){if(Q[x8]===!0)return Q;let $={};for(let J in Q){if(!Object.prototype.hasOwnProperty.call(Q,J))continue;let Z=Q[J];if(A8(Z))$[J]=Z}return Object.assign($,{[x8]:!0}),$}function pQ(Q,$){let J=x0(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,{[x8]:!0}),Z}function LQ(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===E.unminifiable_name);else throw Y}}}return{v:4,id:Z?.id??F$(J),ts:new Date().toISOString(),channel_values:q,channel_versions:Q.channel_versions,versions_seen:Q.versions_seen}}var P1=(Q)=>{return Q!=null&&Q.lc_graph_name==="BinaryOperatorAggregate"},wQ=class Q extends p{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)[this.value]=J,J=J.slice(1);for(let Z of J)if(this.value!==void 0)this.value=this.operator(this.value,Z);return!0}get(){if(this.value===void 0)throw new E;return this.value}checkpoint(){if(this.value===void 0)throw new E;return this.value}isAvailable(){return this.value!==void 0}equals($){if(this===$)return!0;if(!P1($))return!1;return this.operator===$.operator}};var jQ=class Q extends p{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 b("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 E;return this.value[0]}checkpoint(){if(this.value.length===0)throw new E;return this.value[0]}isAvailable(){return this.value.length!==0}},O8=class Q extends p{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 E;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}};var A0=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"}},aQ=function(Q){if(Q)return h0(Q);else return new jQ};aQ.Root=(Q)=>new A0(Q);function h0(Q){if(typeof Q==="object"&&Q&&"reducer"in Q&&Q.reducer)return new wQ(Q.reducer,Q.default);if(typeof Q==="object"&&Q&&"value"in Q&&Q.value)return new wQ(Q.value,Q.default);return new jQ}var R="__start__",A="__end__",PQ="__input__",W$="__copy__",l="__error__",u0="__pregel_ns_writes",HQ="__pregel_send",d0="__pregel_call",RQ="__pregel_read",g="__pregel_checkpointer",yQ="__pregel_resuming",X0="__pregel_task_id",w0="__pregel_stream";var F0="__pregel_resume_map",JQ="__pregel_scratchpad",P0="__pregel_previous",L$="__pregel_durability",w8="checkpoint_id",FQ="checkpoint_ns",j$="__pregel_node_finished",ZQ="checkpoint_map",P8="__pregel_abort_signals",S="__interrupt__",o="__resume__",p0="__no_writes__",VQ="__return__",eQ="__previous__",y="langsmith:hidden",H$="langsmith:nostream",R8="__self__",c="__pregel_tasks",r="__pregel_push",R0="__pregel_pull",n="00000000-0000-0000-0000-000000000000",V$=["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=":",B$=Symbol.for("langgraph.command"),U$=class{[B$];constructor(Q){this[B$]=Q}};function l0(Q){let $=Q;return $!==null&&$!==void 0&&typeof $.node==="string"&&$.args!==void 0}var lQ=class{lg_name="Send";node;args;constructor(Q,$){this.node=Q,this.args=O0($)}toJSON(){return{lg_name:this.lg_name,node:this.node,args:this.args}}};function d(Q){return Q instanceof lQ}function B0(Q){if(!Q||typeof Q!=="object")return!1;if(!("__interrupt__"in Q))return!1;return Array.isArray(Q.__interrupt__)}var a=class extends U${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)?O0(Q.goto):[O0(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 O0(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]=O0(Z,$)});else if(u(Q)&&!(Q instanceof a))J=new a(Q),$.set(Q,J);else if(l0(Q)&&!(Q instanceof lQ))J=new lQ(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]=O0(q,$)}return J}return Q}var U=(Q)=>BigInt(Q),v=(Q,$=0)=>new DataView(Q.buffer,Q.byteOffset+$,Q.byteLength-$),M$=U("0x9E3779B1"),x$=U("0x85EBCA77"),R1=U("0xC2B2AE3D"),oQ=U("0x9E3779B185EBCA87"),Q0=U("0xC2B2AE3D27D4EB4F"),A$=U("0x165667B19E3779F9"),S8=U("0x85EBCA77C2B2AE63"),T1=U("0x27D4EB2F165667C5"),b1=U("0x165667919E3779F9"),S1=U("0x9FB21C651E98DF25"),I1=(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 v(Z)},TQ=I1("b8fe6c3923a44bbe7c01812cf721ad1cded46de9839097db7240a4a4b7b3671fcb79e64eccc0e578825ad07dccff7221b8084674f743248ee03590e6813a264c3c2852bb91c300cb88d0658b1b532ea371644897a20df94e3819ef46a9deacd8a8fa763fe39c343ff9dcbbc7c70b4f1d8a51e04bcdb45931c89f7ec9d9787364eac5ac8334d3ebc3c581a0fffa1363eb170ddd51b7f0da49d316552629d4689e2b16be587d47a1fc8ff8b8d17ad031ce45cb3a8f95160428afd7fbcabb4b407e"),W0=(U(1)<<U(128))-U(1),P=(U(1)<<U(64))-U(1),i0=(U(1)<<U(32))-U(1);function L0(Q){if(!Q)throw Error("Assert failed")}function _1(Q){let $=new DataView(new ArrayBuffer(8));return $.setBigUint64(0,Q,!0),$.getBigUint64(0,!1)}function N1(Q){let $=Q;return $=($&U(65535))<<U(16)|($&U(4294901760))>>U(16),$=($&U(16711935))<<U(8)|($&U(4278255360))>>U(8),$}function E1(Q,$){return(Q&i0)*($&i0)&P}function y1(Q,$){return(Q<<$|Q>>U(32)-$)&i0}function O$(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]+=E1(z,z>>U(32))}return Q}function G$(Q,$,J,Z){for(let q=0;q<Z;q+=1)O$(Q,v($,q*64),v(J,q*8));return Q}function v1(Q,$){for(let J=0;J<8;J+=1){let Z=$.getBigUint64(J*8,!0),q=Q[J];q=T8(q,U(47)),q^=Z,q*=M$,Q[J]=q&P}return Q}function o0(Q,$){return w$(Q[0]^$.getBigUint64(0,!0),Q[1]^$.getBigUint64(8,!0))}function D$(Q,$,J){let Z=J;return Z+=o0(Q.slice(0),v($,0)),Z+=o0(Q.slice(2),v($,16)),Z+=o0(Q.slice(4),v($,32)),Z+=o0(Q.slice(6),v($,48)),bQ(Z&P)}function C1(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=G$(z,v($,F*X),J,Y),z=q(z,v(J,J.byteLength-64));{let F=Math.floor(($.byteLength-1-X*B)/64);z=G$(z,v($,B*X),J,F),z=Z(z,v($,$.byteLength-64),v(J,J.byteLength-64-7))}return z}function f1(Q,$){let J=new BigUint64Array([R1,oQ,Q0,A$,S8,x$,T1,M$]);L0(Q.byteLength>128),J=C1(J,Q,$,O$,v1),L0(J.length*8===64);{let Z=D$(J,v($,11),U(Q.byteLength)*oQ&P);return D$(J,v($,$.byteLength-64-11),~(U(Q.byteLength)*Q0)&P)<<U(64)|Z}}function w$(Q,$){let J=Q*$&W0;return J&P^J>>U(64)}function K$(Q,$,J){return w$((Q.getBigUint64(0,!0)^$.getBigUint64(0,!0)+J)&P,(Q.getBigUint64(8,!0)^$.getBigUint64(8,!0)-J)&P)}function c0(Q,$,J,Z,q){let z=Q&P,Y=Q>>U(64)&P;return z+=K$($,Z,q),z^=J.getBigUint64(0,!0)+J.getBigUint64(8,!0),z&=P,Y+=K$(J,v(Z,16),q),Y^=$.getBigUint64(0,!0)+$.getBigUint64(8,!0),Y&=P,Y<<U(64)|z}function bQ(Q){let $=Q;return $^=$>>U(37),$*=b1,$&=P,$^=$>>U(32),$}function r0(Q){let $=Q;return $^=$>>U(33),$*=Q0,$&=P,$^=$>>U(29),$*=A$,$&=P,$^=$>>U(32),$}function k1(Q,$,J){let Z=Q.byteLength;L0(Z>0&&Z<=3);let q=U(Q.getUint8(Z-1))|U(Z<<8)|U(Q.getUint8(0)<<16)|U(Q.getUint8(Z>>1)<<24),z=(q^(U($.getUint32(0,!0))^U($.getUint32(4,!0)))+J)&P,Y=(U($.getUint32(8,!0))^U($.getUint32(12,!0)))-J;return(r0((y1(N1(q),U(13))^Y)&P)&P)<<U(64)|r0(z)}function T8(Q,$){return Q^Q>>$}function g1(Q,$,J){let Z=Q.byteLength;L0(Z>=4&&Z<=8);{let q=Q.getUint32(0,!0),z=Q.getUint32(Z-4,!0),Y=((U(q)|U(z)<<U(32))^($.getBigUint64(16,!0)^$.getBigUint64(24,!0))+J&P)*(oQ+(U(Z)<<U(2)))&W0;return Y+=(Y&P)<<U(65),Y&=W0,Y^=Y>>U(67),T8(T8(Y&P,U(35))*S1&P,U(28))|bQ(Y>>U(64))<<U(64)}}function m1(Q,$,J){let Z=Q.byteLength;L0(Z>=9&&Z<=16);{let q=($.getBigUint64(32,!0)^$.getBigUint64(40,!0))+J&P,z=($.getBigUint64(48,!0)^$.getBigUint64(56,!0))-J&P,Y=Q.getBigUint64(0,!0),X=Q.getBigUint64(Z-8,!0),B=(Y^X^q)*oQ,F=(B&P)+(U(Z-1)<<U(54));B=B&(W0^P)|F,X^=z,B+=X+(X&i0)*(x$-U(1))<<U(64),B&=W0,B^=_1(B>>U(64));let W=(B&P)*Q0;return W+=(B>>U(64))*Q0<<U(64),W&=W0,bQ(W&P)|bQ(W>>U(64))<<U(64)}}function h1(Q,$){let J=Q.byteLength;if(L0(J<=16),J>8)return m1(Q,TQ,$);if(J>=4)return g1(Q,TQ,$);if(J>0)return k1(Q,TQ,$);return r0($^TQ.getBigUint64(64,!0)^TQ.getBigUint64(72,!0))|r0($^TQ.getBigUint64(80,!0)^TQ.getBigUint64(88,!0))<<U(64)}function b8(Q){return~Q+U(1)&P}function u1(Q,$,J){let Z=U(Q.byteLength)*oQ&P,q=U(Q.byteLength-1)/U(32);while(q>=0){let X=Number(q);Z=c0(Z,v(Q,16*X),v(Q,Q.byteLength-16*(X+1)),v($,32*X),J),q-=U(1)}let z=Z+(Z>>U(64))&P;z=bQ(z);let Y=(Z&P)*oQ+(Z>>U(64))*S8+(U(Q.byteLength)-J&P)*Q0;return Y&=P,Y=b8(bQ(Y)),z|Y<<U(64)}function d1(Q,$,J){let Z=U(Q.byteLength)*oQ&P;for(let Y=32;Y<160;Y+=32)Z=c0(Z,v(Q,Y-32),v(Q,Y-16),v($,Y-32),J);Z=bQ(Z&P)|bQ(Z>>U(64))<<U(64);for(let Y=160;Y<=Q.byteLength;Y+=32)Z=c0(Z,v(Q,Y-32),v(Q,Y-16),v($,3+Y-160),J);Z=c0(Z,v(Q,Q.byteLength-16),v(Q,Q.byteLength-32),v($,103),b8(J));let q=Z+(Z>>U(64))&P;q=bQ(q);let z=(Z&P)*oQ+(Z>>U(64))*S8+(U(Q.byteLength)-J&P)*Q0;return z&=P,z=b8(bQ(z)),q|z<<U(64)}function vQ(Q,$=U(0)){let Z=v(typeof Q==="string"?new TextEncoder().encode(Q):Q),q=Z.byteLength,z=(Y)=>Y.toString(16).padStart(32,"0");if(q<=16)return z(h1(Z,$));if(q<=128)return z(u1(Z,TQ,$));if(q<=240)return z(d1(Z,TQ,$));return z(f1(Z,TQ))}function n0(Q){return/^[0-9a-f]{32}$/.test(Q)}function I8(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[g])throw new uQ("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[HQ]?.([[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[HQ]?.([[o,Z.resume]]),Y}let z=J[FQ]?.split(k);throw new AQ([{id:z?vQ(z.join(k)):void 0,value:Q}])}import{AsyncLocalStorage as p1}from"node:async_hooks";function P$(){QQ.initializeGlobalInstance(new p1)}var l1=["tags","metadata","callbacks","configurable"],o1=["tags","metadata","callbacks","runName","maxConcurrency","recursionLimit","configurable","runId","outputKeys","streamMode","store","writer","interrupt","context","interruptBefore","interruptAfter","checkpointDuring","durability","signal"],c1=25;function T0(...Q){let $={tags:[],metadata:{},callbacks:void 0,recursionLimit:c1,configurable:{}},J=QQ.getRunnableConfig();if(J!==void 0){for(let[Z,q]of Object.entries(J))if(q!==void 0)if(l1.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&&o1.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 _8(){return QQ.getRunnableConfig()}function i1(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 s0(Q){return Q.split(k).filter(($)=>!$.match(/^\d+$/)).map(($)=>$.split(e)[0]).join(k)}function R$(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=cQ($,{callbacks:J?.getChild()});QQ.runWithConfig(z,async()=>{try{Z(await this.func(Q,z))}catch(Y){q(Y)}})})}async invoke(Q,$){let J,Z=T0($),q=UQ(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 T$(Q){return Q!=null&&typeof Q==="function"&&Q instanceof Object.getPrototypeOf(async function*(){}).constructor}function b$(Q){return Q!=null&&typeof Q==="function"&&Q instanceof Object.getPrototypeOf(function*(){}).constructor}var _J={[Symbol.for("LG_SKIP_WRITE")]:!0};function r1(Q){return typeof Q==="object"&&Q?.[Symbol.for("LG_SKIP_WRITE")]!==void 0}var qQ={[Symbol.for("LG_PASSTHROUGH")]:!0};function t0(Q){return typeof Q==="object"&&Q?.[Symbol.for("LG_PASSTHROUGH")]!==void 0}var N8=Symbol("IS_WRITER"),m=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,func:async(q,z)=>{return this._write(q,z??{})}});this.writes=$}async _write($,J){let Z=this.writes.map((q)=>{if(E8(q)&&t0(q.value))return{mapper:q.mapper,value:$};else if(a0(q)&&t0(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(a0(z)){if(z.channel===c)throw new b("Cannot write to the reserved channel TASKS");if(t0(z.value))throw new b("PASSTHROUGH value must be replaced")}if(E8(z)){if(t0(z.value))throw new b("PASSTHROUGH value must be replaced")}}let Z=[];for(let z of J)if(d(z))Z.push([c,z]);else if(E8(z)){let Y=await z.mapper.invoke(z.value,$);if(Y!=null&&Y.length>0)Z.push(...Y)}else if(a0(z)){let Y=z.mapper!==void 0?await z.mapper.invoke(z.value,$):z.value;if(r1(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?.[HQ];q(Z)}static isWriter($){return $ instanceof Q||N8 in $&&!!$[N8]}static registerWriter($){return Object.defineProperty($,N8,{value:!0})}};function a0(Q){return Q!==void 0&&typeof Q.channel==="string"}function E8(Q){return Q!==void 0&&!a0(Q)&&YQ.isRunnable(Q.mapper)}var _$=class Q extends s{lc_graph_name="ChannelRead";channel;fresh=!1;mapper;constructor($,J,Z=!1){super({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?.[RQ];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 I$,DQ=class Q extends S${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}=$,V=[...$.config?.tags?$.config.tags:[],...L??[]];super({...$,bound:$.bound??j0,config:{...$.config?$.config:{},tags:V}});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=V,this.retryPolicy=F,this.cachePolicy=W,this.subgraphs=H,this.ends=j}getWriters(){let $=[...this.writers];while($.length>1&&$[$.length-1]instanceof m&&$[$.length-2]instanceof m){let J=$.slice(-2),Z=J[0].writes.concat(J[1].writes);$[$.length-2]=new m(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(m.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:SQ($),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 n1(Q){return"steps"in Q&&Array.isArray(Q.steps)}function b0(Q){return"lg_is_pregel"in Q&&Q.lg_is_pregel===!0}function e0(Q){let $=[Q];for(let J of $)if(b0(J))return J;else if(n1(J))$.push(...J.steps)}function q0(Q,$,J=!0,Z=!1){try{return Q[$].get()}catch(q){if(q.name===E.unminifiable_name){if(Z)return q;else if(J)return null}throw q}}function KQ(Q,$,J=!0){if(Array.isArray($)){let Z={};for(let q of $)try{Z[q]=q0(Q,q,!J)}catch(z){if(z.name===E.unminifiable_name)continue}return Z}else return q0(Q,$)}function*N$(Q,$){if(Q.graph===a.PARENT)throw new b("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(n0))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*Q8(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*$8(Q,$,J){if(Array.isArray(Q)){if($===!0||$.find(([Z,q])=>Q.includes(Z)))yield KQ(J,Q)}else if($===!0||$.some(([Z,q])=>Z===Q))yield q0(J,Q)}function*E$(Q,$,J){let Z=$.filter(([X,B])=>{return(X.config===void 0||!X.config.tags?.includes(y))&&B[0][0]!==l&&B[0][0]!==S});if(!Z.length)return;let q;if(Z.some(([X])=>X.writes.some(([B,F])=>B===VQ)))q=Z.flatMap(([X])=>X.writes.filter(([B,F])=>B===VQ).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 J8(Q){let $=typeof Q[R];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=J8($);return Object.fromEntries(Object.entries($).filter(([Z,q])=>q>(Q[Z]??J)))}else return $}function y$(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 iQ(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 V0(...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 v$=(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 C$=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 f$(Q){return typeof Q==="object"&&Q!==null&&"__lg_type"in Q&&Q.__lg_type==="call"}function k$(Q,$){return new Z0({name:Q,first:new s({func:(J)=>$(...J),name:Q,trace:!1,recurse:!1}),last:new m([{channel:VQ,value:qQ}],[y])})}function g$(Q,$){return new s({func:(J,Z)=>{return $(J,Z)},name:Q,trace:!1,recurse:!1})}var h$=(Q)=>{return Q!==void 0?Q+1:1};function s1(Q,$){if($==null)return!1;for(let J of Q)if($[J])return!0;return!1}function t1(Q){let $;for(let J in Q){if(!Object.prototype.hasOwnProperty.call(Q,J))continue;if($==null)$=Q[J];else $=m$($,Q[J])}return $}function I0(Q,$,J){let Z=J8(Q.channel_versions),q=Q.versions_seen[S]??{},z=!1;if((Q.channel_versions[R]??Z)>(q[R]??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(y):$.includes(X.name));return z&&Y}function S0(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=LQ(Q,X,-1),F=pQ(X,B);$Q(fQ(B),F,[J],void 0,void 0),Y=KQ({...$,...F},Z)}else Y=KQ($,Z);return Y}function y8(Q,$,J){for(let[Z,q]of J)if([r,c].includes(Z)&&q!=null){if(!d(q))throw new b(`Invalid packet type, expected SendProtocol, got ${JSON.stringify(q)}`);if(!(q.node in $))throw new b(`Invalid node name "${q.node}" in Send packet`)}Q(J)}var a1=new Set([p0,r,o,S,VQ,l]);function $Q(Q,$,J,Z,q){J.sort((H,j)=>{let V=H.path?.slice(0,3)||[],G=j.path?.slice(0,3)||[];for(let M=0;M<Math.min(V.length,G.length);M+=1){if(V[M]<G[M])return-1;if(V[M]>G[M])return 1}return V.length-G.length});let z=J.some((H)=>H.triggers.length>0),Y=x0($);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=t1(Q.channel_versions),B=new Set(J.flatMap((H)=>H.triggers).filter((H)=>!V$.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,V]of H.writes)if(a1.has(j));else if(j in Y)W[j]??=[],W[j].push(V);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 V=Y[H],G;try{G=V.update(j)}catch(M){if(M.name===b.unminifiable_name){let O=new b(`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(G&&Z!==void 0){if(Q.channel_versions[H]=Z(X),V.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&&!s1(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*e1(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 nQ(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=Z8([r,W],Q,$,J,Z,q,z,Y);if(L!==void 0)X[L.id]=L}}for(let F of e1(Q,J,Y)){let W=Z8([R0,F],Q,$,J,Z,q,z,Y);if(W!==void 0)X[W.id]=W}return X}function Z8(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&&f$(Q[Q.length-1])){let j=Q[Q.length-1],V=k$(j.name,j.func),G=[r],M=H===""?j.name:`${H}${k}${j.name}`,O=rQ(JSON.stringify([M,B.toString(),j.name,r,Q[1],Q[2]]),$.id),I=`${M}${e}${O}`,w=[...Q.slice(0,3),!0],N={langgraph_step:B,langgraph_node:j.name,langgraph_triggers:G,langgraph_path:w,langgraph_checkpoint_ns:I};if(Y){let _=[];return{name:j.name,input:j.input,proc:V,writes:_,config:cQ(UQ(z,{metadata:N,store:X.store??z.store}),{runName:j.name,callbacks:W?.getChild(`graph:step:${B}`),configurable:{[X0]:O,[HQ]:(f)=>y8((D)=>_.push(...D),Z,f),[RQ]:(f,D=!1)=>S0($,q,{name:j.name,writes:_,triggers:G,path:w},f,D),[g]:F??L[g],[ZQ]:{...L[ZQ],[H]:$.id},[JQ]:v8({pendingWrites:J??[],taskId:O,currentTaskInput:j.input,resumeMap:z.configurable?.[F0],namespaceHash:vQ(I)}),[P0]:$.channel_values[eQ],checkpoint_id:void 0,checkpoint_ns:I}}),triggers:G,retry_policy:j.retry,cache_key:j.cache?{key:vQ((j.cache.keyFunc??JSON.stringify)([j.input])),ns:[u0,j.name??"__dynamic__"],ttl:j.cache.ttl}:void 0,id:O,path:w,writers:[]}}else return{id:O,name:j.name,interrupts:[],path:w}}else if(Q[0]===r){let j=typeof Q[1]==="number"?Q[1]:parseInt(Q[1],10);if(!q[c]?.isAvailable())return;let V=q[c].get();if(j<0||j>=V.length)return;let G=l0(V[j])&&!d(V[j])?new lQ(V[j].node,V[j].args):V[j];if(!l0(G)){console.warn(`Ignoring invalid packet ${JSON.stringify(G)} in pending sends.`);return}if(!(G.node in Z)){console.warn(`Ignoring unknown node name ${G.node} in pending sends.`);return}let M=[r],O=H===""?G.node:`${H}${k}${G.node}`,I=rQ(JSON.stringify([O,B.toString(),G.node,r,j.toString()]),$.id),w=`${O}${e}${I}`,N={langgraph_step:B,langgraph_node:G.node,langgraph_triggers:M,langgraph_path:Q.slice(0,3),langgraph_checkpoint_ns:w};if(Y){let _=Z[G.node],f=_.getNode();if(f!==void 0){if(_.metadata!==void 0)N={...N,..._.metadata};let D=[];return{name:G.node,input:G.args,proc:f,subgraphs:_.subgraphs,writes:D,config:cQ(UQ(z,{metadata:N,tags:_.tags,store:X.store??z.store}),{runName:G.node,callbacks:W?.getChild(`graph:step:${B}`),configurable:{[X0]:I,[HQ]:(x)=>y8((T)=>D.push(...T),Z,x),[RQ]:(x,T=!1)=>S0($,q,{name:G.node,writes:D,triggers:M,path:Q},x,T),[g]:F??L[g],[ZQ]:{...L[ZQ],[H]:$.id},[JQ]:v8({pendingWrites:J??[],taskId:I,currentTaskInput:G.args,resumeMap:z.configurable?.[F0],namespaceHash:vQ(w)}),[P0]:$.channel_values[eQ],checkpoint_id:void 0,checkpoint_ns:w}}),triggers:M,retry_policy:_.retryPolicy,cache_key:_.cachePolicy?{key:vQ((_.cachePolicy.keyFunc??JSON.stringify)([G.args])),ns:[u0,_.name??"__dynamic__",G.node],ttl:_.cachePolicy.ttl}:void 0,id:I,path:Q,writers:_.getWriters()}}}else return{id:I,name:G.node,interrupts:[],path:Q}}else if(Q[0]===R0){let j=Q[1].toString(),V=Z[j];if(V===void 0)return;if(J?.length){let I=H===""?j:`${H}${k}${j}`,w=rQ(JSON.stringify([I,B.toString(),j,R0,j]),$.id);if(J.some((N)=>N[0]===w&&N[1]!==l))return}let G=J8($.channel_versions);if(G===void 0)return;let M=$.versions_seen[j]??{},O=V.triggers.find((I)=>{if(!q[I].isAvailable())return!1;return($.channel_versions[I]??G)>(M[I]??G)});if(O!==void 0){let I=Q6(V,q,Y);if(I===void 0)return;let w=H===""?j:`${H}${k}${j}`,N=rQ(JSON.stringify([w,B.toString(),j,R0,[O]]),$.id),_=`${w}${e}${N}`,f={langgraph_step:B,langgraph_node:j,langgraph_triggers:[O],langgraph_path:Q,langgraph_checkpoint_ns:_};if(Y){let D=V.getNode();if(D!==void 0){if(V.metadata!==void 0)f={...f,...V.metadata};let x=[];return{name:j,input:I,proc:D,subgraphs:V.subgraphs,writes:x,config:cQ(UQ(z,{metadata:f,tags:V.tags,store:X.store??z.store}),{runName:j,callbacks:W?.getChild(`graph:step:${B}`),configurable:{[X0]:N,[HQ]:(T)=>y8((K)=>{x.push(...K)},Z,T),[RQ]:(T,K=!1)=>S0($,q,{name:j,writes:x,triggers:[O],path:Q},T,K),[g]:F??L[g],[ZQ]:{...L[ZQ],[H]:$.id},[JQ]:v8({pendingWrites:J??[],taskId:N,currentTaskInput:I,resumeMap:z.configurable?.[F0],namespaceHash:vQ(_)}),[P0]:$.channel_values[eQ],checkpoint_id:void 0,checkpoint_ns:_}}),triggers:[O],retry_policy:V.retryPolicy,cache_key:V.cachePolicy?{key:vQ((V.cachePolicy.keyFunc??JSON.stringify)([I])),ns:[u0,V.name??"__dynamic__",j],ttl:V.cachePolicy.ttl}:void 0,id:N,path:Q,writers:V.getWriters()}}}else return{id:N,name:j,interrupts:[],path:Q}}}}function Q6(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===E.unminifiable_name)return;else throw Y}else if(z in $)try{Z[q]=q0($,z,!1)}catch(Y){if(Y.name===E.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===E.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 u$(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 lQ(Q.node,J)}function v8({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 _0={blue:{start:"\x1B[34m",end:"\x1B[0m"},green:{start:"\x1B[32m",end:"\x1B[0m"},yellow:{start:"\x1B[33;1m",end:"\x1B[0m"}},N0=(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(y))continue;yield{id:$,name:J,input:Z,triggers:z,interrupts:Y.filter(([X,B])=>{return X===$&&B===S}).map(([,X])=>{return X})}}}function $6(Q){if(typeof Q!=="object"||Q===null)return!1;return"$writes"in Q&&Array.isArray(Q.$writes)}function d$(Q){let $={};for(let[J,Z]of Q){let q=String(J);if(q in $){let z=$6($[q])?$[q].$writes:[$[q]];z.push(Z),$[q]={$writes:z}}else $[q]=Z}return $}function*p$(Q,$){for(let[{id:J,name:Z,config:q},z]of Q){if(q?.tags?.includes(y))continue;yield{id:J,name:Z,result:d$(z.filter(([Y])=>{return Array.isArray($)?$.includes(Y):Y===$})),interrupts:z.filter((Y)=>Y[0]===S).map((Y)=>Y[1])}}}function*l$(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(e0))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:KQ($,J),metadata:Z,next:q.map((L)=>L.name),tasks:f8(q,z,W,X),parentConfig:Y?B(Y):void 0}}function f8(Q,$,J,Z){return Q.map((q)=>{let z=$.find(([F,W])=>F===q.id&&W===l)?.[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===VQ);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 d$(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 o$(Q,$,J){console.log([`${N0(_0.blue,`[${Q}:checkpoint]`)}`,`\x1B[1m State at the end of step ${Q}:\x1B[0m
|
|
6
|
-
`,JSON.stringify(KQ($,J),null,2)].join(""))}function q8(Q,$){let J=$.length;console.log([`${N0(_0.blue,`[${Q}:tasks]`)}`,`\x1B[1m Starting step ${Q} with ${J} task${J===1?"":"s"}:\x1B[0m
|
|
7
|
-
`,$.map((Z)=>`- ${N0(_0.green,String(Z.name))} -> ${JSON.stringify(Z.input,null,2)}`).join(`
|
|
8
|
-
`)].join(""))}function c$(Q,$,J){let Z={};for(let[q,z]of $)if(J.includes(q)){if(!Z[q])Z[q]=[];Z[q].push(z)}console.log([`${N0(_0.blue,`[${Q}:writes]`)}`,`\x1B[1m Finished step ${Q} with writes to ${Object.keys(Z).length} channel${Object.keys(Z).length!==1?"s":""}:\x1B[0m
|
|
9
|
-
`,Object.entries(Z).map(([q,z])=>`- ${N0(_0.yellow,q)} -> ${z.map((Y)=>JSON.stringify(Y)).join(", ")}`).join(`
|
|
10
|
-
`)].join(""))}var m8=class extends g8{_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}},z8=class extends g8{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)}};function J6(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 Z6(Q){if(Q instanceof Error)return{error:Q.name,message:Q.message};return{error:"Error",message:JSON.stringify(Q)}}function h8(Q){if(typeof Q!=="object"||Q==null)return!1;return"configurable"in Q&&typeof Q.configurable==="object"&&Q.configurable!=null}function k8(Q){if(!h8(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 i$(Q){if(h8(Q)){let $=Object.fromEntries(Object.entries(Q.configurable).filter(([Z])=>!Z.startsWith("__"))),J={...Q,configurable:$};return delete J.callbacks,J}return Q}function r$(Q){let $={...Q,checkpoint:k8(Q.config),parent_checkpoint:k8(Q.parentConfig),config:i$(Q.config),parent_config:i$(Q.parentConfig),tasks:Q.tasks.map((J)=>{if(h8(J.state)){let Z=k8(J.state);if(Z!=null){let q={...J,checkpoint:Z};return delete q.state,q}}return J})};return delete $.parentConfig,$}function n$(Q){let $=new TextEncoder;return new ReadableStream({async start(J){let Z=(q)=>{J.enqueue($.encode(`event: ${q.event}
|
|
11
|
-
data: ${J6(q.data)}
|
|
12
|
-
|
|
13
|
-
`))};try{for await(let q of Q){let[z,Y,X]=q,B=X;if(Y==="debug"){let F=X;if(F.type==="checkpoint")B={...F,payload:r$(F.payload)}}if(Y==="checkpoints")B=r$(X);Z({event:z?.length?`${Y}|${z.join("|")}`:Y,data:B})}}catch(q){Z({event:"error",data:Z6(q)})}J.close()}})}var Y8=Symbol.for("INPUT_DONE"),u8=Symbol.for("INPUT_RESUMING"),q6=25;function z6(...Q){return new z8({passthroughFn:($)=>{for(let J of Q)if(J.modes.has($[1]))J.push($)},modes:new Set(Q.flatMap(($)=>Array.from($.modes)))})}var Y6=class extends t${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}},a$=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(R 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?.[yQ]!==void 0&&this.config.configurable?.[yQ],Z=this.input===null||this.input===void 0,q=u(this.input)&&this.input.resume!=null,z=this.input===u8,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=h$;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 Y6($.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?.[w0]!==void 0)Z=z6(Z,J.configurable[w0]);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=RQ 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:U0(),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??[],V=pQ($.channelSpecs,L),G=(H.step??0)+1,M=G+(J.recursionLimit??q6)+1,O={...L.channel_versions},I=$.store?new X8($.store):void 0;if(I)await I.start();return new Q({input:$.input,config:J,checkpointer:$.checkpointer,checkpoint:L,checkpointMetadata:H,checkpointConfig:X,prevCheckpointConfig:W,checkpointNamespace:B,channels:V,isNested:Y,manager:$.manager,skipDoneTasks:q,step:G,stop:M,checkpointPreviousVersions:O,checkpointPendingWrites:j,outputKeys:$.outputKeys??[],streamKeys:$.streamKeys??[],nodes:$.nodes,stream:Z,store:I,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 s$)))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,u$(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]===l||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(y))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]!==l)this._emit($0(CQ(E$(this.outputKeys,[[q,J]],Z),"updates")))}if(!Z)this._emit($0(CQ(p$([[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(![Y8,u8].includes(this.input))await this._first(J);else if(this.toInterrupt.length>0)throw this.status="interrupt_before",new AQ;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($8(this.outputKeys,q,this.channels),"values"));if(this._emit(z),this.checkpointPendingWrites=[],await this._putCheckpoint({source:"loop"}),I0(this.checkpoint,this.interruptAfter,Object.values(this.tasks)))throw this.status="interrupt_after",new AQ;if(this.config.configurable?.[yQ]!==void 0)delete this.config.configurable?.[yQ]}else return!1;if(this.step>this.stop)return this.status="out_of_steps",!1;if(this.tasks=nQ(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(l$(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===l||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(I0(this.checkpoint,this.interruptBefore,Object.values(this.tasks)))throw this.status="interrupt_before",new AQ;let Z=await GQ(CQ(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=KQ(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($8(this.outputKeys,Object.values(this.tasks).flatMap((Z)=>Z.writes),this.channels),"values")));if(OQ($)&&!$.interrupts.length)this._emit([["updates",{[S]:[]}],["values",{[S]:[]}]])}return J}async acceptPush($,J,Z){if(this.interruptAfter?.length>0&&I0(this.checkpoint,this.interruptAfter,[$])){this.toInterrupt.push($);return}let q=Z8([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&&I0(this.checkpoint,this.interruptBefore,[q])){this.toInterrupt.push(q);return}if(this._emit($0(CQ(C8([q]),"tasks"))),this.debug)q8(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 OQ($)&&!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(n0))this.config.configurable??={},this.config.configurable[F0]=this.input.resume;if(Y&&this.checkpointer==null)throw Error("Cannot use Command(resume=...) without checkpointer");let X={};for(let[B,F,W]of N$(this.input,this.checkpointPendingWrites))X[B]??=[],X[B].push([F,W]);if(Object.keys(X).length===0)throw new M0("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:PQ,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($8(this.outputKeys,!0,this.channels),"values"));this._emit(Y)}if(this.isResuming)this.input=u8;else if(z)await this._putCheckpoint({source:"input"}),this.input=Y8;else{let Y=await GQ(Q8($,this.input));if(Y.length>0){let X=nQ(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:PQ,writes:Y,triggers:[]}]),this.checkpointerGetNextVersion,this.triggerToNodes),await this._putCheckpoint({source:"input"}),this.input=Y8}else if(!(yQ in(this.config.configurable??{})))throw new M0(`Received no input writes for ${JSON.stringify($,null,2)}`);else this.input=Y8}if(!this.isNested)this.config=zQ(this.config,{[yQ]: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=LQ(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===l||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 X6(Q){return kQ(Q?.message)}var J1=class extends $1{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(e$($))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(H$)&&!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(X6(Y))this._emit(this.metadatas[J],Y.message,J);else this._emit(this.metadatas[J],new Q1({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(y))){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)||d8(B))&&B.id!==void 0)this.seen[B.id]=B;else if(Array.isArray(B)){for(let F of B)if((kQ(F)||d8(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 F6=500,B6=2,W6=128000,L6=3,j6=[400,401,402,403,404,405,406,407,409],H6=(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($&&j6.includes(+$))return!1;if(Q?.error?.code==="insufficient_quota")return!1;return!0};async function p8(Q,$,J,Z){let q=Q.retry_policy??$,z=q!==void 0?q.initialInterval??F6: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,g0(X)){let j=F?.configurable?.checkpoint_ns,V=X.command;if(V.graph===j){for(let G of Q.writers)await G.invoke(V,F);X=void 0;break}else if(V.graph===a.PARENT){let G=R$(j);X.command=new a({...X.command,graph:G})}}if(dQ(X))break;if(q===void 0)break;if(Y+=1,Y>=(q.maxAttempts??L6))break;if(!(q.retryOn??H6)(X))break;z=Math.min(q.maxInterval??W6,z*(q.backoffFactor??B6));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,{[yQ]:!0})}}return{task:Q,result:B,error:X,signalAborted:Z?.aborted}}var l8=Symbol.for("promiseAdded");function V6(){let Q={next:()=>{return},wait:Promise.resolve(l8)};function $(J){Q.next=()=>{Q.wait=new Promise($),J(l8)}}return Q.wait=new Promise($),Q}var Z1=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((V)=>V.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:V,error:G,signalAborted:M}of j)if(this._commit(V,G),OQ(G))Y=G;else if(dQ(G)&&!OQ(Y))Y=G;else if(G&&(z.size===0||!M))X.abort(),z.add(G);if(H?.(),Z?.(this.loop.step,Object.values(this.loop.tasks).map((V)=>V.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(OQ(Y))throw Y;if(dQ(Y)&&this.loop.isNested)throw Y}_initializeAbortSignals({exceptionSignal:Q,stepTimeoutSignal:$,signal:J}){let Z=this.loop.config.configurable?.[P8]??{},q=Z.externalAbortSignal??J,z=$??Z.timeoutAbortSignal,{signal:Y,dispose:X}=V0(q,z,Q),B={externalAbortSignal:q,timeoutAbortSignal:z,composedAbortSignal:Y};return this.loop.config=zQ(this.loop.config,{[P8]:B}),{signals:B,disposeCombinedSignal:X}}async*_executeTasksWithRetry(Q,$){let{retryPolicy:J,maxConcurrency:Z,signals:q}=$??{},z=V6(),Y={},X={executingTasksMap:Y,barrier:z,retryPolicy:J,scheduleTask:async(H,j,V)=>this.loop.acceptPush(H,j,V)};if(q?.composedAbortSignal?.aborted)throw Error("Abort");let B=0,F,W=V0(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]=p8(j,J,{[d0]:q1?.bind(X,this,j)},q?.composedAbortSignal).catch((V)=>{return{task:j,error:V,signalAborted:q?.composedAbortSignal?.aborted}})}let H=await Promise.race([...Object.values(Y),...L?[L]:[],z.wait]);if(H===l8)continue;if(yield H,F!=null)W.signal?.removeEventListener("abort",F),W.dispose?.();delete Y[H.task.id]}}_commit(Q,$){if($!==void 0)if(OQ($)){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(dQ($)&&Q.writes.length)this.loop.putWrites(Q.id,Q.writes);else this.loop.putWrites(Q.id,[[l,{message:$.message,name:$.name}]]);else{if(this.nodeFinished&&(Q.config?.tags==null||!Q.config.tags.includes(y)))this.nodeFinished(String(Q.name));if(Q.writes.length===0)Q.writes.push([p0,null]);this.loop.putWrites(Q.id,Q.writes)}}};async function q1(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 C$({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===VQ),H=F.writes.filter(([j])=>j===l);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],V=j instanceof Error?j:Error(String(j));return Promise.reject(V)}throw Error(`BUG: multiple errors found for task ${F.name}__${F.id}`)}return}else{let L=p8(F,z.retry,{[d0]:q1.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 z1({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===DQ)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 o8(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 c8=class Q extends p{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 E;return this.values}checkpoint(){return[[...this.seen],this.values]}isAvailable(){return this.values.length!==0}};var F1=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 DQ({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:SQ(q)});else J.push({channel:Z,value:q,skipNone:!1});return new m(J)}},U6=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,$)}},B8=class extends U6{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 c8({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 $=UQ(this.config,Q);return new this.constructor({...this,config:$})}validate(){z1({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=e0(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=pQ(this.channels,$.checkpoint);if($.pendingWrites?.length){let L=$.pendingWrites.filter(([H,j])=>H===n).map(([H,j,V])=>[String(j),V]);if(L.length>0)$Q($.checkpoint,q,[{name:PQ,writes:L,triggers:[]}],void 0,this.triggerToNodes)}let z=Object.values(nQ($.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(([V])=>V===L.name);if(!H)continue;let j=`${String(L.name)}${e}${L.id}`;if(X)j=`${X}${k}${j}`;if(J===void 0){let V={configurable:{thread_id:$.config.configurable?.thread_id,checkpoint_ns:j}};B[L.id]=V}else{let V={configurable:{[g]:J,thread_id:$.config.configurable?.thread_id,checkpoint_ns:j}},G=H[1];B[L.id]=await G.getState(V,{subgraphs:!0})}}if(Z&&$.pendingWrites?.length){let L=Object.fromEntries(z.map((j)=>[j.id,j]));for(let[j,V,G]of $.pendingWrites){if([l,S,F8].includes(V))continue;if(!(j in L))continue;L[j].writes.push([String(V),G])}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:KQ(q,this.streamChannelsAsIs),next:W,tasks:f8(z,$?.pendingWrites??[],B,this.streamChannelsAsIs),metadata:F,config:iQ($.config,$.metadata),createdAt:$.checkpoint.ts,parentConfig:$.parentConfig}}async getState(Q,$){let J=Q.configurable?.[g]??this.checkpointer;if(!J)throw new uQ("No checkpointer set",{lc_error_code:"MISSING_CHECKPOINTER"});let Z=Q.configurable?.checkpoint_ns??"";if(Z!==""&&Q.configurable?.[g]===void 0){let Y=s0(Z);for await(let[X,B]of this.getSubgraphsAsync(Y,!0))if(X===Y)return await B.getState(J0(Q,{[g]:J}),{subgraphs:$?.subgraphs});throw Error(`Subgraph with namespace "${Y}" not found.`)}let q=UQ(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?.[g]??this.checkpointer;if(!J)throw new uQ("No checkpointer set",{lc_error_code:"MISSING_CHECKPOINTER"});let Z=Q.configurable?.checkpoint_ns??"";if(Z!==""&&Q.configurable?.[g]===void 0){let z=s0(Z);for await(let[Y,X]of this.getSubgraphsAsync(z,!0))if(Y===z){yield*X.getStateHistory(J0(Q,{[g]:J}),$);return}throw Error(`Subgraph with namespace "${z}" not found.`)}let q=UQ(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?.[g]??this.checkpointer;if(!J)throw new uQ("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?.[g]===void 0){let Y=s0(Z);for await(let[,X]of this.getSubgraphsAsync(Y,!0))return await X.bulkUpdateState(J0(Q,{[g]:J}),$);throw Error(`Subgraph "${Y}" not found`)}let q=async(Y,X)=>{let B=this.config?UQ(this.config,Y):Y,F=await J.getTuple(B),W=F!==void 0?fQ(F.checkpoint):U0(),L={...F?.checkpoint.channel_versions},H=F?.metadata?.step??-1,j=J0(B,{checkpoint_ns:B.configurable?.checkpoint_ns??""}),V=B.metadata??{};if(F?.config.configurable)j=J0(B,F.config.configurable),V={...F.metadata,...V};let{values:G,asNode:M}=X[0];if(G==null&&M===void 0){if(X.length>1)throw new b("Cannot create empty checkpoint with multiple updates");return iQ(await J.put(j,LQ(W,void 0,H),{source:"update",step:H+1,parents:F?.metadata?.parents??{}},{}),F?F.metadata:void 0)}let O=pQ(this.channels,W);if(G===null&&M===A){if(X.length>1)throw new b("Cannot apply multiple updates when clearing state");if(F){let D=nQ(W,F.pendingWrites||[],this.nodes,O,F.config,!0,{step:(F.metadata?.step??-1)+1,checkpointer:J,store:this.store}),x=(F.pendingWrites||[]).filter((T)=>T[0]===n).map((T)=>T.slice(1));if(x.length>0)$Q(W,O,[{name:PQ,writes:x,triggers:[]}],J.getNextVersion.bind(J),this.triggerToNodes);for(let[T,K,C]of F.pendingWrites||[]){if([l,S,F8].includes(K))continue;if(!(T in D))continue;D[T].writes.push([K,C])}$Q(W,O,Object.values(D),J.getNextVersion.bind(J),this.triggerToNodes)}return iQ(await J.put(j,LQ(W,O,H),{...V,source:"update",step:H+1,parents:F?.metadata?.parents??{}},H0(L,W.channel_versions)),F?F.metadata:void 0)}if(M===W$){if(X.length>1)throw new b("Cannot copy checkpoint with multiple updates");if(F==null)throw new b("Cannot copy a non-existent checkpoint");let D=(K)=>{if(!Array.isArray(K))return!1;if(K.length===0)return!1;return K.every((C)=>Array.isArray(C)&&C.length===2)},x=LQ(W,void 0,H),T=await J.put(F.parentConfig??J0(F.config,{checkpoint_id:void 0}),x,{source:"fork",step:H+1,parents:F.metadata?.parents??{}},{});if(D(G)){let K=nQ(x,F.pendingWrites,this.nodes,O,T,!1,{step:H+2}),C=Object.values(K).reduce((i,{name:C0,id:M8})=>{return i[C0]??=[],i[C0].push({id:M8}),i},{}),h=G.reduce((i,C0)=>{let[M8,G0]=C0;i[G0]??=[];let O1=i[G0].length,w1=C[G0]?.[O1]?.id;return i[G0].push({values:M8,asNode:G0,taskId:w1}),i},{});return q(iQ(T,F.metadata),Object.values(h).flat())}return iQ(T,F.metadata)}if(M===PQ){if(X.length>1)throw new b("Cannot apply multiple updates when updating as input");let D=await GQ(Q8(this.inputChannels,G));if(D.length===0)throw new b(`Received no input writes for ${JSON.stringify(this.inputChannels,null,2)}`);$Q(W,O,[{name:PQ,writes:D,triggers:[]}],J.getNextVersion.bind(this.checkpointer),this.triggerToNodes);let x=F?.metadata?.step!=null?F.metadata.step+1:-1,T=await J.put(j,LQ(W,O,x),{source:"input",step:x,parents:F?.metadata?.parents??{}},H0(L,W.channel_versions));return await J.putWrites(T,D,rQ(PQ,W.id)),iQ(T,F?F.metadata:void 0)}if(B.configurable?.checkpoint_id===void 0&&F?.pendingWrites!==void 0&&F.pendingWrites.length>0){let D=nQ(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((K)=>K[0]===n).map((K)=>K.slice(1));if(x.length>0)$Q(F.checkpoint,O,[{name:PQ,writes:x,triggers:[]}],void 0,this.triggerToNodes);for(let[K,C,h]of F.pendingWrites){if([l,S,F8].includes(C)||D[K]===void 0)continue;D[K].writes.push([C,h])}let T=Object.values(D).filter((K)=>{return K.writes.length>0});if(T.length>0)$Q(W,O,T,void 0,this.triggerToNodes)}let I=Object.values(W.versions_seen).map((D)=>{return Object.values(D)}).flat().find((D)=>!!D),w=[];if(X.length===1){let{values:D,asNode:x,taskId:T}=X[0];if(x===void 0&&Object.keys(this.nodes).length===1)[x]=Object.keys(this.nodes);else if(x===void 0&&I===void 0){if(typeof this.inputChannels==="string"&&this.nodes[this.inputChannels]!==void 0)x=this.inputChannels}else if(x===void 0){let K=Object.entries(W.versions_seen).map(([C,h])=>{return Object.values(h).map((i)=>{return[i,C]})}).flat().filter(([C,h])=>h!==S).sort(([C],[h])=>X1(C,h));if(K){if(K.length===1)x=K[0][1];else if(K[K.length-1][0]!==K[K.length-2][0])x=K[K.length-1][1]}}if(x===void 0)throw new b('Ambiguous update, specify "asNode"');w.push({values:D,asNode:x,taskId:T})}else for(let{asNode:D,values:x,taskId:T}of X){if(D==null)throw new b('"asNode" is required when applying multiple updates');w.push({values:x,asNode:D,taskId:T})}let N=[];for(let{asNode:D,values:x,taskId:T}of w){if(this.nodes[D]===void 0)throw new b(`Node "${D.toString()}" does not exist`);let K=this.nodes[D].getWriters();if(!K.length)throw new b(`No writers found for node "${D.toString()}"`);N.push({name:D,input:x,proc:K.length>1?Z0.from(K,{omitSequenceTags:!0}):K[0],writes:[],triggers:[S],id:T??rQ(S,W.id),writers:[]})}for(let D of N)await D.proc.invoke(D.input,cQ({...B,store:B?.store??this.store},{runName:B.runName??`${this.getName()}UpdateState`,configurable:{[HQ]:(x)=>D.writes.push(...x),[RQ]:(x,T=!1)=>S0(W,O,D,x,T)}}));for(let D of N){let x=D.writes.filter((T)=>T[0]!==r);if(F!==void 0&&x.length>0)await J.putWrites(j,x,D.id)}$Q(W,O,N,J.getNextVersion.bind(this.checkpointer),this.triggerToNodes);let _=H0(L,W.channel_versions),f=await J.put(j,LQ(W,O,H+1),{source:"update",step:H+1,parents:F?.metadata?.parents??{}},_);for(let D of N){let x=D.writes.filter((T)=>T[0]===r);if(x.length>0)await J.putWrites(f,x,D.id)}return iQ(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 o8(W,this.channels);let L=Z;if(L===void 0)L=this.inputChannels;else o8(L,this.channels);let H=Y??this.interruptBefore??[],j=z??this.interruptAfter??[],V;if(J!==void 0)V=Array.isArray(J)?J:[J],B=typeof J==="string";else{if(Q.configurable?.[X0]!==void 0)V=["values"];else V=this.streamMode;B=!0}let G;if(this.checkpointer===!1)G=void 0;else if(Q!==void 0&&Q.configurable?.[g]!==void 0)G=Q.configurable[g];else if(this.checkpointer===!0)throw Error("checkpointer: true cannot be used for root graphs.");else G=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 I=(()=>{if(Q.checkpointDuring==null)return;if(Q.checkpointDuring===!1)return"exit";return"async"})(),w=Q.durability??I??Q?.configurable?.[L$]??"async";return[F,V,L,W,X,H,j,G,M,B,O,w]}async stream(Q,$){let J=new AbortController,Z={recursionLimit:this.config?.recursionLimit,...$,signal:V0($?.signal,J.signal).signal},q=await super.stream(Q,Z);return new m8($?.encoding==="text/event-stream"?n$(q):q,J)}streamEvents(Q,$,J){let Z=new AbortController,q={recursionLimit:this.config?.recursionLimit,...$,callbacks:v$(this.config?.callbacks,$?.callbacks),signal:V0($?.signal,Z.signal).signal};return new m8(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=T0(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,V,G,M,O,I]=this._defaults(X);if(typeof L.context<"u")L.context=await this._validateContext(L.context);else L.configurable=await this._validateContext(L.configurable);let w=new z8({modes:new Set(F)});if(this.checkpointer===!0){L.configurable??={};let K=L.configurable[FQ]??"";L.configurable[FQ]=K.split(k).map((C)=>C.split(e)[0]).join(k)}if(F.includes("messages")){let K=new J1((h)=>w.push(h)),{callbacks:C}=L;if(C===void 0)L.callbacks=[K];else if(Array.isArray(C))L.callbacks=C.concat(K);else{let h=C.copy();h.addHandler(K,!0),L.callbacks=h}}L.writer??=(K)=>{if(!F.includes("custom"))return;let C=_8()?.configurable?.[FQ]?.split(k).slice(0,-1);w.push([C??[],"custom",K])},L.interrupt??=this.userInterrupt??I8;let N=await(await Y1(L))?.handleChainStart(this.toJSON(),y$(Q,"input"),Y,void 0,void 0,void 0,L?.runName??this.getName()),_=x0(this.channels),f,D,T=(async()=>{try{f=await a$.initialize({input:z,config:L,checkpointer:V,nodes:this.nodes,channelSpecs:_,outputKeys:W,streamKeys:this.streamChannelsAsIs,store:G,cache:O,stream:w,interruptAfter:j,interruptBefore:H,manager:N,debug:this.debug,triggerToNodes:this.triggerToNodes,durability:I});let K=new Z1({loop:f,nodeFinished:L.configurable?.[j$]});if($?.subgraphs)f.config.configurable={...f.config.configurable,[w0]:f.stream};if(await this._runLoop({loop:f,runner:K,debug:B,config:L}),I==="sync")await Promise.all(f?.checkpointerPromises??[])}catch(K){D=K}finally{try{if(f)await f.store?.stop(),await f.cache?.stop();await Promise.all(f?.checkpointerPromises??[])}catch(K){D=D??K}if(D)w.error(D);else w.close()}})();try{for await(let K of w){if(K===void 0)throw Error("Data structure error.");let[C,h,i]=K;if(F.includes(h)){if(J==="text/event-stream"){if(Z)yield[C,h,i];else yield[null,h,i];continue}if(Z&&!M)yield[C,h,i];else if(!M)yield[h,i];else if(Z)yield[C,i];else yield i}}}catch(K){throw await N?.handleChainError(D),K}finally{await T}await N?.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(B0(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)o$($.checkpointMetadata.step,$.channels,this.streamChannelsList);if(Z)q8($.step,Object.values($.tasks));await J.tick({timeout:this.stepTimeout,retryPolicy:this.retryPolicy,onStepWrite:(Y,X)=>{if(Z)c$(Y,X,this.streamChannelsList)},maxConcurrency:q.maxConcurrency,signal:q.signal})}if($.status==="out_of_steps")throw new k0([`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([])}};var MQ=class Q extends p{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 b("EphemeralValue can only receive one value per step.");return this.value=[$[$.length-1]],!0}get(){if(this.value.length===0)throw new E;return this.value[0]}checkpoint(){if(this.value.length===0)throw new E;return this.value[0]}isAvailable(){return this.value.length!==0}};var n8=class{path;ends;constructor(Q){if(YQ.isRunnable(Q.path))this.path=Q.path;else this.path=SQ(Q.path).withConfig({runName:"Branch"});this.ends=Array.isArray(Q.pathMap)?Q.pathMap.reduce(($,J)=>{return $[J]=J,$},{}):Q.pathMap}run(Q,$){return m.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===D0.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 b("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=SQ(q);this.nodes[Z]={runnable:Y,metadata:z?.metadata,subgraphs:b0(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($===R)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)){let z=Array.isArray(Z.pathMap)?Z.pathMap.join(","):Object.keys(Z.pathMap??{}).join(",");Z.path=SQ(Z.path).withConfig({runName:`Branch<${Z.source}${z!==""?`,${z}`:""}>`.slice(0,63)})}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 n8(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(R,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 s8({builder:this,checkpointer:Q,interruptAfter:J,interruptBefore:$,autoValidate:!1,nodes:{},channels:{[R]:new MQ,[A]:new MQ},inputChannels:R,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!==R&&!(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 m0([`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}},s8=class extends B8{builder;constructor({builder:Q,...$}){super($);this.builder=Q}attachNode(Q,$){this.channels[Q]=new MQ,this.nodes[Q]=new DQ({channels:[],triggers:[],metadata:$.metadata,subgraphs:$.subgraphs,ends:$.ends}).pipe($.runnable).pipe(new m([{channel:Q,value:qQ}],[y])),this.streamChannels.push(Q)}attachEdge(Q,$){if($===A){if(Q===R)throw Error("Cannot have an edge from START to END");this.nodes[Q].writers.push(new m([{channel:A,value:qQ}],[y]))}else this.nodes[$].triggers.push(Q),this.nodes[$].channels.push(Q)}attachBranch(Q,$,J){if(Q===R&&!this.nodes[R])this.nodes[R]=F1.subscribeTo(R,{tags:[y]});this.nodes[Q].pipe(J.run((q)=>{return new m(q.map((z)=>{if(d(z))return z;return{channel:z===A?A:`branch:${Q}:${$}:${z}`,value:qQ}}),[y])}));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 MQ,this.nodes[q].triggers.push(z),this.nodes[q].channels.push(z)}}async getGraphAsync(Q){let $=Q?.xray,J=new r8,Z={[R]:J.addNode({schema:sQ.any()},R)},q={},z={};if($)z=Object.fromEntries((await GQ(this.getSubgraphsAsync())).filter((B)=>B1(B[1])));function Y(B,F,W,L=!1){if(F===A&&q[A]===void 0)q[A]=J.addNode({schema:sQ.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:$,V=z[B]!==void 0?await z[B].getGraphAsync({...Q,xray:j}):L.getGraph(Q);if(V.trimFirstNode(),V.trimLastNode(),Object.keys(V.nodes).length>1){let O=function(w){return w?w.lc_runnable:!1},I=function(w,N){if(w!==void 0&&!i8(w))return w;else if(O(N))try{let _=N.getName();return _=_.startsWith("Runnable")?_.slice(8):_,_}catch(_){return N.getName()}else return N.name??"UnknownSchema"},[G,M]=J.extend(V,W);if(G===void 0)throw Error(`Could not extend subgraph "${B}" due to missing entrypoint.`);if(M!==void 0)Z[W]={name:I(M.id,M.data),...M};q[W]={name:I(G.id,G.data),...G}}else{let G=J.addNode(L,W,H);Z[W]=G,q[W]=G}}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,V]of Object.entries(H))Y(t(B),t(V),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 r8,Z={[R]:J.addNode({schema:sQ.any()},R)},q={},z={};if($)z=Object.fromEntries($0(this.getSubgraphs()).filter((B)=>B1(B[1])));function Y(B,F,W,L=!1){if(F===A&&q[A]===void 0)q[A]=J.addNode({schema:sQ.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:$,V=z[B]!==void 0?z[B].getGraph({...Q,xray:j}):L.getGraph(Q);if(V.trimFirstNode(),V.trimLastNode(),Object.keys(V.nodes).length>1){let O=function(w){return w?w.lc_runnable:!1},I=function(w,N){if(w!==void 0&&!i8(w))return w;else if(O(N))try{let _=N.getName();return _=_.startsWith("Runnable")?_.slice(8):_,_}catch(_){return N.getName()}else return N.name??"UnknownSchema"},[G,M]=J.extend(V,W);if(G===void 0)throw Error(`Could not extend subgraph "${B}" due to missing entrypoint.`);if(M!==void 0)Z[W]={name:I(M.id,M.data),...M};q[W]={name:I(G.id,G.data),...G}}else{let G=J.addNode(L,W,H);Z[W]=G,q[W]=G}}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,V]of Object.entries(H))Y(t(B),t(V),j,!0)}}return J}};function B1(Q){return typeof Q.attachNode==="function"&&typeof Q.attachEdge==="function"}function t(Q){if(Q==="subgraph")return`"${Q}"`;return Q}function IQ(Q){return typeof Q==="object"&&Q!==null&&"~standard"in Q&&typeof Q["~standard"]==="object"&&Q["~standard"]!==null&&"validate"in Q["~standard"]}function W1(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(W1(Q))try{return Q["~standard"].jsonSchema.input({target:"draft-07"})}catch{return}}function NQ(Q){if(Q==null)return;if(!IQ(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 t8=Symbol.for("langgraph.channel.missing"),y0=class Q extends p{lc_graph_name="UntrackedValue";guard;_value=t8;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 b("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===t8)throw new E;return this._value}checkpoint(){}isAvailable(){return this._value!==t8}};var a8=Symbol.for("langgraph.state.reduced_value"),BQ=class{[a8]=!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&&a8 in Q&&Q[a8]===!0}};var L1=Symbol.for("langgraph.state.untracked_value"),EQ=class{[L1]=!0;schema;guard;constructor(Q,$){this.schema=Q,this.guard=$?.guard??!0}static isInstance(Q){return typeof Q==="object"&&Q!==null&&L1 in Q}};var tQ=(Q,$)=>Q.size===$.size&&[...Q].every((J)=>$.has(J)),e8=class Q extends p{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 b(`Value ${JSON.stringify(Z)} not in names ${JSON.stringify(this.names)}`);return J}get(){if(!tQ(this.names,this.seen))throw new E}checkpoint(){return[...this.seen]}consume(){if(this.seen&&this.names&&tQ(this.seen,this.names))return this.seen=new Set,!0;return!1}isAvailable(){return!!this.names&&tQ(this.names,this.seen)}},Q$=class Q extends p{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 b(`Value ${JSON.stringify(Z)} not in names ${JSON.stringify(this.names)}`);return J}get(){if(!this.finished||!tQ(this.names,this.seen))throw new E}checkpoint(){return[[...this.seen],this.finished]}consume(){if(this.finished&&this.seen&&this.names&&tQ(this.seen,this.names))return this.seen=new Set,this.finished=!1,!0;return!1}finish(){if(!this.finished&&!!this.names&&tQ(this.names,this.seen))return this.finished=!0,!0;return!1}isAvailable(){return this.finished&&!!this.names&&tQ(this.names,this.seen)}};var $$=Symbol.for("langgraph.state.state_schema"),WQ=class{[$$]=!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 wQ(J.reducer,Z)}else if(EQ.isInstance(J)){let Z=J.schema?NQ(J.schema):void 0;Q[$]=new y0({guard:J.guard,initialValueFactory:Z})}else if(IQ(J))Q[$]=new jQ(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(EQ.isInstance(Z))q=Z.schema?_Q(Z.schema):void 0;else if(IQ(Z))q=_Q(Z);if(q){Q[J]=q;let z=!1;if(BQ.isInstance(Z))z=NQ(Z.valueSchema)!==void 0;else if(EQ.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(EQ.isInstance(J))Z=J.schema?_Q(J.schema):void 0;else if(IQ(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(EQ.isInstance(q))z=q.schema;else if(IQ(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&&$$ in Q&&Q[$$]===!0}};var j8="__remove_all__";function mQ(Q,$){let J=Array.isArray(Q)?Q:[Q],Z=Array.isArray($)?$:[$],q=J.map(L8),z=Z.map(L8);for(let W of q)if(W.id===null||W.id===void 0)W.id=J$(),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=J$(),L.lc_kwargs.id=L.id;if(W8.isInstance(L)&&L.id===j8)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(W8.isInstance(W))F.add(W.id);else F.delete(W.id),X[L]=W;else{if(W8.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 G6=sQ.custom().default(()=>[]),D6=sQ.custom(),H8=new BQ(G6,{inputSchema:D6,reducer:mQ,jsonSchemaExtra:{langgraph_type:"messages",description:"A list of chat messages"}});var K6="lg:",M6=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=q$(Q);for(let[Z,q]of Object.entries(J)){let z=this.get(q);if(z?.reducer)$[Z]=new wQ(z.reducer.fn,z.default);else $[Z]=new jQ(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(q$(Q)).map(([Y,X])=>{let B=this.get(X),F=$.withReducerSchema?B?.reducer?.schema??X:X;if($.withJsonSchemaExtrasAsDescription&&B?.jsonSchemaExtra){let W=Z$(F)??Z$(X),L=JSON.stringify({...B.jsonSchemaExtra,description:W});F=F.describe(`${K6}${L}`)}return[Y,F]});if(q=V1(Q,Object.fromEntries(z)),H1(q))q._def.unknownKeys="strip"}if($.asPartial)q=V8(q);return Z.set(Q,q),this._extensionCache.set(J,Z),q}},v0=new M6;function G1(Q,$){if($.reducer&&!$.default){let J=U1(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(WQ.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"||A8($)))return!0;return!1}function D1(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__",G8=Symbol.for("langgraph.state.partial"),D8=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 Y0;let q=this._getChannelsFromSchema(Z);if(this._schemaDefinition=q,WQ.isInstance(Z))this._schemaRuntimeDefinition=Z;else if(XQ(Z))this._schemaRuntimeDefinition=Z;if(J.input)if(WQ.isInstance(J.input))this._inputRuntimeDefinition=J.input;else if(XQ(J.input))this._inputRuntimeDefinition=J.input;else this._inputRuntimeDefinition=G8;else this._inputRuntimeDefinition=G8;if(J.output)if(WQ.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(D1(Q)){if(XQ($)||A0.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($)||A0.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(A6(Q))return{state:x6(Q.channels)};throw new Y0}_getChannelsFromSchema(Q){if(WQ.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 Y0("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===R)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=SQ(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:b0(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 K8({builder:this,checkpointer:Q,interruptAfter:q,interruptBefore:Z,autoValidate:!1,nodes:{},channels:{...this.channels,[R]:new MQ},inputChannels:R,outputChannels:B,streamChannels:W,streamMode:"updates",store:$,cache:J,name:z,description:Y,userInterrupt:L});H.attachNode(R);for(let[j,V]of Object.entries(this.nodes))H.attachNode(j,V);H.attachBranch(R,R8,K1(),{withReader:!1});for(let[j]of Object.entries(this.nodes))H.attachBranch(j,R8,K1(),{withReader:!1});for(let[j,V]of this.edges)H.attachEdge(j,V);for(let[j,V]of this.waitingEdges)H.attachEdge(j,V);for(let[j,V]of Object.entries(this.branches))for(let[G,M]of Object.entries(V))H.attachBranch(j,G,M);return H.validate()}};function x6(Q){let $={};for(let[J,Z]of Object.entries(Q))if(J===hQ)$[J]=h0(Z);else $[J]=h0(Z);return $}var K8=class extends s8{description;_metaRegistry=v0;constructor({description:Q,...$}){super($);this.description=Q}attachNode(Q,$){let J;if(Q===R)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 b(`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===R)this.nodes[Q]=new DQ({tags:[y],triggers:[R],channels:[R],writers:[new m(Y,[y])]});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 O8:new MQ(!1),this.nodes[Q]=new DQ({triggers:[W],channels:F?Object.keys(B):B,writers:[new m(Y,[y])],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 m([{channel:`branch:to:${$}`,value:null}],[y]));else if(Array.isArray(Q)){let J=`join:${Q.join("+")}:${$}`;this.channels[J]=this.builder.nodes[$].defer?new Q$(new Set(Q)):new e8(new Set(Q)),this.nodes[$].triggers.push(J);for(let Z of Q)this.nodes[Z].writers.push(new m([{channel:J,value:Z}],[y]))}}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 m.doWrite({...Y,tags:(Y.tags??[]).concat([y])},B)};this.nodes[Q].writers.push(J.run(q,Z.withReader?(z)=>_$.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(WQ.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($===G8&&WQ.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($===G8){if(XQ(J))return V8(q(J));return}})();if(u(Q)){let q=Q;if(Q.update&&Z!=null)q.update=U8(Z,Q.update);return q}if(Z!=null)return U8(Z,Q);return Q}isInterrupted(Q){return B0(Q)}async _validateContext(Q){let $=this.builder._configRuntimeSchema;if(XQ($))U8($,Q);return Q}};function A6(Q){return typeof Q==="object"&&Q!==null&&Q.channels!==void 0}function O6(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 K0(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 K1(){return new n8({path:new s({func:O6,tags:[y],trace:!1,recurse:!1,name:"<control_branch>"})})}var z$=function($,J){let{name:Z,checkpointer:q,store:z,cache:Y}=typeof $==="string"?{name:$,checkpointer:void 0,store:void 0}:$;if(T$(J)||b$(J))throw Error("Generators are disallowed as entrypoints. For streaming responses, use config.write.");let X="updates",B=g$(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 DQ({bound:B,triggers:[R],channels:[R],writers:[new m([{channel:A,value:qQ,mapper:W},{channel:eQ,value:qQ,mapper:L}],[y])]});return new B8({name:Z,checkpointer:q,nodes:{[Z]:H},channels:{[R]:new MQ,[A]:new jQ,[eQ]:new jQ},inputChannels:R,outputChannels:A,streamChannels:A,streamMode:X,store:z,cache:Y})};z$.final=function({value:$,save:J}){return{value:$,save:J,__lg_type:"__pregel_final"}};var M1=aQ.Root({messages:aQ({reducer:mQ,default:()=>[]})}),X$={reducer:{fn:mQ},jsonSchemaExtra:{langgraph_type:"messages"},default:()=>[]},x1=Y$.object({messages:G1(Y$.custom(),X$)});P$();
|
|
16
|
-
export{OQ as Lg,aQ as Mg,R as Ng,A as Og,lQ as Pg,a as Qg,u as Rg,i1 as Sg,I8 as Tg,j8 as Ug,v0 as Vg,G1 as Wg,D8 as Xg,M1 as Yg,X$ as Zg};
|
package/dist/chunk-b4vvgbav.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{q as f}from"./chunk-kym9tb01.js";import"./chunk-vfwbx331.js";import{O as C,Q as _}from"./chunk-55nx49pj.js";import{Ae as X,Be as Y,Ke as K,Oe as M,ye as g}from"./chunk-a90fm6gz.js";import{Ue as A}from"./chunk-jrepjpft.js";import{ug as R}from"./chunk-p0vzbr7s.js";import"./chunk-x552nspp.js";import"./chunk-48vkm1yn.js";import"./chunk-afhxxkmv.js";import"./chunk-43xrz4wp.js";import"./chunk-ac5t2ywn.js";import"./chunk-dcwnpdtk.js";import"./chunk-cbjnwrt7.js";import"./chunk-vh9zd1v3.js";import"./chunk-w2hbsa9j.js";import"./chunk-rztre6k0.js";import"./chunk-wpy5r9ma.js";import"./chunk-frhhpxxy.js";import"./chunk-h1enhch1.js";import"./chunk-hyf24r36.js";import"./chunk-hra0748z.js";import"./chunk-k38fjqj7.js";import{pq as Q}from"./chunk-dcs1r9as.js";var F=Q(g(),1);import{join as w}from"path";function $({type:G,enabled:J=!0}){return C({queryKey:G==="memories"?_.knowledge.memories():_.knowledge.skills(),queryFn:async()=>{let L=w(process.cwd(),".claude",G),N=w(process.env.HOME||"",".deepagents/code",G);try{if(G==="memories")return A(N,L).map((W)=>({...W,type:"memory"}));else return R(N,L).map((W)=>({...W,type:"skill"}))}catch(O){return console.warn(`Failed to load ${G}:`,O),[]}},enabled:J,staleTime:120000})}var H=Q(K(),1),S=(G)=>{return G.length>80?G.slice(0,80)+"...":G},k=({onClose:G})=>{let[J,L]=F.useState("memories"),N=F.useRef(L);F.default.useEffect(()=>{N.current=L},[L]);let{data:O=[]}=$({type:"memories",enabled:J==="memories"}),{data:W=[]}=$({type:"skills",enabled:J==="skills"}),U=F.useCallback(async()=>{return J==="memories"?O:W},[J,O,W]),q=F.useCallback((z,E,Z)=>{let V=S(z.description);return H.jsxDEV(X,{flexDirection:"column",paddingY:1,children:[H.jsxDEV(X,{children:H.jsxDEV(Y,{bold:!0,color:Z?"cyan":"gray",children:[E+1,". ",z.name]},void 0,!0,void 0,this)},void 0,!1,void 0,this),H.jsxDEV(X,{paddingY:1,children:H.jsxDEV(Y,{color:Z?"white":"gray",children:V},void 0,!1,void 0,this)},void 0,!1,void 0,this),H.jsxDEV(X,{children:H.jsxDEV(Y,{color:"cyan",dimColor:!Z,children:[f(z.path),z.category&&H.jsxDEV(Y,{color:"yellow",children:[" ",z.category]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},z.path,!0,void 0,this)},[]),I=F.useCallback((z)=>{console.log("Selected knowledge item:",z.name)},[]),P=F.useMemo(()=>[{id:"memory",label:"记忆",predicate:(z)=>z.type==="memory"},{id:"skill",label:"技能",predicate:(z)=>z.type==="skill"}],[]),B=F.useMemo(()=>({h:(z)=>{N.current("memories"),z.setActiveFilter("memory")},s:(z)=>{N.current("skills"),z.setActiveFilter("skill")}}),[]),h=F.useMemo(()=>({id:"knowledge",title:"知识库",icon:"\uD83D\uDCDA",dataSource:U,searchable:!0,searchFields:["name","description"],searchPlaceholder:"搜索知识库 (名称/描述/分类)...",filterable:!0,filters:P,defaultFilter:J==="memories"?"memory":"skill",itemHeight:8,visibleCount:3,renderItem:q,showCount:!0,onSelect:I,keyMap:B}),[U,P,q,I,B,J]);return H.jsxDEV(M,{config:h,onClose:G},void 0,!1,void 0,this)},l=k;export{l as default};
|
package/dist/chunk-b9pcntkv.js
DELETED
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
import{Xe as D}from"./chunk-62zh99t6.js";import{kf as p,nf as E,of as k,pf as C}from"./chunk-738m8242.js";import{Rf as F,Sf as G,Vf as P}from"./chunk-p0vzbr7s.js";import{Ng as _,Ug as L,Xg as N}from"./chunk-afhxxkmv.js";import{ri as K}from"./chunk-cbjnwrt7.js";import{Bj as x,Oj as R,xj as Y}from"./chunk-w2hbsa9j.js";import{oq as S}from"./chunk-k38fjqj7.js";import{pq as I}from"./chunk-dcs1r9as.js";function H($,f="Human",J="AI"){let q=[];for(let B of $){let U;if(B.type==="human")U=f;else if(B.type==="ai")U=J;else if(B.type==="system")U="System";else if(B.type==="tool")U="Tool";else if(B.type==="generic")U=B.role;else throw Error(`Got unsupported message type: ${B.type}`);let O=B.name?`${B.name}, `:"",Q=typeof B.content==="string"?B.content:JSON.stringify(B.content,null,2);q.push(`${U}: ${O}${Q}`)}return q.join(`
|
|
2
|
-
`)}var T=I(S(),1);import{promises as W}from"fs";import X from"path";var b=($)=>{return $?.replace(process.cwd(),".")||$||""};var v=K.object({summary_of_chat:K.string().describe("对话总结(300-500字):1) 完整复现对话的核心过程(任务背景→关键决策→解决方案→最终结果);2) 明确说明接下来要做什么(后续行动、待完成任务、需要用户确认的事项);3) 突出关键成果和交付物"),name:K.string().describe("记忆名称(kebab-case 格式)"),description:K.string().describe("对于这个记忆的中等长度描述(索引综述,200-500字符,包含背景、关键点、适用场景)"),tags:K.array(K.string()).describe("记忆标签"),category:K.enum(["architecture","bug-fix","workflow","configuration","optimization"]).describe("记忆分类"),created:K.string().describe("创建日期(ISO 格式:YYYY-MM-DD)"),last_updated:K.string().describe("最后更新日期(ISO 格式:YYYY-MM-DD)"),priority:K.enum(["high","medium","low"]).describe("优先级"),context_scope:K.enum(["user","project"]).describe("上下文范围"),content:K.string().describe("记忆内容(详细说明,包含代码示例)")}),u=`你是一个负责分析对话并提取关键信息的智能助手。
|
|
3
|
-
|
|
4
|
-
## 任务
|
|
5
|
-
|
|
6
|
-
1. **对话总结 (summary_of_chat)**:完整复现对话并明确后续行动
|
|
7
|
-
2. **记忆提取**:判断是否有值得保存为长期记忆的信息
|
|
8
|
-
|
|
9
|
-
## 对话总结要求 (summary_of_chat)
|
|
10
|
-
|
|
11
|
-
**必须包含以下三个部分**:
|
|
12
|
-
|
|
13
|
-
### 1. 完整复现对话核心过程
|
|
14
|
-
- **任务背景**:用户想做什么?遇到什么问题?
|
|
15
|
-
- **关键决策**:做出了什么选择?为什么?
|
|
16
|
-
- **解决方案**:具体怎么实现的?用了什么技术/方法?
|
|
17
|
-
- **最终结果**:完成了什么?输出了什么?
|
|
18
|
-
|
|
19
|
-
### 2. 明确后续行动
|
|
20
|
-
- **待完成任务**:还有哪些未完成的工作?
|
|
21
|
-
- **需要确认**:哪些事项需要用户决策?
|
|
22
|
-
- **下一步建议**:建议接下来做什么?
|
|
23
|
-
|
|
24
|
-
### 3. 突出关键成果
|
|
25
|
-
- **交付物**:生成了什么文件/代码/文档?
|
|
26
|
-
- **价值点**:解决了什么核心问题?
|
|
27
|
-
- **可复用性**:什么内容可以复用?
|
|
28
|
-
|
|
29
|
-
**格式要求**:
|
|
30
|
-
- 300-500 字
|
|
31
|
-
- 使用清晰的结构(可用 → 表示流程)
|
|
32
|
-
- 突出关键信息(文件路径、函数名、配置项)
|
|
33
|
-
|
|
34
|
-
**示例**:
|
|
35
|
-
\`\`\`
|
|
36
|
-
用户需要为 TUI 应用添加模型选择面板。通过创建 ModelPanel 组件实现交互式界面(↑↓选择、Enter切换、q关闭),在 Chat.tsx 中扩展 activeView 状态添加 'model' 类型,定义 switchToModel 回调并传递到命令系统,注册 /model-panel 和 /mp 命令。修复了 CommandHandler 未解构 switchToModel 的 bug。✓ 完成:可用的模型选择面板;⏳ 待定:是否需要添加模型描述信息展示;→ 建议:测试面板在不同终端下的渲染效果
|
|
37
|
-
\`\`\`
|
|
38
|
-
|
|
39
|
-
## 记忆评分机制(总分 10 分,≥ 6 分才保存)
|
|
40
|
-
|
|
41
|
-
## 记忆评分机制(总分 10 分,≥ 6 分才保存)
|
|
42
|
-
|
|
43
|
-
1. **重要性** (0-3 分)
|
|
44
|
-
- 3 分:关键技术决策、架构设计、重要问题解决方案
|
|
45
|
-
- 2 分:有用的编码模式、最佳实践
|
|
46
|
-
- 1 分:一般性建议、参考信息
|
|
47
|
-
- 0 分:无实际内容
|
|
48
|
-
|
|
49
|
-
2. **独特性** (0-3 分)
|
|
50
|
-
- 3 分:项目特定配置、非常规解决方案
|
|
51
|
-
- 2 分:非显而易见的技巧、特定场景知识
|
|
52
|
-
- 1 分:略有新意的做法
|
|
53
|
-
- 0 分:常见知识、通用做法
|
|
54
|
-
|
|
55
|
-
3. **可复用性** (0-2 分)
|
|
56
|
-
- 2 分:跨场景可复用的模式/方法
|
|
57
|
-
- 1 分:特定场景下可复用
|
|
58
|
-
- 0 分:一次性信息、临时性内容
|
|
59
|
-
|
|
60
|
-
4. **持久性** (0-2 分)
|
|
61
|
-
- 2 分:长期有效(架构决策、代码模式)
|
|
62
|
-
- 1 分:中期有效(配置信息、工作流程)
|
|
63
|
-
- 0 分:临时信息(调试过程、一次性请求)
|
|
64
|
-
|
|
65
|
-
**评分 < 6 分**:设置 name 为 "no-memory-{timestamp}",content 为 "无重要信息"
|
|
66
|
-
|
|
67
|
-
## 记忆命名规范(强制执行)
|
|
68
|
-
|
|
69
|
-
**格式要求**:
|
|
70
|
-
- **仅包含小写字母、数字和单个连字符(-)**
|
|
71
|
-
- **不能包含空格、下划线、中文或其他特殊字符**
|
|
72
|
-
- **不能以连字符开头或结尾**
|
|
73
|
-
- **不能有连续的连字符**
|
|
74
|
-
|
|
75
|
-
**正确示例**:
|
|
76
|
-
- \`memory-system-design\`
|
|
77
|
-
- \`langchain-structured-output\`
|
|
78
|
-
- \`tui-panel-implementation\`
|
|
79
|
-
|
|
80
|
-
**错误示例**:
|
|
81
|
-
- \`Memory_System\` ❌(大写、下划线)
|
|
82
|
-
- \`zen-code-user-guide\` ❌(中文)
|
|
83
|
-
- \`memory--system\` ❌(连续连字符)
|
|
84
|
-
- \`-memory-system\` ❌(以连字符开头)
|
|
85
|
-
- \`memory system\` ❌(包含空格)
|
|
86
|
-
|
|
87
|
-
**命名建议**:
|
|
88
|
-
- 从核心主题中提取 2-4 个英文关键词
|
|
89
|
-
- 使用具体的技术术语
|
|
90
|
-
- 示例:
|
|
91
|
-
- "langchain-structured-output-single-object"
|
|
92
|
-
- "memory-system-design"
|
|
93
|
-
- "middleware-execution-order"
|
|
94
|
-
- "tui-panel-system"
|
|
95
|
-
- 避免通用名称:不使用 "fix-bug" 或 "optimization"
|
|
96
|
-
|
|
97
|
-
## 内容提取模板
|
|
98
|
-
|
|
99
|
-
提取的内容应包含以下部分(按需选择):
|
|
100
|
-
|
|
101
|
-
**背景**:什么问题/场景?
|
|
102
|
-
**决策**:做了什么选择?
|
|
103
|
-
**原因**:为什么这样选择?
|
|
104
|
-
**实现**:关键代码、文件路径、配置
|
|
105
|
-
**适用**:什么场景适用?什么场景不适用?
|
|
106
|
-
**注意**:有什么陷阱或边界情况?
|
|
107
|
-
|
|
108
|
-
## 代码引用原则(强制执行)
|
|
109
|
-
|
|
110
|
-
**默认规则:代码超过 5 行 → 使用文件引用**
|
|
111
|
-
|
|
112
|
-
### 何时使用文件引用
|
|
113
|
-
- 完整函数或方法实现
|
|
114
|
-
- 完整类或组件定义
|
|
115
|
-
- 长配置文件
|
|
116
|
-
- 任何 > 5 行的代码块
|
|
117
|
-
|
|
118
|
-
### 文件引用格式
|
|
119
|
-
\`文件路径[:行号范围]\`:简短说明
|
|
120
|
-
|
|
121
|
-
示例:
|
|
122
|
-
- \`agents/code/graph.ts:120-180\`:中间件链执行顺序
|
|
123
|
-
- \`tui/src/chat/Chat.tsx\`:完整的面板切换回调实现
|
|
124
|
-
- \`.claude/skills/web-research/SKILL.md\`:技能结构模板
|
|
125
|
-
|
|
126
|
-
### 何时内联代码(仅限以下情况)
|
|
127
|
-
1. **极短片段**(≤ 5 行):用于说明关键概念
|
|
128
|
-
2. **配置示例**:JSON/YAML 配置片段
|
|
129
|
-
3. **错误示例**:展示错误模式(不超过 5 行)
|
|
130
|
-
|
|
131
|
-
### 代码长度限制
|
|
132
|
-
- **总代码占比**:content 中代码块总行数 ≤ 30%
|
|
133
|
-
- **单个代码块**:不超过 5 行
|
|
134
|
-
- **优先级**:文件引用 > 概述 > 短片段
|
|
135
|
-
|
|
136
|
-
### 长代码处理方式
|
|
137
|
-
|
|
138
|
-
**错误示范**(代码过长):
|
|
139
|
-
\`\`\`typescript
|
|
140
|
-
const middleware = [
|
|
141
|
-
new SubAgentsMiddleware(),
|
|
142
|
-
new AgentsMdMiddleware(),
|
|
143
|
-
// ... 省略 20 行
|
|
144
|
-
];
|
|
145
|
-
\`\`\`
|
|
146
|
-
|
|
147
|
-
**正确示范**(文件引用):
|
|
148
|
-
中间件列表定义参见 \`agents/code/graph.ts:45-60\`,执行顺序为:SubAgents → AgentsMd → Skills → MCP → HumanInTheLoop → Cache
|
|
149
|
-
|
|
150
|
-
**关键片段**(如必要):
|
|
151
|
-
\`\`\`typescript
|
|
152
|
-
// 仅 3 行核心逻辑
|
|
153
|
-
middleware.forEach(m => m.wrapModelCall(req, handler))
|
|
154
|
-
\`\`\`
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
## 输出格式要求
|
|
158
|
-
|
|
159
|
-
**你必须输出单个 JSON 对象(不是数组)**,包含以下字段:
|
|
160
|
-
|
|
161
|
-
- **name** (string): 记忆名称,kebab-case 格式,例如 "memory-system-design"
|
|
162
|
-
- **description** (string): 中等长度描述,索引综述(200-500字符),包含:
|
|
163
|
-
* 背景和问题/场景
|
|
164
|
-
* 关键决策或解决方案
|
|
165
|
-
* 适用场景或范围
|
|
166
|
-
* 使用清晰的分号或句号分隔各部分
|
|
167
|
-
- **content** (string): 详细内容,包含技术实现细节、文件路径、代码示例、关键决策等,按照内容提取模板组织
|
|
168
|
-
- **tags** (array of string): 记忆标签,3-5 个,用于检索和分类,例如 ["langchain", "structured-output", "zod"]
|
|
169
|
-
- **category** (enum): 记忆分类,可选值:architecture, bug-fix, workflow, configuration, optimization
|
|
170
|
-
- **priority** (enum): 优先级,可选值:high, medium, low
|
|
171
|
-
- **created** (string): 创建日期,ISO 格式 YYYY-MM-DD,例如 "2025-01-13"
|
|
172
|
-
- **last_updated** (string): 最后更新日期,ISO 格式 YYYY-MM-DD,例如 "2025-01-13"
|
|
173
|
-
- **context_scope** (enum): 上下文范围,可选值:user, project
|
|
174
|
-
|
|
175
|
-
## 分类标准
|
|
176
|
-
|
|
177
|
-
- **architecture**: 架构决策、设计模式、系统结构
|
|
178
|
-
- **bug-fix**: Bug 修复和问题解决方案
|
|
179
|
-
- **workflow**: 工作流程和最佳实践
|
|
180
|
-
- **configuration**: 配置和环境设置
|
|
181
|
-
- **optimization**: 性能优化和改进
|
|
182
|
-
|
|
183
|
-
## 优先级标准
|
|
184
|
-
|
|
185
|
-
- **high**: 关键架构决策、重要问题解决方案、影响系统正确性的问题
|
|
186
|
-
- **medium**: 有用的模式、次要的配置信息、影响开发效率的问题
|
|
187
|
-
- **low**: 一般性建议、参考信息、优化建议
|
|
188
|
-
|
|
189
|
-
## 示例输出
|
|
190
|
-
|
|
191
|
-
### 示例 1:有价值的记忆
|
|
192
|
-
\`\`\`json
|
|
193
|
-
{
|
|
194
|
-
"summary_of_chat": "用户反馈记忆系统的 summary_of_chat 字段过于简单,需要增强对话复现和后续行动说明。修改了 agents/code/memories/analyze.ts:1) 更新 MemoryCandidateSchema 中 summary_of_chat 的描述,要求 300-500 字包含完整对话过程、后续行动、关键成果;2) 在 smart_memory_prompt 中添加专门的"对话总结要求"章节,明确三部分内容(完整复现、后续行动、关键成果);3) 提供格式示例和清晰的模板。✓ 完成:增强版记忆提示词;⏳ 待定:是否需要添加示例输出展示新的 summary_of_chat 格式;→ 建议:测试新提示词在实际对话中的表现",
|
|
195
|
-
"name": "memory-prompt-summary-enhancement",
|
|
196
|
-
"description": "增强记忆系统的 summary_of_chat 字段要求,要求完整复现对话过程并明确后续行动;包括任务背景→关键决策→解决方案→最终结果的完整流程,以及待完成任务、需要确认事项、下一步建议;适用于所有需要高质量对话总结的场景",
|
|
197
|
-
"content": "## 背景\\n\\n用户反馈记忆系统生成的 summary_of_chat 过于简单,缺少后续行动说明,无法有效回顾对话和继续工作。\\n\\n## 解决方案\\n\\n修改 \`agents/code/memories/analyze.ts\` 的三处:\\n\\n1. **Schema 增强**(第 18 行):\\n\\\`\\\`\\\`typescript\\nsummary_of_chat: z.string().describe('对话总结(300-500字):1) 完整复现对话的核心过程(任务背景→关键决策→解决方案→最终结果);2) 明确说明接下来要做什么(后续行动、待完成任务、需要用户确认的事项);3) 突出关键成果和交付物')\\n\\\`\\\`\\\`\\n\\n2. **提示词添加专门章节**:在 smart_memory_prompt 中添加"对话总结要求"部分,明确三个组成部分:完整复现、后续行动、关键成果\\n\\n3. **提供格式示例**:使用 → 表示流程,✓ 表示完成,⏳ 表示待定,→ 表示建议\\n\\n## 适用场景\\n\\n- 需要高质量对话总结的 AI 系统\\n- 需要明确后续行动的任务管理场景",
|
|
198
|
-
"tags": ["prompt-engineering", "memory-system", "conversation-summary", "langchain"],
|
|
199
|
-
"category": "optimization",
|
|
200
|
-
"priority": "medium",
|
|
201
|
-
"created": "2025-01-17",
|
|
202
|
-
"last_updated": "2025-01-17",
|
|
203
|
-
"context_scope": "project"
|
|
204
|
-
}
|
|
205
|
-
\`\`\`
|
|
206
|
-
|
|
207
|
-
### 示例 2:无重要信息
|
|
208
|
-
\`\`\`json
|
|
209
|
-
{
|
|
210
|
-
"summary_of_chat": "用户询问如何查看 TUI 应用中的模型列表。已告知可通过 /model-panel 或 /mp 命令打开模型选择面板,使用 ↑↓ 键选择、Enter 键切换模型、q 键关闭面板。当前无其他问题。✓ 完成:问题已解答;⏳ 待定:无;→ 建议:如需更多帮助可使用 /help 命令",
|
|
211
|
-
"name": "no-memory-1736736000000",
|
|
212
|
-
"description": "本次对话无重要信息需要保存",
|
|
213
|
-
"content": "无重要信息",
|
|
214
|
-
"tags": [],
|
|
215
|
-
"category": "workflow",
|
|
216
|
-
"priority": "low",
|
|
217
|
-
"created": "2025-01-13",
|
|
218
|
-
"last_updated": "2025-01-13",
|
|
219
|
-
"context_scope": "project"
|
|
220
|
-
}
|
|
221
|
-
\`\`\`
|
|
222
|
-
|
|
223
|
-
## 重要原则
|
|
224
|
-
|
|
225
|
-
1. **宁缺毋滥**:评分 < 6 分时,返回"无重要信息"
|
|
226
|
-
2. **避免重复**:不要记录显而易见或通用的知识
|
|
227
|
-
3. **用户优先**:明确记录用户的指示和偏好
|
|
228
|
-
4. **精确具体**:使用具体的文件名、代码片段、配置项
|
|
229
|
-
5. **独立完整**:记忆应能独立理解,不依赖外部上下文
|
|
230
|
-
`;async function V($,f){let J=[new Y(f),new Y("请分析这段对话,提取值得保存的信息。")],B=await G({model:$,tools:[],systemPrompt:u,responseFormat:F(v)}).invoke({messages:J});return await A(B.structuredResponse)}function w($,f){let J=$.toLowerCase().replace(/[^\u4e00-\u9fa5a-z0-9\s]/gi," ").split(/\s+/).filter((U)=>U.length>1).slice(0,4);if(J.length===0)return`memory-${Date.now()}-${f}`;let B=`${J.join("-")}-${Date.now()}-${f}`;return B.length>64?B.substring(0,61)+"...":B}function c($){return $.toLowerCase().trim().replace(/[^a-z0-9]+/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")}async function A($){if($.name.startsWith("no-memory-"))return`${$.summary_of_chat}
|
|
231
|
-
|
|
232
|
-
---
|
|
233
|
-
|
|
234
|
-
name: "${$.name}"
|
|
235
|
-
description: "${$.description}"
|
|
236
|
-
|
|
237
|
-
⚠️ 无重要信息,未保存记忆`;let f=X.join(process.cwd(),".claude/memories");await W.mkdir(f,{recursive:!0});let q=c($.name||w($.content,0))||w($.content,0),B=X.join(f,q);await W.mkdir(B,{recursive:!0});let U=$.content.indexOf(`
|
|
238
|
-
`),O=U>0?$.content.substring(0,Math.min(U,100)):$.content.substring(0,Math.min(100,$.content.length)),Q={name:q,description:$.description.replace(/\n/g," "),tags:$.tags,category:$.category,created:$.created,last_updated:$.last_updated,priority:$.priority,context_scope:$.context_scope},j=`---
|
|
239
|
-
${T.default.stringify(Q,{indent:2,lineWidth:0})}
|
|
240
|
-
---
|
|
241
|
-
|
|
242
|
-
# ${O}
|
|
243
|
-
|
|
244
|
-
${$.content}
|
|
245
|
-
`,Z=X.join(B,"MEMORY.md");return await W.writeFile(Z,j,"utf-8"),`${$.summary_of_chat}
|
|
246
|
-
|
|
247
|
-
---
|
|
248
|
-
|
|
249
|
-
name: "${$.name}"
|
|
250
|
-
description: "${$.description}"
|
|
251
|
-
|
|
252
|
-
✓ 保存记忆: ${b(Z)}`}var z={smart_memory:async($)=>{let f=await E($.model_id,{modelProvider:$.provider_type,streamUsage:!0,enableThinking:$.enable_thinking??!0}),J=await V(f,H($.messages));return{switch_command:"",messages:[new x({id:L}),new R(J)]}}};async function M($,f,J,q){let B=await k($,f,J,q);J.thread_id=P(q);let U=await B.invoke(J,{recursionLimit:500,configurable:q.configurable,context:q.context});return{switch_command:"",task_store:U.task_store,messages:U.messages}}function h(){return new N(p).addNode("graph",async($,f)=>{let{switch_command:J}=$;if(J==="smart_memory")return z.smart_memory($);let q=D,B=await C(q),U=(J==="default"?"agents/default":J)||"agents/default";if(!B.includes(U))throw Error(`Unknown agent: ${J||"default"}. Available: ${B.join(", ")}`);return await M(U,q,$,f)}).addEdge(_,"graph").compile()}var Q$=h();
|
|
253
|
-
export{Q$ as Ve};
|
package/dist/chunk-c7y5efa0.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Te as a}from"./chunk-yqwxbcc7.js";import"./chunk-jrepjpft.js";import"./chunk-vh9zd1v3.js";import"./chunk-w2hbsa9j.js";import"./chunk-rztre6k0.js";import"./chunk-wpy5r9ma.js";import"./chunk-h1enhch1.js";import"./chunk-hyf24r36.js";import"./chunk-k38fjqj7.js";import"./chunk-dcs1r9as.js";export{a as MemoriesMiddleware};
|