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,4 +1,4 @@
1
- import{Mf as m9}from"./chunk-y524zd2h.js";import{Rf as i9,Wf as bX,Xf as KJ,Yf as ZJ,_f as WJ}from"./chunk-4eaqmt3c.js";import{bh as aU,ch as Z$}from"./chunk-9011y634.js";import{Kh as Q9,Xh as K8,dj as GJ,hi as h4,mi as A1,tk as MX,uk as h9}from"./chunk-v0e9bsvt.js";import{Dk as M8}from"./chunk-mv5m8bf4.js";import{Ok as P8,Qk as L}from"./chunk-qfa5v4n5.js";import{Rk as y}from"./chunk-0kfw8bwn.js";import{Al as QY,Bl as D,Sk as oX,Xk as P6,el as TX,fl as R8,gl as V,hl as rX,il as u,jl as l,kl as l8,ll as tX,ml as s,nl as M,ol as b,pl as e,ql as p,rl as m8,sl as p8,tl as i,ul as j0,vl as R,wl as a,xl as EX,yl as d8,zl as eX}from"./chunk-78ksrp8v.js";import{$l as G3,Wl as Z1,Yl as N}from"./chunk-4fs853nh.js";var q9=N((AY)=>{Object.defineProperty(AY,"__esModule",{value:!0});AY.regexpCode=AY.getEsmExportName=AY.getProperty=AY.safeStringify=AY.stringify=AY.strConcat=AY.addCodeArg=AY.str=AY._=AY.nil=AY._Code=AY.Name=AY.IDENTIFIER=AY._CodeOrName=void 0;class wQ{}AY._CodeOrName=wQ;AY.IDENTIFIER=/^[a-z$_][a-z$_0-9]*$/i;class g1 extends wQ{constructor(Q){super();if(!AY.IDENTIFIER.test(Q))throw Error("CodeGen: name must be a valid identifier");this.str=Q}toString(){return this.str}emptyStr(){return!1}get names(){return{[this.str]:1}}}AY.Name=g1;class T0 extends wQ{constructor(Q){super();this._items=typeof Q==="string"?[Q]:Q}toString(){return this.str}emptyStr(){if(this._items.length>1)return!1;let Q=this._items[0];return Q===""||Q==='""'}get str(){var Q;return(Q=this._str)!==null&&Q!==void 0?Q:this._str=this._items.reduce((X,Y)=>`${X}${Y}`,"")}get names(){var Q;return(Q=this._names)!==null&&Q!==void 0?Q:this._names=this._items.reduce((X,Y)=>{if(Y instanceof g1)X[Y.str]=(X[Y.str]||0)+1;return X},{})}}AY._Code=T0;AY.nil=new T0("");function zY(Q,...X){let Y=[Q[0]],Z=0;while(Z<X.length)S6(Y,X[Z]),Y.push(Q[++Z]);return new T0(Y)}AY._=zY;var C6=new T0("+");function qY(Q,...X){let Y=[z9(Q[0])],Z=0;while(Z<X.length)Y.push(C6),S6(Y,X[Z]),Y.push(C6,z9(Q[++Z]));return v3(Y),new T0(Y)}AY.str=qY;function S6(Q,X){if(X instanceof T0)Q.push(...X._items);else if(X instanceof g1)Q.push(X);else Q.push(u3(X))}AY.addCodeArg=S6;function v3(Q){let X=1;while(X<Q.length-1){if(Q[X]===C6){let Y=g3(Q[X-1],Q[X+1]);if(Y!==void 0){Q.splice(X-1,3,Y);continue}Q[X++]="+"}X++}}function g3(Q,X){if(X==='""')return Q;if(Q==='""')return X;if(typeof Q=="string"){if(X instanceof g1||Q[Q.length-1]!=='"')return;if(typeof X!="string")return`${Q.slice(0,-1)}${X}"`;if(X[0]==='"')return Q.slice(0,-1)+X.slice(1);return}if(typeof X=="string"&&X[0]==='"'&&!(Q instanceof g1))return`"${Q}${X.slice(1)}`;return}function h3(Q,X){return X.emptyStr()?Q:Q.emptyStr()?X:qY`${Q}${X}`}AY.strConcat=h3;function u3(Q){return typeof Q=="number"||typeof Q=="boolean"||Q===null?Q:z9(Array.isArray(Q)?Q.join(","):Q)}function l3(Q){return new T0(z9(Q))}AY.stringify=l3;function z9(Q){return JSON.stringify(Q).replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}AY.safeStringify=z9;function m3(Q){return typeof Q=="string"&&AY.IDENTIFIER.test(Q)?new T0(`.${Q}`):zY`[${Q}]`}AY.getProperty=m3;function p3(Q){if(typeof Q=="string"&&AY.IDENTIFIER.test(Q))return new T0(`${Q}`);throw Error(`CodeGen: invalid export name: ${Q}, use explicit $id name mapping`)}AY.getEsmExportName=p3;function d3(Q){return new T0(Q.toString())}AY.regexpCode=d3});var _6=N((bY)=>{Object.defineProperty(bY,"__esModule",{value:!0});bY.ValueScope=bY.ValueScopeName=bY.Scope=bY.varKinds=bY.UsedValueState=void 0;var U0=q9();class DY extends Error{constructor(Q){super(`CodeGen: "code" for ${Q} not defined`);this.value=Q.value}}var RQ;(function(Q){Q[Q.Started=0]="Started",Q[Q.Completed=1]="Completed"})(RQ||(bY.UsedValueState=RQ={}));bY.varKinds={const:new U0.Name("const"),let:new U0.Name("let"),var:new U0.Name("var")};class x6{constructor({prefixes:Q,parent:X}={}){this._names={},this._prefixes=Q,this._parent=X}toName(Q){return Q instanceof U0.Name?Q:this.name(Q)}name(Q){return new U0.Name(this._newName(Q))}_newName(Q){let X=this._names[Q]||this._nameGroup(Q);return`${Q}${X.index++}`}_nameGroup(Q){var X,Y;if(((Y=(X=this._parent)===null||X===void 0?void 0:X._prefixes)===null||Y===void 0?void 0:Y.has(Q))||this._prefixes&&!this._prefixes.has(Q))throw Error(`CodeGen: prefix "${Q}" is not allowed in this scope`);return this._names[Q]={prefix:Q,index:0}}}bY.Scope=x6;class y6 extends U0.Name{constructor(Q,X){super(X);this.prefix=Q}setValue(Q,{property:X,itemIndex:Y}){this.value=Q,this.scopePath=U0._`.${new U0.Name(X)}[${Y}]`}}bY.ValueScopeName=y6;var ZK=U0._`\n`;class MY extends x6{constructor(Q){super(Q);this._values={},this._scope=Q.scope,this.opts={...Q,_n:Q.lines?ZK:U0.nil}}get(){return this._scope}name(Q){return new y6(Q,this._newName(Q))}value(Q,X){var Y;if(X.ref===void 0)throw Error("CodeGen: ref must be passed in value");let Z=this.toName(Q),{prefix:W}=Z,J=(Y=X.key)!==null&&Y!==void 0?Y:X.ref,$=this._values[W];if($){let B=$.get(J);if(B)return B}else $=this._values[W]=new Map;$.set(J,Z);let G=this._scope[W]||(this._scope[W]=[]),K=G.length;return G[K]=X.ref,Z.setValue(X,{property:W,itemIndex:K}),Z}getValue(Q,X){let Y=this._values[Q];if(!Y)return;return Y.get(X)}scopeRefs(Q,X=this._values){return this._reduceValues(X,(Y)=>{if(Y.scopePath===void 0)throw Error(`CodeGen: name "${Y}" has no value`);return U0._`${Q}${Y.scopePath}`})}scopeCode(Q=this._values,X,Y){return this._reduceValues(Q,(Z)=>{if(Z.value===void 0)throw Error(`CodeGen: name "${Z}" has no value`);return Z.value.code},X,Y)}_reduceValues(Q,X,Y={},Z){let W=U0.nil;for(let J in Q){let $=Q[J];if(!$)continue;let G=Y[J]=Y[J]||new Map;$.forEach((K)=>{if(G.has(K))return;G.set(K,RQ.Started);let B=X(K);if(B){let F=this.opts.es5?bY.varKinds.var:bY.varKinds.const;W=U0._`${W}${F} ${K} = ${B};${this.opts._n}`}else if(B=Z===null||Z===void 0?void 0:Z(K))W=U0._`${W}${B}${this.opts._n}`;else throw new DY(K);G.set(K,RQ.Completed)})}return W}}bY.ValueScope=MY});var _=N((z0)=>{Object.defineProperty(z0,"__esModule",{value:!0});z0.or=z0.and=z0.not=z0.CodeGen=z0.operators=z0.varKinds=z0.ValueScopeName=z0.ValueScope=z0.Scope=z0.Name=z0.regexpCode=z0.stringify=z0.getProperty=z0.nil=z0.strConcat=z0.str=z0._=void 0;var v=q9(),E0=_6(),o0=q9();Object.defineProperty(z0,"_",{enumerable:!0,get:function(){return o0._}});Object.defineProperty(z0,"str",{enumerable:!0,get:function(){return o0.str}});Object.defineProperty(z0,"strConcat",{enumerable:!0,get:function(){return o0.strConcat}});Object.defineProperty(z0,"nil",{enumerable:!0,get:function(){return o0.nil}});Object.defineProperty(z0,"getProperty",{enumerable:!0,get:function(){return o0.getProperty}});Object.defineProperty(z0,"stringify",{enumerable:!0,get:function(){return o0.stringify}});Object.defineProperty(z0,"regexpCode",{enumerable:!0,get:function(){return o0.regexpCode}});Object.defineProperty(z0,"Name",{enumerable:!0,get:function(){return o0.Name}});var SQ=_6();Object.defineProperty(z0,"Scope",{enumerable:!0,get:function(){return SQ.Scope}});Object.defineProperty(z0,"ValueScope",{enumerable:!0,get:function(){return SQ.ValueScope}});Object.defineProperty(z0,"ValueScopeName",{enumerable:!0,get:function(){return SQ.ValueScopeName}});Object.defineProperty(z0,"varKinds",{enumerable:!0,get:function(){return SQ.varKinds}});z0.operators={GT:new v._Code(">"),GTE:new v._Code(">="),LT:new v._Code("<"),LTE:new v._Code("<="),EQ:new v._Code("==="),NEQ:new v._Code("!=="),NOT:new v._Code("!"),OR:new v._Code("||"),AND:new v._Code("&&"),ADD:new v._Code("+")};class r0{optimizeNodes(){return this}optimizeNames(Q,X){return this}}class NY extends r0{constructor(Q,X,Y){super();this.varKind=Q,this.name=X,this.rhs=Y}render({es5:Q,_n:X}){let Y=Q?E0.varKinds.var:this.varKind,Z=this.rhs===void 0?"":` = ${this.rhs}`;return`${Y} ${this.name}${Z};`+X}optimizeNames(Q,X){if(!Q[this.name.str])return;if(this.rhs)this.rhs=u1(this.rhs,Q,X);return this}get names(){return this.rhs instanceof v._CodeOrName?this.rhs.names:{}}}class g6 extends r0{constructor(Q,X,Y){super();this.lhs=Q,this.rhs=X,this.sideEffects=Y}render({_n:Q}){return`${this.lhs} = ${this.rhs};`+Q}optimizeNames(Q,X){if(this.lhs instanceof v.Name&&!Q[this.lhs.str]&&!this.sideEffects)return;return this.rhs=u1(this.rhs,Q,X),this}get names(){let Q=this.lhs instanceof v.Name?{}:{...this.lhs.names};return CQ(Q,this.rhs)}}class RY extends g6{constructor(Q,X,Y,Z){super(Q,Y,Z);this.op=X}render({_n:Q}){return`${this.lhs} ${this.op}= ${this.rhs};`+Q}}class PY extends r0{constructor(Q){super();this.label=Q,this.names={}}render({_n:Q}){return`${this.label}:`+Q}}class IY extends r0{constructor(Q){super();this.label=Q,this.names={}}render({_n:Q}){return`break${this.label?` ${this.label}`:""};`+Q}}class TY extends r0{constructor(Q){super();this.error=Q}render({_n:Q}){return`throw ${this.error};`+Q}get names(){return this.error.names}}class EY extends r0{constructor(Q){super();this.code=Q}render({_n:Q}){return`${this.code};`+Q}optimizeNodes(){return`${this.code}`?this:void 0}optimizeNames(Q,X){return this.code=u1(this.code,Q,X),this}get names(){return this.code instanceof v._CodeOrName?this.code.names:{}}}class kQ extends r0{constructor(Q=[]){super();this.nodes=Q}render(Q){return this.nodes.reduce((X,Y)=>X+Y.render(Q),"")}optimizeNodes(){let{nodes:Q}=this,X=Q.length;while(X--){let Y=Q[X].optimizeNodes();if(Array.isArray(Y))Q.splice(X,1,...Y);else if(Y)Q[X]=Y;else Q.splice(X,1)}return Q.length>0?this:void 0}optimizeNames(Q,X){let{nodes:Y}=this,Z=Y.length;while(Z--){let W=Y[Z];if(W.optimizeNames(Q,X))continue;GK(Q,W.names),Y.splice(Z,1)}return Y.length>0?this:void 0}get names(){return this.nodes.reduce((Q,X)=>V1(Q,X.names),{})}}class t0 extends kQ{render(Q){return"{"+Q._n+super.render(Q)+"}"+Q._n}}class CY extends kQ{}class A9 extends t0{}A9.kind="else";class h0 extends t0{constructor(Q,X){super(X);this.condition=Q}render(Q){let X=`if(${this.condition})`+super.render(Q);if(this.else)X+="else "+this.else.render(Q);return X}optimizeNodes(){super.optimizeNodes();let Q=this.condition;if(Q===!0)return this.nodes;let X=this.else;if(X){let Y=X.optimizeNodes();X=this.else=Array.isArray(Y)?new A9(Y):Y}if(X){if(Q===!1)return X instanceof h0?X:X.nodes;if(this.nodes.length)return this;return new h0(_Y(Q),X instanceof h0?[X]:X.nodes)}if(Q===!1||!this.nodes.length)return;return this}optimizeNames(Q,X){var Y;if(this.else=(Y=this.else)===null||Y===void 0?void 0:Y.optimizeNames(Q,X),!(super.optimizeNames(Q,X)||this.else))return;return this.condition=u1(this.condition,Q,X),this}get names(){let Q=super.names;if(CQ(Q,this.condition),this.else)V1(Q,this.else.names);return Q}}h0.kind="if";class h1 extends t0{}h1.kind="for";class SY extends h1{constructor(Q){super();this.iteration=Q}render(Q){return`for(${this.iteration})`+super.render(Q)}optimizeNames(Q,X){if(!super.optimizeNames(Q,X))return;return this.iteration=u1(this.iteration,Q,X),this}get names(){return V1(super.names,this.iteration.names)}}class kY extends h1{constructor(Q,X,Y,Z){super();this.varKind=Q,this.name=X,this.from=Y,this.to=Z}render(Q){let X=Q.es5?E0.varKinds.var:this.varKind,{name:Y,from:Z,to:W}=this;return`for(${X} ${Y}=${Z}; ${Y}<${W}; ${Y}++)`+super.render(Q)}get names(){let Q=CQ(super.names,this.from);return CQ(Q,this.to)}}class f6 extends h1{constructor(Q,X,Y,Z){super();this.loop=Q,this.varKind=X,this.name=Y,this.iterable=Z}render(Q){return`for(${this.varKind} ${this.name} ${this.loop} ${this.iterable})`+super.render(Q)}optimizeNames(Q,X){if(!super.optimizeNames(Q,X))return;return this.iterable=u1(this.iterable,Q,X),this}get names(){return V1(super.names,this.iterable.names)}}class PQ extends t0{constructor(Q,X,Y){super();this.name=Q,this.args=X,this.async=Y}render(Q){return`${this.async?"async ":""}function ${this.name}(${this.args})`+super.render(Q)}}PQ.kind="func";class IQ extends kQ{render(Q){return"return "+super.render(Q)}}IQ.kind="return";class xY extends t0{render(Q){let X="try"+super.render(Q);if(this.catch)X+=this.catch.render(Q);if(this.finally)X+=this.finally.render(Q);return X}optimizeNodes(){var Q,X;return super.optimizeNodes(),(Q=this.catch)===null||Q===void 0||Q.optimizeNodes(),(X=this.finally)===null||X===void 0||X.optimizeNodes(),this}optimizeNames(Q,X){var Y,Z;return super.optimizeNames(Q,X),(Y=this.catch)===null||Y===void 0||Y.optimizeNames(Q,X),(Z=this.finally)===null||Z===void 0||Z.optimizeNames(Q,X),this}get names(){let Q=super.names;if(this.catch)V1(Q,this.catch.names);if(this.finally)V1(Q,this.finally.names);return Q}}class TQ extends t0{constructor(Q){super();this.error=Q}render(Q){return`catch(${this.error})`+super.render(Q)}}TQ.kind="catch";class EQ extends t0{render(Q){return"finally"+super.render(Q)}}EQ.kind="finally";class yY{constructor(Q,X={}){this._values={},this._blockStarts=[],this._constants={},this.opts={...X,_n:X.lines?`
1
+ import{Mf as m9}from"./chunk-nh11afw0.js";import{Rf as i9,Wf as bX,Xf as KJ,Yf as ZJ,_f as WJ}from"./chunk-mqm8wnc8.js";import{Zg as aU,_g as Z$}from"./chunk-csn4vg3d.js";import{$i as GJ,Gh as Q9,Th as K8,di as h4,ii as A1,pk as MX,qk as h9}from"./chunk-9kbktaf8.js";import{zk as M8}from"./chunk-ge071wp4.js";import{Kk as P8,Mk as L}from"./chunk-femf7e4d.js";import{Nk as y}from"./chunk-jbqqb1ht.js";import{Ok as oX,Tk as P6,al as TX,bl as R8,cl as V,dl as rX,el as u,fl as l,gl as l8,hl as tX,il as s,jl as M,kl as b,ll as e,ml as p,nl as m8,ol as p8,pl as i,ql as j0,rl as R,sl as a,tl as EX,ul as d8,vl as eX,wl as QY,xl as D}from"./chunk-0pzpg2ra.js";import{Rl as Z1,Tl as N,Wl as G3}from"./chunk-x17jyjan.js";var q9=N((AY)=>{Object.defineProperty(AY,"__esModule",{value:!0});AY.regexpCode=AY.getEsmExportName=AY.getProperty=AY.safeStringify=AY.stringify=AY.strConcat=AY.addCodeArg=AY.str=AY._=AY.nil=AY._Code=AY.Name=AY.IDENTIFIER=AY._CodeOrName=void 0;class wQ{}AY._CodeOrName=wQ;AY.IDENTIFIER=/^[a-z$_][a-z$_0-9]*$/i;class g1 extends wQ{constructor(Q){super();if(!AY.IDENTIFIER.test(Q))throw Error("CodeGen: name must be a valid identifier");this.str=Q}toString(){return this.str}emptyStr(){return!1}get names(){return{[this.str]:1}}}AY.Name=g1;class T0 extends wQ{constructor(Q){super();this._items=typeof Q==="string"?[Q]:Q}toString(){return this.str}emptyStr(){if(this._items.length>1)return!1;let Q=this._items[0];return Q===""||Q==='""'}get str(){var Q;return(Q=this._str)!==null&&Q!==void 0?Q:this._str=this._items.reduce((X,Y)=>`${X}${Y}`,"")}get names(){var Q;return(Q=this._names)!==null&&Q!==void 0?Q:this._names=this._items.reduce((X,Y)=>{if(Y instanceof g1)X[Y.str]=(X[Y.str]||0)+1;return X},{})}}AY._Code=T0;AY.nil=new T0("");function zY(Q,...X){let Y=[Q[0]],Z=0;while(Z<X.length)S6(Y,X[Z]),Y.push(Q[++Z]);return new T0(Y)}AY._=zY;var C6=new T0("+");function qY(Q,...X){let Y=[z9(Q[0])],Z=0;while(Z<X.length)Y.push(C6),S6(Y,X[Z]),Y.push(C6,z9(Q[++Z]));return v3(Y),new T0(Y)}AY.str=qY;function S6(Q,X){if(X instanceof T0)Q.push(...X._items);else if(X instanceof g1)Q.push(X);else Q.push(u3(X))}AY.addCodeArg=S6;function v3(Q){let X=1;while(X<Q.length-1){if(Q[X]===C6){let Y=g3(Q[X-1],Q[X+1]);if(Y!==void 0){Q.splice(X-1,3,Y);continue}Q[X++]="+"}X++}}function g3(Q,X){if(X==='""')return Q;if(Q==='""')return X;if(typeof Q=="string"){if(X instanceof g1||Q[Q.length-1]!=='"')return;if(typeof X!="string")return`${Q.slice(0,-1)}${X}"`;if(X[0]==='"')return Q.slice(0,-1)+X.slice(1);return}if(typeof X=="string"&&X[0]==='"'&&!(Q instanceof g1))return`"${Q}${X.slice(1)}`;return}function h3(Q,X){return X.emptyStr()?Q:Q.emptyStr()?X:qY`${Q}${X}`}AY.strConcat=h3;function u3(Q){return typeof Q=="number"||typeof Q=="boolean"||Q===null?Q:z9(Array.isArray(Q)?Q.join(","):Q)}function l3(Q){return new T0(z9(Q))}AY.stringify=l3;function z9(Q){return JSON.stringify(Q).replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}AY.safeStringify=z9;function m3(Q){return typeof Q=="string"&&AY.IDENTIFIER.test(Q)?new T0(`.${Q}`):zY`[${Q}]`}AY.getProperty=m3;function p3(Q){if(typeof Q=="string"&&AY.IDENTIFIER.test(Q))return new T0(`${Q}`);throw Error(`CodeGen: invalid export name: ${Q}, use explicit $id name mapping`)}AY.getEsmExportName=p3;function d3(Q){return new T0(Q.toString())}AY.regexpCode=d3});var _6=N((bY)=>{Object.defineProperty(bY,"__esModule",{value:!0});bY.ValueScope=bY.ValueScopeName=bY.Scope=bY.varKinds=bY.UsedValueState=void 0;var U0=q9();class DY extends Error{constructor(Q){super(`CodeGen: "code" for ${Q} not defined`);this.value=Q.value}}var RQ;(function(Q){Q[Q.Started=0]="Started",Q[Q.Completed=1]="Completed"})(RQ||(bY.UsedValueState=RQ={}));bY.varKinds={const:new U0.Name("const"),let:new U0.Name("let"),var:new U0.Name("var")};class x6{constructor({prefixes:Q,parent:X}={}){this._names={},this._prefixes=Q,this._parent=X}toName(Q){return Q instanceof U0.Name?Q:this.name(Q)}name(Q){return new U0.Name(this._newName(Q))}_newName(Q){let X=this._names[Q]||this._nameGroup(Q);return`${Q}${X.index++}`}_nameGroup(Q){var X,Y;if(((Y=(X=this._parent)===null||X===void 0?void 0:X._prefixes)===null||Y===void 0?void 0:Y.has(Q))||this._prefixes&&!this._prefixes.has(Q))throw Error(`CodeGen: prefix "${Q}" is not allowed in this scope`);return this._names[Q]={prefix:Q,index:0}}}bY.Scope=x6;class y6 extends U0.Name{constructor(Q,X){super(X);this.prefix=Q}setValue(Q,{property:X,itemIndex:Y}){this.value=Q,this.scopePath=U0._`.${new U0.Name(X)}[${Y}]`}}bY.ValueScopeName=y6;var ZK=U0._`\n`;class MY extends x6{constructor(Q){super(Q);this._values={},this._scope=Q.scope,this.opts={...Q,_n:Q.lines?ZK:U0.nil}}get(){return this._scope}name(Q){return new y6(Q,this._newName(Q))}value(Q,X){var Y;if(X.ref===void 0)throw Error("CodeGen: ref must be passed in value");let Z=this.toName(Q),{prefix:W}=Z,J=(Y=X.key)!==null&&Y!==void 0?Y:X.ref,$=this._values[W];if($){let B=$.get(J);if(B)return B}else $=this._values[W]=new Map;$.set(J,Z);let G=this._scope[W]||(this._scope[W]=[]),K=G.length;return G[K]=X.ref,Z.setValue(X,{property:W,itemIndex:K}),Z}getValue(Q,X){let Y=this._values[Q];if(!Y)return;return Y.get(X)}scopeRefs(Q,X=this._values){return this._reduceValues(X,(Y)=>{if(Y.scopePath===void 0)throw Error(`CodeGen: name "${Y}" has no value`);return U0._`${Q}${Y.scopePath}`})}scopeCode(Q=this._values,X,Y){return this._reduceValues(Q,(Z)=>{if(Z.value===void 0)throw Error(`CodeGen: name "${Z}" has no value`);return Z.value.code},X,Y)}_reduceValues(Q,X,Y={},Z){let W=U0.nil;for(let J in Q){let $=Q[J];if(!$)continue;let G=Y[J]=Y[J]||new Map;$.forEach((K)=>{if(G.has(K))return;G.set(K,RQ.Started);let B=X(K);if(B){let F=this.opts.es5?bY.varKinds.var:bY.varKinds.const;W=U0._`${W}${F} ${K} = ${B};${this.opts._n}`}else if(B=Z===null||Z===void 0?void 0:Z(K))W=U0._`${W}${B}${this.opts._n}`;else throw new DY(K);G.set(K,RQ.Completed)})}return W}}bY.ValueScope=MY});var _=N((z0)=>{Object.defineProperty(z0,"__esModule",{value:!0});z0.or=z0.and=z0.not=z0.CodeGen=z0.operators=z0.varKinds=z0.ValueScopeName=z0.ValueScope=z0.Scope=z0.Name=z0.regexpCode=z0.stringify=z0.getProperty=z0.nil=z0.strConcat=z0.str=z0._=void 0;var v=q9(),E0=_6(),o0=q9();Object.defineProperty(z0,"_",{enumerable:!0,get:function(){return o0._}});Object.defineProperty(z0,"str",{enumerable:!0,get:function(){return o0.str}});Object.defineProperty(z0,"strConcat",{enumerable:!0,get:function(){return o0.strConcat}});Object.defineProperty(z0,"nil",{enumerable:!0,get:function(){return o0.nil}});Object.defineProperty(z0,"getProperty",{enumerable:!0,get:function(){return o0.getProperty}});Object.defineProperty(z0,"stringify",{enumerable:!0,get:function(){return o0.stringify}});Object.defineProperty(z0,"regexpCode",{enumerable:!0,get:function(){return o0.regexpCode}});Object.defineProperty(z0,"Name",{enumerable:!0,get:function(){return o0.Name}});var SQ=_6();Object.defineProperty(z0,"Scope",{enumerable:!0,get:function(){return SQ.Scope}});Object.defineProperty(z0,"ValueScope",{enumerable:!0,get:function(){return SQ.ValueScope}});Object.defineProperty(z0,"ValueScopeName",{enumerable:!0,get:function(){return SQ.ValueScopeName}});Object.defineProperty(z0,"varKinds",{enumerable:!0,get:function(){return SQ.varKinds}});z0.operators={GT:new v._Code(">"),GTE:new v._Code(">="),LT:new v._Code("<"),LTE:new v._Code("<="),EQ:new v._Code("==="),NEQ:new v._Code("!=="),NOT:new v._Code("!"),OR:new v._Code("||"),AND:new v._Code("&&"),ADD:new v._Code("+")};class r0{optimizeNodes(){return this}optimizeNames(Q,X){return this}}class NY extends r0{constructor(Q,X,Y){super();this.varKind=Q,this.name=X,this.rhs=Y}render({es5:Q,_n:X}){let Y=Q?E0.varKinds.var:this.varKind,Z=this.rhs===void 0?"":` = ${this.rhs}`;return`${Y} ${this.name}${Z};`+X}optimizeNames(Q,X){if(!Q[this.name.str])return;if(this.rhs)this.rhs=u1(this.rhs,Q,X);return this}get names(){return this.rhs instanceof v._CodeOrName?this.rhs.names:{}}}class g6 extends r0{constructor(Q,X,Y){super();this.lhs=Q,this.rhs=X,this.sideEffects=Y}render({_n:Q}){return`${this.lhs} = ${this.rhs};`+Q}optimizeNames(Q,X){if(this.lhs instanceof v.Name&&!Q[this.lhs.str]&&!this.sideEffects)return;return this.rhs=u1(this.rhs,Q,X),this}get names(){let Q=this.lhs instanceof v.Name?{}:{...this.lhs.names};return CQ(Q,this.rhs)}}class RY extends g6{constructor(Q,X,Y,Z){super(Q,Y,Z);this.op=X}render({_n:Q}){return`${this.lhs} ${this.op}= ${this.rhs};`+Q}}class PY extends r0{constructor(Q){super();this.label=Q,this.names={}}render({_n:Q}){return`${this.label}:`+Q}}class IY extends r0{constructor(Q){super();this.label=Q,this.names={}}render({_n:Q}){return`break${this.label?` ${this.label}`:""};`+Q}}class TY extends r0{constructor(Q){super();this.error=Q}render({_n:Q}){return`throw ${this.error};`+Q}get names(){return this.error.names}}class EY extends r0{constructor(Q){super();this.code=Q}render({_n:Q}){return`${this.code};`+Q}optimizeNodes(){return`${this.code}`?this:void 0}optimizeNames(Q,X){return this.code=u1(this.code,Q,X),this}get names(){return this.code instanceof v._CodeOrName?this.code.names:{}}}class kQ extends r0{constructor(Q=[]){super();this.nodes=Q}render(Q){return this.nodes.reduce((X,Y)=>X+Y.render(Q),"")}optimizeNodes(){let{nodes:Q}=this,X=Q.length;while(X--){let Y=Q[X].optimizeNodes();if(Array.isArray(Y))Q.splice(X,1,...Y);else if(Y)Q[X]=Y;else Q.splice(X,1)}return Q.length>0?this:void 0}optimizeNames(Q,X){let{nodes:Y}=this,Z=Y.length;while(Z--){let W=Y[Z];if(W.optimizeNames(Q,X))continue;GK(Q,W.names),Y.splice(Z,1)}return Y.length>0?this:void 0}get names(){return this.nodes.reduce((Q,X)=>V1(Q,X.names),{})}}class t0 extends kQ{render(Q){return"{"+Q._n+super.render(Q)+"}"+Q._n}}class CY extends kQ{}class A9 extends t0{}A9.kind="else";class h0 extends t0{constructor(Q,X){super(X);this.condition=Q}render(Q){let X=`if(${this.condition})`+super.render(Q);if(this.else)X+="else "+this.else.render(Q);return X}optimizeNodes(){super.optimizeNodes();let Q=this.condition;if(Q===!0)return this.nodes;let X=this.else;if(X){let Y=X.optimizeNodes();X=this.else=Array.isArray(Y)?new A9(Y):Y}if(X){if(Q===!1)return X instanceof h0?X:X.nodes;if(this.nodes.length)return this;return new h0(_Y(Q),X instanceof h0?[X]:X.nodes)}if(Q===!1||!this.nodes.length)return;return this}optimizeNames(Q,X){var Y;if(this.else=(Y=this.else)===null||Y===void 0?void 0:Y.optimizeNames(Q,X),!(super.optimizeNames(Q,X)||this.else))return;return this.condition=u1(this.condition,Q,X),this}get names(){let Q=super.names;if(CQ(Q,this.condition),this.else)V1(Q,this.else.names);return Q}}h0.kind="if";class h1 extends t0{}h1.kind="for";class SY extends h1{constructor(Q){super();this.iteration=Q}render(Q){return`for(${this.iteration})`+super.render(Q)}optimizeNames(Q,X){if(!super.optimizeNames(Q,X))return;return this.iteration=u1(this.iteration,Q,X),this}get names(){return V1(super.names,this.iteration.names)}}class kY extends h1{constructor(Q,X,Y,Z){super();this.varKind=Q,this.name=X,this.from=Y,this.to=Z}render(Q){let X=Q.es5?E0.varKinds.var:this.varKind,{name:Y,from:Z,to:W}=this;return`for(${X} ${Y}=${Z}; ${Y}<${W}; ${Y}++)`+super.render(Q)}get names(){let Q=CQ(super.names,this.from);return CQ(Q,this.to)}}class f6 extends h1{constructor(Q,X,Y,Z){super();this.loop=Q,this.varKind=X,this.name=Y,this.iterable=Z}render(Q){return`for(${this.varKind} ${this.name} ${this.loop} ${this.iterable})`+super.render(Q)}optimizeNames(Q,X){if(!super.optimizeNames(Q,X))return;return this.iterable=u1(this.iterable,Q,X),this}get names(){return V1(super.names,this.iterable.names)}}class PQ extends t0{constructor(Q,X,Y){super();this.name=Q,this.args=X,this.async=Y}render(Q){return`${this.async?"async ":""}function ${this.name}(${this.args})`+super.render(Q)}}PQ.kind="func";class IQ extends kQ{render(Q){return"return "+super.render(Q)}}IQ.kind="return";class xY extends t0{render(Q){let X="try"+super.render(Q);if(this.catch)X+=this.catch.render(Q);if(this.finally)X+=this.finally.render(Q);return X}optimizeNodes(){var Q,X;return super.optimizeNodes(),(Q=this.catch)===null||Q===void 0||Q.optimizeNodes(),(X=this.finally)===null||X===void 0||X.optimizeNodes(),this}optimizeNames(Q,X){var Y,Z;return super.optimizeNames(Q,X),(Y=this.catch)===null||Y===void 0||Y.optimizeNames(Q,X),(Z=this.finally)===null||Z===void 0||Z.optimizeNames(Q,X),this}get names(){let Q=super.names;if(this.catch)V1(Q,this.catch.names);if(this.finally)V1(Q,this.finally.names);return Q}}class TQ extends t0{constructor(Q){super();this.error=Q}render(Q){return`catch(${this.error})`+super.render(Q)}}TQ.kind="catch";class EQ extends t0{render(Q){return"finally"+super.render(Q)}}EQ.kind="finally";class yY{constructor(Q,X={}){this._values={},this._blockStarts=[],this._constants={},this.opts={...X,_n:X.lines?`
2
2
  `:""},this._extScope=Q,this._scope=new E0.Scope({parent:Q}),this._nodes=[new CY]}toString(){return this._root.render(this.opts)}name(Q){return this._scope.name(Q)}scopeName(Q){return this._extScope.name(Q)}scopeValue(Q,X){let Y=this._extScope.value(Q,X);return(this._values[Y.prefix]||(this._values[Y.prefix]=new Set)).add(Y),Y}getScopeValue(Q,X){return this._extScope.getValue(Q,X)}scopeRefs(Q){return this._extScope.scopeRefs(Q,this._values)}scopeCode(){return this._extScope.scopeCode(this._values)}_def(Q,X,Y,Z){let W=this._scope.toName(X);if(Y!==void 0&&Z)this._constants[W.str]=Y;return this._leafNode(new NY(Q,W,Y)),W}const(Q,X,Y){return this._def(E0.varKinds.const,Q,X,Y)}let(Q,X,Y){return this._def(E0.varKinds.let,Q,X,Y)}var(Q,X,Y){return this._def(E0.varKinds.var,Q,X,Y)}assign(Q,X,Y){return this._leafNode(new g6(Q,X,Y))}add(Q,X){return this._leafNode(new RY(Q,z0.operators.ADD,X))}code(Q){if(typeof Q=="function")Q();else if(Q!==v.nil)this._leafNode(new EY(Q));return this}object(...Q){let X=["{"];for(let[Y,Z]of Q){if(X.length>1)X.push(",");if(X.push(Y),Y!==Z||this.opts.es5)X.push(":"),(0,v.addCodeArg)(X,Z)}return X.push("}"),new v._Code(X)}if(Q,X,Y){if(this._blockNode(new h0(Q)),X&&Y)this.code(X).else().code(Y).endIf();else if(X)this.code(X).endIf();else if(Y)throw Error('CodeGen: "else" body without "then" body');return this}elseIf(Q){return this._elseNode(new h0(Q))}else(){return this._elseNode(new A9)}endIf(){return this._endBlockNode(h0,A9)}_for(Q,X){if(this._blockNode(Q),X)this.code(X).endFor();return this}for(Q,X){return this._for(new SY(Q),X)}forRange(Q,X,Y,Z,W=this.opts.es5?E0.varKinds.var:E0.varKinds.let){let J=this._scope.toName(Q);return this._for(new kY(W,J,X,Y),()=>Z(J))}forOf(Q,X,Y,Z=E0.varKinds.const){let W=this._scope.toName(Q);if(this.opts.es5){let J=X instanceof v.Name?X:this.var("_arr",X);return this.forRange("_i",0,v._`${J}.length`,($)=>{this.var(W,v._`${J}[${$}]`),Y(W)})}return this._for(new f6("of",Z,W,X),()=>Y(W))}forIn(Q,X,Y,Z=this.opts.es5?E0.varKinds.var:E0.varKinds.const){if(this.opts.ownProperties)return this.forOf(Q,v._`Object.keys(${X})`,Y);let W=this._scope.toName(Q);return this._for(new f6("in",Z,W,X),()=>Y(W))}endFor(){return this._endBlockNode(h1)}label(Q){return this._leafNode(new PY(Q))}break(Q){return this._leafNode(new IY(Q))}return(Q){let X=new IQ;if(this._blockNode(X),this.code(Q),X.nodes.length!==1)throw Error('CodeGen: "return" should have one node');return this._endBlockNode(IQ)}try(Q,X,Y){if(!X&&!Y)throw Error('CodeGen: "try" without "catch" and "finally"');let Z=new xY;if(this._blockNode(Z),this.code(Q),X){let W=this.name("e");this._currNode=Z.catch=new TQ(W),X(W)}if(Y)this._currNode=Z.finally=new EQ,this.code(Y);return this._endBlockNode(TQ,EQ)}throw(Q){return this._leafNode(new TY(Q))}block(Q,X){if(this._blockStarts.push(this._nodes.length),Q)this.code(Q).endBlock(X);return this}endBlock(Q){let X=this._blockStarts.pop();if(X===void 0)throw Error("CodeGen: not in self-balancing block");let Y=this._nodes.length-X;if(Y<0||Q!==void 0&&Y!==Q)throw Error(`CodeGen: wrong number of nodes: ${Y} vs ${Q} expected`);return this._nodes.length=X,this}func(Q,X=v.nil,Y,Z){if(this._blockNode(new PQ(Q,X,Y)),Z)this.code(Z).endFunc();return this}endFunc(){return this._endBlockNode(PQ)}optimize(Q=1){while(Q-- >0)this._root.optimizeNodes(),this._root.optimizeNames(this._root.names,this._constants)}_leafNode(Q){return this._currNode.nodes.push(Q),this}_blockNode(Q){this._currNode.nodes.push(Q),this._nodes.push(Q)}_endBlockNode(Q,X){let Y=this._currNode;if(Y instanceof Q||X&&Y instanceof X)return this._nodes.pop(),this;throw Error(`CodeGen: not in block "${X?`${Q.kind}/${X.kind}`:Q.kind}"`)}_elseNode(Q){let X=this._currNode;if(!(X instanceof h0))throw Error('CodeGen: "else" without "if"');return this._currNode=X.else=Q,this}get _root(){return this._nodes[0]}get _currNode(){let Q=this._nodes;return Q[Q.length-1]}set _currNode(Q){let X=this._nodes;X[X.length-1]=Q}}z0.CodeGen=yY;function V1(Q,X){for(let Y in X)Q[Y]=(Q[Y]||0)+(X[Y]||0);return Q}function CQ(Q,X){return X instanceof v._CodeOrName?V1(Q,X.names):Q}function u1(Q,X,Y){if(Q instanceof v.Name)return Z(Q);if(!W(Q))return Q;return new v._Code(Q._items.reduce((J,$)=>{if($ instanceof v.Name)$=Z($);if($ instanceof v._Code)J.push(...$._items);else J.push($);return J},[]));function Z(J){let $=Y[J.str];if($===void 0||X[J.str]!==1)return J;return delete X[J.str],$}function W(J){return J instanceof v._Code&&J._items.some(($)=>$ instanceof v.Name&&X[$.str]===1&&Y[$.str]!==void 0)}}function GK(Q,X){for(let Y in X)Q[Y]=(Q[Y]||0)-(X[Y]||0)}function _Y(Q){return typeof Q=="boolean"||typeof Q=="number"||Q===null?!Q:v._`!${v6(Q)}`}z0.not=_Y;var KK=fY(z0.operators.AND);function BK(...Q){return Q.reduce(KK)}z0.and=BK;var FK=fY(z0.operators.OR);function HK(...Q){return Q.reduce(FK)}z0.or=HK;function fY(Q){return(X,Y)=>X===v.nil?Y:Y===v.nil?X:v._`${v6(X)} ${Q} ${v6(Y)}`}function v6(Q){return Q instanceof v.Name?Q:v._`(${Q})`}});var g=N((cY)=>{Object.defineProperty(cY,"__esModule",{value:!0});cY.checkStrictMode=cY.getErrorPath=cY.Type=cY.useFunc=cY.setEvaluated=cY.evaluatedPropsToName=cY.mergeEvaluated=cY.eachItem=cY.unescapeJsonPointer=cY.escapeJsonPointer=cY.escapeFragment=cY.unescapeFragment=cY.schemaRefOrVal=cY.schemaHasRulesButRef=cY.schemaHasRules=cY.checkUnknownRules=cY.alwaysValidSchema=cY.toHash=void 0;var m=_(),UK=q9();function zK(Q){let X={};for(let Y of Q)X[Y]=!0;return X}cY.toHash=zK;function qK(Q,X){if(typeof X=="boolean")return X;if(Object.keys(X).length===0)return!0;return uY(Q,X),!lY(X,Q.self.RULES.all)}cY.alwaysValidSchema=qK;function uY(Q,X=Q.schema){let{opts:Y,self:Z}=Q;if(!Y.strictSchema)return;if(typeof X==="boolean")return;let W=Z.RULES.keywords;for(let J in X)if(!W[J])dY(Q,`unknown keyword: "${J}"`)}cY.checkUnknownRules=uY;function lY(Q,X){if(typeof Q=="boolean")return!Q;for(let Y in Q)if(X[Y])return!0;return!1}cY.schemaHasRules=lY;function AK(Q,X){if(typeof Q=="boolean")return!Q;for(let Y in Q)if(Y!=="$ref"&&X.all[Y])return!0;return!1}cY.schemaHasRulesButRef=AK;function jK({topSchemaRef:Q,schemaPath:X},Y,Z,W){if(!W){if(typeof Y=="number"||typeof Y=="boolean")return Y;if(typeof Y=="string")return m._`${Y}`}return m._`${Q}${X}${(0,m.getProperty)(Z)}`}cY.schemaRefOrVal=jK;function DK(Q){return mY(decodeURIComponent(Q))}cY.unescapeFragment=DK;function MK(Q){return encodeURIComponent(u6(Q))}cY.escapeFragment=MK;function u6(Q){if(typeof Q=="number")return`${Q}`;return Q.replace(/~/g,"~0").replace(/\//g,"~1")}cY.escapeJsonPointer=u6;function mY(Q){return Q.replace(/~1/g,"/").replace(/~0/g,"~")}cY.unescapeJsonPointer=mY;function bK(Q,X){if(Array.isArray(Q))for(let Y of Q)X(Y);else X(Q)}cY.eachItem=bK;function gY({mergeNames:Q,mergeToName:X,mergeValues:Y,resultToName:Z}){return(W,J,$,G)=>{let K=$===void 0?J:$ instanceof m.Name?(J instanceof m.Name?Q(W,J,$):X(W,J,$),$):J instanceof m.Name?(X(W,$,J),J):Y(J,$);return G===m.Name&&!(K instanceof m.Name)?Z(W,K):K}}cY.mergeEvaluated={props:gY({mergeNames:(Q,X,Y)=>Q.if(m._`${Y} !== true && ${X} !== undefined`,()=>{Q.if(m._`${X} === true`,()=>Q.assign(Y,!0),()=>Q.assign(Y,m._`${Y} || {}`).code(m._`Object.assign(${Y}, ${X})`))}),mergeToName:(Q,X,Y)=>Q.if(m._`${Y} !== true`,()=>{if(X===!0)Q.assign(Y,!0);else Q.assign(Y,m._`${Y} || {}`),l6(Q,Y,X)}),mergeValues:(Q,X)=>Q===!0?!0:{...Q,...X},resultToName:pY}),items:gY({mergeNames:(Q,X,Y)=>Q.if(m._`${Y} !== true && ${X} !== undefined`,()=>Q.assign(Y,m._`${X} === true ? true : ${Y} > ${X} ? ${Y} : ${X}`)),mergeToName:(Q,X,Y)=>Q.if(m._`${Y} !== true`,()=>Q.assign(Y,X===!0?!0:m._`${Y} > ${X} ? ${Y} : ${X}`)),mergeValues:(Q,X)=>Q===!0?!0:Math.max(Q,X),resultToName:(Q,X)=>Q.var("items",X)})};function pY(Q,X){if(X===!0)return Q.var("props",!0);let Y=Q.var("props",m._`{}`);if(X!==void 0)l6(Q,Y,X);return Y}cY.evaluatedPropsToName=pY;function l6(Q,X,Y){Object.keys(Y).forEach((Z)=>Q.assign(m._`${X}${(0,m.getProperty)(Z)}`,!0))}cY.setEvaluated=l6;var hY={};function wK(Q,X){return Q.scopeValue("func",{ref:X,code:hY[X.code]||(hY[X.code]=new UK._Code(X.code))})}cY.useFunc=wK;var h6;(function(Q){Q[Q.Num=0]="Num",Q[Q.Str=1]="Str"})(h6||(cY.Type=h6={}));function NK(Q,X,Y){if(Q instanceof m.Name){let Z=X===h6.Num;return Y?Z?m._`"[" + ${Q} + "]"`:m._`"['" + ${Q} + "']"`:Z?m._`"/" + ${Q}`:m._`"/" + ${Q}.replace(/~/g, "~0").replace(/\\//g, "~1")`}return Y?(0,m.getProperty)(Q).toString():"/"+u6(Q)}cY.getErrorPath=NK;function dY(Q,X,Y=Q.opts.strictSchema){if(!Y)return;if(X=`strict mode: ${X}`,Y===!0)throw Error(X);Q.self.logger.warn(X)}cY.checkStrictMode=dY});var u0=N((nY)=>{Object.defineProperty(nY,"__esModule",{value:!0});var K0=_(),mK={data:new K0.Name("data"),valCxt:new K0.Name("valCxt"),instancePath:new K0.Name("instancePath"),parentData:new K0.Name("parentData"),parentDataProperty:new K0.Name("parentDataProperty"),rootData:new K0.Name("rootData"),dynamicAnchors:new K0.Name("dynamicAnchors"),vErrors:new K0.Name("vErrors"),errors:new K0.Name("errors"),this:new K0.Name("this"),self:new K0.Name("self"),scope:new K0.Name("scope"),json:new K0.Name("json"),jsonPos:new K0.Name("jsonPos"),jsonLen:new K0.Name("jsonLen"),jsonPart:new K0.Name("jsonPart")};nY.default=mK});var j9=N((rY)=>{Object.defineProperty(rY,"__esModule",{value:!0});rY.extendErrors=rY.resetErrorsCount=rY.reportExtraError=rY.reportError=rY.keyword$DataError=rY.keywordError=void 0;var h=_(),yQ=g(),F0=u0();rY.keywordError={message:({keyword:Q})=>h.str`must pass "${Q}" keyword validation`};rY.keyword$DataError={message:({keyword:Q,schemaType:X})=>X?h.str`"${Q}" keyword must be ${X} ($data)`:h.str`"${Q}" keyword is invalid ($data)`};function dK(Q,X=rY.keywordError,Y,Z){let{it:W}=Q,{gen:J,compositeRule:$,allErrors:G}=W,K=oY(Q,X,Y);if(Z!==null&&Z!==void 0?Z:$||G)sY(J,K);else aY(W,h._`[${K}]`)}rY.reportError=dK;function cK(Q,X=rY.keywordError,Y){let{it:Z}=Q,{gen:W,compositeRule:J,allErrors:$}=Z,G=oY(Q,X,Y);if(sY(W,G),!(J||$))aY(Z,F0.default.vErrors)}rY.reportExtraError=cK;function iK(Q,X){Q.assign(F0.default.errors,X),Q.if(h._`${F0.default.vErrors} !== null`,()=>Q.if(X,()=>Q.assign(h._`${F0.default.vErrors}.length`,X),()=>Q.assign(F0.default.vErrors,null)))}rY.resetErrorsCount=iK;function nK({gen:Q,keyword:X,schemaValue:Y,data:Z,errsCount:W,it:J}){if(W===void 0)throw Error("ajv implementation error");let $=Q.name("err");Q.forRange("i",W,F0.default.errors,(G)=>{if(Q.const($,h._`${F0.default.vErrors}[${G}]`),Q.if(h._`${$}.instancePath === undefined`,()=>Q.assign(h._`${$}.instancePath`,(0,h.strConcat)(F0.default.instancePath,J.errorPath))),Q.assign(h._`${$}.schemaPath`,h.str`${J.errSchemaPath}/${X}`),J.opts.verbose)Q.assign(h._`${$}.schema`,Y),Q.assign(h._`${$}.data`,Z)})}rY.extendErrors=nK;function sY(Q,X){let Y=Q.const("err",X);Q.if(h._`${F0.default.vErrors} === null`,()=>Q.assign(F0.default.vErrors,h._`[${Y}]`),h._`${F0.default.vErrors}.push(${Y})`),Q.code(h._`${F0.default.errors}++`)}function aY(Q,X){let{gen:Y,validateName:Z,schemaEnv:W}=Q;if(W.$async)Y.throw(h._`new ${Q.ValidationError}(${X})`);else Y.assign(h._`${Z}.errors`,X),Y.return(!1)}var L1={keyword:new h.Name("keyword"),schemaPath:new h.Name("schemaPath"),params:new h.Name("params"),propertyName:new h.Name("propertyName"),message:new h.Name("message"),schema:new h.Name("schema"),parentSchema:new h.Name("parentSchema")};function oY(Q,X,Y){let{createErrors:Z}=Q.it;if(Z===!1)return h._`{}`;return sK(Q,X,Y)}function sK(Q,X,Y={}){let{gen:Z,it:W}=Q,J=[aK(W,Y),oK(Q,Y)];return rK(Q,X,J),Z.object(...J)}function aK({errorPath:Q},{instancePath:X}){let Y=X?h.str`${Q}${(0,yQ.getErrorPath)(X,yQ.Type.Str)}`:Q;return[F0.default.instancePath,(0,h.strConcat)(F0.default.instancePath,Y)]}function oK({keyword:Q,it:{errSchemaPath:X}},{schemaPath:Y,parentSchema:Z}){let W=Z?X:h.str`${X}/${Q}`;if(Y)W=h.str`${W}${(0,yQ.getErrorPath)(Y,yQ.Type.Str)}`;return[L1.schemaPath,W]}function rK(Q,{params:X,message:Y},Z){let{keyword:W,data:J,schemaValue:$,it:G}=Q,{opts:K,propertyName:B,topSchemaRef:F,schemaPath:H}=G;if(Z.push([L1.keyword,W],[L1.params,typeof X=="function"?X(Q):X||h._`{}`]),K.messages)Z.push([L1.message,typeof Y=="function"?Y(Q):Y]);if(K.verbose)Z.push([L1.schema,$],[L1.parentSchema,h._`${F}${H}`],[F0.default.data,J]);if(B)Z.push([L1.propertyName,B])}});var Y7=N((Q7)=>{Object.defineProperty(Q7,"__esModule",{value:!0});Q7.boolOrEmptySchema=Q7.topBoolOrEmptySchema=void 0;var YB=j9(),ZB=_(),WB=u0(),JB={message:"boolean schema is false"};function $B(Q){let{gen:X,schema:Y,validateName:Z}=Q;if(Y===!1)eY(Q,!1);else if(typeof Y=="object"&&Y.$async===!0)X.return(WB.default.data);else X.assign(ZB._`${Z}.errors`,null),X.return(!0)}Q7.topBoolOrEmptySchema=$B;function GB(Q,X){let{gen:Y,schema:Z}=Q;if(Z===!1)Y.var(X,!1),eY(Q);else Y.var(X,!0)}Q7.boolOrEmptySchema=GB;function eY(Q,X){let{gen:Y,data:Z}=Q,W={gen:Y,keyword:"false schema",data:Z,schema:!1,schemaCode:!1,schemaValue:!1,params:{},it:Q};(0,YB.reportError)(W,JB,void 0,X)}});var p6=N((Z7)=>{Object.defineProperty(Z7,"__esModule",{value:!0});Z7.getRules=Z7.isJSONType=void 0;var BB=["string","number","integer","boolean","null","object","array"],FB=new Set(BB);function HB(Q){return typeof Q=="string"&&FB.has(Q)}Z7.isJSONType=HB;function VB(){let Q={number:{type:"number",rules:[]},string:{type:"string",rules:[]},array:{type:"array",rules:[]},object:{type:"object",rules:[]}};return{types:{...Q,integer:!0,boolean:!0,null:!0},rules:[{rules:[]},Q.number,Q.string,Q.array,Q.object],post:{rules:[]},all:{},keywords:{}}}Z7.getRules=VB});var d6=N((G7)=>{Object.defineProperty(G7,"__esModule",{value:!0});G7.shouldUseRule=G7.shouldUseGroup=G7.schemaHasRulesForType=void 0;function OB({schema:Q,self:X},Y){let Z=X.RULES.types[Y];return Z&&Z!==!0&&J7(Q,Z)}G7.schemaHasRulesForType=OB;function J7(Q,X){return X.rules.some((Y)=>$7(Q,Y))}G7.shouldUseGroup=J7;function $7(Q,X){var Y;return Q[X.keyword]!==void 0||((Y=X.definition.implements)===null||Y===void 0?void 0:Y.some((Z)=>Q[Z]!==void 0))}G7.shouldUseRule=$7});var D9=N((V7)=>{Object.defineProperty(V7,"__esModule",{value:!0});V7.reportTypeError=V7.checkDataTypes=V7.checkDataType=V7.coerceAndCheckDataType=V7.getJSONTypes=V7.getSchemaTypes=V7.DataType=void 0;var qB=p6(),AB=d6(),jB=j9(),x=_(),B7=g(),l1;(function(Q){Q[Q.Correct=0]="Correct",Q[Q.Wrong=1]="Wrong"})(l1||(V7.DataType=l1={}));function DB(Q){let X=F7(Q.type);if(X.includes("null")){if(Q.nullable===!1)throw Error("type: null contradicts nullable: false")}else{if(!X.length&&Q.nullable!==void 0)throw Error('"nullable" cannot be used without "type"');if(Q.nullable===!0)X.push("null")}return X}V7.getSchemaTypes=DB;function F7(Q){let X=Array.isArray(Q)?Q:Q?[Q]:[];if(X.every(qB.isJSONType))return X;throw Error("type must be JSONType or JSONType[]: "+X.join(","))}V7.getJSONTypes=F7;function MB(Q,X){let{gen:Y,data:Z,opts:W}=Q,J=bB(X,W.coerceTypes),$=X.length>0&&!(J.length===0&&X.length===1&&(0,AB.schemaHasRulesForType)(Q,X[0]));if($){let G=i6(X,Z,W.strictNumbers,l1.Wrong);Y.if(G,()=>{if(J.length)wB(Q,X,J);else n6(Q)})}return $}V7.coerceAndCheckDataType=MB;var H7=new Set(["string","number","integer","boolean","null"]);function bB(Q,X){return X?Q.filter((Y)=>H7.has(Y)||X==="array"&&Y==="array"):[]}function wB(Q,X,Y){let{gen:Z,data:W,opts:J}=Q,$=Z.let("dataType",x._`typeof ${W}`),G=Z.let("coerced",x._`undefined`);if(J.coerceTypes==="array")Z.if(x._`${$} == 'object' && Array.isArray(${W}) && ${W}.length == 1`,()=>Z.assign(W,x._`${W}[0]`).assign($,x._`typeof ${W}`).if(i6(X,W,J.strictNumbers),()=>Z.assign(G,W)));Z.if(x._`${G} !== undefined`);for(let B of Y)if(H7.has(B)||B==="array"&&J.coerceTypes==="array")K(B);Z.else(),n6(Q),Z.endIf(),Z.if(x._`${G} !== undefined`,()=>{Z.assign(W,G),NB(Q,G)});function K(B){switch(B){case"string":Z.elseIf(x._`${$} == "number" || ${$} == "boolean"`).assign(G,x._`"" + ${W}`).elseIf(x._`${W} === null`).assign(G,x._`""`);return;case"number":Z.elseIf(x._`${$} == "boolean" || ${W} === null
3
3
  || (${$} == "string" && ${W} && ${W} == +${W})`).assign(G,x._`+${W}`);return;case"integer":Z.elseIf(x._`${$} === "boolean" || ${W} === null
4
4
  || (${$} === "string" && ${W} && ${W} == +${W} && !(${W} % 1))`).assign(G,x._`+${W}`);return;case"boolean":Z.elseIf(x._`${W} === "false" || ${W} === 0 || ${W} === null`).assign(G,!1).elseIf(x._`${W} === "true" || ${W} === 1`).assign(G,!0);return;case"null":Z.elseIf(x._`${W} === "" || ${W} === 0 || ${W} === false`),Z.assign(G,null);return;case"array":Z.elseIf(x._`${$} === "string" || ${$} === "number"
@@ -1 +1 @@
1
- import{e as x,f as I}from"./chunk-akc3s5aw.js";import"./chunk-b0beqmg2.js";import{Ag as w,Cg as v,sg as C,ug as T,zg as b}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 K}from"./chunk-4fs853nh.js";var W=K(I(),1),g=[{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_blobs",prefix:"checkpoint_blob:",schema:{"$.thread_id":{type:"TAG",AS:"thread_id"},"$.checkpoint_ns":{type:"TAG",AS:"checkpoint_ns"},"$.checkpoint_id":{type:"TAG",AS:"checkpoint_id"},"$.channel":{type:"TAG",AS:"channel"},"$.version":{type:"TAG",AS:"version"},"$.type":{type:"TAG",AS:"type"}}},{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"}}}],f=class z extends w{client;ttlConfig;constructor(G,J){super();this.client=G,this.ttlConfig=J}static async fromUrl(G,J){let Z=W.createClient({url:G});await Z.connect();let Q=new z(Z,J);return await Q.ensureIndexes(),Q}static async fromCluster(G,J){let Z=W.createCluster({rootNodes:G});await Z.connect();let Q=new z(Z,J);return await Q.ensureIndexes(),Q}async get(G){return(await this.getTuple(G))?.checkpoint}async getTuple(G){let J=G.configurable?.thread_id,Z=G.configurable?.checkpoint_ns??"",Q=G.configurable?.checkpoint_id;if(!J)return;let Y,E;if(Q)Y=`checkpoint:${J}:${Z}:${Q}`,E=await this.client.json.get(Y);else{let $=`checkpoint:${J}:${Z}:*`,_=await this.client.keys($);if(_.length===0)return;_.sort(),Y=_[_.length-1],E=await this.client.json.get(Y)}if(!E)return;if(this.ttlConfig?.refreshOnRead&&this.ttlConfig?.defaultTTL)await this.applyTTL(Y);let{checkpoint:F,pendingWrites:X}=await this.loadCheckpointWithWrites(E);return await this.createCheckpointTuple(E,F,X)}async put(G,J,Z,Q){await this.ensureIndexes();let Y=G.configurable?.thread_id,E=G.configurable?.checkpoint_ns??"",F=G.configurable?.checkpoint_id;if(!Y)throw Error("thread_id is required");let X=J.id||C(0),$=`checkpoint:${Y}:${E}:${X}`,_=b(J);if(_.channel_values&&Q!==void 0)if(Object.keys(Q).length===0)_.channel_values={};else{let U={};for(let B of Object.keys(Q))if(B in _.channel_values)U[B]=_.channel_values[B];_.channel_values=U}let H={thread_id:Y,checkpoint_ns:E===""?"__empty__":E,checkpoint_id:X,parent_checkpoint_id:F||null,checkpoint:_,metadata:Z,checkpoint_ts:Date.now(),has_writes:"false"};if(this.addSearchableMetadataFields(H,Z),await this.client.json.set($,"$",H),this.ttlConfig?.defaultTTL)await this.applyTTL($);return{configurable:{thread_id:Y,checkpoint_ns:E,checkpoint_id:X}}}async*list(G,J){if(await this.ensureIndexes(),J?.filter!==void 0){let Q=Object.values(J.filter).some((X)=>X===null),Y=[];if(G?.configurable?.thread_id){let X=G.configurable.thread_id.replace(/[-.@]/g,"\\$&");Y.push(`(@thread_id:{${X}})`)}if(G?.configurable?.checkpoint_ns!==void 0){let X=G.configurable.checkpoint_ns;if(X==="")Y.push("(@checkpoint_ns:{__empty__})");else{let $=X.replace(/[-.@]/g,"\\$&");Y.push(`(@checkpoint_ns:{${$}})`)}}if(!J?.before&&J?.filter){for(let[X,$]of Object.entries(J.filter))if($===void 0);else if($===null);else if(typeof $==="string"){let _=x(X),H=x($);Y.push(`(@${_}:{${H}})`)}else if(typeof $==="number"){let _=x(X);Y.push(`(@${_}:[${$} ${$}])`)}else if(typeof $==="object"&&Object.keys($).length===0);}if(Y.length===0)Y.push("*");let E=Y.join(" "),F=J?.limit??10;try{let X=J?.before&&!G?.configurable?.thread_id?1000:J?.before?F*10:F,$=(await this.client.ft.search("checkpoints",E,{LIMIT:{from:0,size:X},SORTBY:{BY:"checkpoint_ts",DIRECTION:"DESC"}})).documents,_=0;for(let H of $){if(_>=F)break;if(J?.before?.configurable?.checkpoint_id){if(H.value.checkpoint_id>=J.before.configurable.checkpoint_id)continue}let U=H.value,B=!0;if((Q||J?.before)&&J?.filter){for(let[M,O]of Object.entries(J.filter))if(O===null){if(U.metadata?.[M]!==null){B=!1;break}}else if(O!==void 0){let A=U.metadata?.[M];if(typeof O==="object"&&O!==null){if(q(A)!==q(O)){B=!1;break}}else if(A!==O){B=!1;break}}if(!B)continue}let{checkpoint:L,pendingWrites:R}=await this.loadCheckpointWithWrites(U);yield await this.createCheckpointTuple(U,L,R),_++}return}catch(X){if(X.message?.includes("no such index"));else throw X}if(G?.configurable?.thread_id){let X=G.configurable.thread_id,$=G.configurable.checkpoint_ns??"",_=`checkpoint:${X}:${$}:*`,H=await this.client.keys(_);H.sort().reverse();let U=H;if(J?.before?.configurable?.checkpoint_id){let R=`checkpoint:${J.before.configurable.thread_id||X}:${J.before.configurable.checkpoint_ns??$}:${J.before.configurable.checkpoint_id}`,M=H.indexOf(R);if(M>0)U=H.slice(M+1);else if(M===0)U=[]}let B=J?.limit??10,L=U.slice(0,B);for(let R of L){let M=await this.client.json.get(R);if(M){let O=!0;for(let[V,S]of Object.entries(J.filter)){let N=M.metadata?.[V];if(S===null){if(N!==null){O=!1;break}}else if(N!==S){O=!1;break}}if(!O)continue;let{checkpoint:A,pendingWrites:P}=await this.loadCheckpointWithWrites(M);yield await this.createCheckpointTuple(M,A,P)}}}else{let X=G?.configurable?.checkpoint_ns!==void 0?`checkpoint:*:${G.configurable.checkpoint_ns===""?"__empty__":G.configurable.checkpoint_ns}:*`:"checkpoint:*",$=await this.client.keys(X),_=[];for(let B of $){let L=await this.client.json.get(B);if(L)_.push({key:B,doc:L})}_.sort((B,L)=>L.doc.checkpoint_ts-B.doc.checkpoint_ts);let H=0,U=J?.limit??10;for(let{doc:B}of _){if(H>=U)break;if(J?.before?.configurable?.checkpoint_id){if(B.checkpoint_id>=J.before.configurable.checkpoint_id)continue}let L=!0;if(J?.filter){for(let[O,A]of Object.entries(J.filter))if(A===null){if(B.metadata?.[O]!==null){L=!1;break}}else if(A!==void 0){let P=B.metadata?.[O];if(typeof A==="object"&&A!==null){if(q(P)!==q(A)){L=!1;break}}else if(P!==A){L=!1;break}}if(!L)continue}let{checkpoint:R,pendingWrites:M}=await this.loadCheckpointWithWrites(B);yield await this.createCheckpointTuple(B,R,M),H++}}return}let Z={...J,filter:{}};yield*this.list(G,Z)}async putWrites(G,J,Z){await this.ensureIndexes();let Q=G.configurable?.thread_id,Y=G.configurable?.checkpoint_ns??"",E=G.configurable?.checkpoint_id;if(!Q||!E)throw Error("thread_id and checkpoint_id are required");let F=[],X=performance.now()*1000;for(let _=0;_<J.length;_++){let[H,U]=J[_],B=`checkpoint_write:${Q}:${Y}:${E}:${Z}:${_}`;F.push(B);let L={thread_id:Q,checkpoint_ns:Y,checkpoint_id:E,task_id:Z,idx:_,channel:H,type:typeof U==="object"?"json":"string",value:U,timestamp:X,global_idx:X+_};await this.client.json.set(B,"$",L)}if(F.length>0){let _=`write_keys_zset:${Q}:${Y}:${E}`,H={};if(F.forEach((U,B)=>{H[U]=X+B}),await this.client.zAdd(_,Object.entries(H).map(([U,B])=>({score:B,value:U}))),this.ttlConfig?.defaultTTL)await this.applyTTL(...F,_)}let $=`checkpoint:${Q}:${Y}:${E}`;if(await this.client.exists($)){let _=await this.client.json.get($);if(_)_.has_writes="true",await this.client.json.set($,"$",_)}}async deleteThread(G){let J=`checkpoint:${G}:*`,Z=await this.client.keys(J);if(Z.length>0)await this.client.del(Z);let Q=`writes:${G}:*`,Y=await this.client.keys(Q);if(Y.length>0)await this.client.del(Y)}async end(){await this.client.quit()}async loadPendingWrites(G,J,Z){let Q=`checkpoint_write:${G}:${J}:${Z}:*`,Y=await this.client.keys(Q);if(Y.length===0)return;let E=[];for(let X of Y){let $=await this.client.json.get(X);if($)E.push($)}E.sort((X,$)=>(X.global_idx||0)-($.global_idx||0));let F=[];for(let X of E){let $=await this.serde.loadsTyped("json",JSON.stringify(X.value));F.push([X.task_id,X.channel,$])}return F}async loadCheckpointWithWrites(G){let J=await this.serde.loadsTyped("json",JSON.stringify(G.checkpoint));if(J.v<4&&G.parent_checkpoint_id!=null){let Q=G.checkpoint_ns==="__empty__"?"":G.checkpoint_ns;await this.migratePendingSends(J,G.thread_id,Q,G.parent_checkpoint_id)}let Z;if(G.has_writes==="true"){let Q=G.checkpoint_ns==="__empty__"?"":G.checkpoint_ns;Z=await this.loadPendingWrites(G.thread_id,Q,G.checkpoint_id)}return{checkpoint:J,pendingWrites:Z}}async migratePendingSends(G,J,Z,Q){let Y=await this.loadPendingWrites(J,Z,Q);if(!Y||Y.length===0)return;let E=Y.filter(([,X])=>X===T);if(E.length===0)return;let F=[];for(let[,,X]of E)F.push(X);G.channel_values??={},G.channel_values[T]=F,G.channel_versions[T]=Object.keys(G.channel_versions).length>0?v(...Object.values(G.channel_versions)):1}async createCheckpointTuple(G,J,Z){let Q=G.checkpoint_ns==="__empty__"?"":G.checkpoint_ns,Y=await this.serde.loadsTyped("json",JSON.stringify(G.metadata));return{config:{configurable:{thread_id:G.thread_id,checkpoint_ns:Q,checkpoint_id:G.checkpoint_id}},checkpoint:J,metadata:Y,parentConfig:G.parent_checkpoint_id?{configurable:{thread_id:G.thread_id,checkpoint_ns:Q,checkpoint_id:G.parent_checkpoint_id}}:void 0,pendingWrites:Z}}addSearchableMetadataFields(G,J){if(!J)return;if("source"in J)G.source=J.source;if("step"in J)G.step=J.step;if("writes"in J)G.writes=typeof J.writes==="object"?JSON.stringify(J.writes):J.writes;if("score"in J)G.score=J.score}async applyTTL(...G){if(!this.ttlConfig?.defaultTTL)return;let J=Math.floor(this.ttlConfig.defaultTTL*60),Z=await Promise.allSettled(G.map((Q)=>this.client.expire(Q,J)));for(let Q=0;Q<Z.length;Q++)if(Z[Q].status==="rejected")console.warn(`Failed to set TTL for key ${G[Q]}:`,Z[Q].reason)}async ensureIndexes(){for(let G of g)try{await this.client.ft.create(G.index,G.schema,{ON:"JSON",PREFIX:G.prefix})}catch(J){if(!J.message?.includes("Index already exists"))console.error(`Failed to create index ${G.index}:`,J.message)}}};function q(z){if(z===null||typeof z!=="object")return JSON.stringify(z);if(Array.isArray(z))return JSON.stringify(z.map((Z)=>q(Z)));let G={},J=Object.keys(z).sort();for(let Z of J)G[Z]=z[Z];return JSON.stringify(G,(Z,Q)=>{if(Q!==null&&typeof Q==="object"&&!Array.isArray(Q)){let Y={},E=Object.keys(Q).sort();for(let F of E)Y[F]=Q[F];return Y}return Q})}export{f as RedisSaver};
1
+ import{e as x,f as I}from"./chunk-q0452p0f.js";import"./chunk-pffdbhs6.js";import{Ag as w,Cg as v,sg as C,ug as T,zg as b}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 K}from"./chunk-x17jyjan.js";var W=K(I(),1),g=[{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_blobs",prefix:"checkpoint_blob:",schema:{"$.thread_id":{type:"TAG",AS:"thread_id"},"$.checkpoint_ns":{type:"TAG",AS:"checkpoint_ns"},"$.checkpoint_id":{type:"TAG",AS:"checkpoint_id"},"$.channel":{type:"TAG",AS:"channel"},"$.version":{type:"TAG",AS:"version"},"$.type":{type:"TAG",AS:"type"}}},{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"}}}],f=class z extends w{client;ttlConfig;constructor(G,J){super();this.client=G,this.ttlConfig=J}static async fromUrl(G,J){let Z=W.createClient({url:G});await Z.connect();let Q=new z(Z,J);return await Q.ensureIndexes(),Q}static async fromCluster(G,J){let Z=W.createCluster({rootNodes:G});await Z.connect();let Q=new z(Z,J);return await Q.ensureIndexes(),Q}async get(G){return(await this.getTuple(G))?.checkpoint}async getTuple(G){let J=G.configurable?.thread_id,Z=G.configurable?.checkpoint_ns??"",Q=G.configurable?.checkpoint_id;if(!J)return;let Y,E;if(Q)Y=`checkpoint:${J}:${Z}:${Q}`,E=await this.client.json.get(Y);else{let $=`checkpoint:${J}:${Z}:*`,_=await this.client.keys($);if(_.length===0)return;_.sort(),Y=_[_.length-1],E=await this.client.json.get(Y)}if(!E)return;if(this.ttlConfig?.refreshOnRead&&this.ttlConfig?.defaultTTL)await this.applyTTL(Y);let{checkpoint:F,pendingWrites:X}=await this.loadCheckpointWithWrites(E);return await this.createCheckpointTuple(E,F,X)}async put(G,J,Z,Q){await this.ensureIndexes();let Y=G.configurable?.thread_id,E=G.configurable?.checkpoint_ns??"",F=G.configurable?.checkpoint_id;if(!Y)throw Error("thread_id is required");let X=J.id||C(0),$=`checkpoint:${Y}:${E}:${X}`,_=b(J);if(_.channel_values&&Q!==void 0)if(Object.keys(Q).length===0)_.channel_values={};else{let U={};for(let B of Object.keys(Q))if(B in _.channel_values)U[B]=_.channel_values[B];_.channel_values=U}let H={thread_id:Y,checkpoint_ns:E===""?"__empty__":E,checkpoint_id:X,parent_checkpoint_id:F||null,checkpoint:_,metadata:Z,checkpoint_ts:Date.now(),has_writes:"false"};if(this.addSearchableMetadataFields(H,Z),await this.client.json.set($,"$",H),this.ttlConfig?.defaultTTL)await this.applyTTL($);return{configurable:{thread_id:Y,checkpoint_ns:E,checkpoint_id:X}}}async*list(G,J){if(await this.ensureIndexes(),J?.filter!==void 0){let Q=Object.values(J.filter).some((X)=>X===null),Y=[];if(G?.configurable?.thread_id){let X=G.configurable.thread_id.replace(/[-.@]/g,"\\$&");Y.push(`(@thread_id:{${X}})`)}if(G?.configurable?.checkpoint_ns!==void 0){let X=G.configurable.checkpoint_ns;if(X==="")Y.push("(@checkpoint_ns:{__empty__})");else{let $=X.replace(/[-.@]/g,"\\$&");Y.push(`(@checkpoint_ns:{${$}})`)}}if(!J?.before&&J?.filter){for(let[X,$]of Object.entries(J.filter))if($===void 0);else if($===null);else if(typeof $==="string"){let _=x(X),H=x($);Y.push(`(@${_}:{${H}})`)}else if(typeof $==="number"){let _=x(X);Y.push(`(@${_}:[${$} ${$}])`)}else if(typeof $==="object"&&Object.keys($).length===0);}if(Y.length===0)Y.push("*");let E=Y.join(" "),F=J?.limit??10;try{let X=J?.before&&!G?.configurable?.thread_id?1000:J?.before?F*10:F,$=(await this.client.ft.search("checkpoints",E,{LIMIT:{from:0,size:X},SORTBY:{BY:"checkpoint_ts",DIRECTION:"DESC"}})).documents,_=0;for(let H of $){if(_>=F)break;if(J?.before?.configurable?.checkpoint_id){if(H.value.checkpoint_id>=J.before.configurable.checkpoint_id)continue}let U=H.value,B=!0;if((Q||J?.before)&&J?.filter){for(let[M,O]of Object.entries(J.filter))if(O===null){if(U.metadata?.[M]!==null){B=!1;break}}else if(O!==void 0){let A=U.metadata?.[M];if(typeof O==="object"&&O!==null){if(q(A)!==q(O)){B=!1;break}}else if(A!==O){B=!1;break}}if(!B)continue}let{checkpoint:L,pendingWrites:R}=await this.loadCheckpointWithWrites(U);yield await this.createCheckpointTuple(U,L,R),_++}return}catch(X){if(X.message?.includes("no such index"));else throw X}if(G?.configurable?.thread_id){let X=G.configurable.thread_id,$=G.configurable.checkpoint_ns??"",_=`checkpoint:${X}:${$}:*`,H=await this.client.keys(_);H.sort().reverse();let U=H;if(J?.before?.configurable?.checkpoint_id){let R=`checkpoint:${J.before.configurable.thread_id||X}:${J.before.configurable.checkpoint_ns??$}:${J.before.configurable.checkpoint_id}`,M=H.indexOf(R);if(M>0)U=H.slice(M+1);else if(M===0)U=[]}let B=J?.limit??10,L=U.slice(0,B);for(let R of L){let M=await this.client.json.get(R);if(M){let O=!0;for(let[V,S]of Object.entries(J.filter)){let N=M.metadata?.[V];if(S===null){if(N!==null){O=!1;break}}else if(N!==S){O=!1;break}}if(!O)continue;let{checkpoint:A,pendingWrites:P}=await this.loadCheckpointWithWrites(M);yield await this.createCheckpointTuple(M,A,P)}}}else{let X=G?.configurable?.checkpoint_ns!==void 0?`checkpoint:*:${G.configurable.checkpoint_ns===""?"__empty__":G.configurable.checkpoint_ns}:*`:"checkpoint:*",$=await this.client.keys(X),_=[];for(let B of $){let L=await this.client.json.get(B);if(L)_.push({key:B,doc:L})}_.sort((B,L)=>L.doc.checkpoint_ts-B.doc.checkpoint_ts);let H=0,U=J?.limit??10;for(let{doc:B}of _){if(H>=U)break;if(J?.before?.configurable?.checkpoint_id){if(B.checkpoint_id>=J.before.configurable.checkpoint_id)continue}let L=!0;if(J?.filter){for(let[O,A]of Object.entries(J.filter))if(A===null){if(B.metadata?.[O]!==null){L=!1;break}}else if(A!==void 0){let P=B.metadata?.[O];if(typeof A==="object"&&A!==null){if(q(P)!==q(A)){L=!1;break}}else if(P!==A){L=!1;break}}if(!L)continue}let{checkpoint:R,pendingWrites:M}=await this.loadCheckpointWithWrites(B);yield await this.createCheckpointTuple(B,R,M),H++}}return}let Z={...J,filter:{}};yield*this.list(G,Z)}async putWrites(G,J,Z){await this.ensureIndexes();let Q=G.configurable?.thread_id,Y=G.configurable?.checkpoint_ns??"",E=G.configurable?.checkpoint_id;if(!Q||!E)throw Error("thread_id and checkpoint_id are required");let F=[],X=performance.now()*1000;for(let _=0;_<J.length;_++){let[H,U]=J[_],B=`checkpoint_write:${Q}:${Y}:${E}:${Z}:${_}`;F.push(B);let L={thread_id:Q,checkpoint_ns:Y,checkpoint_id:E,task_id:Z,idx:_,channel:H,type:typeof U==="object"?"json":"string",value:U,timestamp:X,global_idx:X+_};await this.client.json.set(B,"$",L)}if(F.length>0){let _=`write_keys_zset:${Q}:${Y}:${E}`,H={};if(F.forEach((U,B)=>{H[U]=X+B}),await this.client.zAdd(_,Object.entries(H).map(([U,B])=>({score:B,value:U}))),this.ttlConfig?.defaultTTL)await this.applyTTL(...F,_)}let $=`checkpoint:${Q}:${Y}:${E}`;if(await this.client.exists($)){let _=await this.client.json.get($);if(_)_.has_writes="true",await this.client.json.set($,"$",_)}}async deleteThread(G){let J=`checkpoint:${G}:*`,Z=await this.client.keys(J);if(Z.length>0)await this.client.del(Z);let Q=`writes:${G}:*`,Y=await this.client.keys(Q);if(Y.length>0)await this.client.del(Y)}async end(){await this.client.quit()}async loadPendingWrites(G,J,Z){let Q=`checkpoint_write:${G}:${J}:${Z}:*`,Y=await this.client.keys(Q);if(Y.length===0)return;let E=[];for(let X of Y){let $=await this.client.json.get(X);if($)E.push($)}E.sort((X,$)=>(X.global_idx||0)-($.global_idx||0));let F=[];for(let X of E){let $=await this.serde.loadsTyped("json",JSON.stringify(X.value));F.push([X.task_id,X.channel,$])}return F}async loadCheckpointWithWrites(G){let J=await this.serde.loadsTyped("json",JSON.stringify(G.checkpoint));if(J.v<4&&G.parent_checkpoint_id!=null){let Q=G.checkpoint_ns==="__empty__"?"":G.checkpoint_ns;await this.migratePendingSends(J,G.thread_id,Q,G.parent_checkpoint_id)}let Z;if(G.has_writes==="true"){let Q=G.checkpoint_ns==="__empty__"?"":G.checkpoint_ns;Z=await this.loadPendingWrites(G.thread_id,Q,G.checkpoint_id)}return{checkpoint:J,pendingWrites:Z}}async migratePendingSends(G,J,Z,Q){let Y=await this.loadPendingWrites(J,Z,Q);if(!Y||Y.length===0)return;let E=Y.filter(([,X])=>X===T);if(E.length===0)return;let F=[];for(let[,,X]of E)F.push(X);G.channel_values??={},G.channel_values[T]=F,G.channel_versions[T]=Object.keys(G.channel_versions).length>0?v(...Object.values(G.channel_versions)):1}async createCheckpointTuple(G,J,Z){let Q=G.checkpoint_ns==="__empty__"?"":G.checkpoint_ns,Y=await this.serde.loadsTyped("json",JSON.stringify(G.metadata));return{config:{configurable:{thread_id:G.thread_id,checkpoint_ns:Q,checkpoint_id:G.checkpoint_id}},checkpoint:J,metadata:Y,parentConfig:G.parent_checkpoint_id?{configurable:{thread_id:G.thread_id,checkpoint_ns:Q,checkpoint_id:G.parent_checkpoint_id}}:void 0,pendingWrites:Z}}addSearchableMetadataFields(G,J){if(!J)return;if("source"in J)G.source=J.source;if("step"in J)G.step=J.step;if("writes"in J)G.writes=typeof J.writes==="object"?JSON.stringify(J.writes):J.writes;if("score"in J)G.score=J.score}async applyTTL(...G){if(!this.ttlConfig?.defaultTTL)return;let J=Math.floor(this.ttlConfig.defaultTTL*60),Z=await Promise.allSettled(G.map((Q)=>this.client.expire(Q,J)));for(let Q=0;Q<Z.length;Q++)if(Z[Q].status==="rejected")console.warn(`Failed to set TTL for key ${G[Q]}:`,Z[Q].reason)}async ensureIndexes(){for(let G of g)try{await this.client.ft.create(G.index,G.schema,{ON:"JSON",PREFIX:G.prefix})}catch(J){if(!J.message?.includes("Index already exists"))console.error(`Failed to create index ${G.index}:`,J.message)}}};function q(z){if(z===null||typeof z!=="object")return JSON.stringify(z);if(Array.isArray(z))return JSON.stringify(z.map((Z)=>q(Z)));let G={},J=Object.keys(z).sort();for(let Z of J)G[Z]=z[Z];return JSON.stringify(G,(Z,Q)=>{if(Q!==null&&typeof Q==="object"&&!Array.isArray(Q)){let Y={},E=Object.keys(Q).sort();for(let F of E)Y[F]=Q[F];return Y}return Q})}export{f as RedisSaver};
@@ -1,4 +1,4 @@
1
- import{Ek as g1,Fk as m1,Gk as kY,Hk as bG,Ik as Q1,Jk as $1,Kk as k1,Lk as Y1,Mk as I1,Nk as x1}from"./chunk-bk32cwxa.js";import{Pk as x,Qk as tQ}from"./chunk-qfa5v4n5.js";import{Bl as y1,Tk as vQ,Uk as aY,Vk as L$,Wk as eY,Yk as uW,Zk as cW,_k as Q8,al as KQ,bl as lW,cl as iW,dl as k8}from"./chunk-78ksrp8v.js";import{Cl as NG,Dl as m0,El as pQ,Fl as PW,Hl as FQ,Jl as Q0}from"./chunk-yb71zqvt.js";import{Wl as rQ}from"./chunk-4fs853nh.js";var r8=Object.defineProperty,M=(Q,$)=>{let Y={};for(var q in Q)r8(Y,q,{get:Q[q],enumerable:!0});if(!$)r8(Y,Symbol.toStringTag,{value:"Module"});return Y};function fQ(Q){return!!(Q&&typeof Q==="object"&&("type"in Q)&&Q.type==="tool_call")}function a8(Q){return!!(Q&&typeof Q==="object"&&("toolCall"in Q)&&Q.toolCall!=null&&typeof Q.toolCall==="object"&&("id"in Q.toolCall)&&typeof Q.toolCall.id==="string")}var U0=class extends Error{output;constructor(Q,$){super(Q);this.output=$}};var e8=rQ(g1(),1),Q6=rQ(m1(),1);function $6(Q,$){return $?.[Q]||e8.default(Q)}function rJ(Q,$){return $?.[Q]||Q6.default(Q)}function Y6(Q,$,Y){let q={};for(let W in Q)if(Object.hasOwn(Q,W))q[$(W,Y)]=Q[W];return q}function d1(Q){return"lc"in Q||Object.keys(Q).length===1&&"__lc_escaped__"in Q}function p1(Q){return{["__lc_escaped__"]:Q}}function u1(Q){return Object.keys(Q).length===1&&"__lc_escaped__"in Q}function c1(Q){return Q!==null&&typeof Q==="object"&&"lc_serializable"in Q&&typeof Q.toJSON==="function"}function l1(Q){let $;if(Q!==null&&typeof Q==="object")if("lc_id"in Q&&Array.isArray(Q.lc_id))$=Q.lc_id;else $=[Q.constructor?.name??"Object"];else $=[typeof Q];return{lc:1,type:"not_implemented",id:$}}function d0(Q,$=new WeakSet){if(Q!==null&&typeof Q==="object"&&!Array.isArray(Q)){if($.has(Q))return l1(Q);if(c1(Q))return Q;$.add(Q);let Y=Q;if(d1(Y))return $.delete(Q),p1(Y);let q={};for(let[W,Z]of Object.entries(Y))q[W]=d0(Z,$);return $.delete(Q),q}if(Array.isArray(Q))return Q.map((Y)=>d0(Y,$));return Q}function q6(Q){if(Q!==null&&typeof Q==="object"&&!Array.isArray(Q)){let $=Q;if(u1($))return $.__lc_escaped__;let Y={};for(let[q,W]of Object.entries($))Y[q]=q6(W);return Y}if(Array.isArray(Q))return Q.map(($)=>q6($));return Q}var q9=M({Serializable:()=>RQ,get_lc_unique_name:()=>p0});function W6(Q){return Array.isArray(Q)?[...Q]:{...Q}}function i1(Q,$){let Y=W6(Q);for(let[q,W]of Object.entries($)){let[Z,...G]=q.split(".").reverse(),J=Y;for(let z of G.reverse()){if(J[z]===void 0)break;J[z]=W6(J[z]),J=J[z]}if(J[Z]!==void 0)J[Z]={lc:1,type:"secret",id:[W]}}return Y}function p0(Q){let $=Object.getPrototypeOf(Q);if(typeof Q.lc_name==="function"&&(typeof $.lc_name!=="function"||Q.lc_name()!==$.lc_name()))return Q.lc_name();else return Q.name}var RQ=class Q{lc_serializable=!1;lc_kwargs;static lc_name(){return this.name}get lc_id(){return[...this.lc_namespace,p0(this.constructor)]}get lc_secrets(){}get lc_attributes(){}get lc_aliases(){}get lc_serializable_keys(){}constructor($,...Y){if(this.lc_serializable_keys!==void 0)this.lc_kwargs=Object.fromEntries(Object.entries($||{}).filter(([q])=>this.lc_serializable_keys?.includes(q)));else this.lc_kwargs=$??{}}toJSON(){if(!this.lc_serializable)return this.toJSONNotImplemented();if(this.lc_kwargs instanceof Q||typeof this.lc_kwargs!=="object"||Array.isArray(this.lc_kwargs))return this.toJSONNotImplemented();let $={},Y={},q=Object.keys(this.lc_kwargs).reduce((J,z)=>{return J[z]=z in this?this[z]:this.lc_kwargs[z],J},{});for(let J=Object.getPrototypeOf(this);J;J=Object.getPrototypeOf(J))Object.assign($,Reflect.get(J,"lc_aliases",this)),Object.assign(Y,Reflect.get(J,"lc_secrets",this)),Object.assign(q,Reflect.get(J,"lc_attributes",this));Object.keys(Y).forEach((J)=>{let z=this,K=q,[X,...U]=J.split(".").reverse();for(let N of U.reverse()){if(!(N in z)||z[N]===void 0)return;if(!(N in K)||K[N]===void 0){if(typeof z[N]==="object"&&z[N]!=null)K[N]={};else if(Array.isArray(z[N]))K[N]=[]}z=z[N],K=K[N]}if(X in z&&z[X]!==void 0)K[X]=K[X]||z[X]});let W={},Z=new WeakSet;Z.add(this);for(let[J,z]of Object.entries(q))W[J]=d0(z,Z);let G=Y6(Object.keys(Y).length?i1(W,Y):W,$6,$);return{lc:1,type:"constructor",id:this.lc_id,kwargs:G}}toJSONNotImplemented(){return{lc:1,type:"not_implemented",id:this.lc_id}}};function gQ(Q){return typeof Q==="object"&&Q!==null&&"type"in Q&&typeof Q.type==="string"&&"source_type"in Q&&(Q.source_type==="url"||Q.source_type==="base64"||Q.source_type==="text"||Q.source_type==="id")}function Z6(Q){return gQ(Q)&&Q.source_type==="url"&&"url"in Q&&typeof Q.url==="string"}function G6(Q){return gQ(Q)&&Q.source_type==="base64"&&"data"in Q&&typeof Q.data==="string"}function Z9(Q){return gQ(Q)&&Q.source_type==="text"&&"text"in Q&&typeof Q.text==="string"}function J6(Q){return gQ(Q)&&Q.source_type==="id"&&"id"in Q&&typeof Q.id==="string"}function G9(Q){if(gQ(Q)){if(Q.source_type==="url")return{type:"image_url",image_url:{url:Q.url}};if(Q.source_type==="base64"){if(!Q.mime_type)throw Error("mime_type key is required for base64 data.");return{type:"image_url",image_url:{url:`data:${Q.mime_type};base64,${Q.data}`}}}}throw Error("Unsupported source type. Only 'url' and 'base64' are supported.")}function J9(Q){let $=Q.split(";")[0].split("/");if($.length!==2)throw Error(`Invalid mime type: "${Q}" - does not match type/subtype format.`);let Y=$[0].trim(),q=$[1].trim();if(Y===""||q==="")throw Error(`Invalid mime type: "${Q}" - type or subtype is empty.`);let W={};for(let Z of Q.split(";").slice(1)){let G=Z.split("=");if(G.length!==2)throw Error(`Invalid parameter syntax in mime type: "${Q}".`);let J=G[0].trim(),z=G[1].trim();if(J==="")throw Error(`Invalid parameter syntax in mime type: "${Q}".`);W[J]=z}return{type:Y,subtype:q,parameters:W}}function e$({dataUrl:Q,asTypedArray:$=!1}){let Y=Q.match(/^data:(\w+\/\w+);base64,([A-Za-z0-9+/]+=*)$/),q;if(Y){q=Y[1].toLowerCase();let W=$?Uint8Array.from(atob(Y[2]),(Z)=>Z.charCodeAt(0)):Y[2];return{mime_type:q,data:W}}}function z9(Q,$){if(Q.type==="text"){if(!$.fromStandardTextBlock)throw Error(`Converter for ${$.providerName} does not implement \`fromStandardTextBlock\` method.`);return $.fromStandardTextBlock(Q)}if(Q.type==="image"){if(!$.fromStandardImageBlock)throw Error(`Converter for ${$.providerName} does not implement \`fromStandardImageBlock\` method.`);return $.fromStandardImageBlock(Q)}if(Q.type==="audio"){if(!$.fromStandardAudioBlock)throw Error(`Converter for ${$.providerName} does not implement \`fromStandardAudioBlock\` method.`);return $.fromStandardAudioBlock(Q)}if(Q.type==="file"){if(!$.fromStandardFileBlock)throw Error(`Converter for ${$.providerName} does not implement \`fromStandardFileBlock\` method.`);return $.fromStandardFileBlock(Q)}throw Error(`Unable to convert content block type '${Q.type}' to provider-specific format: not recognized.`)}function O(Q,$){return P(Q)&&Q.type===$}function P(Q){return typeof Q==="object"&&Q!==null}function o(Q){return Array.isArray(Q)}function V(Q){return typeof Q==="string"}function UQ(Q){return typeof Q==="number"}function u0(Q){return Q instanceof Uint8Array}function QY(Q){try{return JSON.parse(Q)}catch{return}}var NQ=(Q)=>Q();function s1(Q){if(Q.type==="char_location"&&V(Q.document_title)&&UQ(Q.start_char_index)&&UQ(Q.end_char_index)&&V(Q.cited_text)){let{document_title:$,start_char_index:Y,end_char_index:q,cited_text:W,...Z}=Q;return{...Z,type:"citation",source:"char",title:$??void 0,startIndex:Y,endIndex:q,citedText:W}}if(Q.type==="page_location"&&V(Q.document_title)&&UQ(Q.start_page_number)&&UQ(Q.end_page_number)&&V(Q.cited_text)){let{document_title:$,start_page_number:Y,end_page_number:q,cited_text:W,...Z}=Q;return{...Z,type:"citation",source:"page",title:$??void 0,startIndex:Y,endIndex:q,citedText:W}}if(Q.type==="content_block_location"&&V(Q.document_title)&&UQ(Q.start_block_index)&&UQ(Q.end_block_index)&&V(Q.cited_text)){let{document_title:$,start_block_index:Y,end_block_index:q,cited_text:W,...Z}=Q;return{...Z,type:"citation",source:"block",title:$??void 0,startIndex:Y,endIndex:q,citedText:W}}if(Q.type==="web_search_result_location"&&V(Q.url)&&V(Q.title)&&V(Q.encrypted_index)&&V(Q.cited_text)){let{url:$,title:Y,encrypted_index:q,cited_text:W,...Z}=Q;return{...Z,type:"citation",source:"url",url:$,title:Y,startIndex:Number(q),endIndex:Number(q),citedText:W}}if(Q.type==="search_result_location"&&V(Q.source)&&V(Q.title)&&UQ(Q.start_block_index)&&UQ(Q.end_block_index)&&V(Q.cited_text)){let{source:$,title:Y,start_block_index:q,end_block_index:W,cited_text:Z,...G}=Q;return{...G,type:"citation",source:"search",url:$,title:Y??void 0,startIndex:q,endIndex:W,citedText:Z}}}function K6(Q){if(O(Q,"document")&&P(Q.source)&&"type"in Q.source){if(Q.source.type==="base64"&&V(Q.source.media_type)&&V(Q.source.data))return{type:"file",mimeType:Q.source.media_type,data:Q.source.data};else if(Q.source.type==="url"&&V(Q.source.url))return{type:"file",url:Q.source.url};else if(Q.source.type==="file"&&V(Q.source.file_id))return{type:"file",fileId:Q.source.file_id};else if(Q.source.type==="text"&&V(Q.source.data))return{type:"file",mimeType:String(Q.source.media_type??"text/plain"),data:Q.source.data}}else if(O(Q,"image")&&P(Q.source)&&"type"in Q.source){if(Q.source.type==="base64"&&V(Q.source.media_type)&&V(Q.source.data))return{type:"image",mimeType:Q.source.media_type,data:Q.source.data};else if(Q.source.type==="url"&&V(Q.source.url))return{type:"image",url:Q.source.url};else if(Q.source.type==="file"&&V(Q.source.file_id))return{type:"image",fileId:Q.source.file_id}}}function X6(Q){function*$(){for(let Y of Q){let q=K6(Y);if(q)yield q;else yield Y}}return Array.from($())}function z6(Q){function*$(){let Y=typeof Q.content==="string"?[{type:"text",text:Q.content}]:Q.content;for(let q of Y){if(O(q,"text")&&V(q.text)){let{text:W,citations:Z,...G}=q;if(o(Z)&&Z.length){let J=Z.reduce((z,K)=>{let X=s1(K);if(X)return[...z,X];return z},[]);yield{...G,type:"text",text:W,annotations:J};continue}else{yield{...G,type:"text",text:W};continue}}else if(O(q,"thinking")&&V(q.thinking)){let{thinking:W,signature:Z,...G}=q;yield{...G,type:"reasoning",reasoning:W,signature:Z};continue}else if(O(q,"redacted_thinking")){yield{type:"non_standard",value:q};continue}else if(O(q,"tool_use")&&V(q.name)&&V(q.id)){yield{type:"tool_call",id:q.id,name:q.name,args:q.input};continue}else if(O(q,"input_json_delta")){if(o1(Q)&&Q.tool_call_chunks?.length){let W=Q.tool_call_chunks[0];yield{type:"tool_call_chunk",id:W.id,name:W.name,args:W.args,index:W.index};continue}}else if(O(q,"server_tool_use")&&V(q.name)&&V(q.id)){let{name:W,id:Z}=q;if(W==="web_search"){yield{id:Z,type:"server_tool_call",name:"web_search",args:{query:NQ(()=>{if(typeof q.input==="string")return q.input;else if(P(q.input)&&V(q.input.query))return q.input.query;else if(V(q.partial_json)){let G=QY(q.partial_json);if(G?.query)return G.query}return""})}};continue}else if(q.name==="code_execution"){yield{id:Z,type:"server_tool_call",name:"code_execution",args:{code:NQ(()=>{if(typeof q.input==="string")return q.input;else if(P(q.input)&&V(q.input.code))return q.input.code;else if(V(q.partial_json)){let G=QY(q.partial_json);if(G?.code)return G.code}return""})}};continue}}else if(O(q,"web_search_tool_result")&&V(q.tool_use_id)&&o(q.content)){let{content:W,tool_use_id:Z}=q;yield{type:"server_tool_call_result",name:"web_search",toolCallId:Z,status:"success",output:{urls:W.reduce((G,J)=>{if(O(J,"web_search_result"))return[...G,J.url];return G},[])}};continue}else if(O(q,"code_execution_tool_result")&&V(q.tool_use_id)&&P(q.content)){yield{type:"server_tool_call_result",name:"code_execution",toolCallId:q.tool_use_id,status:"success",output:q.content};continue}else if(O(q,"mcp_tool_use")){yield{id:q.id,type:"server_tool_call",name:"mcp_tool_use",args:q.input};continue}else if(O(q,"mcp_tool_result")&&V(q.tool_use_id)&&P(q.content)){yield{type:"server_tool_call_result",name:"mcp_tool_use",toolCallId:q.tool_use_id,status:"success",output:q.content};continue}else if(O(q,"container_upload")){yield{type:"server_tool_call",name:"container_upload",args:q.input};continue}else if(O(q,"search_result")){yield{id:q.id,type:"non_standard",value:q};continue}else if(O(q,"tool_result")){yield{id:q.id,type:"non_standard",value:q};continue}else{let W=K6(q);if(W){yield W;continue}}yield{type:"non_standard",value:q}}}return Array.from($())}var U6={translateContent:z6,translateContentChunk:z6};function o1(Q){return typeof Q?._getType==="function"&&typeof Q.concat==="function"&&Q._getType()==="ai"}function t1(Q){if(Z6(Q))return{type:Q.type,mimeType:Q.mime_type,url:Q.url,metadata:Q.metadata};if(G6(Q))return{type:Q.type,mimeType:Q.mime_type??"application/octet-stream",data:Q.data,metadata:Q.metadata};if(J6(Q))return{type:Q.type,mimeType:Q.mime_type,fileId:Q.id,metadata:Q.metadata};return Q}function N6(Q){return Q.map(t1)}function B6(Q){if(O(Q,"image_url")&&P(Q.image_url))return!0;if(O(Q,"input_audio")&&P(Q.input_audio))return!0;if(O(Q,"file")&&P(Q.file))return!0;return!1}function F6(Q){if(O(Q,"image_url")&&P(Q.image_url)&&V(Q.image_url.url)){let $=e$({dataUrl:Q.image_url.url});if($)return{type:"image",mimeType:$.mime_type,data:$.data};else return{type:"image",url:Q.image_url.url}}else if(O(Q,"input_audio")&&P(Q.input_audio)&&V(Q.input_audio.data)&&V(Q.input_audio.format))return{type:"audio",data:Q.input_audio.data,mimeType:`audio/${Q.input_audio.format}`};else if(O(Q,"file")&&P(Q.file)&&V(Q.file.data)){let $=e$({dataUrl:Q.file.data});if($)return{type:"file",data:$.data,mimeType:$.mime_type};else if(V(Q.file.file_id))return{type:"file",fileId:Q.file.file_id}}return Q}function n1(Q){let $=[];if(typeof Q.content==="string"){if(Q.content.length>0)$.push({type:"text",text:Q.content})}else $.push(...c0(Q.content));for(let Y of Q.tool_calls??[])$.push({type:"tool_call",id:Y.id,name:Y.name,args:Y.args});return $}function r1(Q){let $=[];if(typeof Q.content==="string"){if(Q.content.length>0)$.push({type:"text",text:Q.content})}else $.push(...c0(Q.content));for(let Y of Q.tool_calls??[])$.push({type:"tool_call",id:Y.id,name:Y.name,args:Y.args});return $}function c0(Q){let $=[];for(let Y of Q)if(B6(Y))$.push(F6(Y));else $.push(Y);return $}function a1(Q){if(Q.type==="url_citation"){let{url:$,title:Y,start_index:q,end_index:W}=Q;return{type:"citation",url:$,title:Y,startIndex:q,endIndex:W}}if(Q.type==="file_citation"){let{file_id:$,filename:Y,index:q}=Q;return{type:"citation",title:Y,startIndex:q,endIndex:q,fileId:$}}return Q}function V6(Q){function*$(){if(P(Q.additional_kwargs?.reasoning)&&o(Q.additional_kwargs.reasoning.summary))yield{type:"reasoning",reasoning:Q.additional_kwargs.reasoning.summary.reduce((q,W)=>{if(P(W)&&V(W.text))return`${q}${W.text}`;return q},"")};let Y=typeof Q.content==="string"?[{type:"text",text:Q.content}]:Q.content;for(let q of Y)if(O(q,"text")){let{text:W,annotations:Z,...G}=q;if(Array.isArray(Z))yield{...G,type:"text",text:String(W),annotations:Z.map(a1)};else yield{...G,type:"text",text:String(W)}}for(let q of Q.tool_calls??[])yield{type:"tool_call",id:q.id,name:q.name,args:q.args};if(P(Q.additional_kwargs)&&o(Q.additional_kwargs.tool_outputs))for(let q of Q.additional_kwargs.tool_outputs){if(O(q,"web_search_call")){let W={};if(P(q.action)&&V(q.action.query))W.query=q.action.query;if(yield{id:q.id,type:"server_tool_call",name:"web_search",args:W},q.status==="completed"||q.status==="failed"){let Z={};if(P(q.action))Z.action=q.action;yield{type:"server_tool_call_result",toolCallId:V(q.id)?q.id:"",status:q.status==="completed"?"success":"error",output:Z}}continue}else if(O(q,"file_search_call")){if(yield{id:q.id,type:"server_tool_call",name:"file_search",args:{queries:o(q.queries)?q.queries:[]}},q.status==="completed"||q.status==="failed")yield{type:"server_tool_call_result",toolCallId:V(q.id)?q.id:"",status:q.status==="completed"?"success":"error",output:o(q.results)?{results:q.results}:{}};continue}else if(O(q,"computer_call")){yield{type:"non_standard",value:q};continue}else if(O(q,"code_interpreter_call")){if(V(q.code))yield{id:q.id,type:"server_tool_call",name:"code_interpreter",args:{code:q.code}};if(o(q.outputs)){let W=NQ(()=>{if(q.status==="in_progress")return;if(q.status==="completed")return 0;if(q.status==="incomplete")return 127;if(q.status==="interpreting")return;if(q.status==="failed")return 1});for(let Z of q.outputs)if(O(Z,"logs")){yield{type:"server_tool_call_result",toolCallId:q.id??"",status:"success",output:{type:"code_interpreter_output",returnCode:W??0,stderr:[0,void 0].includes(W)?void 0:String(Z.logs),stdout:[0,void 0].includes(W)?String(Z.logs):void 0}};continue}}continue}else if(O(q,"mcp_call")){yield{id:q.id,type:"server_tool_call",name:"mcp_call",args:q.input};continue}else if(O(q,"mcp_list_tools")){yield{id:q.id,type:"server_tool_call",name:"mcp_list_tools",args:q.input};continue}else if(O(q,"mcp_approval_request")){yield{type:"non_standard",value:q};continue}else if(O(q,"image_generation_call")){if(V(q.result))yield{type:"image",mimeType:"image/png",data:q.result,id:V(q.id)?q.id:void 0,metadata:{status:V(q.status)?q.status:void 0}};yield{type:"non_standard",value:q};continue}if(P(q))yield{type:"non_standard",value:q}}}return Array.from($())}function e1(Q){function*$(){yield*V6(Q);for(let Y of Q.tool_call_chunks??[])yield{type:"tool_call_chunk",id:Y.id,name:Y.name,args:Y.args}}return Array.from($())}var A6={translateContent:(Q)=>{if(typeof Q.content==="string")return n1(Q);return V6(Q)},translateContentChunk:(Q)=>{if(typeof Q.content==="string")return r1(Q);return e1(Q)}};function H6(Q){return typeof Q==="object"&&Q!==null&&"type"in Q&&"content"in Q&&(typeof Q.content==="string"||Array.isArray(Q.content))}function D6(Q,$="pretty"){if($==="pretty")return QZ(Q);return JSON.stringify(Q)}function QZ(Q){let $=[],Y=` ${Q.type.charAt(0).toUpperCase()+Q.type.slice(1)} Message `,q=Math.floor((80-Y.length)/2),W="=".repeat(q),Z=Y.length%2===0?W:`${W}=`;if($.push(`${W}${Y}${Z}`),Q.type==="ai"){let G=Q;if(G.tool_calls&&G.tool_calls.length>0){$.push("Tool Calls:");for(let J of G.tool_calls){$.push(` ${J.name} (${J.id})`),$.push(` Call ID: ${J.id}`),$.push(" Args:");for(let[z,K]of Object.entries(J.args))$.push(` ${z}: ${typeof K==="object"?JSON.stringify(K):K}`)}}}if(Q.type==="tool"){let G=Q;if(G.name)$.push(`Name: ${G.name}`)}if(typeof Q.content==="string"&&Q.content.trim()){if($.length>1)$.push("");$.push(Q.content)}return $.join(`
1
+ import{Ak as g1,Bk as m1,Ck as kY,Dk as bG,Ek as Q1,Fk as $1,Gk as k1,Hk as Y1,Ik as I1,Jk as x1}from"./chunk-g2n6hnjp.js";import{Lk as x,Mk as tQ}from"./chunk-femf7e4d.js";import{$k as k8,Pk as vQ,Qk as aY,Rk as L$,Sk as eY,Uk as uW,Vk as cW,Wk as Q8,Yk as KQ,Zk as lW,_k as iW,xl as y1}from"./chunk-0pzpg2ra.js";import{Al as pQ,Bl as PW,Dl as FQ,Fl as Q0,yl as NG,zl as m0}from"./chunk-xtr6s7kh.js";import{Rl as rQ}from"./chunk-x17jyjan.js";var r8=Object.defineProperty,M=(Q,$)=>{let Y={};for(var q in Q)r8(Y,q,{get:Q[q],enumerable:!0});if(!$)r8(Y,Symbol.toStringTag,{value:"Module"});return Y};function fQ(Q){return!!(Q&&typeof Q==="object"&&("type"in Q)&&Q.type==="tool_call")}function a8(Q){return!!(Q&&typeof Q==="object"&&("toolCall"in Q)&&Q.toolCall!=null&&typeof Q.toolCall==="object"&&("id"in Q.toolCall)&&typeof Q.toolCall.id==="string")}var U0=class extends Error{output;constructor(Q,$){super(Q);this.output=$}};var e8=rQ(g1(),1),Q6=rQ(m1(),1);function $6(Q,$){return $?.[Q]||e8.default(Q)}function rJ(Q,$){return $?.[Q]||Q6.default(Q)}function Y6(Q,$,Y){let q={};for(let W in Q)if(Object.hasOwn(Q,W))q[$(W,Y)]=Q[W];return q}function d1(Q){return"lc"in Q||Object.keys(Q).length===1&&"__lc_escaped__"in Q}function p1(Q){return{["__lc_escaped__"]:Q}}function u1(Q){return Object.keys(Q).length===1&&"__lc_escaped__"in Q}function c1(Q){return Q!==null&&typeof Q==="object"&&"lc_serializable"in Q&&typeof Q.toJSON==="function"}function l1(Q){let $;if(Q!==null&&typeof Q==="object")if("lc_id"in Q&&Array.isArray(Q.lc_id))$=Q.lc_id;else $=[Q.constructor?.name??"Object"];else $=[typeof Q];return{lc:1,type:"not_implemented",id:$}}function d0(Q,$=new WeakSet){if(Q!==null&&typeof Q==="object"&&!Array.isArray(Q)){if($.has(Q))return l1(Q);if(c1(Q))return Q;$.add(Q);let Y=Q;if(d1(Y))return $.delete(Q),p1(Y);let q={};for(let[W,Z]of Object.entries(Y))q[W]=d0(Z,$);return $.delete(Q),q}if(Array.isArray(Q))return Q.map((Y)=>d0(Y,$));return Q}function q6(Q){if(Q!==null&&typeof Q==="object"&&!Array.isArray(Q)){let $=Q;if(u1($))return $.__lc_escaped__;let Y={};for(let[q,W]of Object.entries($))Y[q]=q6(W);return Y}if(Array.isArray(Q))return Q.map(($)=>q6($));return Q}var q9=M({Serializable:()=>RQ,get_lc_unique_name:()=>p0});function W6(Q){return Array.isArray(Q)?[...Q]:{...Q}}function i1(Q,$){let Y=W6(Q);for(let[q,W]of Object.entries($)){let[Z,...G]=q.split(".").reverse(),J=Y;for(let z of G.reverse()){if(J[z]===void 0)break;J[z]=W6(J[z]),J=J[z]}if(J[Z]!==void 0)J[Z]={lc:1,type:"secret",id:[W]}}return Y}function p0(Q){let $=Object.getPrototypeOf(Q);if(typeof Q.lc_name==="function"&&(typeof $.lc_name!=="function"||Q.lc_name()!==$.lc_name()))return Q.lc_name();else return Q.name}var RQ=class Q{lc_serializable=!1;lc_kwargs;static lc_name(){return this.name}get lc_id(){return[...this.lc_namespace,p0(this.constructor)]}get lc_secrets(){}get lc_attributes(){}get lc_aliases(){}get lc_serializable_keys(){}constructor($,...Y){if(this.lc_serializable_keys!==void 0)this.lc_kwargs=Object.fromEntries(Object.entries($||{}).filter(([q])=>this.lc_serializable_keys?.includes(q)));else this.lc_kwargs=$??{}}toJSON(){if(!this.lc_serializable)return this.toJSONNotImplemented();if(this.lc_kwargs instanceof Q||typeof this.lc_kwargs!=="object"||Array.isArray(this.lc_kwargs))return this.toJSONNotImplemented();let $={},Y={},q=Object.keys(this.lc_kwargs).reduce((J,z)=>{return J[z]=z in this?this[z]:this.lc_kwargs[z],J},{});for(let J=Object.getPrototypeOf(this);J;J=Object.getPrototypeOf(J))Object.assign($,Reflect.get(J,"lc_aliases",this)),Object.assign(Y,Reflect.get(J,"lc_secrets",this)),Object.assign(q,Reflect.get(J,"lc_attributes",this));Object.keys(Y).forEach((J)=>{let z=this,K=q,[X,...U]=J.split(".").reverse();for(let N of U.reverse()){if(!(N in z)||z[N]===void 0)return;if(!(N in K)||K[N]===void 0){if(typeof z[N]==="object"&&z[N]!=null)K[N]={};else if(Array.isArray(z[N]))K[N]=[]}z=z[N],K=K[N]}if(X in z&&z[X]!==void 0)K[X]=K[X]||z[X]});let W={},Z=new WeakSet;Z.add(this);for(let[J,z]of Object.entries(q))W[J]=d0(z,Z);let G=Y6(Object.keys(Y).length?i1(W,Y):W,$6,$);return{lc:1,type:"constructor",id:this.lc_id,kwargs:G}}toJSONNotImplemented(){return{lc:1,type:"not_implemented",id:this.lc_id}}};function gQ(Q){return typeof Q==="object"&&Q!==null&&"type"in Q&&typeof Q.type==="string"&&"source_type"in Q&&(Q.source_type==="url"||Q.source_type==="base64"||Q.source_type==="text"||Q.source_type==="id")}function Z6(Q){return gQ(Q)&&Q.source_type==="url"&&"url"in Q&&typeof Q.url==="string"}function G6(Q){return gQ(Q)&&Q.source_type==="base64"&&"data"in Q&&typeof Q.data==="string"}function Z9(Q){return gQ(Q)&&Q.source_type==="text"&&"text"in Q&&typeof Q.text==="string"}function J6(Q){return gQ(Q)&&Q.source_type==="id"&&"id"in Q&&typeof Q.id==="string"}function G9(Q){if(gQ(Q)){if(Q.source_type==="url")return{type:"image_url",image_url:{url:Q.url}};if(Q.source_type==="base64"){if(!Q.mime_type)throw Error("mime_type key is required for base64 data.");return{type:"image_url",image_url:{url:`data:${Q.mime_type};base64,${Q.data}`}}}}throw Error("Unsupported source type. Only 'url' and 'base64' are supported.")}function J9(Q){let $=Q.split(";")[0].split("/");if($.length!==2)throw Error(`Invalid mime type: "${Q}" - does not match type/subtype format.`);let Y=$[0].trim(),q=$[1].trim();if(Y===""||q==="")throw Error(`Invalid mime type: "${Q}" - type or subtype is empty.`);let W={};for(let Z of Q.split(";").slice(1)){let G=Z.split("=");if(G.length!==2)throw Error(`Invalid parameter syntax in mime type: "${Q}".`);let J=G[0].trim(),z=G[1].trim();if(J==="")throw Error(`Invalid parameter syntax in mime type: "${Q}".`);W[J]=z}return{type:Y,subtype:q,parameters:W}}function e$({dataUrl:Q,asTypedArray:$=!1}){let Y=Q.match(/^data:(\w+\/\w+);base64,([A-Za-z0-9+/]+=*)$/),q;if(Y){q=Y[1].toLowerCase();let W=$?Uint8Array.from(atob(Y[2]),(Z)=>Z.charCodeAt(0)):Y[2];return{mime_type:q,data:W}}}function z9(Q,$){if(Q.type==="text"){if(!$.fromStandardTextBlock)throw Error(`Converter for ${$.providerName} does not implement \`fromStandardTextBlock\` method.`);return $.fromStandardTextBlock(Q)}if(Q.type==="image"){if(!$.fromStandardImageBlock)throw Error(`Converter for ${$.providerName} does not implement \`fromStandardImageBlock\` method.`);return $.fromStandardImageBlock(Q)}if(Q.type==="audio"){if(!$.fromStandardAudioBlock)throw Error(`Converter for ${$.providerName} does not implement \`fromStandardAudioBlock\` method.`);return $.fromStandardAudioBlock(Q)}if(Q.type==="file"){if(!$.fromStandardFileBlock)throw Error(`Converter for ${$.providerName} does not implement \`fromStandardFileBlock\` method.`);return $.fromStandardFileBlock(Q)}throw Error(`Unable to convert content block type '${Q.type}' to provider-specific format: not recognized.`)}function O(Q,$){return P(Q)&&Q.type===$}function P(Q){return typeof Q==="object"&&Q!==null}function o(Q){return Array.isArray(Q)}function V(Q){return typeof Q==="string"}function UQ(Q){return typeof Q==="number"}function u0(Q){return Q instanceof Uint8Array}function QY(Q){try{return JSON.parse(Q)}catch{return}}var NQ=(Q)=>Q();function s1(Q){if(Q.type==="char_location"&&V(Q.document_title)&&UQ(Q.start_char_index)&&UQ(Q.end_char_index)&&V(Q.cited_text)){let{document_title:$,start_char_index:Y,end_char_index:q,cited_text:W,...Z}=Q;return{...Z,type:"citation",source:"char",title:$??void 0,startIndex:Y,endIndex:q,citedText:W}}if(Q.type==="page_location"&&V(Q.document_title)&&UQ(Q.start_page_number)&&UQ(Q.end_page_number)&&V(Q.cited_text)){let{document_title:$,start_page_number:Y,end_page_number:q,cited_text:W,...Z}=Q;return{...Z,type:"citation",source:"page",title:$??void 0,startIndex:Y,endIndex:q,citedText:W}}if(Q.type==="content_block_location"&&V(Q.document_title)&&UQ(Q.start_block_index)&&UQ(Q.end_block_index)&&V(Q.cited_text)){let{document_title:$,start_block_index:Y,end_block_index:q,cited_text:W,...Z}=Q;return{...Z,type:"citation",source:"block",title:$??void 0,startIndex:Y,endIndex:q,citedText:W}}if(Q.type==="web_search_result_location"&&V(Q.url)&&V(Q.title)&&V(Q.encrypted_index)&&V(Q.cited_text)){let{url:$,title:Y,encrypted_index:q,cited_text:W,...Z}=Q;return{...Z,type:"citation",source:"url",url:$,title:Y,startIndex:Number(q),endIndex:Number(q),citedText:W}}if(Q.type==="search_result_location"&&V(Q.source)&&V(Q.title)&&UQ(Q.start_block_index)&&UQ(Q.end_block_index)&&V(Q.cited_text)){let{source:$,title:Y,start_block_index:q,end_block_index:W,cited_text:Z,...G}=Q;return{...G,type:"citation",source:"search",url:$,title:Y??void 0,startIndex:q,endIndex:W,citedText:Z}}}function K6(Q){if(O(Q,"document")&&P(Q.source)&&"type"in Q.source){if(Q.source.type==="base64"&&V(Q.source.media_type)&&V(Q.source.data))return{type:"file",mimeType:Q.source.media_type,data:Q.source.data};else if(Q.source.type==="url"&&V(Q.source.url))return{type:"file",url:Q.source.url};else if(Q.source.type==="file"&&V(Q.source.file_id))return{type:"file",fileId:Q.source.file_id};else if(Q.source.type==="text"&&V(Q.source.data))return{type:"file",mimeType:String(Q.source.media_type??"text/plain"),data:Q.source.data}}else if(O(Q,"image")&&P(Q.source)&&"type"in Q.source){if(Q.source.type==="base64"&&V(Q.source.media_type)&&V(Q.source.data))return{type:"image",mimeType:Q.source.media_type,data:Q.source.data};else if(Q.source.type==="url"&&V(Q.source.url))return{type:"image",url:Q.source.url};else if(Q.source.type==="file"&&V(Q.source.file_id))return{type:"image",fileId:Q.source.file_id}}}function X6(Q){function*$(){for(let Y of Q){let q=K6(Y);if(q)yield q;else yield Y}}return Array.from($())}function z6(Q){function*$(){let Y=typeof Q.content==="string"?[{type:"text",text:Q.content}]:Q.content;for(let q of Y){if(O(q,"text")&&V(q.text)){let{text:W,citations:Z,...G}=q;if(o(Z)&&Z.length){let J=Z.reduce((z,K)=>{let X=s1(K);if(X)return[...z,X];return z},[]);yield{...G,type:"text",text:W,annotations:J};continue}else{yield{...G,type:"text",text:W};continue}}else if(O(q,"thinking")&&V(q.thinking)){let{thinking:W,signature:Z,...G}=q;yield{...G,type:"reasoning",reasoning:W,signature:Z};continue}else if(O(q,"redacted_thinking")){yield{type:"non_standard",value:q};continue}else if(O(q,"tool_use")&&V(q.name)&&V(q.id)){yield{type:"tool_call",id:q.id,name:q.name,args:q.input};continue}else if(O(q,"input_json_delta")){if(o1(Q)&&Q.tool_call_chunks?.length){let W=Q.tool_call_chunks[0];yield{type:"tool_call_chunk",id:W.id,name:W.name,args:W.args,index:W.index};continue}}else if(O(q,"server_tool_use")&&V(q.name)&&V(q.id)){let{name:W,id:Z}=q;if(W==="web_search"){yield{id:Z,type:"server_tool_call",name:"web_search",args:{query:NQ(()=>{if(typeof q.input==="string")return q.input;else if(P(q.input)&&V(q.input.query))return q.input.query;else if(V(q.partial_json)){let G=QY(q.partial_json);if(G?.query)return G.query}return""})}};continue}else if(q.name==="code_execution"){yield{id:Z,type:"server_tool_call",name:"code_execution",args:{code:NQ(()=>{if(typeof q.input==="string")return q.input;else if(P(q.input)&&V(q.input.code))return q.input.code;else if(V(q.partial_json)){let G=QY(q.partial_json);if(G?.code)return G.code}return""})}};continue}}else if(O(q,"web_search_tool_result")&&V(q.tool_use_id)&&o(q.content)){let{content:W,tool_use_id:Z}=q;yield{type:"server_tool_call_result",name:"web_search",toolCallId:Z,status:"success",output:{urls:W.reduce((G,J)=>{if(O(J,"web_search_result"))return[...G,J.url];return G},[])}};continue}else if(O(q,"code_execution_tool_result")&&V(q.tool_use_id)&&P(q.content)){yield{type:"server_tool_call_result",name:"code_execution",toolCallId:q.tool_use_id,status:"success",output:q.content};continue}else if(O(q,"mcp_tool_use")){yield{id:q.id,type:"server_tool_call",name:"mcp_tool_use",args:q.input};continue}else if(O(q,"mcp_tool_result")&&V(q.tool_use_id)&&P(q.content)){yield{type:"server_tool_call_result",name:"mcp_tool_use",toolCallId:q.tool_use_id,status:"success",output:q.content};continue}else if(O(q,"container_upload")){yield{type:"server_tool_call",name:"container_upload",args:q.input};continue}else if(O(q,"search_result")){yield{id:q.id,type:"non_standard",value:q};continue}else if(O(q,"tool_result")){yield{id:q.id,type:"non_standard",value:q};continue}else{let W=K6(q);if(W){yield W;continue}}yield{type:"non_standard",value:q}}}return Array.from($())}var U6={translateContent:z6,translateContentChunk:z6};function o1(Q){return typeof Q?._getType==="function"&&typeof Q.concat==="function"&&Q._getType()==="ai"}function t1(Q){if(Z6(Q))return{type:Q.type,mimeType:Q.mime_type,url:Q.url,metadata:Q.metadata};if(G6(Q))return{type:Q.type,mimeType:Q.mime_type??"application/octet-stream",data:Q.data,metadata:Q.metadata};if(J6(Q))return{type:Q.type,mimeType:Q.mime_type,fileId:Q.id,metadata:Q.metadata};return Q}function N6(Q){return Q.map(t1)}function B6(Q){if(O(Q,"image_url")&&P(Q.image_url))return!0;if(O(Q,"input_audio")&&P(Q.input_audio))return!0;if(O(Q,"file")&&P(Q.file))return!0;return!1}function F6(Q){if(O(Q,"image_url")&&P(Q.image_url)&&V(Q.image_url.url)){let $=e$({dataUrl:Q.image_url.url});if($)return{type:"image",mimeType:$.mime_type,data:$.data};else return{type:"image",url:Q.image_url.url}}else if(O(Q,"input_audio")&&P(Q.input_audio)&&V(Q.input_audio.data)&&V(Q.input_audio.format))return{type:"audio",data:Q.input_audio.data,mimeType:`audio/${Q.input_audio.format}`};else if(O(Q,"file")&&P(Q.file)&&V(Q.file.data)){let $=e$({dataUrl:Q.file.data});if($)return{type:"file",data:$.data,mimeType:$.mime_type};else if(V(Q.file.file_id))return{type:"file",fileId:Q.file.file_id}}return Q}function n1(Q){let $=[];if(typeof Q.content==="string"){if(Q.content.length>0)$.push({type:"text",text:Q.content})}else $.push(...c0(Q.content));for(let Y of Q.tool_calls??[])$.push({type:"tool_call",id:Y.id,name:Y.name,args:Y.args});return $}function r1(Q){let $=[];if(typeof Q.content==="string"){if(Q.content.length>0)$.push({type:"text",text:Q.content})}else $.push(...c0(Q.content));for(let Y of Q.tool_calls??[])$.push({type:"tool_call",id:Y.id,name:Y.name,args:Y.args});return $}function c0(Q){let $=[];for(let Y of Q)if(B6(Y))$.push(F6(Y));else $.push(Y);return $}function a1(Q){if(Q.type==="url_citation"){let{url:$,title:Y,start_index:q,end_index:W}=Q;return{type:"citation",url:$,title:Y,startIndex:q,endIndex:W}}if(Q.type==="file_citation"){let{file_id:$,filename:Y,index:q}=Q;return{type:"citation",title:Y,startIndex:q,endIndex:q,fileId:$}}return Q}function V6(Q){function*$(){if(P(Q.additional_kwargs?.reasoning)&&o(Q.additional_kwargs.reasoning.summary))yield{type:"reasoning",reasoning:Q.additional_kwargs.reasoning.summary.reduce((q,W)=>{if(P(W)&&V(W.text))return`${q}${W.text}`;return q},"")};let Y=typeof Q.content==="string"?[{type:"text",text:Q.content}]:Q.content;for(let q of Y)if(O(q,"text")){let{text:W,annotations:Z,...G}=q;if(Array.isArray(Z))yield{...G,type:"text",text:String(W),annotations:Z.map(a1)};else yield{...G,type:"text",text:String(W)}}for(let q of Q.tool_calls??[])yield{type:"tool_call",id:q.id,name:q.name,args:q.args};if(P(Q.additional_kwargs)&&o(Q.additional_kwargs.tool_outputs))for(let q of Q.additional_kwargs.tool_outputs){if(O(q,"web_search_call")){let W={};if(P(q.action)&&V(q.action.query))W.query=q.action.query;if(yield{id:q.id,type:"server_tool_call",name:"web_search",args:W},q.status==="completed"||q.status==="failed"){let Z={};if(P(q.action))Z.action=q.action;yield{type:"server_tool_call_result",toolCallId:V(q.id)?q.id:"",status:q.status==="completed"?"success":"error",output:Z}}continue}else if(O(q,"file_search_call")){if(yield{id:q.id,type:"server_tool_call",name:"file_search",args:{queries:o(q.queries)?q.queries:[]}},q.status==="completed"||q.status==="failed")yield{type:"server_tool_call_result",toolCallId:V(q.id)?q.id:"",status:q.status==="completed"?"success":"error",output:o(q.results)?{results:q.results}:{}};continue}else if(O(q,"computer_call")){yield{type:"non_standard",value:q};continue}else if(O(q,"code_interpreter_call")){if(V(q.code))yield{id:q.id,type:"server_tool_call",name:"code_interpreter",args:{code:q.code}};if(o(q.outputs)){let W=NQ(()=>{if(q.status==="in_progress")return;if(q.status==="completed")return 0;if(q.status==="incomplete")return 127;if(q.status==="interpreting")return;if(q.status==="failed")return 1});for(let Z of q.outputs)if(O(Z,"logs")){yield{type:"server_tool_call_result",toolCallId:q.id??"",status:"success",output:{type:"code_interpreter_output",returnCode:W??0,stderr:[0,void 0].includes(W)?void 0:String(Z.logs),stdout:[0,void 0].includes(W)?String(Z.logs):void 0}};continue}}continue}else if(O(q,"mcp_call")){yield{id:q.id,type:"server_tool_call",name:"mcp_call",args:q.input};continue}else if(O(q,"mcp_list_tools")){yield{id:q.id,type:"server_tool_call",name:"mcp_list_tools",args:q.input};continue}else if(O(q,"mcp_approval_request")){yield{type:"non_standard",value:q};continue}else if(O(q,"image_generation_call")){if(V(q.result))yield{type:"image",mimeType:"image/png",data:q.result,id:V(q.id)?q.id:void 0,metadata:{status:V(q.status)?q.status:void 0}};yield{type:"non_standard",value:q};continue}if(P(q))yield{type:"non_standard",value:q}}}return Array.from($())}function e1(Q){function*$(){yield*V6(Q);for(let Y of Q.tool_call_chunks??[])yield{type:"tool_call_chunk",id:Y.id,name:Y.name,args:Y.args}}return Array.from($())}var A6={translateContent:(Q)=>{if(typeof Q.content==="string")return n1(Q);return V6(Q)},translateContentChunk:(Q)=>{if(typeof Q.content==="string")return r1(Q);return e1(Q)}};function H6(Q){return typeof Q==="object"&&Q!==null&&"type"in Q&&"content"in Q&&(typeof Q.content==="string"||Array.isArray(Q.content))}function D6(Q,$="pretty"){if($==="pretty")return QZ(Q);return JSON.stringify(Q)}function QZ(Q){let $=[],Y=` ${Q.type.charAt(0).toUpperCase()+Q.type.slice(1)} Message `,q=Math.floor((80-Y.length)/2),W="=".repeat(q),Z=Y.length%2===0?W:`${W}=`;if($.push(`${W}${Y}${Z}`),Q.type==="ai"){let G=Q;if(G.tool_calls&&G.tool_calls.length>0){$.push("Tool Calls:");for(let J of G.tool_calls){$.push(` ${J.name} (${J.id})`),$.push(` Call ID: ${J.id}`),$.push(" Args:");for(let[z,K]of Object.entries(J.args))$.push(` ${z}: ${typeof K==="object"?JSON.stringify(K):K}`)}}}if(Q.type==="tool"){let G=Q;if(G.name)$.push(`Name: ${G.name}`)}if(typeof Q.content==="string"&&Q.content.trim()){if($.length>1)$.push("");$.push(Q.content)}return $.join(`
2
2
  `)}var $Y=Symbol.for("langchain.message");function ZQ(Q,$){if(typeof Q==="string"){if(Q==="")return $;if(typeof $==="string")return Q+$;else if(Array.isArray($)&&$.length===0)return Q;else if(Array.isArray($)&&$.some((Y)=>gQ(Y)))return[{type:"text",source_type:"text",text:Q},...$];else return[{type:"text",text:Q},...$]}else if(Array.isArray($))return N0(Q,$)??[...Q,...$];else if($==="")return Q;else if(Array.isArray(Q)&&Q.some((Y)=>gQ(Y)))return[...Q,{type:"file",source_type:"text",text:$}];else return[...Q,{type:"text",text:$}]}function O6(Q,$){if(Q==="error"||$==="error")return"error";return"success"}function $Z(Q,$){function Y(q,W){if(typeof q!=="object"||q===null||q===void 0)return q;if(W>=$){if(Array.isArray(q))return"[Array]";return"[Object]"}if(Array.isArray(q))return q.map((G)=>Y(G,W+1));let Z={};for(let G of Object.keys(q))Z[G]=Y(q[G],W+1);return Z}return JSON.stringify(Y(Q,0),null,2)}var e=class extends RQ{lc_namespace=["langchain_core","messages"];lc_serializable=!0;get lc_aliases(){return{additional_kwargs:"additional_kwargs",response_metadata:"response_metadata"}}[$Y]=!0;id;name;content;additional_kwargs;response_metadata;_getType(){return this.type}getType(){return this._getType()}constructor(Q){let $=typeof Q==="string"||Array.isArray(Q)?{content:Q}:Q;if(!$.additional_kwargs)$.additional_kwargs={};if(!$.response_metadata)$.response_metadata={};super($);if(this.name=$.name,$.content===void 0&&$.contentBlocks!==void 0)this.content=$.contentBlocks,this.response_metadata={output_version:"v1",...$.response_metadata};else if($.content!==void 0)this.content=$.content??[],this.response_metadata=$.response_metadata;else this.content=[],this.response_metadata=$.response_metadata;this.additional_kwargs=$.additional_kwargs,this.id=$.id}get text(){if(typeof this.content==="string")return this.content;if(!Array.isArray(this.content))return"";return this.content.map((Q)=>{if(typeof Q==="string")return Q;if(Q.type==="text")return Q.text;return""}).join("")}get contentBlocks(){let Q=typeof this.content==="string"?[{type:"text",text:this.content}]:this.content;return[N6,c0,X6].reduce(($,Y)=>Y($),Q)}toDict(){return{type:this.getType(),data:this.toJSON().kwargs}}static lc_name(){return"BaseMessage"}get _printableFields(){return{id:this.id,content:this.content,name:this.name,additional_kwargs:this.additional_kwargs,response_metadata:this.response_metadata}}static isInstance(Q){return typeof Q==="object"&&Q!==null&&$Y in Q&&Q[$Y]===!0&&H6(Q)}_updateId(Q){this.id=Q,this.lc_kwargs.id=Q}get[Symbol.toStringTag](){return this.constructor.lc_name()}[Symbol.for("nodejs.util.inspect.custom")](Q){if(Q===null)return this;let $=$Z(this._printableFields,Math.max(4,Q));return`${this.constructor.lc_name()} ${$}`}toFormattedString(Q="pretty"){return D6(this,Q)}};function _9(Q){return Array.isArray(Q)&&Q.every(($)=>typeof $.index==="number")}var YZ=["index","created","timestamp"];function p(Q,$,Y){let q=Y?.ignoreKeys??YZ;if(Q==null&&$==null)return;if(Q==null||$==null)return Q??$;let W={...Q};for(let[Z,G]of Object.entries($))if(W[Z]==null)W[Z]=G;else if(G==null)continue;else if(typeof W[Z]!==typeof G||Array.isArray(W[Z])!==Array.isArray(G))throw Error(`field[${Z}] already exists in the message chunk, but with a different type.`);else if(typeof W[Z]==="string")if(Z==="type")continue;else if(["id","name","output_version","model_provider"].includes(Z)){if(G)W[Z]=G}else if(q.includes(Z))continue;else W[Z]+=G;else if(typeof W[Z]==="number"){if(q.includes(Z))continue;W[Z]=W[Z]+G}else if(typeof W[Z]==="object"&&!Array.isArray(W[Z]))W[Z]=p(W[Z],G,Y);else if(Array.isArray(W[Z]))W[Z]=N0(W[Z],G,Y);else if(W[Z]===G)continue;else console.warn(`field[${Z}] already exists in this message chunk and value has unsupported type.`);return W}function qZ(Q){return typeof Q==="number"||typeof Q==="string"}function w6(Q){if(typeof Q!=="object"||Q===null)return!1;if(!("index"in Q))return!1;return qZ(Q.index)}function N0(Q,$,Y){if(Q==null&&$==null)return;else if(Q==null||$==null)return Q||$;else{let q=[...Q];for(let W of $)if(w6(W)){let Z=q.findIndex((G)=>{if(!w6(G))return!1;let J=G.index===W.index,z=G.id!=null&&W.id!=null&&G.id===W.id,K=G.id==null||W.id==null;return J&&(z||K)});if(Z!==-1&&typeof q[Z]==="object"&&q[Z]!==null)q[Z]=p(q[Z],W,Y);else q.push(W)}else if(typeof W==="object"&&W!==null&&"text"in W&&W.text==="")continue;else q.push(W);return q}}function E6(Q,$,Y){if(Q==null&&$==null)return;if(Q==null||$==null)return Q??$;else if(typeof Q!==typeof $)throw Error(`Cannot merge objects of different types.
3
3
  Left ${typeof Q}
4
4
  Right ${typeof $}`);else if(typeof Q==="string"&&typeof $==="string")return Q+$;else if(Array.isArray(Q)&&Array.isArray($))return N0(Q,$,Y);else if(typeof Q==="object"&&typeof $==="object")return p(Q,$,Y);else if(Q===$)return Q;else throw Error(`Can not merge objects of different types.
@@ -86,4 +86,4 @@ ${y1.prettifyError(B)}`;throw new U0(A,JSON.stringify(Q))}else{let B=k1(q,this.s
86
86
  Details: ${B.errors.map((D)=>`${D.keywordLocation}: ${D.error}`).join(`
87
87
  `)}`;throw new U0(A,JSON.stringify(Q))}W=q}let Z=_0($),G=LQ.configure(Z.callbacks,this.callbacks,Z.tags||Y,this.tags,Z.metadata,this.metadata,{verbose:this.verbose}),J;if(fQ(Q))J=Q.id;if(!J&&a8(Z))J=Z.toolCall.id;let z=await G?.handleToolStart(this.toJSON(),typeof Q==="string"?Q:JSON.stringify(Q),Z.runId,void 0,void 0,void 0,Z.runName,J);delete Z.runId;let K;try{let B=await this._call(W,z,Z);K=W1(B)?await Z1(B,async(A)=>{try{await z?.handleToolEvent(A)}catch(D){await z?.handleToolError(D)}}):B}catch(B){throw await z?.handleToolError(B),B}let X,U;if(this.responseFormat==="content_and_artifact")if(Array.isArray(K)&&K.length===2)[X,U]=K;else throw Error(`Tool response format is "content_and_artifact" but the output was not a two-tuple.
88
88
  Result: ${JSON.stringify(K)}`);else X=K;let N=iJ({content:X,artifact:U,toolCallId:J,name:this.name,metadata:this.metadata});return await z?.handleToolEnd(N),N}},b1=class extends n8{schema=tQ.object({input:tQ.string().optional()}).transform((Q)=>Q.input);constructor(Q){super(Q)}call(Q,$){let Y=typeof Q==="string"||Q==null?{input:Q}:Q;return super.call(Y,$)}},h1=class extends b1{static lc_name(){return"DynamicTool"}name;description;func;constructor(Q){super(Q);this.name=Q.name,this.description=Q.description,this.func=Q.func,this.returnDirect=Q.returnDirect??this.returnDirect}async call(Q,$){let Y=_0($);if(Y.runName===void 0)Y.runName=this.name;return super.call(Q,Y)}_call(Q,$,Y){return this.func(Q,$,Y)}},f1=class extends n8{static lc_name(){return"DynamicStructuredTool"}description;func;schema;constructor(Q){super(Q);this.name=Q.name,this.description=Q.description,this.func=Q.func,this.returnDirect=Q.returnDirect??this.returnDirect,this.schema=Q.schema}async call(Q,$,Y){let q=_0($);if(q.runName===void 0)q.runName=this.name;return super.call(Q,q,Y)}_call(Q,$,Y){return this.func(Q,$,Y)}},cJ=class{getTools(){return this.tools}};function lJ(Q,$){let Y=S$($.schema),q=L0($.schema);if(!$.schema||Y||q)return new h1({...$,description:$.description??$.schema?.description??`${$.name} tool`,func:async(G,J,z)=>{return new Promise((K,X)=>{let U=l(z,{callbacks:J?.getChild()});a.runWithConfig(DQ(U),async()=>{try{K(Q(G,U))}catch(N){X(N)}})})}});let W=$.schema,Z=$.description??$.schema.description??`${$.name} tool`;return new f1({...$,description:Z,schema:W,func:async(G,J,z)=>{return new Promise((K,X)=>{let U,N=()=>{if(z?.signal&&U)z.signal.removeEventListener("abort",U)};if(z?.signal)U=()=>{N(),X(iQ(z.signal))},z.signal.addEventListener("abort",U,{once:!0});let B=l(z,{callbacks:J?.getChild()});a.runWithConfig(DQ(B),async()=>{try{let A=await Q(G,B);if(z?.signal?.aborted){N();return}N(),K(A)}catch(A){N(),X(A)}})})}})}function iJ(Q){let{content:$,artifact:Y,toolCallId:q,metadata:W}=Q;if(q&&!YY($))if(typeof $==="string"||Array.isArray($)&&$.every((Z)=>typeof Z==="object"))return new aQ({status:"success",content:$,artifact:Y,tool_call_id:q,name:Q.name,metadata:W});else return new aQ({status:"success",content:sJ($),artifact:Y,tool_call_id:q,name:Q.name,metadata:W});else return $}function sJ(Q){try{return JSON.stringify(Q)??""}catch($){return`${Q}`}}
89
- export{M as dh,U0 as eh,rJ as fh,Y6 as gh,u1 as hh,q6 as ih,q9 as jh,p0 as kh,RQ as lh,gQ as mh,Z6 as nh,G6 as oh,Z9 as ph,J6 as qh,G9 as rh,J9 as sh,e$ as th,z9 as uh,H6 as vh,ZQ as wh,O6 as xh,e as yh,_9 as zh,YZ as Ah,p as Bh,N0 as Ch,E6 as Dh,BQ as Eh,L6 as Fh,P6 as Gh,I9 as Hh,y9 as Ih,YY as Jh,aQ as Kh,WZ as Lh,qY as Mh,ZZ as Nh,GZ as Oh,d9 as Ph,WY as Qh,JZ as Rh,zZ as Sh,l9 as Th,GY as Uh,p6 as Vh,i0 as Wh,B0 as Xh,M4 as Yh,_4 as Zh,F0 as _h,KY as $h,l6 as ai,C4 as bi,y4 as ci,i6 as di,s6 as ei,f4 as fi,g4 as gi,eQ as hi,o6 as ii,c4 as ji,l4 as ki,t6 as li,s0 as mi,n6 as ni,e4 as oi,Qz as pi,Fz as qi,r6 as ri,o0 as si,UY as ti,Vz as ui,Az as vi,Hz as wi,c6 as xi,Oz as yi,Yq as zi,OQ as Ai,Tz as Bi,OZ as Ci,$0 as Di,dQ as Ei,YX as Fi,EQ as Gi,JX as Hi,RX as Ii,yX as Ji,eX as Ki,_0 as Li,LQ as Mi,a as Ni,A2 as Oi,HQ as Pi,x0 as Qi,C as Ri,l as Si,DQ as Ti,jQ as Ui,m as Vi,s as Wi,S2 as Xi,O0 as Yi,iG as Zi,sG as _i,T2 as $i,R2 as aj,P$ as bj,M2 as cj,_2 as dj,sW as ej,I2 as fj,S$ as gj,oW as hj,CQ as ij,$8 as jj,oG as kj,tG as lj,x2 as mj,dW as nj,j2 as oj,v2 as pj,E$ as qj,pW as rj,C2 as sj,tW as tj,y2 as uj,nW as vj,T5 as wj,GJ as xj,y5 as yj,b8 as zj,j$ as Aj,u5 as Bj,t5 as Cj,Z7 as Dj,J0 as Ej,B7 as Fj,YQ as Gj,k$ as Hj,sQ as Ij,z0 as Jj,PJ as Kj,y7 as Lj,g7 as Mj,TJ as Nj,f0 as Oj,RJ as Pj,ZN as Qj,l$ as Rj,n as Sj,r as Tj,i$ as Uj,IN as Vj,R1 as Wj,M1 as Xj,s$ as Yj,_1 as Zj,xN as _j,CJ as $j,K0 as ak,yJ as bk,kJ as ck,T1 as dk,uN as ek,l8 as fk,i8 as gk,hJ as hk,aN as ik,JB as jk,v1 as kk,mJ as lk,uJ as mk,s8 as nk,o8 as ok,t8 as pk,C1 as qk,xB as rk,n8 as sk,f1 as tk,lJ as uk};
89
+ export{M as $g,U0 as ah,rJ as bh,Y6 as ch,u1 as dh,q6 as eh,q9 as fh,p0 as gh,RQ as hh,gQ as ih,Z6 as jh,G6 as kh,Z9 as lh,J6 as mh,G9 as nh,J9 as oh,e$ as ph,z9 as qh,H6 as rh,ZQ as sh,O6 as th,e as uh,_9 as vh,YZ as wh,p as xh,N0 as yh,E6 as zh,BQ as Ah,L6 as Bh,P6 as Ch,I9 as Dh,y9 as Eh,YY as Fh,aQ as Gh,WZ as Hh,qY as Ih,ZZ as Jh,GZ as Kh,d9 as Lh,WY as Mh,JZ as Nh,zZ as Oh,l9 as Ph,GY as Qh,p6 as Rh,i0 as Sh,B0 as Th,M4 as Uh,_4 as Vh,F0 as Wh,KY as Xh,l6 as Yh,C4 as Zh,y4 as _h,i6 as $h,s6 as ai,f4 as bi,g4 as ci,eQ as di,o6 as ei,c4 as fi,l4 as gi,t6 as hi,s0 as ii,n6 as ji,e4 as ki,Qz as li,Fz as mi,r6 as ni,o0 as oi,UY as pi,Vz as qi,Az as ri,Hz as si,c6 as ti,Oz as ui,Yq as vi,OQ as wi,Tz as xi,OZ as yi,$0 as zi,dQ as Ai,YX as Bi,EQ as Ci,JX as Di,RX as Ei,yX as Fi,eX as Gi,_0 as Hi,LQ as Ii,a as Ji,A2 as Ki,HQ as Li,x0 as Mi,C as Ni,l as Oi,DQ as Pi,jQ as Qi,m as Ri,s as Si,S2 as Ti,O0 as Ui,iG as Vi,sG as Wi,T2 as Xi,R2 as Yi,P$ as Zi,M2 as _i,_2 as $i,sW as aj,I2 as bj,S$ as cj,oW as dj,CQ as ej,$8 as fj,oG as gj,tG as hj,x2 as ij,dW as jj,j2 as kj,v2 as lj,E$ as mj,pW as nj,C2 as oj,tW as pj,y2 as qj,nW as rj,T5 as sj,GJ as tj,y5 as uj,b8 as vj,j$ as wj,u5 as xj,t5 as yj,Z7 as zj,J0 as Aj,B7 as Bj,YQ as Cj,k$ as Dj,sQ as Ej,z0 as Fj,PJ as Gj,y7 as Hj,g7 as Ij,TJ as Jj,f0 as Kj,RJ as Lj,ZN as Mj,l$ as Nj,n as Oj,r as Pj,i$ as Qj,IN as Rj,R1 as Sj,M1 as Tj,s$ as Uj,_1 as Vj,xN as Wj,CJ as Xj,K0 as Yj,yJ as Zj,kJ as _j,T1 as $j,uN as ak,l8 as bk,i8 as ck,hJ as dk,aN as ek,JB as fk,v1 as gk,mJ as hk,uJ as ik,s8 as jk,o8 as kk,t8 as lk,C1 as mk,xB as nk,n8 as ok,f1 as pk,lJ as qk};
@@ -1 +1 @@
1
- import{E as k}from"./chunk-1d47g6nc.js";import"./chunk-5fe27s34.js";import"./chunk-5hqvapp1.js";import{U as R,X as g,Y as r,fa as b,ga as B}from"./chunk-h7ypcqp3.js";import{Wl as m}from"./chunk-4fs853nh.js";var w=m(R(),1);var u=m(R(),1);var n=m(b(),1),H=({field:e,value:t,isFocused:o})=>n.jsxDEV(g,{flexDirection:"row",children:[n.jsxDEV(r,{bold:o,color:o?"cyan":void 0,children:e.label},void 0,!1,void 0,this),n.jsxDEV(r,{dimColor:!0,children:": "},void 0,!1,void 0,this),n.jsxDEV(r,{color:t?"green":"gray",bold:o,children:t?"ON":"OFF"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),J=({field:e,value:t,isFocused:o})=>n.jsxDEV(g,{flexDirection:"row",children:[n.jsxDEV(r,{bold:o,color:o?"cyan":void 0,children:e.label},void 0,!1,void 0,this),n.jsxDEV(r,{dimColor:!0,children:": "},void 0,!1,void 0,this),n.jsxDEV(r,{color:o?"yellow":void 0,bold:o,children:t??e.min??0},void 0,!1,void 0,this),n.jsxDEV(r,{dimColor:!0,children:" ms"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),L=({field:e,value:t,isFocused:o})=>{let a=e.options?.find((y)=>y.value===t);return n.jsxDEV(g,{flexDirection:"row",children:[n.jsxDEV(r,{bold:o,color:o?"cyan":void 0,children:e.label},void 0,!1,void 0,this),n.jsxDEV(r,{dimColor:!0,children:": "},void 0,!1,void 0,this),n.jsxDEV(r,{color:o?"yellow":void 0,bold:o,children:a?.label||t},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},Y=({field:e,value:t,isFocused:o})=>n.jsxDEV(g,{flexDirection:"row",children:[n.jsxDEV(r,{bold:o,color:o?"cyan":void 0,children:e.label},void 0,!1,void 0,this),n.jsxDEV(r,{dimColor:!0,children:": "},void 0,!1,void 0,this),n.jsxDEV(r,{color:o?"yellow":"gray",bold:o,children:t||e.placeholder||"-"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),q=(e)=>{switch(e.field.type){case"toggle":return n.jsxDEV(H,{...e},void 0,!1,void 0,this);case"number":return n.jsxDEV(J,{...e},void 0,!1,void 0,this);case"select":return n.jsxDEV(L,{...e},void 0,!1,void 0,this);case"input":return n.jsxDEV(Y,{...e},void 0,!1,void 0,this);default:return n.jsxDEV(r,{color:"red",children:"Unknown"},void 0,!1,void 0,this)}},M=q;var x=[{key:"compact_mode",label:"紧凑模式",type:"toggle",group:"显示",tab:"General",help:"紧凑显示消息 (Ctrl+O)"},{key:"show_detailed_info",label:"系统信息",type:"toggle",group:"显示",tab:"General",help:"显示系统资源信息"},{key:"enable_thinking",label:"思考模式",type:"toggle",group:"模型",tab:"General",help:"启用模型思考"},{key:"streaming",label:"流式输出",type:"toggle",group:"模型",tab:"General",help:"关闭后等待完整响应再显示(适用于不支持流式的模型)"},{key:"stream_refresh_interval",label:"流刷新间隔",type:"number",group:"模型",tab:"General",min:50,max:1000,step:50,help:"流刷新间隔 (ms)"}],S=(()=>{let e=new Map;return x.forEach((t)=>{let o=t.tab||"General";if(!e.has(o))e.set(o,{id:o,label:o,icon:"⚙"})}),Array.from(e.values())})(),D=(()=>{let e=new Map;return x.forEach((t)=>{if(!e.has(t.group))e.set(t.group,{id:t.group,label:t.group,fields:[]});e.get(t.group).fields.push(t)}),Array.from(e.values())})();function z(e){return x.filter((t)=>(t.tab||"General")===e)}function _(e){let t=z(e),o=new Map;return t.forEach((a)=>{if(!o.has(a.group))o.set(a.group,{id:a.group,label:a.group,fields:[]});o.get(a.group).fields.push(a)}),Array.from(o.values())}var f=m(b(),1);function K(e){switch(e.type){case"toggle":return!1;case"number":return e.min??0;case"select":return e.options?.[0]?.value;case"input":return"";default:return}}var Q=({schema:e,config:t,onUpdate:o,activeTab:a="General"})=>{let y=u.useMemo(()=>_(a),[a]),T=u.useMemo(()=>y.flatMap((l)=>l.fields),[y]),[P,h]=u.useState(0),p=T[P],c=u.useCallback((l,i)=>{o(l.key,i)},[o]),G=u.useCallback((l)=>{c(l,!t[l.key])},[t,c]),A=u.useCallback((l,i)=>{let d=t[l.key]??K(l),F=l.step||1,C=l.min??-1/0,I=l.max??1/0;c(l,Math.max(C,Math.min(I,d+i*F)))},[t,c]),U=u.useCallback((l,i)=>{let d=l.options||[];if(!d.length)return;let C=(d.findIndex((I)=>I.value===t[l.key])+i+d.length)%d.length;c(l,d[C].value)},[t,c]);B((l,i)=>{if(i.upArrow)h((d)=>Math.max(0,d-1));else if(i.downArrow)h((d)=>Math.min(T.length-1,d+1));else if(i.leftArrow||i.rightArrow){let d=i.leftArrow?-1:1;if(p?.type==="toggle")G(p);else if(p?.type==="number")A(p,d);else if(p?.type==="select")U(p,d)}},{isActive:!0});let X=0;return f.jsxDEV(g,{flexDirection:"column",paddingX:2,paddingY:1,children:[y.map((l)=>f.jsxDEV(g,{flexDirection:"column",marginBottom:1,children:[f.jsxDEV(r,{bold:!0,color:"gray",children:["[",l.label,"]"]},void 0,!0,void 0,this),l.fields.map((i)=>{let F=X++===P;return f.jsxDEV(g,{flexDirection:"column",children:[f.jsxDEV(M,{field:i,value:t[i.key],onChange:(C)=>c(i,C),isFocused:F},void 0,!1,void 0,this),F&&i.help&&f.jsxDEV(r,{dimColor:!0,color:"yellow",children:[" ","→ ",i.help]},void 0,!0,void 0,this)]},i.key,!0,void 0,this)})]},l.id,!0,void 0,this)),f.jsxDEV(g,{marginTop:1,children:f.jsxDEV(r,{dimColor:!0,children:"↑↓ 导航 | ←→ 修改"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},v=Q;var s=m(b(),1),W=({onClose:e})=>{let{config:t,updateConfig:o}=k(),[a,y]=w.useState("General"),T=S.length>1,P=w.useCallback(async(p,c)=>{await o({[p]:c})},[o]),h=w.useCallback((p)=>{if(!T)return;let G=(S.findIndex((A)=>A.id===a)+p+S.length)%S.length;y(S[G].id)},[a,T]);if(B((p,c)=>{if(c.escape)e();else if(c.leftArrow&&c.alt)h(-1);else if(c.rightArrow&&c.alt)h(1)},{isActive:t!==null}),!t)return s.jsxDEV(g,{padding:2,children:s.jsxDEV(r,{children:"Loading..."},void 0,!1,void 0,this)},void 0,!1,void 0,this);return s.jsxDEV(g,{flexDirection:"column",width:"100%",borderStyle:"single",borderColor:"gray",children:[s.jsxDEV(g,{paddingX:2,borderBottom:!0,borderColor:"gray",children:s.jsxDEV(r,{bold:!0,color:"cyan",children:"⚙ Settings"},void 0,!1,void 0,this)},void 0,!1,void 0,this),T&&s.jsxDEV(g,{flexDirection:"row",gap:2,paddingX:2,borderBottom:!0,borderColor:"gray",children:S.map((p)=>s.jsxDEV(r,{bold:a===p.id,color:a===p.id?"cyan":"gray",children:[p.icon," ",p.label]},p.id,!0,void 0,this))},void 0,!1,void 0,this),s.jsxDEV(v,{schema:x,config:t,onUpdate:P,activeTab:a},void 0,!1,void 0,this),s.jsxDEV(g,{paddingX:2,borderTop:!0,borderColor:"gray",children:s.jsxDEV(r,{dimColor:!0,children:"Esc: Close | Auto-save | Global: Ctrl+O (Compact)"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},N=W;var O=m(b(),1),Z=({onClose:e})=>{return O.jsxDEV(N,{onClose:e},void 0,!1,void 0,this)},ue=Z;export{ue as default};
1
+ import{E as k}from"./chunk-j40cj742.js";import"./chunk-6t0qzren.js";import"./chunk-w4tbr5h7.js";import{U as R,X as g,Y as r,fa as b,ga as B}from"./chunk-bqkrynm6.js";import{Rl as m}from"./chunk-x17jyjan.js";var w=m(R(),1);var u=m(R(),1);var n=m(b(),1),H=({field:e,value:t,isFocused:o})=>n.jsxDEV(g,{flexDirection:"row",children:[n.jsxDEV(r,{bold:o,color:o?"cyan":void 0,children:e.label},void 0,!1,void 0,this),n.jsxDEV(r,{dimColor:!0,children:": "},void 0,!1,void 0,this),n.jsxDEV(r,{color:t?"green":"gray",bold:o,children:t?"ON":"OFF"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),J=({field:e,value:t,isFocused:o})=>n.jsxDEV(g,{flexDirection:"row",children:[n.jsxDEV(r,{bold:o,color:o?"cyan":void 0,children:e.label},void 0,!1,void 0,this),n.jsxDEV(r,{dimColor:!0,children:": "},void 0,!1,void 0,this),n.jsxDEV(r,{color:o?"yellow":void 0,bold:o,children:t??e.min??0},void 0,!1,void 0,this),n.jsxDEV(r,{dimColor:!0,children:" ms"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),L=({field:e,value:t,isFocused:o})=>{let a=e.options?.find((y)=>y.value===t);return n.jsxDEV(g,{flexDirection:"row",children:[n.jsxDEV(r,{bold:o,color:o?"cyan":void 0,children:e.label},void 0,!1,void 0,this),n.jsxDEV(r,{dimColor:!0,children:": "},void 0,!1,void 0,this),n.jsxDEV(r,{color:o?"yellow":void 0,bold:o,children:a?.label||t},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},Y=({field:e,value:t,isFocused:o})=>n.jsxDEV(g,{flexDirection:"row",children:[n.jsxDEV(r,{bold:o,color:o?"cyan":void 0,children:e.label},void 0,!1,void 0,this),n.jsxDEV(r,{dimColor:!0,children:": "},void 0,!1,void 0,this),n.jsxDEV(r,{color:o?"yellow":"gray",bold:o,children:t||e.placeholder||"-"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),q=(e)=>{switch(e.field.type){case"toggle":return n.jsxDEV(H,{...e},void 0,!1,void 0,this);case"number":return n.jsxDEV(J,{...e},void 0,!1,void 0,this);case"select":return n.jsxDEV(L,{...e},void 0,!1,void 0,this);case"input":return n.jsxDEV(Y,{...e},void 0,!1,void 0,this);default:return n.jsxDEV(r,{color:"red",children:"Unknown"},void 0,!1,void 0,this)}},M=q;var x=[{key:"compact_mode",label:"紧凑模式",type:"toggle",group:"显示",tab:"General",help:"紧凑显示消息 (Ctrl+O)"},{key:"show_detailed_info",label:"系统信息",type:"toggle",group:"显示",tab:"General",help:"显示系统资源信息"},{key:"enable_thinking",label:"思考模式",type:"toggle",group:"模型",tab:"General",help:"启用模型思考"},{key:"streaming",label:"流式输出",type:"toggle",group:"模型",tab:"General",help:"关闭后等待完整响应再显示(适用于不支持流式的模型)"},{key:"stream_refresh_interval",label:"流刷新间隔",type:"number",group:"模型",tab:"General",min:50,max:1000,step:50,help:"流刷新间隔 (ms)"}],S=(()=>{let e=new Map;return x.forEach((t)=>{let o=t.tab||"General";if(!e.has(o))e.set(o,{id:o,label:o,icon:"⚙"})}),Array.from(e.values())})(),D=(()=>{let e=new Map;return x.forEach((t)=>{if(!e.has(t.group))e.set(t.group,{id:t.group,label:t.group,fields:[]});e.get(t.group).fields.push(t)}),Array.from(e.values())})();function z(e){return x.filter((t)=>(t.tab||"General")===e)}function _(e){let t=z(e),o=new Map;return t.forEach((a)=>{if(!o.has(a.group))o.set(a.group,{id:a.group,label:a.group,fields:[]});o.get(a.group).fields.push(a)}),Array.from(o.values())}var f=m(b(),1);function K(e){switch(e.type){case"toggle":return!1;case"number":return e.min??0;case"select":return e.options?.[0]?.value;case"input":return"";default:return}}var Q=({schema:e,config:t,onUpdate:o,activeTab:a="General"})=>{let y=u.useMemo(()=>_(a),[a]),T=u.useMemo(()=>y.flatMap((l)=>l.fields),[y]),[P,h]=u.useState(0),p=T[P],c=u.useCallback((l,i)=>{o(l.key,i)},[o]),G=u.useCallback((l)=>{c(l,!t[l.key])},[t,c]),A=u.useCallback((l,i)=>{let d=t[l.key]??K(l),F=l.step||1,C=l.min??-1/0,I=l.max??1/0;c(l,Math.max(C,Math.min(I,d+i*F)))},[t,c]),U=u.useCallback((l,i)=>{let d=l.options||[];if(!d.length)return;let C=(d.findIndex((I)=>I.value===t[l.key])+i+d.length)%d.length;c(l,d[C].value)},[t,c]);B((l,i)=>{if(i.upArrow)h((d)=>Math.max(0,d-1));else if(i.downArrow)h((d)=>Math.min(T.length-1,d+1));else if(i.leftArrow||i.rightArrow){let d=i.leftArrow?-1:1;if(p?.type==="toggle")G(p);else if(p?.type==="number")A(p,d);else if(p?.type==="select")U(p,d)}},{isActive:!0});let X=0;return f.jsxDEV(g,{flexDirection:"column",paddingX:2,paddingY:1,children:[y.map((l)=>f.jsxDEV(g,{flexDirection:"column",marginBottom:1,children:[f.jsxDEV(r,{bold:!0,color:"gray",children:["[",l.label,"]"]},void 0,!0,void 0,this),l.fields.map((i)=>{let F=X++===P;return f.jsxDEV(g,{flexDirection:"column",children:[f.jsxDEV(M,{field:i,value:t[i.key],onChange:(C)=>c(i,C),isFocused:F},void 0,!1,void 0,this),F&&i.help&&f.jsxDEV(r,{dimColor:!0,color:"yellow",children:[" ","→ ",i.help]},void 0,!0,void 0,this)]},i.key,!0,void 0,this)})]},l.id,!0,void 0,this)),f.jsxDEV(g,{marginTop:1,children:f.jsxDEV(r,{dimColor:!0,children:"↑↓ 导航 | ←→ 修改"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},v=Q;var s=m(b(),1),W=({onClose:e})=>{let{config:t,updateConfig:o}=k(),[a,y]=w.useState("General"),T=S.length>1,P=w.useCallback(async(p,c)=>{await o({[p]:c})},[o]),h=w.useCallback((p)=>{if(!T)return;let G=(S.findIndex((A)=>A.id===a)+p+S.length)%S.length;y(S[G].id)},[a,T]);if(B((p,c)=>{if(c.escape)e();else if(c.leftArrow&&c.alt)h(-1);else if(c.rightArrow&&c.alt)h(1)},{isActive:t!==null}),!t)return s.jsxDEV(g,{padding:2,children:s.jsxDEV(r,{children:"Loading..."},void 0,!1,void 0,this)},void 0,!1,void 0,this);return s.jsxDEV(g,{flexDirection:"column",width:"100%",borderStyle:"single",borderColor:"gray",children:[s.jsxDEV(g,{paddingX:2,borderBottom:!0,borderColor:"gray",children:s.jsxDEV(r,{bold:!0,color:"cyan",children:"⚙ Settings"},void 0,!1,void 0,this)},void 0,!1,void 0,this),T&&s.jsxDEV(g,{flexDirection:"row",gap:2,paddingX:2,borderBottom:!0,borderColor:"gray",children:S.map((p)=>s.jsxDEV(r,{bold:a===p.id,color:a===p.id?"cyan":"gray",children:[p.icon," ",p.label]},p.id,!0,void 0,this))},void 0,!1,void 0,this),s.jsxDEV(v,{schema:x,config:t,onUpdate:P,activeTab:a},void 0,!1,void 0,this),s.jsxDEV(g,{paddingX:2,borderTop:!0,borderColor:"gray",children:s.jsxDEV(r,{dimColor:!0,children:"Esc: Close | Auto-save | Global: Ctrl+O (Compact)"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},N=W;var O=m(b(),1),Z=({onClose:e})=>{return O.jsxDEV(N,{onClose:e},void 0,!1,void 0,this)},ue=Z;export{ue as default};
@@ -1 +1 @@
1
- import{A as I,D as C,y as L}from"./chunk-6b3vfr39.js";import{U as V,fa as x}from"./chunk-h7ypcqp3.js";import{Wl as Z}from"./chunk-4fs853nh.js";function e(J){return J?.replace(process.cwd(),".")||J||""}var _=Z(V(),1);var l=()=>{return process.env.TERM?.includes("256color")||process.env.TERM==="xterm-256color"||process.env.WT_SESSION!==void 0||process.platform==="darwin"||process.env.TERM_PROGRAM==="vscode"||process.env.TERM_PROGRAM==="iTerm.app"};var T={success:{hex:"#4fd6be",fallback:"green"},warning:{hex:"#ffdb95",fallback:"yellow"},error:{hex:"#f7768e",fallback:"red"},info:{hex:"#7dcfff",fallback:"cyan"},muted:{hex:"#565f89",fallback:"gray"},highlight:{hex:"#7dcfff",fallback:"cyanBright"},accent:{hex:"#bb9af7",fallback:"magentaBright"},border:{hex:"#414868",fallback:"gray"},primary:{hex:"#7aa2f7",fallback:"cyan"},secondary:{hex:"#bb9af7",fallback:"magenta"},keyword:{hex:"#bb9af7",fallback:"magenta"},function:{hex:"#7aa2f7",fallback:"blue"},string:{hex:"#9ece6a",fallback:"green"},number:{hex:"#ff9e64",fallback:"yellow"},comment:{hex:"#565f89",fallback:"gray"},variable:{hex:"#c0caf5",fallback:"white"},type:{hex:"#0db9d7",fallback:"cyan"},constant:{hex:"#e0af68",fallback:"yellow"},textPrimary:{hex:"#c0caf5",fallback:"white"},textSecondary:{hex:"#9aa5ce",fallback:"whiteBright"},textMuted:{hex:"#565f89",fallback:"gray"},bg:{hex:"#1a1b26",fallback:"black"},bgCard:{hex:"#24283b",fallback:"black"},indigo:{hex:"#6366f1",fallback:"blue"},purple:{hex:"#a855f7",fallback:"magenta"},pink:{hex:"#ec4899",fallback:"redBright"},rose:{hex:"#f43f5e",fallback:"red"},orange:{hex:"#f97316",fallback:"yellowBright"},amber:{hex:"#f59e0b",fallback:"yellow"},emerald:{hex:"#10b981",fallback:"green"},teal:{hex:"#14b8a6",fallback:"cyan"},sky:{hex:"#0ea5e9",fallback:"blue"}},yP=(J)=>{if(!(J in T))J="sky";return l()?T[J].hex:T[J].fallback};import r from"os";function KP(){try{return r.userInfo().username}catch(J){return process.env.USER||process.env.USERNAME||"User"}}var Q=Z(V(),1);var k=Z(x(),1),i=1800000,o=300000,M=Q.createContext(null),EP=({children:J})=>{let[y,z]=Q.useState(""),W=Q.useRef(Date.now()),A=Q.useCallback(()=>{z("")},[]),$=Q.useCallback((F)=>{W.current=Date.now(),z(F)},[]);L(()=>{if(Date.now()-W.current>i)A()},o);let w={bufferedMessage:y,setBufferedMessage:$,clearBuffer:A};return k.jsxDEV(M.Provider,{value:w,children:J},void 0,!1,void 0,this)},RP=()=>{let J=Q.useContext(M);if(!J)throw Error("useChatInputBuffer must be used within ChatInputBufferProvider");return J};var G=Z(V(),1);var s=Z(x(),1),fP=G.createContext(void 0);var q=Z(V(),1);var d=Z(x(),1),a=100,n=1800000,t=300000,m=q.createContext(null),mP=()=>{let J=q.useContext(m);if(!J)throw Error("useInteractionContext must be used within InteractionProvider");return J},dP=({children:J,onInteractionSubmit:y})=>{let[z,W]=q.useState([]),[A,$]=q.useState(0),w=q.useCallback(()=>{return`interaction_${Date.now()}_${Math.random().toString(36).substring(2,9)}`},[]),F=q.useCallback((H,P)=>{let Y=new Date,X={id:w(),category:"panel",state:"idle",metadata:{title:P?.metadata?.title,description:P?.metadata?.description,icon:P?.metadata?.icon,priority:P?.metadata?.priority??"medium",groupKey:P?.metadata?.groupKey,messageIndex:P?.metadata?.messageIndex},tool:P?.tool,config:{layout:{border:!0,padding:1,...P?.config?.layout},interaction:{autoSubmit:!1,allowSkip:!1,showPreview:!0,...P?.config?.interaction},style:P?.config?.style??{}},content:H,createdAt:Y,updatedAt:Y};return W((B)=>{let N=[...B,X];if(N.length>a){let h=N.filter((j)=>j.state==="submitted"||j.state==="edited"||j.state==="cancelled");if(h.length>0){let j=h[0].id;return N.filter((c)=>c.id!==j)}}return N}),$((B)=>B+1),X},[w]),K=q.useCallback((H,P)=>{W((Y)=>Y.map((X)=>X.id===H?{...X,...P,updatedAt:new Date}:X)),$((Y)=>Y+1)},[]),E=q.useCallback((H)=>{W((P)=>P.filter((Y)=>Y.id!==H)),$((P)=>P+1)},[]),R=q.useCallback(()=>{W([]),$((H)=>H+1)},[]),p=q.useCallback((H)=>{return z.find((P)=>P.id===H)},[z]),S=q.useCallback(()=>{return[...z]},[z]),f=q.useCallback((H)=>{return z.filter((P)=>P.state===H)},[z]),b=q.useCallback((H)=>{return z.filter((P)=>P.content.type===H)},[z]),D=q.useCallback(async()=>{let H=z.filter((P)=>P.state==="submitted"||P.state==="edited"||P.state==="cancelled");for(let P of H)if(!P.resultSent&&y)await y(P),K(P.id,{resultSent:!0})},[z,y,K]),v=q.useCallback(()=>{W((H)=>H.filter((P)=>P.state==="idle"||P.state==="active")),$((H)=>H+1)},[]),g=q.useCallback(()=>{let H=Date.now();W((P)=>P.filter((Y)=>Y.updatedAt.getTime()>H-n))},[]);L(()=>{g()},t),I(()=>{W((H)=>H.map((P)=>({...P,tool:void 0})))});let U=q.useMemo(()=>z.some((H)=>H.state==="idle"||H.state==="active"),[z]),O=q.useMemo(()=>z.length>0&&z.every((H)=>H.state==="submitted"||H.state==="edited"||H.state==="cancelled"),[z]);C(()=>{v()},O&&U===!1?100:null),q.useEffect(()=>{if(O&&U===!1)D()},[O,U,D]);let u=q.useMemo(()=>({addInteraction:F,updateInteraction:K,removeInteraction:E,clearAll:R,getInteraction:p,getInteractions:S,getInteractionsByState:f,getInteractionsByContent:b,submitInteractions:D,clearCompleted:v,interactions:z,updateCount:A,hasPendingInteractions:U,allInteractionsProcessed:O}),[F,K,E,R,p,S,f,b,D,v,z,A,U,O]);return d.jsxDEV(m.Provider,{value:u,children:J},void 0,!1,void 0,this)};export{e as o,yP as p,KP as q,EP as r,RP as s,mP as t,dP as u};
1
+ import{A as I,D as C,y as L}from"./chunk-3gn0c0j2.js";import{U as V,fa as x}from"./chunk-bqkrynm6.js";import{Rl as Z}from"./chunk-x17jyjan.js";function e(J){return J?.replace(process.cwd(),".")||J||""}var _=Z(V(),1);var l=()=>{return process.env.TERM?.includes("256color")||process.env.TERM==="xterm-256color"||process.env.WT_SESSION!==void 0||process.platform==="darwin"||process.env.TERM_PROGRAM==="vscode"||process.env.TERM_PROGRAM==="iTerm.app"};var T={success:{hex:"#4fd6be",fallback:"green"},warning:{hex:"#ffdb95",fallback:"yellow"},error:{hex:"#f7768e",fallback:"red"},info:{hex:"#7dcfff",fallback:"cyan"},muted:{hex:"#565f89",fallback:"gray"},highlight:{hex:"#7dcfff",fallback:"cyanBright"},accent:{hex:"#bb9af7",fallback:"magentaBright"},border:{hex:"#414868",fallback:"gray"},primary:{hex:"#7aa2f7",fallback:"cyan"},secondary:{hex:"#bb9af7",fallback:"magenta"},keyword:{hex:"#bb9af7",fallback:"magenta"},function:{hex:"#7aa2f7",fallback:"blue"},string:{hex:"#9ece6a",fallback:"green"},number:{hex:"#ff9e64",fallback:"yellow"},comment:{hex:"#565f89",fallback:"gray"},variable:{hex:"#c0caf5",fallback:"white"},type:{hex:"#0db9d7",fallback:"cyan"},constant:{hex:"#e0af68",fallback:"yellow"},textPrimary:{hex:"#c0caf5",fallback:"white"},textSecondary:{hex:"#9aa5ce",fallback:"whiteBright"},textMuted:{hex:"#565f89",fallback:"gray"},bg:{hex:"#1a1b26",fallback:"black"},bgCard:{hex:"#24283b",fallback:"black"},indigo:{hex:"#6366f1",fallback:"blue"},purple:{hex:"#a855f7",fallback:"magenta"},pink:{hex:"#ec4899",fallback:"redBright"},rose:{hex:"#f43f5e",fallback:"red"},orange:{hex:"#f97316",fallback:"yellowBright"},amber:{hex:"#f59e0b",fallback:"yellow"},emerald:{hex:"#10b981",fallback:"green"},teal:{hex:"#14b8a6",fallback:"cyan"},sky:{hex:"#0ea5e9",fallback:"blue"}},yP=(J)=>{if(!(J in T))J="sky";return l()?T[J].hex:T[J].fallback};import r from"os";function KP(){try{return r.userInfo().username}catch(J){return process.env.USER||process.env.USERNAME||"User"}}var Q=Z(V(),1);var k=Z(x(),1),i=1800000,o=300000,M=Q.createContext(null),EP=({children:J})=>{let[y,z]=Q.useState(""),W=Q.useRef(Date.now()),A=Q.useCallback(()=>{z("")},[]),$=Q.useCallback((F)=>{W.current=Date.now(),z(F)},[]);L(()=>{if(Date.now()-W.current>i)A()},o);let w={bufferedMessage:y,setBufferedMessage:$,clearBuffer:A};return k.jsxDEV(M.Provider,{value:w,children:J},void 0,!1,void 0,this)},RP=()=>{let J=Q.useContext(M);if(!J)throw Error("useChatInputBuffer must be used within ChatInputBufferProvider");return J};var G=Z(V(),1);var s=Z(x(),1),fP=G.createContext(void 0);var q=Z(V(),1);var d=Z(x(),1),a=100,n=1800000,t=300000,m=q.createContext(null),mP=()=>{let J=q.useContext(m);if(!J)throw Error("useInteractionContext must be used within InteractionProvider");return J},dP=({children:J,onInteractionSubmit:y})=>{let[z,W]=q.useState([]),[A,$]=q.useState(0),w=q.useCallback(()=>{return`interaction_${Date.now()}_${Math.random().toString(36).substring(2,9)}`},[]),F=q.useCallback((H,P)=>{let Y=new Date,X={id:w(),category:"panel",state:"idle",metadata:{title:P?.metadata?.title,description:P?.metadata?.description,icon:P?.metadata?.icon,priority:P?.metadata?.priority??"medium",groupKey:P?.metadata?.groupKey,messageIndex:P?.metadata?.messageIndex},tool:P?.tool,config:{layout:{border:!0,padding:1,...P?.config?.layout},interaction:{autoSubmit:!1,allowSkip:!1,showPreview:!0,...P?.config?.interaction},style:P?.config?.style??{}},content:H,createdAt:Y,updatedAt:Y};return W((B)=>{let N=[...B,X];if(N.length>a){let h=N.filter((j)=>j.state==="submitted"||j.state==="edited"||j.state==="cancelled");if(h.length>0){let j=h[0].id;return N.filter((c)=>c.id!==j)}}return N}),$((B)=>B+1),X},[w]),K=q.useCallback((H,P)=>{W((Y)=>Y.map((X)=>X.id===H?{...X,...P,updatedAt:new Date}:X)),$((Y)=>Y+1)},[]),E=q.useCallback((H)=>{W((P)=>P.filter((Y)=>Y.id!==H)),$((P)=>P+1)},[]),R=q.useCallback(()=>{W([]),$((H)=>H+1)},[]),p=q.useCallback((H)=>{return z.find((P)=>P.id===H)},[z]),S=q.useCallback(()=>{return[...z]},[z]),f=q.useCallback((H)=>{return z.filter((P)=>P.state===H)},[z]),b=q.useCallback((H)=>{return z.filter((P)=>P.content.type===H)},[z]),D=q.useCallback(async()=>{let H=z.filter((P)=>P.state==="submitted"||P.state==="edited"||P.state==="cancelled");for(let P of H)if(!P.resultSent&&y)await y(P),K(P.id,{resultSent:!0})},[z,y,K]),v=q.useCallback(()=>{W((H)=>H.filter((P)=>P.state==="idle"||P.state==="active")),$((H)=>H+1)},[]),g=q.useCallback(()=>{let H=Date.now();W((P)=>P.filter((Y)=>Y.updatedAt.getTime()>H-n))},[]);L(()=>{g()},t),I(()=>{W((H)=>H.map((P)=>({...P,tool:void 0})))});let U=q.useMemo(()=>z.some((H)=>H.state==="idle"||H.state==="active"),[z]),O=q.useMemo(()=>z.length>0&&z.every((H)=>H.state==="submitted"||H.state==="edited"||H.state==="cancelled"),[z]);C(()=>{v()},O&&U===!1?100:null),q.useEffect(()=>{if(O&&U===!1)D()},[O,U,D]);let u=q.useMemo(()=>({addInteraction:F,updateInteraction:K,removeInteraction:E,clearAll:R,getInteraction:p,getInteractions:S,getInteractionsByState:f,getInteractionsByContent:b,submitInteractions:D,clearCompleted:v,interactions:z,updateCount:A,hasPendingInteractions:U,allInteractionsProcessed:O}),[F,K,E,R,p,S,f,b,D,v,z,A,U,O]);return d.jsxDEV(m.Provider,{value:u,children:J},void 0,!1,void 0,this)};export{e as o,yP as p,KP as q,EP as r,RP as s,mP as t,dP as u};
@@ -1,2 +1,2 @@
1
1
  import p from"os";import a from"path";import r from"fs";var t={config:{provider_id:"default",provider_type:"openai",model_id:"glm-5",providers:[{id:"default",type:"openai",apiKey:"",baseUrl:"https://api.openai.com/v1"}],compact_mode:!0}};async function n(e,i){try{let o=await r.promises.readFile(e,"utf-8");return JSON.parse(o)}catch{return i}}async function s(e,i){await r.promises.writeFile(e,JSON.stringify(i,null,2),"utf-8")}class c{zenConfigDir;dbPath;constructor(){let e=p.homedir();this.zenConfigDir=a.join(e,".zen-code"),this.dbPath=a.join(this.zenConfigDir,"settings.json")}async initialize(){await r.promises.mkdir(this.zenConfigDir,{recursive:!0});let e=await n(this.dbPath,t);if(!e.config)await s(this.dbPath,t),this.syncEnvFromConfig(t.config);else await s(this.dbPath,e),this.syncEnvFromConfig(e.config)}async getConfig(){return(await n(this.dbPath,t)).config}async updateConfig(e){let i=await n(this.dbPath,t);Object.assign(i.config,e),await s(this.dbPath,i),this.syncEnvFromConfig(i.config)}syncEnvFromConfig(e){let i=e.providers.find((o)=>o.id===e.provider_id);if(i){if(i.type==="openai")process.env.MODEL_PROVIDER="openai",process.env.OPENAI_API_KEY=i.apiKey,process.env.OPENAI_BASE_URL=i.baseUrl;else if(i.type==="anthropic")process.env.MODEL_PROVIDER="anthropic",process.env.ANTHROPIC_API_KEY=i.apiKey,process.env.ANTHROPIC_BASE_URL=i.baseUrl;else if(i.type==="gemini"||i.type==="google")process.env.MODEL_PROVIDER="gemini",process.env.GOOGLE_API_KEY=i.apiKey,process.env.GOOGLE_BASE_URL=i.baseUrl}}getZenConfigDir(){return this.zenConfigDir}}
2
- export{c as xk};
2
+ export{c as tk};
@@ -0,0 +1 @@
1
+ import{wk as a,xk as b}from"./chunk-rqymdmqg.js";import"./chunk-jbqqb1ht.js";import"./chunk-0pzpg2ra.js";import"./chunk-x17jyjan.js";export{a as createFSManager,b as createCustomManager};
@@ -1,4 +1,4 @@
1
- import{Yd as L,fe as D}from"./chunk-vwj4n000.js";import{Ag as K,Cg as O,ug as z,zg as P}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{$l as b,Wl as R}from"./chunk-4fs853nh.js";var G={maxRetries:3,baseDelayMs:100,nonRetryablePatterns:["database disk image is malformed","database is malformed","cannot rollback","no transaction is active","database or disk is full"],isRetryableError:(J)=>{let $=J?.message?.toLowerCase()||"";for(let Z of G.nonRetryablePatterns)if($.includes(Z.toLowerCase()))return!1;return $.includes("sqlite_busy")||$.includes("database is locked")||$==="sqlite_busy"||$==="database is locked"}};async function F(J,$){let Z=null;for(let H=0;H<G.maxRetries;H++)try{return await J()}catch(U){Z=U;let j=U?.message?.toLowerCase()||"";if(!G.isRetryableError(U)){if(j.includes("malformed")){let V=Error(`SQLite database is corrupted: ${U.message}
1
+ import{Yd as L,fe as D}from"./chunk-vwj4n000.js";import{Ag as K,Cg as O,ug as z,zg as P}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 R,Wl as b}from"./chunk-x17jyjan.js";var G={maxRetries:3,baseDelayMs:100,nonRetryablePatterns:["database disk image is malformed","database is malformed","cannot rollback","no transaction is active","database or disk is full"],isRetryableError:(J)=>{let $=J?.message?.toLowerCase()||"";for(let Z of G.nonRetryablePatterns)if($.includes(Z.toLowerCase()))return!1;return $.includes("sqlite_busy")||$.includes("database is locked")||$==="sqlite_busy"||$==="database is locked"}};async function F(J,$){let Z=null;for(let H=0;H<G.maxRetries;H++)try{return await J()}catch(U){Z=U;let j=U?.message?.toLowerCase()||"";if(!G.isRetryableError(U)){if(j.includes("malformed")){let V=Error(`SQLite database is corrupted: ${U.message}
2
2
 
3
3
  Context: ${$||"unknown"}
4
4
 
@@ -10,7 +10,7 @@ Possible causes:
10
10
  Recovery options:
11
11
  - Delete the database file to start fresh (data will be lost)
12
12
  - Use SQLite recovery tools: sqlite3 <db> ".recover" > recover.sql
13
- - Switch to PostgreSQL/Redis for production use`);throw V.name="SQLiteCorruptError",V.cause=U,V}throw U}if(H<G.maxRetries-1){let V=G.baseDelayMs*Math.pow(2,H);console.warn(`SQLite lock detected${$?` (${$})`:""}, retrying in ${V}ms (attempt ${H+1}/${G.maxRetries})`),await new Promise((X)=>setTimeout(X,V))}}throw Z}var x=["source","step","parents"];function E(J){return J}var T=E(x);class N extends K{db;isSetup;constructor(J,$){super($);this.db=new L({dialect:J}),this.isSetup=!1}static async fromConnStringAsync(J){let $;if(globalThis.Bun&&!process.env.DISABLE_BUN_SQLITE){console.log("LG | Using BunWorkerDialect "+J);let{BunSqliteDialect:Z}=await import("./chunk-0qz8rr2k.js");$=new N(new Z({url:J}))}else{console.log("LG | Using NodeWasmDialect");let{default:Z}=await import("./chunk-069q9hkz.js").then((m)=>R(m.default,1)),{NodeWasmDialect:H}=await import("./chunk-b175s7dm.js");console.log(J);let U=new H({database:new Z.Database(J)});$=new N(U)}return await $.setup(),$}async setup(){if(this.isSetup)return;await D`PRAGMA busy_timeout = 5000`.execute(this.db),await D`PRAGMA journal_mode = WAL`.execute(this.db),await D`PRAGMA synchronous = NORMAL`.execute(this.db),await D`PRAGMA wal_autocheckpoint = 1000`.execute(this.db),await D`
13
+ - Switch to PostgreSQL/Redis for production use`);throw V.name="SQLiteCorruptError",V.cause=U,V}throw U}if(H<G.maxRetries-1){let V=G.baseDelayMs*Math.pow(2,H);console.warn(`SQLite lock detected${$?` (${$})`:""}, retrying in ${V}ms (attempt ${H+1}/${G.maxRetries})`),await new Promise((X)=>setTimeout(X,V))}}throw Z}var x=["source","step","parents"];function E(J){return J}var T=E(x);class N extends K{db;isSetup;constructor(J,$){super($);this.db=new L({dialect:J}),this.isSetup=!1}static async fromConnStringAsync(J){let $;if(globalThis.Bun&&!process.env.DISABLE_BUN_SQLITE){console.log("LG | Using BunWorkerDialect "+J);let{BunSqliteDialect:Z}=await import("./chunk-c59eqb10.js");$=new N(new Z({url:J}))}else{console.log("LG | Using NodeWasmDialect");let{default:Z}=await import("./chunk-e6m161vn.js").then((m)=>R(m.default,1)),{NodeWasmDialect:H}=await import("./chunk-kvnw06wg.js");console.log(J);let U=new H({database:new Z.Database(J)});$=new N(U)}return await $.setup(),$}async setup(){if(this.isSetup)return;await D`PRAGMA busy_timeout = 5000`.execute(this.db),await D`PRAGMA journal_mode = WAL`.execute(this.db),await D`PRAGMA synchronous = NORMAL`.execute(this.db),await D`PRAGMA wal_autocheckpoint = 1000`.execute(this.db),await D`
14
14
  CREATE TABLE IF NOT EXISTS checkpoints (
15
15
  thread_id TEXT NOT NULL,
16
16
  checkpoint_ns TEXT NOT NULL DEFAULT '',
@@ -1,4 +1,4 @@
1
- import{D as n}from"./chunk-6b3vfr39.js";import{E as o}from"./chunk-1d47g6nc.js";import"./chunk-5fe27s34.js";import{K as m,N as d,O as x}from"./chunk-5hqvapp1.js";import{$ as a,U as u,X,Y as G,fa as D,ga as g,ha as E}from"./chunk-h7ypcqp3.js";import{Wl as S}from"./chunk-4fs853nh.js";var H=S(u(),1);var b=S(u(),1);var _=S(D(),1);function Xz(Y){try{let $=JSON.parse(Y);if(typeof $!=="object"||$===null)return{isValid:!1,error:{message:"配置必须是 JSON 对象"}};if(!$.command&&!$.url)return{isValid:!1,error:{message:'配置必须包含 "command" (stdio) 或 "url" (SSE)'}};return{isValid:!0,config:$}}catch($){let L=$ instanceof Error?$.message:String($),B=L.match(/position (\d+)/),Q=B?parseInt(B[1],10):void 0;return{isValid:!1,error:{message:`JSON 格式错误: ${L}`,line:Q}}}}function Yz(Y,$,L){if(!Y||Y.length<2||Y.length>32)return"名称必须为 2-32 个字符";if(!/^[a-zA-Z0-9_-]+$/.test(Y))return"名称只能包含字母、数字、下划线和连字符";if($.includes(Y)&&Y!==L)return"名称已存在";return null}function Zz(Y,$=2){return JSON.stringify(Y,null,$)}var _z=[{key:"serverName",label:"Server ID"},{key:"config",label:"Config (JSON)"}],$z=({mode:Y,serverName:$,serverConfig:L,onCancel:B,onSave:Q})=>{let[O,y]=b.useState({serverName:$||"",configJSON:L?Zz(L):""}),[F,I]=b.useState(0),[j,V]=b.useState(null),M=b.useMemo(()=>{return[]},[]),U=b.useMemo(()=>{return Xz(O.configJSON)},[O.configJSON]),k=b.useCallback(()=>{let A=Yz(O.serverName,M,Y==="edit"?$:void 0);return V(A),A===null},[O.serverName,M,$,Y]),N=b.useCallback(()=>{if(Y==="add"&&!k())return;if(!U.isValid||!U.config)return;Q(O.serverName,U.config)},[Y,O.serverName,U,Q,k]),w=b.useCallback((A)=>{let h=Y==="add"?_z.length-1:1,q=A==="next"?(F+1)%h:(F-1+h)%h;I(q)},[F,Y]),f=()=>{if(Y!=="add")return null;let A=F===0,h=j!==null;return _.jsxDEV(X,{marginBottom:1,children:[_.jsxDEV(G,{color:A?"cyan":h?"red":"gray",children:"Server ID: "},void 0,!1,void 0,this),A?_.jsxDEV(X,{width:40,children:_.jsxDEV(E,{value:O.serverName,onChange:(q)=>{y((K)=>({...K,serverName:q})),V(null)},onSubmit:N,placeholder:"my-server",maxVisibleLines:1,showCursor:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this):_.jsxDEV(G,{children:O.serverName||"my-server"},void 0,!1,void 0,this),h&&_.jsxDEV(G,{color:"red",children:[" ",j]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},p=()=>{let A=Y==="add"?F===1:F===0,h=U.isValid;return _.jsxDEV(X,{flexDirection:"column",marginBottom:1,children:[_.jsxDEV(G,{color:A?"cyan":"gray",children:"Config (JSON):"},void 0,!1,void 0,this),_.jsxDEV(X,{marginTop:1,children:_.jsxDEV(E,{value:O.configJSON,onChange:(q)=>y((K)=>({...K,configJSON:q})),onSubmit:N,placeholder:`{
1
+ import{D as n}from"./chunk-3gn0c0j2.js";import{E as o}from"./chunk-j40cj742.js";import"./chunk-6t0qzren.js";import{K as m,N as d,O as x}from"./chunk-w4tbr5h7.js";import{$ as a,U as u,X,Y as G,fa as D,ga as g,ha as E}from"./chunk-bqkrynm6.js";import{Rl as S}from"./chunk-x17jyjan.js";var H=S(u(),1);var b=S(u(),1);var _=S(D(),1);function Xz(Y){try{let $=JSON.parse(Y);if(typeof $!=="object"||$===null)return{isValid:!1,error:{message:"配置必须是 JSON 对象"}};if(!$.command&&!$.url)return{isValid:!1,error:{message:'配置必须包含 "command" (stdio) 或 "url" (SSE)'}};return{isValid:!0,config:$}}catch($){let L=$ instanceof Error?$.message:String($),B=L.match(/position (\d+)/),Q=B?parseInt(B[1],10):void 0;return{isValid:!1,error:{message:`JSON 格式错误: ${L}`,line:Q}}}}function Yz(Y,$,L){if(!Y||Y.length<2||Y.length>32)return"名称必须为 2-32 个字符";if(!/^[a-zA-Z0-9_-]+$/.test(Y))return"名称只能包含字母、数字、下划线和连字符";if($.includes(Y)&&Y!==L)return"名称已存在";return null}function Zz(Y,$=2){return JSON.stringify(Y,null,$)}var _z=[{key:"serverName",label:"Server ID"},{key:"config",label:"Config (JSON)"}],$z=({mode:Y,serverName:$,serverConfig:L,onCancel:B,onSave:Q})=>{let[O,y]=b.useState({serverName:$||"",configJSON:L?Zz(L):""}),[F,I]=b.useState(0),[j,V]=b.useState(null),M=b.useMemo(()=>{return[]},[]),U=b.useMemo(()=>{return Xz(O.configJSON)},[O.configJSON]),k=b.useCallback(()=>{let A=Yz(O.serverName,M,Y==="edit"?$:void 0);return V(A),A===null},[O.serverName,M,$,Y]),N=b.useCallback(()=>{if(Y==="add"&&!k())return;if(!U.isValid||!U.config)return;Q(O.serverName,U.config)},[Y,O.serverName,U,Q,k]),w=b.useCallback((A)=>{let h=Y==="add"?_z.length-1:1,q=A==="next"?(F+1)%h:(F-1+h)%h;I(q)},[F,Y]),f=()=>{if(Y!=="add")return null;let A=F===0,h=j!==null;return _.jsxDEV(X,{marginBottom:1,children:[_.jsxDEV(G,{color:A?"cyan":h?"red":"gray",children:"Server ID: "},void 0,!1,void 0,this),A?_.jsxDEV(X,{width:40,children:_.jsxDEV(E,{value:O.serverName,onChange:(q)=>{y((K)=>({...K,serverName:q})),V(null)},onSubmit:N,placeholder:"my-server",maxVisibleLines:1,showCursor:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this):_.jsxDEV(G,{children:O.serverName||"my-server"},void 0,!1,void 0,this),h&&_.jsxDEV(G,{color:"red",children:[" ",j]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},p=()=>{let A=Y==="add"?F===1:F===0,h=U.isValid;return _.jsxDEV(X,{flexDirection:"column",marginBottom:1,children:[_.jsxDEV(G,{color:A?"cyan":"gray",children:"Config (JSON):"},void 0,!1,void 0,this),_.jsxDEV(X,{marginTop:1,children:_.jsxDEV(E,{value:O.configJSON,onChange:(q)=>y((K)=>({...K,configJSON:q})),onSubmit:N,placeholder:`{
2
2
  "command": "npx",
3
3
  "args": ["-y", "..."]
4
4
  }`,showCursor:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),O.configJSON&&_.jsxDEV(X,{marginTop:1,children:h?_.jsxDEV(G,{color:"green",children:"✓ JSON 格式有效"},void 0,!1,void 0,this):_.jsxDEV(G,{color:"red",children:["✗ ",U.error?.message||"JSON 格式错误"]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},P=()=>_.jsxDEV(X,{marginTop:1,children:_.jsxDEV(G,{color:"gray",dimColor:!0,children:[_.jsxDEV(G,{color:"cyan",children:"Enter"},void 0,!1,void 0,this)," 保存 ",_.jsxDEV(G,{color:"cyan",children:"Tab"},void 0,!1,void 0,this)," 切换字段"," ",_.jsxDEV(G,{color:"cyan",children:"Esc"},void 0,!1,void 0,this)," 取消"]},void 0,!0,void 0,this)},void 0,!1,void 0,this);return _.jsxDEV(X,{flexDirection:"column",paddingX:2,children:[_.jsxDEV(X,{marginBottom:1,children:_.jsxDEV(G,{bold:!0,color:"cyan",children:Y==="add"?"Add MCP Server":`Edit MCP Server: ${$}`},void 0,!1,void 0,this)},void 0,!1,void 0,this),_.jsxDEV(X,{flexDirection:"column",gap:1,children:[f(),p()]},void 0,!0,void 0,this),P()]},void 0,!0,void 0,this)},l=$z;function i({mcpConfig:Y,updateConfig:$}){let L=m(),B=d({mutationFn:async(Q)=>{return await $({mcp_config:Q}),Q},onSuccess:(Q)=>{L.setQueryData(x.mcp.config(),Q)}});return{mcpConfig:Y,updateMcpConfig:B.mutateAsync,isUpdating:B.isPending}}var z=S(D(),1),Hz=({onClose:Y})=>{let{config:$,updateConfig:L}=o(),B=$?.mcp_config||{},{mcpConfig:Q,updateMcpConfig:O}=i({mcpConfig:B,updateConfig:L}),[y,F]=H.useState("list"),[I,j]=H.useState("add"),[V,M]=H.useState(null),[U,k]=H.useState(0),[N,w]=H.useState(null),[f,p]=H.useState(null),[P,A]=H.useState(null),h=H.useCallback(()=>w(null),[]);n(h,N?3000:null);let q=Object.keys(Q),K=q[U],R=K?Q[K]:null,v=H.useCallback((W)=>{if(W.command)return"stdio";if(W.url)return"SSE";return"unknown"},[]),r=H.useCallback(()=>{j("add"),M(null),F("json"),w(null)},[]),t=H.useCallback(()=>{if(!K||!R)return;j("edit"),M(K),F("json"),w(null)},[K,R]),s=H.useCallback(async()=>{if(!K||!R)return;p(K),A(null),F("test");try{let W=!!(R.command&&R.args),Z=!!R.url;if(!W&&!Z){A({success:!1,message:"配置无效:必须包含 command (stdio) 或 url (SSE)"});return}if(W&&(!R.command||!Array.isArray(R.args))){A({success:!1,message:"配置无效:stdio 模式需要 command 和 args 字段"});return}A({success:!0,message:`配置格式验证通过 (${Z?"SSE":"stdio"} 模式)`,tools:[]})}catch(W){A({success:!1,message:`验证失败: ${W instanceof Error?W.message:String(W)}`})}},[K,R]),C=H.useCallback(()=>{F("list"),M(null),A(null),w(null)},[]),e=H.useCallback(async(W,Z)=>{let J={...Q};if(J[W]=Z,await O(J),w(I==="add"?`已添加服务器: ${W}`:`已更新服务器: ${W}`),I==="add"){let T=Object.keys(J).findIndex((c)=>c===W);k(T>=0?T:0)}C()},[I,Q,O,C]),zz=H.useCallback(async()=>{if(!K)return;let W={...Q};delete W[K],await O(W);let Z=Math.min(U,Object.keys(W).length-1);k(Z>=0?Z:0),w(`已删除服务器: ${K}`)},[K,U,Q,O]);g((W,Z)=>{if(y==="json"||y==="test"){if(Z.escape)C();return}if(Z.upArrow)k((J)=>J>0?J-1:q.length-1);else if(Z.downArrow)k((J)=>J<q.length-1?J+1:0);else if(W==="n"||W==="N")r();else if((W==="e"||W==="E"||Z.return)&&K)t();else if((W==="d"||W==="D")&&K)zz();else if((W==="t"||W==="T")&&K)s();else if(Z.escape)Y()},{isActive:!0});let Gz=H.useMemo(()=>{if(q.length===0)return z.jsxDEV(X,{paddingX:2,paddingY:1,children:[z.jsxDEV(G,{color:"yellow",children:"未配置任何 MCP 服务器"},void 0,!1,void 0,this),z.jsxDEV(X,{marginTop:1,children:z.jsxDEV(G,{color:"gray",dimColor:!0,children:["按 ",z.jsxDEV(G,{color:"cyan",children:"n"},void 0,!1,void 0,this)," 添加新服务器"]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return z.jsxDEV(X,{flexDirection:"column",paddingX:2,gap:1,children:[q.map((W,Z)=>{let J=Q[W],T=v(J);return z.jsxDEV(X,{marginBottom:0,gap:1,children:[z.jsxDEV(G,{color:Z===U?"cyan":"gray",bold:Z===U,children:Z===U?">":" "},void 0,!1,void 0,this),z.jsxDEV(G,{bold:Z===U,color:Z===U?"cyan":void 0,children:W},void 0,!1,void 0,this),z.jsxDEV(a,{},void 0,!1,void 0,this),z.jsxDEV(G,{color:T==="stdio"?"green":T==="SSE"?"blue":"yellow",dimColor:Z!==U,children:["[",T.toUpperCase(),"]"]},void 0,!0,void 0,this)]},`server-${Z}-${W}`,!0,void 0,this)}),z.jsxDEV(X,{marginTop:1,children:z.jsxDEV(G,{color:"gray",dimColor:!0,children:[z.jsxDEV(G,{color:"cyan",children:"↑↓"},void 0,!1,void 0,this)," 导航 ",z.jsxDEV(G,{color:"cyan",children:"n"},void 0,!1,void 0,this)," 新增 ",z.jsxDEV(G,{color:"cyan",children:"e"},void 0,!1,void 0,this)," ","编辑 ",z.jsxDEV(G,{color:"cyan",children:"d"},void 0,!1,void 0,this)," 删除 ",z.jsxDEV(G,{color:"cyan",children:"t"},void 0,!1,void 0,this)," 测试"," ",z.jsxDEV(G,{color:"cyan",children:"Esc"},void 0,!1,void 0,this)," 关闭"]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},[q,Q,U,v]),Wz=H.useMemo(()=>{if(!f||!P)return z.jsxDEV(X,{paddingX:2,paddingY:1,children:z.jsxDEV(G,{color:"yellow",children:"正在验证配置..."},void 0,!1,void 0,this)},void 0,!1,void 0,this);if(P.success)return z.jsxDEV(X,{flexDirection:"column",paddingX:2,gap:1,children:[z.jsxDEV(X,{children:z.jsxDEV(G,{color:"green",children:["✓ ",P.message]},void 0,!0,void 0,this)},void 0,!1,void 0,this),P.tools&&P.tools.length>0&&z.jsxDEV(X,{flexDirection:"column",marginTop:1,children:[z.jsxDEV(G,{color:"gray",children:["发现 ",P.tools.length," 个工具:"]},void 0,!0,void 0,this),P.tools.slice(0,10).map((W)=>z.jsxDEV(X,{paddingLeft:2,children:z.jsxDEV(G,{color:"gray",children:["- ",W]},void 0,!0,void 0,this)},W,!1,void 0,this)),P.tools.length>10&&z.jsxDEV(X,{paddingLeft:2,children:z.jsxDEV(G,{color:"gray",children:["... 还有 ",P.tools.length-10," 个工具"]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV(X,{marginTop:1,children:z.jsxDEV(G,{color:"gray",dimColor:!0,children:["按 ",z.jsxDEV(G,{color:"cyan",children:"Enter"},void 0,!1,void 0,this)," 关闭"]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this);else return z.jsxDEV(X,{flexDirection:"column",paddingX:2,gap:1,children:[z.jsxDEV(X,{children:z.jsxDEV(G,{color:"red",children:"✗ 验证失败"},void 0,!1,void 0,this)},void 0,!1,void 0,this),z.jsxDEV(X,{children:z.jsxDEV(G,{color:"yellow",children:P.message},void 0,!1,void 0,this)},void 0,!1,void 0,this),z.jsxDEV(X,{marginTop:1,children:[z.jsxDEV(G,{color:"gray",children:"建议检查:"},void 0,!1,void 0,this),z.jsxDEV(G,{color:"gray",children:"- 配置格式是否正确"},void 0,!1,void 0,this),z.jsxDEV(G,{color:"gray",children:"- 命令是否已安装(stdio 模式)"},void 0,!1,void 0,this),z.jsxDEV(G,{color:"gray",children:"- URL 是否可访问(SSE 模式)"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z.jsxDEV(X,{marginTop:1,children:z.jsxDEV(G,{color:"gray",dimColor:!0,children:["按 ",z.jsxDEV(G,{color:"cyan",children:"Enter"},void 0,!1,void 0,this)," 关闭"]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},[f,P]);return g((W,Z)=>{if(y==="test"&&Z.return)C()},{isActive:y==="test"}),z.jsxDEV(X,{flexDirection:"column",children:[z.jsxDEV(X,{paddingX:2,paddingY:1,children:z.jsxDEV(G,{bold:!0,color:"cyan",children:"MCP Servers"},void 0,!1,void 0,this)},void 0,!1,void 0,this),y==="list"?Gz:y==="json"?z.jsxDEV(l,{mode:I,serverName:V||void 0,serverConfig:R||void 0,onCancel:C,onSave:e},void 0,!1,void 0,this):Wz,N&&z.jsxDEV(X,{paddingX:2,paddingY:0,children:z.jsxDEV(G,{color:"green",children:N},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},kz=Hz;export{kz as default};