zen-code 5.0.0 → 5.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/dist/app.js +3 -3
  2. package/dist/{chunk-6saqxa3z.js → chunk-0p3df51n.js} +1 -1
  3. package/dist/{chunk-78ksrp8v.js → chunk-0pzpg2ra.js} +2 -2
  4. package/dist/{chunk-tbav8trq.js → chunk-142wmdx8.js} +1 -1
  5. package/dist/chunk-1t3rabge.js +1 -0
  6. package/dist/{chunk-bn077sjq.js → chunk-2z45fjmt.js} +51 -51
  7. package/dist/{chunk-6b3vfr39.js → chunk-3gn0c0j2.js} +1 -1
  8. package/dist/{chunk-9zcr1qh6.js → chunk-3nhw50tg.js} +1 -1
  9. package/dist/{chunk-yfjs6pf8.js → chunk-4260bzp9.js} +1 -1
  10. package/dist/{chunk-agevsn2e.js → chunk-4vh3dxeg.js} +1 -1
  11. package/dist/{chunk-cb0f54ar.js → chunk-5e2s5jvw.js} +1 -1
  12. package/dist/{chunk-1rcc9xzn.js → chunk-5kcxxes1.js} +1 -1
  13. package/dist/{chunk-5fe27s34.js → chunk-6t0qzren.js} +1 -1
  14. package/dist/{chunk-7qba2raw.js → chunk-74k5n8f5.js} +1 -1
  15. package/dist/chunk-780j97nd.js +1 -0
  16. package/dist/chunk-78t2g3ht.js +1 -0
  17. package/dist/{chunk-7cx9kda0.js → chunk-7d48d71t.js} +1 -1
  18. package/dist/{chunk-ctqtahz4.js → chunk-96b00ygr.js} +1 -1
  19. package/dist/{chunk-v0e9bsvt.js → chunk-9kbktaf8.js} +2 -2
  20. package/dist/{chunk-kgc6ws03.js → chunk-a4rvf135.js} +1 -1
  21. package/dist/{chunk-81b2s97q.js → chunk-ahsvdb98.js} +1 -1
  22. package/dist/{chunk-gphssgy6.js → chunk-an34z8wv.js} +1 -1
  23. package/dist/chunk-arm90pny.js +1 -0
  24. package/dist/{chunk-jd1razfg.js → chunk-avqzptcg.js} +2 -2
  25. package/dist/{chunk-pgnhcznr.js → chunk-b0yk07x5.js} +1 -1
  26. package/dist/{chunk-1gssqf6g.js → chunk-be8n8w26.js} +1 -1
  27. package/dist/{chunk-h7ypcqp3.js → chunk-bqkrynm6.js} +2 -2
  28. package/dist/chunk-bv28r5cf.js +1 -0
  29. package/dist/{chunk-0qz8rr2k.js → chunk-c59eqb10.js} +1 -1
  30. package/dist/{chunk-6j695pam.js → chunk-cbr2vrpt.js} +1 -1
  31. package/dist/{chunk-9011y634.js → chunk-csn4vg3d.js} +2 -2
  32. package/dist/{chunk-nt2yp4jh.js → chunk-df36fv24.js} +1 -1
  33. package/dist/{chunk-sv0k2v66.js → chunk-e3jv1c1w.js} +1 -1
  34. package/dist/{chunk-069q9hkz.js → chunk-e6m161vn.js} +1 -1
  35. package/dist/{chunk-dz9sqfph.js → chunk-eqetcfer.js} +1 -1
  36. package/dist/{chunk-492hjs9k.js → chunk-eze2fzrq.js} +1 -1
  37. package/dist/{chunk-qfa5v4n5.js → chunk-femf7e4d.js} +1 -1
  38. package/dist/{chunk-d2sr8fnm.js → chunk-fvg6pct8.js} +1 -1
  39. package/dist/{chunk-bk32cwxa.js → chunk-g2n6hnjp.js} +2 -2
  40. package/dist/{chunk-mv5m8bf4.js → chunk-ge071wp4.js} +2 -2
  41. package/dist/{chunk-mv8a5svx.js → chunk-h9w6y105.js} +1 -1
  42. package/dist/{chunk-e7mbewmw.js → chunk-hzxg9kx6.js} +1 -1
  43. package/dist/{chunk-q8zsxwd8.js → chunk-j2qd9mfs.js} +2 -2
  44. package/dist/{chunk-1d47g6nc.js → chunk-j40cj742.js} +1 -1
  45. package/dist/chunk-jbqqb1ht.js +2 -0
  46. package/dist/{chunk-zhqdp4ak.js → chunk-jz0kw4yt.js} +1 -1
  47. package/dist/{chunk-fkt5b511.js → chunk-kknfcsyy.js} +1 -1
  48. package/dist/{chunk-b175s7dm.js → chunk-kvnw06wg.js} +1 -1
  49. package/dist/{chunk-a0nr8jva.js → chunk-kyb15dg8.js} +1 -1
  50. package/dist/{chunk-snmkgfbe.js → chunk-mq4m1w4w.js} +1 -1
  51. package/dist/{chunk-tmyzfvsy.js → chunk-mqcbjght.js} +1 -1
  52. package/dist/{chunk-4eaqmt3c.js → chunk-mqm8wnc8.js} +1 -1
  53. package/dist/{chunk-h2hk7vx4.js → chunk-n7bpjcb0.js} +1 -1
  54. package/dist/{chunk-88w3txtb.js → chunk-ncaqgas1.js} +1 -1
  55. package/dist/{chunk-y524zd2h.js → chunk-nh11afw0.js} +1 -1
  56. package/dist/{chunk-2gprcgep.js → chunk-nwmvyez4.js} +2 -2
  57. package/dist/{chunk-3k3c686f.js → chunk-nzyvqxt4.js} +1 -1
  58. package/dist/{chunk-j8tq0e8m.js → chunk-p6c1xbd5.js} +2 -2
  59. package/dist/chunk-p75m7q2h.js +1 -0
  60. package/dist/{chunk-b0beqmg2.js → chunk-pffdbhs6.js} +1 -1
  61. package/dist/{chunk-em03xqy9.js → chunk-phw7yp5t.js} +1 -1
  62. package/dist/{chunk-akc3s5aw.js → chunk-q0452p0f.js} +1 -1
  63. package/dist/{chunk-jhxvctg5.js → chunk-r133z8tq.js} +1 -1
  64. package/dist/{chunk-c9yrpb3g.js → chunk-rqymdmqg.js} +3 -3
  65. package/dist/{chunk-ts4jreym.js → chunk-rr7h6wdp.js} +1 -1
  66. package/dist/{chunk-wd6s7gg7.js → chunk-s04zfe57.js} +1 -1
  67. package/dist/{chunk-kada5fyh.js → chunk-twhnh3dc.js} +1 -1
  68. package/dist/{chunk-d5gzkkgg.js → chunk-txnezkkt.js} +1 -1
  69. package/dist/{chunk-2bjeg40f.js → chunk-vttq7sqg.js} +1 -1
  70. package/dist/{chunk-0mq8786q.js → chunk-vvs5da2x.js} +2 -2
  71. package/dist/{chunk-5hqvapp1.js → chunk-w4tbr5h7.js} +1 -1
  72. package/dist/{chunk-yejgw2hm.js → chunk-wts8db9p.js} +1 -1
  73. package/dist/{chunk-4fs853nh.js → chunk-x17jyjan.js} +1 -1
  74. package/dist/{chunk-q8cfxky4.js → chunk-x7x7esvz.js} +2 -2
  75. package/dist/{chunk-mk8ggmt8.js → chunk-xprg4hxp.js} +6 -6
  76. package/dist/{chunk-ss4bh5wb.js → chunk-xrfpz1vw.js} +1 -1
  77. package/dist/{chunk-yb71zqvt.js → chunk-xtr6s7kh.js} +2 -2
  78. package/dist/{chunk-dh2f4xyb.js → chunk-y807k0kw.js} +1 -1
  79. package/dist/{chunk-43h0n2td.js → chunk-ycp2e43r.js} +1 -1
  80. package/dist/{chunk-n61yv4t5.js → chunk-yfv1xeeh.js} +1 -1
  81. package/dist/chunk-zxpb45tb.js +1 -0
  82. package/dist/cli.js +1 -1
  83. package/dist/nonInteractive.js +1 -1
  84. package/dist/zen-core.js +11 -394
  85. package/dist/zen-keyboard.js +1 -1
  86. package/package.json +1 -1
  87. package/dist/chunk-06trk066.js +0 -1
  88. package/dist/chunk-0kfw8bwn.js +0 -2
  89. package/dist/chunk-8ygdre0g.js +0 -1
  90. package/dist/chunk-dr32dt9y.js +0 -1
  91. package/dist/chunk-dv1vt080.js +0 -1
  92. package/dist/chunk-p7ew4trx.js +0 -1
  93. package/dist/chunk-qhzztj83.js +0 -1
  94. package/dist/chunk-zkd3m39v.js +0 -1
@@ -1,2 +1,2 @@
1
- import{U as JJ}from"./chunk-h7ypcqp3.js";import{Wl as g,Yl as y}from"./chunk-4fs853nh.js";var C=y((XJ,E)=>{var f="Expected a function",w=NaN,V="[object Symbol]",S=/^\s+|\s+$/g,v=/^[-+]0x[0-9a-f]+$/i,p=/^0b[01]+$/i,d=/^0o[0-7]+$/i,c=parseInt,r=typeof global=="object"&&global&&global.Object===Object&&global,u=typeof self=="object"&&self&&self.Object===Object&&self,o=r||u||Function("return this")(),s=Object.prototype,n=s.toString,l=Math.max,i=Math.min,N=function(){return o.Date.now()};function a(J,Z,$){var Y,j,G,B,Q,P,q=0,F=!1,U=!1,W=!0;if(typeof J!="function")throw TypeError(f);if(Z=I(Z)||0,L($))F=!!$.leading,U="maxWait"in $,G=U?l(I($.maxWait)||0,Z):G,W="trailing"in $?!!$.trailing:W;function _(K){var H=Y,A=j;return Y=j=void 0,q=K,B=J.apply(A,H),B}function h(K){return q=K,Q=setTimeout(D,Z),F?_(K):B}function b(K){var H=K-P,A=K-q,R=Z-H;return U?i(R,G-A):R}function T(K){var H=K-P,A=K-q;return P===void 0||H>=Z||H<0||U&&A>=G}function D(){var K=N();if(T(K))return z(K);Q=setTimeout(D,b(K))}function z(K){if(Q=void 0,W&&Y)return _(K);return Y=j=void 0,B}function m(){if(Q!==void 0)clearTimeout(Q);q=0,Y=P=j=Q=void 0}function k(){return Q===void 0?B:z(N())}function O(){var K=N(),H=T(K);if(Y=arguments,j=this,P=K,H){if(Q===void 0)return h(P);if(U)return Q=setTimeout(D,Z),_(P)}if(Q===void 0)Q=setTimeout(D,Z);return B}return O.cancel=m,O.flush=k,O}function L(J){var Z=typeof J;return!!J&&(Z=="object"||Z=="function")}function t(J){return!!J&&typeof J=="object"}function e(J){return typeof J=="symbol"||t(J)&&n.call(J)==V}function I(J){if(typeof J=="number")return J;if(e(J))return w;if(L(J)){var Z=typeof J.valueOf=="function"?J.valueOf():J;J=L(Z)?Z+"":Z}if(typeof J!="string")return J===0?J:+J;J=J.replace(S,"");var $=p.test(J);return $||d.test(J)?c(J.slice(2),$?2:8):v.test(J)?w:+J}E.exports=a});var X=g(JJ(),1),M=g(C(),1);function YJ(J=!1){if(typeof J!=="boolean")throw Error("defaultValue must be `true` or `false`");let[Z,$]=X.useState(J),Y=X.useCallback(()=>{$(!0)},[]),j=X.useCallback(()=>{$(!1)},[]),G=X.useCallback(()=>{$((B)=>!B)},[]);return{value:Z,setValue:$,setTrue:Y,setFalse:j,toggle:G}}var x=typeof window<"u"?X.useLayoutEffect:X.useEffect;function KJ(J,Z){let $=X.useRef(J);x(()=>{$.current=J},[J]),X.useEffect(()=>{if(Z===null)return;let Y=setInterval(()=>{$.current()},Z);return()=>{clearInterval(Y)}},[Z])}function QJ(J){let Z=X.useRef(()=>{throw Error("Cannot call an event handler while rendering.")});return x(()=>{Z.current=J},[J]),X.useCallback((...$)=>{var Y;return(Y=Z.current)==null?void 0:Y.call(Z,...$)},[Z])}function ZJ(J){let Z=X.useRef(J);Z.current=J,X.useEffect(()=>()=>{Z.current()},[])}function $J(J,Z=500,$){let Y=X.useRef();ZJ(()=>{if(Y.current)Y.current.cancel()});let j=X.useMemo(()=>{let G=M.default(J,Z,$),B=(...Q)=>{return G(...Q)};return B.cancel=()=>{G.cancel()},B.isPending=()=>{return!!Y.current},B.flush=()=>{return G.flush()},B},[J,Z,$]);return X.useEffect(()=>{Y.current=M.default(J,Z,$)},[J,Z,$]),j}function jJ(J,Z,$){let Y=($==null?void 0:$.equalityFn)??((q,F)=>q===F),j=J instanceof Function?J():J,[G,B]=X.useState(j),Q=X.useRef(j),P=$J(B,Z,$);if(!Y(Q.current,j))P(j),Q.current=j;return[G,P]}function BJ(){let J=X.useRef(!1);return X.useEffect(()=>{return J.current=!0,()=>{J.current=!1}},[]),X.useCallback(()=>J.current,[])}function GJ(J,Z){let $=X.useRef(J);x(()=>{$.current=J},[J]),X.useEffect(()=>{if(!Z&&Z!==0)return;let Y=setTimeout(()=>{$.current()},Z);return()=>{clearTimeout(Y)}},[Z])}
1
+ import{U as JJ}from"./chunk-bqkrynm6.js";import{Rl as g,Tl as y}from"./chunk-x17jyjan.js";var C=y((XJ,E)=>{var f="Expected a function",w=NaN,V="[object Symbol]",S=/^\s+|\s+$/g,v=/^[-+]0x[0-9a-f]+$/i,p=/^0b[01]+$/i,d=/^0o[0-7]+$/i,c=parseInt,r=typeof global=="object"&&global&&global.Object===Object&&global,u=typeof self=="object"&&self&&self.Object===Object&&self,o=r||u||Function("return this")(),s=Object.prototype,n=s.toString,l=Math.max,i=Math.min,N=function(){return o.Date.now()};function a(J,Z,$){var Y,j,G,B,Q,P,q=0,F=!1,U=!1,W=!0;if(typeof J!="function")throw TypeError(f);if(Z=I(Z)||0,L($))F=!!$.leading,U="maxWait"in $,G=U?l(I($.maxWait)||0,Z):G,W="trailing"in $?!!$.trailing:W;function _(K){var H=Y,A=j;return Y=j=void 0,q=K,B=J.apply(A,H),B}function h(K){return q=K,Q=setTimeout(D,Z),F?_(K):B}function b(K){var H=K-P,A=K-q,R=Z-H;return U?i(R,G-A):R}function T(K){var H=K-P,A=K-q;return P===void 0||H>=Z||H<0||U&&A>=G}function D(){var K=N();if(T(K))return z(K);Q=setTimeout(D,b(K))}function z(K){if(Q=void 0,W&&Y)return _(K);return Y=j=void 0,B}function m(){if(Q!==void 0)clearTimeout(Q);q=0,Y=P=j=Q=void 0}function k(){return Q===void 0?B:z(N())}function O(){var K=N(),H=T(K);if(Y=arguments,j=this,P=K,H){if(Q===void 0)return h(P);if(U)return Q=setTimeout(D,Z),_(P)}if(Q===void 0)Q=setTimeout(D,Z);return B}return O.cancel=m,O.flush=k,O}function L(J){var Z=typeof J;return!!J&&(Z=="object"||Z=="function")}function t(J){return!!J&&typeof J=="object"}function e(J){return typeof J=="symbol"||t(J)&&n.call(J)==V}function I(J){if(typeof J=="number")return J;if(e(J))return w;if(L(J)){var Z=typeof J.valueOf=="function"?J.valueOf():J;J=L(Z)?Z+"":Z}if(typeof J!="string")return J===0?J:+J;J=J.replace(S,"");var $=p.test(J);return $||d.test(J)?c(J.slice(2),$?2:8):v.test(J)?w:+J}E.exports=a});var X=g(JJ(),1),M=g(C(),1);function YJ(J=!1){if(typeof J!=="boolean")throw Error("defaultValue must be `true` or `false`");let[Z,$]=X.useState(J),Y=X.useCallback(()=>{$(!0)},[]),j=X.useCallback(()=>{$(!1)},[]),G=X.useCallback(()=>{$((B)=>!B)},[]);return{value:Z,setValue:$,setTrue:Y,setFalse:j,toggle:G}}var x=typeof window<"u"?X.useLayoutEffect:X.useEffect;function KJ(J,Z){let $=X.useRef(J);x(()=>{$.current=J},[J]),X.useEffect(()=>{if(Z===null)return;let Y=setInterval(()=>{$.current()},Z);return()=>{clearInterval(Y)}},[Z])}function QJ(J){let Z=X.useRef(()=>{throw Error("Cannot call an event handler while rendering.")});return x(()=>{Z.current=J},[J]),X.useCallback((...$)=>{var Y;return(Y=Z.current)==null?void 0:Y.call(Z,...$)},[Z])}function ZJ(J){let Z=X.useRef(J);Z.current=J,X.useEffect(()=>()=>{Z.current()},[])}function $J(J,Z=500,$){let Y=X.useRef();ZJ(()=>{if(Y.current)Y.current.cancel()});let j=X.useMemo(()=>{let G=M.default(J,Z,$),B=(...Q)=>{return G(...Q)};return B.cancel=()=>{G.cancel()},B.isPending=()=>{return!!Y.current},B.flush=()=>{return G.flush()},B},[J,Z,$]);return X.useEffect(()=>{Y.current=M.default(J,Z,$)},[J,Z,$]),j}function jJ(J,Z,$){let Y=($==null?void 0:$.equalityFn)??((q,F)=>q===F),j=J instanceof Function?J():J,[G,B]=X.useState(j),Q=X.useRef(j),P=$J(B,Z,$);if(!Y(Q.current,j))P(j),Q.current=j;return[G,P]}function BJ(){let J=X.useRef(!1);return X.useEffect(()=>{return J.current=!0,()=>{J.current=!1}},[]),X.useCallback(()=>J.current,[])}function GJ(J,Z){let $=X.useRef(J);x(()=>{$.current=J},[J]),X.useEffect(()=>{if(!Z&&Z!==0)return;let Y=setTimeout(()=>{$.current()},Z);return()=>{clearTimeout(Y)}},[Z])}
2
2
  export{YJ as x,KJ as y,QJ as z,ZJ as A,jJ as B,BJ as C,GJ as D};
@@ -1 +1 @@
1
- import{e as A,f as W}from"./chunk-akc3s5aw.js";import"./chunk-b0beqmg2.js";import{Ag as R,sg as q}from"./chunk-88w3txtb.js";import"./chunk-v0e9bsvt.js";import"./chunk-jhxvctg5.js";import"./chunk-bk32cwxa.js";import"./chunk-qfa5v4n5.js";import"./chunk-78ksrp8v.js";import"./chunk-yb71zqvt.js";import{Wl as V}from"./chunk-4fs853nh.js";var x=V(W(),1);function B(M){if(M===null||typeof M!=="object")return JSON.stringify(M);if(Array.isArray(M))return JSON.stringify(M.map((J)=>B(J)));let F={},G=Object.keys(M).sort();for(let J of G)F[J]=M[J];return JSON.stringify(F,(J,Q)=>{if(Q!==null&&typeof Q==="object"&&!Array.isArray(Q)){let X={},Y=Object.keys(Q).sort();for(let Z of Y)X[Z]=Q[Z];return X}return Q})}var P=[{index:"checkpoints",prefix:"checkpoint:",schema:{"$.thread_id":{type:"TAG",AS:"thread_id"},"$.checkpoint_ns":{type:"TAG",AS:"checkpoint_ns"},"$.checkpoint_id":{type:"TAG",AS:"checkpoint_id"},"$.parent_checkpoint_id":{type:"TAG",AS:"parent_checkpoint_id"},"$.checkpoint_ts":{type:"NUMERIC",AS:"checkpoint_ts"},"$.has_writes":{type:"TAG",AS:"has_writes"},"$.source":{type:"TAG",AS:"source"},"$.step":{type:"NUMERIC",AS:"step"}}},{index:"checkpoint_writes",prefix:"checkpoint_write:",schema:{"$.thread_id":{type:"TAG",AS:"thread_id"},"$.checkpoint_ns":{type:"TAG",AS:"checkpoint_ns"},"$.checkpoint_id":{type:"TAG",AS:"checkpoint_id"},"$.task_id":{type:"TAG",AS:"task_id"},"$.idx":{type:"NUMERIC",AS:"idx"},"$.channel":{type:"TAG",AS:"channel"},"$.type":{type:"TAG",AS:"type"}}}],N=class M extends R{client;ttlConfig;constructor(F,G){super();this.client=F,this.ttlConfig=G}static async fromUrl(F,G){let J=x.createClient({url:F});await J.connect();let Q=new M(J,G);return await Q.ensureIndexes(),Q}async get(F){return(await this.getTuple(F))?.checkpoint}async put(F,G,J,Q){await this.ensureIndexes();let X=F.configurable?.thread_id,Y=F.configurable?.checkpoint_ns??"",Z=F.configurable?.checkpoint_id;if(!X)throw Error("thread_id is required");let _=G.id||q(0),E=`checkpoint:${X}:${Y}:shallow`,H=null,$=null;try{if(H=await this.client.json.get(E),H&&typeof H==="object")$=H.checkpoint_id}catch(O){}if($&&$!==_)await this.cleanupOldCheckpoint(X,Y,$);let L={...G,channel_values:G.channel_values||{},channel_blobs:void 0},U={thread_id:X,checkpoint_ns:Y,checkpoint_id:_,parent_checkpoint_id:Z||null,checkpoint:L,metadata:this.sanitizeMetadata(J),checkpoint_ts:Date.now(),has_writes:"false"};if(this.addSearchableMetadataFields(U,J),await this.client.json.set(E,"$",U),this.ttlConfig?.defaultTTL)await this.applyTTL(E);return{configurable:{thread_id:X,checkpoint_ns:Y,checkpoint_id:_}}}async getTuple(F){let G=F.configurable?.thread_id,J=F.configurable?.checkpoint_ns??"",Q=F.configurable?.checkpoint_id;if(!G)return;let X=`checkpoint:${G}:${J}:shallow`,Y=await this.client.json.get(X);if(!Y)return;if(Q&&Y.checkpoint_id!==Q)return;if(this.ttlConfig?.refreshOnRead&&this.ttlConfig?.defaultTTL)await this.applyTTL(X);let Z=await this.serde.loadsTyped("json",JSON.stringify(Y.checkpoint)),_;if(Y.has_writes==="true")_=await this.loadPendingWrites(Y.thread_id,Y.checkpoint_ns,Y.checkpoint_id);return await this.createCheckpointTuple(Y,Z,_)}async*list(F,G){if(await this.ensureIndexes(),F?.configurable?.thread_id){let J=await this.getTuple(F);if(J)if(G?.filter){if(this.checkMetadataFilterMatch(J.metadata,G.filter))yield J}else yield J}else{let J=[];if(G?.filter){for(let[Y,Z]of Object.entries(G.filter))if(Z===void 0);else if(Z===null);else if(typeof Z==="string"){let _=A(Y),E=A(Z);J.push(`(@${_}:{${E}})`)}else if(typeof Z==="number"){let _=A(Y);J.push(`(@${_}:[${Z} ${Z}])`)}}if(J.length===0)J.push("*");let Q=J.join(" "),X=G?.limit??10;try{let Y=await this.client.ft.search("checkpoints",Q,{LIMIT:{from:0,size:X*2},SORTBY:{BY:"checkpoint_ts",DIRECTION:"DESC"}}),Z=new Set,_=0;for(let E of Y.documents){if(_>=X)break;let H=E.value,$=`${H.thread_id}:${H.checkpoint_ns}`;if(Z.has($))continue;if(Z.add($),G?.filter){if(!this.checkMetadataFilterMatch(H.metadata,G.filter))continue}let L=await this.serde.loadsTyped("json",JSON.stringify(H.checkpoint));yield await this.createCheckpointTuple(H,L),_++}}catch(Y){if(Y.message?.includes("no such index")){let Z=await this.client.keys("checkpoint:*:*:shallow");if(Z.length===0)return;Z.sort().reverse();let _=new Set,E=0,H=G?.limit??10;for(let $ of Z){if(E>=H)break;let L=await this.client.json.get($);if(!L)continue;let U=`${L.thread_id}:${L.checkpoint_ns}`;if(_.has(U))continue;if(_.add(U),G?.filter){if(!this.checkMetadataFilterMatch(L.metadata,G.filter))continue}let O=await this.serde.loadsTyped("json",JSON.stringify(L.checkpoint));yield await this.createCheckpointTuple(L,O),E++}return}throw Y}}}async putWrites(F,G,J){await this.ensureIndexes();let Q=F.configurable?.thread_id,X=F.configurable?.checkpoint_ns??"",Y=F.configurable?.checkpoint_id;if(!Q||!Y)throw Error("thread_id and checkpoint_id are required");let Z=`checkpoint_write:${Q}:${X}:${Y}:${J}:*`,_=await this.client.keys(Z);if(_.length>0)await this.client.del(_);let E=[];for(let $=0;$<G.length;$++){let[L,U]=G[$],O=`checkpoint_write:${Q}:${X}:${Y}:${J}:${$}`;E.push(O);let T={thread_id:Q,checkpoint_ns:X,checkpoint_id:Y,task_id:J,idx:$,channel:L,type:typeof U==="object"?"json":"string",value:U};await this.client.json.set(O,"$",T)}if(E.length>0){let $=`write_keys_zset:${Q}:${X}:${Y}`,L={};if(E.forEach((U,O)=>{L[U]=O}),await this.client.zAdd($,Object.entries(L).map(([U,O])=>({score:O,value:U}))),this.ttlConfig?.defaultTTL)await this.applyTTL(...E,$)}let H=`checkpoint:${Q}:${X}:shallow`;if(await this.client.exists(H)){let $=await this.client.json.get(H);if($)$.has_writes="true",await this.client.json.set(H,"$",$)}}async deleteThread(F){let G=`checkpoint:${F}:*:shallow`,J=await this.client.keys(G);if(J.length>0)await this.client.del(J);let Q=`checkpoint_write:${F}:*`,X=await this.client.keys(Q);if(X.length>0)await this.client.del(X);let Y=`write_keys_zset:${F}:*`,Z=await this.client.keys(Y);if(Z.length>0)await this.client.del(Z)}async end(){await this.client.quit()}addSearchableMetadataFields(F,G){if(!G)return;if("source"in G)F.source=G.source;if("step"in G)F.step=G.step;if("writes"in G)F.writes=typeof G.writes==="object"?JSON.stringify(G.writes):G.writes;if("score"in G)F.score=G.score}async createCheckpointTuple(F,G,J){let Q=await this.serde.loadsTyped("json",JSON.stringify(F.metadata));return{config:{configurable:{thread_id:F.thread_id,checkpoint_ns:F.checkpoint_ns,checkpoint_id:F.checkpoint_id}},checkpoint:G,metadata:Q,parentConfig:F.parent_checkpoint_id?{configurable:{thread_id:F.thread_id,checkpoint_ns:F.checkpoint_ns,checkpoint_id:F.parent_checkpoint_id}}:void 0,pendingWrites:J}}async applyTTL(...F){if(!this.ttlConfig?.defaultTTL)return;let G=Math.floor(this.ttlConfig.defaultTTL*60),J=await Promise.allSettled(F.map((Q)=>this.client.expire(Q,G)));for(let Q=0;Q<J.length;Q++)if(J[Q].status==="rejected")console.warn(`Failed to set TTL for key ${F[Q]}:`,J[Q].reason)}async loadPendingWrites(F,G,J){let Q=`write_keys_zset:${F}:${G}:${J}`,X=await this.client.zRange(Q,0,-1);if(X.length===0)return;let Y=[];for(let Z of X){let _=await this.client.json.get(Z);if(_){let E=await this.serde.loadsTyped("json",JSON.stringify(_.value));Y.push([_.task_id,_.channel,E])}}return Y}checkMetadataFilterMatch(F,G){for(let[J,Q]of Object.entries(G)){let X=F?.[J];if(Q===null){if(!(J in(F||{}))||X!==null)return!1}else if(typeof Q==="object"&&!Array.isArray(Q)){if(typeof X!=="object"||X===null)return!1;if(B(Q)!==B(X))return!1}else if(X!==Q)return!1}return!0}async cleanupOldCheckpoint(F,G,J){let Q=`checkpoint_write:${F}:${G}:${J}:*`,X=await this.client.keys(Q);if(X.length>0)await this.client.del(X);let Y=`write_keys_zset:${F}:${G}:${J}`;await this.client.del(Y);let Z=`checkpoint_blob:${F}:${G}:${J}:*`,_=await this.client.keys(Z);if(_.length>0)await this.client.del(_)}sanitizeMetadata(F){if(!F)return{};let G={};for(let[J,Q]of Object.entries(F)){let X=J.replace(/\x00/g,"");G[X]=typeof Q==="string"?Q.replace(/\x00/g,""):Q}return G}async ensureIndexes(){for(let F of P)try{await this.client.ft.create(F.index,F.schema,{ON:"JSON",PREFIX:F.prefix})}catch(G){if(!G.message?.includes("Index already exists"))console.error(`Failed to create index ${F.index}:`,G.message)}}};export{N as ShallowRedisSaver};
1
+ import{e as A,f as W}from"./chunk-q0452p0f.js";import"./chunk-pffdbhs6.js";import{Ag as R,sg as q}from"./chunk-ncaqgas1.js";import"./chunk-9kbktaf8.js";import"./chunk-r133z8tq.js";import"./chunk-g2n6hnjp.js";import"./chunk-femf7e4d.js";import"./chunk-0pzpg2ra.js";import"./chunk-xtr6s7kh.js";import{Rl as V}from"./chunk-x17jyjan.js";var x=V(W(),1);function B(M){if(M===null||typeof M!=="object")return JSON.stringify(M);if(Array.isArray(M))return JSON.stringify(M.map((J)=>B(J)));let F={},G=Object.keys(M).sort();for(let J of G)F[J]=M[J];return JSON.stringify(F,(J,Q)=>{if(Q!==null&&typeof Q==="object"&&!Array.isArray(Q)){let X={},Y=Object.keys(Q).sort();for(let Z of Y)X[Z]=Q[Z];return X}return Q})}var P=[{index:"checkpoints",prefix:"checkpoint:",schema:{"$.thread_id":{type:"TAG",AS:"thread_id"},"$.checkpoint_ns":{type:"TAG",AS:"checkpoint_ns"},"$.checkpoint_id":{type:"TAG",AS:"checkpoint_id"},"$.parent_checkpoint_id":{type:"TAG",AS:"parent_checkpoint_id"},"$.checkpoint_ts":{type:"NUMERIC",AS:"checkpoint_ts"},"$.has_writes":{type:"TAG",AS:"has_writes"},"$.source":{type:"TAG",AS:"source"},"$.step":{type:"NUMERIC",AS:"step"}}},{index:"checkpoint_writes",prefix:"checkpoint_write:",schema:{"$.thread_id":{type:"TAG",AS:"thread_id"},"$.checkpoint_ns":{type:"TAG",AS:"checkpoint_ns"},"$.checkpoint_id":{type:"TAG",AS:"checkpoint_id"},"$.task_id":{type:"TAG",AS:"task_id"},"$.idx":{type:"NUMERIC",AS:"idx"},"$.channel":{type:"TAG",AS:"channel"},"$.type":{type:"TAG",AS:"type"}}}],N=class M extends R{client;ttlConfig;constructor(F,G){super();this.client=F,this.ttlConfig=G}static async fromUrl(F,G){let J=x.createClient({url:F});await J.connect();let Q=new M(J,G);return await Q.ensureIndexes(),Q}async get(F){return(await this.getTuple(F))?.checkpoint}async put(F,G,J,Q){await this.ensureIndexes();let X=F.configurable?.thread_id,Y=F.configurable?.checkpoint_ns??"",Z=F.configurable?.checkpoint_id;if(!X)throw Error("thread_id is required");let _=G.id||q(0),E=`checkpoint:${X}:${Y}:shallow`,H=null,$=null;try{if(H=await this.client.json.get(E),H&&typeof H==="object")$=H.checkpoint_id}catch(O){}if($&&$!==_)await this.cleanupOldCheckpoint(X,Y,$);let L={...G,channel_values:G.channel_values||{},channel_blobs:void 0},U={thread_id:X,checkpoint_ns:Y,checkpoint_id:_,parent_checkpoint_id:Z||null,checkpoint:L,metadata:this.sanitizeMetadata(J),checkpoint_ts:Date.now(),has_writes:"false"};if(this.addSearchableMetadataFields(U,J),await this.client.json.set(E,"$",U),this.ttlConfig?.defaultTTL)await this.applyTTL(E);return{configurable:{thread_id:X,checkpoint_ns:Y,checkpoint_id:_}}}async getTuple(F){let G=F.configurable?.thread_id,J=F.configurable?.checkpoint_ns??"",Q=F.configurable?.checkpoint_id;if(!G)return;let X=`checkpoint:${G}:${J}:shallow`,Y=await this.client.json.get(X);if(!Y)return;if(Q&&Y.checkpoint_id!==Q)return;if(this.ttlConfig?.refreshOnRead&&this.ttlConfig?.defaultTTL)await this.applyTTL(X);let Z=await this.serde.loadsTyped("json",JSON.stringify(Y.checkpoint)),_;if(Y.has_writes==="true")_=await this.loadPendingWrites(Y.thread_id,Y.checkpoint_ns,Y.checkpoint_id);return await this.createCheckpointTuple(Y,Z,_)}async*list(F,G){if(await this.ensureIndexes(),F?.configurable?.thread_id){let J=await this.getTuple(F);if(J)if(G?.filter){if(this.checkMetadataFilterMatch(J.metadata,G.filter))yield J}else yield J}else{let J=[];if(G?.filter){for(let[Y,Z]of Object.entries(G.filter))if(Z===void 0);else if(Z===null);else if(typeof Z==="string"){let _=A(Y),E=A(Z);J.push(`(@${_}:{${E}})`)}else if(typeof Z==="number"){let _=A(Y);J.push(`(@${_}:[${Z} ${Z}])`)}}if(J.length===0)J.push("*");let Q=J.join(" "),X=G?.limit??10;try{let Y=await this.client.ft.search("checkpoints",Q,{LIMIT:{from:0,size:X*2},SORTBY:{BY:"checkpoint_ts",DIRECTION:"DESC"}}),Z=new Set,_=0;for(let E of Y.documents){if(_>=X)break;let H=E.value,$=`${H.thread_id}:${H.checkpoint_ns}`;if(Z.has($))continue;if(Z.add($),G?.filter){if(!this.checkMetadataFilterMatch(H.metadata,G.filter))continue}let L=await this.serde.loadsTyped("json",JSON.stringify(H.checkpoint));yield await this.createCheckpointTuple(H,L),_++}}catch(Y){if(Y.message?.includes("no such index")){let Z=await this.client.keys("checkpoint:*:*:shallow");if(Z.length===0)return;Z.sort().reverse();let _=new Set,E=0,H=G?.limit??10;for(let $ of Z){if(E>=H)break;let L=await this.client.json.get($);if(!L)continue;let U=`${L.thread_id}:${L.checkpoint_ns}`;if(_.has(U))continue;if(_.add(U),G?.filter){if(!this.checkMetadataFilterMatch(L.metadata,G.filter))continue}let O=await this.serde.loadsTyped("json",JSON.stringify(L.checkpoint));yield await this.createCheckpointTuple(L,O),E++}return}throw Y}}}async putWrites(F,G,J){await this.ensureIndexes();let Q=F.configurable?.thread_id,X=F.configurable?.checkpoint_ns??"",Y=F.configurable?.checkpoint_id;if(!Q||!Y)throw Error("thread_id and checkpoint_id are required");let Z=`checkpoint_write:${Q}:${X}:${Y}:${J}:*`,_=await this.client.keys(Z);if(_.length>0)await this.client.del(_);let E=[];for(let $=0;$<G.length;$++){let[L,U]=G[$],O=`checkpoint_write:${Q}:${X}:${Y}:${J}:${$}`;E.push(O);let T={thread_id:Q,checkpoint_ns:X,checkpoint_id:Y,task_id:J,idx:$,channel:L,type:typeof U==="object"?"json":"string",value:U};await this.client.json.set(O,"$",T)}if(E.length>0){let $=`write_keys_zset:${Q}:${X}:${Y}`,L={};if(E.forEach((U,O)=>{L[U]=O}),await this.client.zAdd($,Object.entries(L).map(([U,O])=>({score:O,value:U}))),this.ttlConfig?.defaultTTL)await this.applyTTL(...E,$)}let H=`checkpoint:${Q}:${X}:shallow`;if(await this.client.exists(H)){let $=await this.client.json.get(H);if($)$.has_writes="true",await this.client.json.set(H,"$",$)}}async deleteThread(F){let G=`checkpoint:${F}:*:shallow`,J=await this.client.keys(G);if(J.length>0)await this.client.del(J);let Q=`checkpoint_write:${F}:*`,X=await this.client.keys(Q);if(X.length>0)await this.client.del(X);let Y=`write_keys_zset:${F}:*`,Z=await this.client.keys(Y);if(Z.length>0)await this.client.del(Z)}async end(){await this.client.quit()}addSearchableMetadataFields(F,G){if(!G)return;if("source"in G)F.source=G.source;if("step"in G)F.step=G.step;if("writes"in G)F.writes=typeof G.writes==="object"?JSON.stringify(G.writes):G.writes;if("score"in G)F.score=G.score}async createCheckpointTuple(F,G,J){let Q=await this.serde.loadsTyped("json",JSON.stringify(F.metadata));return{config:{configurable:{thread_id:F.thread_id,checkpoint_ns:F.checkpoint_ns,checkpoint_id:F.checkpoint_id}},checkpoint:G,metadata:Q,parentConfig:F.parent_checkpoint_id?{configurable:{thread_id:F.thread_id,checkpoint_ns:F.checkpoint_ns,checkpoint_id:F.parent_checkpoint_id}}:void 0,pendingWrites:J}}async applyTTL(...F){if(!this.ttlConfig?.defaultTTL)return;let G=Math.floor(this.ttlConfig.defaultTTL*60),J=await Promise.allSettled(F.map((Q)=>this.client.expire(Q,G)));for(let Q=0;Q<J.length;Q++)if(J[Q].status==="rejected")console.warn(`Failed to set TTL for key ${F[Q]}:`,J[Q].reason)}async loadPendingWrites(F,G,J){let Q=`write_keys_zset:${F}:${G}:${J}`,X=await this.client.zRange(Q,0,-1);if(X.length===0)return;let Y=[];for(let Z of X){let _=await this.client.json.get(Z);if(_){let E=await this.serde.loadsTyped("json",JSON.stringify(_.value));Y.push([_.task_id,_.channel,E])}}return Y}checkMetadataFilterMatch(F,G){for(let[J,Q]of Object.entries(G)){let X=F?.[J];if(Q===null){if(!(J in(F||{}))||X!==null)return!1}else if(typeof Q==="object"&&!Array.isArray(Q)){if(typeof X!=="object"||X===null)return!1;if(B(Q)!==B(X))return!1}else if(X!==Q)return!1}return!0}async cleanupOldCheckpoint(F,G,J){let Q=`checkpoint_write:${F}:${G}:${J}:*`,X=await this.client.keys(Q);if(X.length>0)await this.client.del(X);let Y=`write_keys_zset:${F}:${G}:${J}`;await this.client.del(Y);let Z=`checkpoint_blob:${F}:${G}:${J}:*`,_=await this.client.keys(Z);if(_.length>0)await this.client.del(_)}sanitizeMetadata(F){if(!F)return{};let G={};for(let[J,Q]of Object.entries(F)){let X=J.replace(/\x00/g,"");G[X]=typeof Q==="string"?Q.replace(/\x00/g,""):Q}return G}async ensureIndexes(){for(let F of P)try{await this.client.ft.create(F.index,F.schema,{ON:"JSON",PREFIX:F.prefix})}catch(G){if(!G.message?.includes("Index already exists"))console.error(`Failed to create index ${F.index}:`,G.message)}}};export{N as ShallowRedisSaver};