zen-code 4.10.2 → 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.
- package/dist/app.js +149 -239
- package/dist/{chunk-pzb224c5.js → chunk-0p3df51n.js} +2 -2
- package/dist/{chunk-tjg2e8v3.js → chunk-0pzpg2ra.js} +2 -2
- package/dist/{chunk-wmyc17aa.js → chunk-142wmdx8.js} +1 -1
- package/dist/chunk-1t3rabge.js +1 -0
- package/dist/chunk-2gd8vzrf.js +2 -0
- package/dist/{chunk-vrnj0659.js → chunk-2z45fjmt.js} +51 -51
- package/dist/chunk-3gn0c0j2.js +2 -0
- package/dist/chunk-3nhw50tg.js +1 -0
- package/dist/{chunk-g974hxbz.js → chunk-4260bzp9.js} +1 -1
- package/dist/{chunk-5c3bpcpm.js → chunk-4vh3dxeg.js} +1 -1
- package/dist/{chunk-hnnwbfqk.js → chunk-5e2s5jvw.js} +2 -2
- package/dist/{chunk-s5cqejr6.js → chunk-5kcxxes1.js} +1 -1
- package/dist/chunk-6t0qzren.js +2 -0
- package/dist/chunk-74k5n8f5.js +2 -0
- package/dist/chunk-780j97nd.js +1 -0
- package/dist/chunk-78t2g3ht.js +1 -0
- package/dist/chunk-7d48d71t.js +228 -0
- package/dist/chunk-96b00ygr.js +1 -0
- package/dist/chunk-9kbktaf8.js +89 -0
- package/dist/chunk-a4rvf135.js +1 -0
- package/dist/chunk-ahsvdb98.js +1 -0
- package/dist/{chunk-k4q8j7pg.js → chunk-an34z8wv.js} +1 -1
- package/dist/chunk-arm90pny.js +1 -0
- package/dist/{chunk-40ht9pe1.js → chunk-avqzptcg.js} +2 -2
- package/dist/{chunk-s1tbdcs8.js → chunk-b0yk07x5.js} +1 -1
- package/dist/{chunk-nqh1pptf.js → chunk-be8n8w26.js} +1 -1
- package/dist/{chunk-c7kd2qrp.js → chunk-bqkrynm6.js} +112 -111
- package/dist/chunk-bv28r5cf.js +1 -0
- package/dist/{chunk-mmx0k2yq.js → chunk-c59eqb10.js} +1 -1
- package/dist/{chunk-t6440ajd.js → chunk-cbr2vrpt.js} +2 -2
- package/dist/{chunk-fzh0v6r0.js → chunk-csn4vg3d.js} +2 -2
- package/dist/chunk-df36fv24.js +1 -0
- package/dist/chunk-e3jv1c1w.js +1 -0
- package/dist/{chunk-vbb3m0vz.js → chunk-e6m161vn.js} +1 -1
- package/dist/{chunk-vfxjbdz4.js → chunk-eqetcfer.js} +1 -1
- package/dist/{chunk-8f19qk9r.js → chunk-eze2fzrq.js} +1 -1
- package/dist/{chunk-nmzx5nmt.js → chunk-femf7e4d.js} +1 -1
- package/dist/{chunk-gt8c6dne.js → chunk-fvg6pct8.js} +1 -1
- package/dist/chunk-g2n6hnjp.js +5 -0
- package/dist/{chunk-e8kxa5vj.js → chunk-ge071wp4.js} +2 -2
- package/dist/chunk-h9w6y105.js +1 -0
- package/dist/chunk-hzxg9kx6.js +1 -0
- package/dist/{chunk-g2zskge5.js → chunk-j2qd9mfs.js} +2 -2
- package/dist/chunk-j40cj742.js +2 -0
- package/dist/chunk-jbqqb1ht.js +2 -0
- package/dist/chunk-jz0kw4yt.js +2 -0
- package/dist/chunk-kknfcsyy.js +1 -0
- package/dist/{chunk-zg54h6gy.js → chunk-kvnw06wg.js} +1 -1
- package/dist/chunk-kyb15dg8.js +2 -0
- package/dist/chunk-mq4m1w4w.js +15 -0
- package/dist/chunk-mqcbjght.js +1 -0
- package/dist/{chunk-pe8mzxwn.js → chunk-mqm8wnc8.js} +11 -11
- package/dist/chunk-n7bpjcb0.js +1 -0
- package/dist/chunk-ncaqgas1.js +160 -0
- package/dist/{chunk-f0m4532p.js → chunk-nh11afw0.js} +5 -5
- package/dist/{chunk-spx7nn8t.js → chunk-nwmvyez4.js} +2 -2
- package/dist/chunk-nzyvqxt4.js +1 -0
- package/dist/{chunk-nsw5168d.js → chunk-p6c1xbd5.js} +2 -2
- package/dist/chunk-p75m7q2h.js +1 -0
- package/dist/{chunk-spa69h7p.js → chunk-pffdbhs6.js} +2 -2
- package/dist/chunk-phw7yp5t.js +1 -0
- package/dist/{chunk-8tbtavry.js → chunk-q0452p0f.js} +2 -2
- package/dist/chunk-r133z8tq.js +8 -0
- package/dist/{chunk-qxebn3jw.js → chunk-rqymdmqg.js} +3 -3
- package/dist/chunk-rr7h6wdp.js +7 -0
- package/dist/{chunk-gfhmzpy7.js → chunk-s04zfe57.js} +2 -3
- package/dist/chunk-twhnh3dc.js +1 -0
- package/dist/chunk-tws3wcnm.js +2 -0
- package/dist/chunk-txnezkkt.js +1 -0
- package/dist/{chunk-tjvhqr94.js → chunk-vttq7sqg.js} +1 -1
- package/dist/chunk-vvs5da2x.js +281 -0
- package/dist/{chunk-n9rpnke9.js → chunk-vwj4n000.js} +1 -1
- package/dist/{chunk-4wnmk2tj.js → chunk-w4tbr5h7.js} +3 -3
- package/dist/{chunk-n7s6my89.js → chunk-wts8db9p.js} +32 -32
- package/dist/{chunk-y8qhrx11.js → chunk-x17jyjan.js} +1 -1
- package/dist/chunk-x7x7esvz.js +8 -0
- package/dist/chunk-xprg4hxp.js +17 -0
- package/dist/chunk-xrfpz1vw.js +2 -0
- package/dist/{chunk-hve2a279.js → chunk-xtr6s7kh.js} +2 -2
- package/dist/{chunk-bzgznka5.js → chunk-y807k0kw.js} +1 -1
- package/dist/chunk-ycp2e43r.js +1 -0
- package/dist/chunk-yfv1xeeh.js +2 -0
- package/dist/chunk-zxpb45tb.js +1 -0
- package/dist/cli.js +1 -1
- package/dist/nonInteractive.js +80 -80
- package/dist/zen-core.js +261 -0
- package/dist/zen-keyboard.js +1 -1
- package/package.json +5 -3
- package/dist/chunk-0ddrb30y.js +0 -1
- package/dist/chunk-215an3fz.js +0 -1
- package/dist/chunk-4z0w0ng1.js +0 -2
- package/dist/chunk-57bj89e2.js +0 -1
- package/dist/chunk-5a5mepqj.js +0 -1
- package/dist/chunk-7kw7ss8d.js +0 -1
- package/dist/chunk-86m0rmtc.js +0 -1
- package/dist/chunk-9rayxazs.js +0 -8
- package/dist/chunk-a9gpb2tx.js +0 -2
- package/dist/chunk-a9tw6d68.js +0 -1
- package/dist/chunk-anbtppz1.js +0 -294
- package/dist/chunk-bca8tkkr.js +0 -1
- package/dist/chunk-bdqds8vh.js +0 -1
- package/dist/chunk-dvbb3dd1.js +0 -233
- package/dist/chunk-ehmmd8qc.js +0 -1
- package/dist/chunk-ejfa95sm.js +0 -1
- package/dist/chunk-f7cps5x1.js +0 -1
- package/dist/chunk-fbemqjck.js +0 -2
- package/dist/chunk-feeqtzv5.js +0 -1
- package/dist/chunk-g9911ymn.js +0 -1
- package/dist/chunk-h8fdexm4.js +0 -2
- package/dist/chunk-hp2jzn9x.js +0 -166
- package/dist/chunk-js4qp900.js +0 -2
- package/dist/chunk-m21hvv91.js +0 -2
- package/dist/chunk-mnnyjmgw.js +0 -224
- package/dist/chunk-mw7x6xqp.js +0 -1
- package/dist/chunk-nk62q95g.js +0 -93
- package/dist/chunk-pg1ppq4y.js +0 -1
- package/dist/chunk-q1cxrg0x.js +0 -2
- package/dist/chunk-swc7se71.js +0 -2
- package/dist/chunk-swyc15ym.js +0 -1
- package/dist/chunk-t2s3s6af.js +0 -1
- package/dist/chunk-vdmq9d9x.js +0 -4
- package/dist/chunk-wt3p1w1g.js +0 -1
- package/dist/chunk-y5ry5c7v.js +0 -1
- package/dist/chunk-yy8p9zph.js +0 -2
- package/dist/chunk-z61m3anh.js +0 -1
- package/dist/chunk-zr90qp47.js +0 -1
- package/dist/chunk-zsa62xr0.js +0 -2
package/dist/zen-core.js
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import{na as ee}from"./chunk-yfv1xeeh.js";import{ra as g}from"./chunk-74k5n8f5.js";import"./chunk-mq4m1w4w.js";import"./chunk-vwj4n000.js";import{Se as L,Te as ht,Ue as I,Ve as _,We as Ut,Xe as p,Ye as Ot}from"./chunk-wts8db9p.js";import{Lf as At,lf as V,nf as $t,sf as Gt,uf as Rt}from"./chunk-7d48d71t.js";import"./chunk-nh11afw0.js";import{Of as dt,cg as vt}from"./chunk-mqm8wnc8.js";import"./chunk-ncaqgas1.js";import"./chunk-vvs5da2x.js";import"./chunk-tws3wcnm.js";import"./chunk-0p3df51n.js";import"./chunk-cbr2vrpt.js";import{Qg as Et,Tg as Nt,Wg as k,Xg as jt,Yg as H}from"./chunk-2z45fjmt.js";import"./chunk-csn4vg3d.js";import"./chunk-9kbktaf8.js";import"./chunk-p6c1xbd5.js";import{sk as Bt}from"./chunk-e3jv1c1w.js";import"./chunk-an34z8wv.js";import"./chunk-nwmvyez4.js";import"./chunk-eqetcfer.js";import{wk as Yt}from"./chunk-rqymdmqg.js";import"./chunk-r133z8tq.js";import"./chunk-ge071wp4.js";import"./chunk-g2n6hnjp.js";import"./chunk-femf7e4d.js";import"./chunk-jbqqb1ht.js";import{xl as n}from"./chunk-0pzpg2ra.js";import{Al as Dt,Fl as ze}from"./chunk-xtr6s7kh.js";import{Kl as It,Nl as _t,Pl as pt,Ql as Wt}from"./chunk-xprg4hxp.js";import{Wl as T}from"./chunk-x17jyjan.js";function re(){let{process:t,Deno:e}=globalThis;return!(typeof e?.noColor==="boolean"?e.noColor:t!==void 0?"NO_COLOR"in t?.env:!1)}async function lt(){let{navigator:t}=globalThis,e="cloudflare:workers";return!(t!==void 0&&t.userAgent==="Cloudflare-Workers"?await(async()=>{try{return"NO_COLOR"in((await import("cloudflare:workers")).env??{})}catch{return!1}})():!re())}var ue=(t)=>{let[e,o]=[",","."];return t.map((l)=>l.replace(/(\d)(?=(\d\d\d)+(?!\d))/g,"$1"+e)).join(o)},fe=(t)=>{let e=Date.now()-t;return ue([e<1000?e+"ms":Math.round(e/1000)+"s"])},ie=async(t)=>{if(await lt())switch(t/100|0){case 5:return`\x1B[31m${t}\x1B[0m`;case 4:return`\x1B[33m${t}\x1B[0m`;case 3:return`\x1B[36m${t}\x1B[0m`;case 2:return`\x1B[32m${t}\x1B[0m`}return`${t}`};async function ot(t,e,o,s,l=0,a){let r=e==="<--"?`${e} ${o} ${s}`:`${e} ${o} ${s} ${await ie(l)} ${a}`;t(r)}var at=(t=console.log)=>{return async function(o,s){let{method:l,url:a}=o.req,r=a.slice(a.indexOf("/",8));await ot(t,"<--",l,r);let u=Date.now();await s(),await ot(t,"-->",l,r,o.res.status,fe(u))}};import{createServer as ye}from"http";import{Http2ServerRequest as me}from"http2";import{Http2ServerRequest as E}from"http2";import{Readable as nt}from"stream";import Ue from"crypto";var A=class extends Error{constructor(t,e){super(t,e);this.name="RequestError"}},we=(t)=>{if(t instanceof A)return t;return new A(t.message,{cause:t})},he=global.Request,K=class extends he{constructor(t,e){if(typeof t==="object"&&O in t)t=t[O]();if(typeof e?.body?.getReader<"u")e.duplex??="half";super(t,e)}},ce=(t)=>{let e=[],o=t.rawHeaders;for(let s=0;s<o.length;s+=2){let{[s]:l,[s+1]:a}=o;if(l.charCodeAt(0)!==58)e.push([l,a])}return new Headers(e)},ut=Symbol("wrapBodyStream"),xe=(t,e,o,s,l)=>{let a={method:t,headers:o,signal:l.signal};if(t==="TRACE"){a.method="GET";let r=new K(e,a);return Object.defineProperty(r,"method",{get(){return"TRACE"}}),r}if(!(t==="GET"||t==="HEAD"))if("rawBody"in s&&s.rawBody instanceof Buffer)a.body=new ReadableStream({start(r){r.enqueue(s.rawBody),r.close()}});else if(s[ut]){let r;a.body=new ReadableStream({async pull(u){try{r||=nt.toWeb(s).getReader();let{done:f,value:y}=await r.read();if(f)u.close();else u.enqueue(y)}catch(f){u.error(f)}}})}else a.body=nt.toWeb(s);return new K(e,a)},O=Symbol("getRequestCache"),Te=Symbol("requestCache"),z=Symbol("incomingKey"),X=Symbol("urlKey"),$e=Symbol("headersKey"),U=Symbol("abortControllerKey"),Ae=Symbol("getAbortController"),G={get method(){return this[z].method||"GET"},get url(){return this[X]},get headers(){return this[$e]||=ce(this[z])},[Ae](){return this[O](),this[U]},[O](){return this[U]||=new AbortController,this[Te]||=xe(this.method,this[X],this.headers,this[z],this[U])}};["body","bodyUsed","cache","credentials","destination","integrity","mode","redirect","referrer","referrerPolicy","signal","keepalive"].forEach((t)=>{Object.defineProperty(G,t,{get(){return this[O]()[t]}})});["arrayBuffer","blob","clone","formData","json","text"].forEach((t)=>{Object.defineProperty(G,t,{value:function(){return this[O]()[t]()}})});Object.setPrototypeOf(G,K.prototype);var Ze=(t,e)=>{let o=Object.create(G);o[z]=t;let s=t.url||"";if(s[0]!=="/"&&(s.startsWith("http://")||s.startsWith("https://"))){if(t instanceof E)throw new A("Absolute URL for :path is not allowed in HTTP/2");try{let u=new URL(s);o[X]=u.href}catch(u){throw new A("Invalid absolute URL",{cause:u})}return o}let l=(t instanceof E?t.authority:t.headers.host)||e;if(!l)throw new A("Missing host header");let a;if(t instanceof E){if(a=t.scheme,!(a==="http"||a==="https"))throw new A("Unsupported scheme")}else a=t.socket&&t.socket.encrypted?"https":"http";let r=new URL(`${a}://${l}${s}`);if(r.hostname.length!==l.length&&r.hostname!==l.replace(/:\d+$/,""))throw new A("Invalid host header");return o[X]=r.href,o},rt=Symbol("responseCache"),v=Symbol("getResponseCache"),Z=Symbol("cache"),P=global.Response,W=class t{#e;#t;[v](){return delete this[Z],this[rt]||=new P(this.#e,this.#t)}constructor(e,o){let s;if(this.#e=e,o instanceof t){let l=o[rt];if(l){this.#t=l,this[v]();return}else this.#t=o.#t,s=new Headers(o.#t.headers)}else this.#t=o;if(typeof e==="string"||typeof e?.getReader<"u"||e instanceof Blob||e instanceof Uint8Array)this[Z]=[o?.status||200,e,s||o?.headers]}get headers(){let e=this[Z];if(e){if(!(e[2]instanceof Headers))e[2]=new Headers(e[2]||{"content-type":"text/plain; charset=UTF-8"});return e[2]}return this[v]().headers}get status(){return this[Z]?.[0]??this[v]().status}get ok(){let e=this.status;return e>=200&&e<300}};["body","bodyUsed","redirected","statusText","trailers","type","url"].forEach((t)=>{Object.defineProperty(W.prototype,t,{get(){return this[v]()[t]}})});["arrayBuffer","blob","clone","formData","json","text"].forEach((t)=>{Object.defineProperty(W.prototype,t,{value:function(){return this[v]()[t]()}})});Object.setPrototypeOf(W,P);Object.setPrototypeOf(W.prototype,P.prototype);async function Ne(t){return Promise.race([t,Promise.resolve().then(()=>Promise.resolve(void 0))])}function ft(t,e,o){let s=(u)=>{t.cancel(u).catch(()=>{})};return e.on("close",s),e.on("error",s),(o??t.read()).then(r,l),t.closed.finally(()=>{e.off("close",s),e.off("error",s)});function l(u){if(u)e.destroy(u)}function a(){t.read().then(r,l)}function r({done:u,value:f}){try{if(u)e.end();else if(!e.write(f))e.once("drain",a);else return t.read().then(r,l)}catch(y){l(y)}}}function de(t,e){if(t.locked)throw TypeError("ReadableStream is locked.");else if(e.destroyed)return;return ft(t.getReader(),e)}var j=(t)=>{let e={};if(!(t instanceof Headers))t=new Headers(t??void 0);let o=[];for(let[s,l]of t)if(s==="set-cookie")o.push(l);else e[s]=l;if(o.length>0)e["set-cookie"]=o;return e["content-type"]??="text/plain; charset=UTF-8",e},ve="x-hono-already-sent";if(typeof global.crypto>"u")global.crypto=Ue;var C=Symbol("outgoingEnded"),Oe=()=>new Response(null,{status:400}),it=(t)=>new Response(null,{status:t instanceof Error&&(t.name==="TimeoutError"||t.constructor.name==="TimeoutError")?504:500}),q=(t,e)=>{let o=t instanceof Error?t:Error("unknown error",{cause:t});if(o.code==="ERR_STREAM_PREMATURE_CLOSE")console.info("The user aborted a request.");else{if(console.error(t),!e.headersSent)e.writeHead(500,{"Content-Type":"text/plain"});e.end(`Error: ${o.message}`),e.destroy(o)}},yt=(t)=>{if("flushHeaders"in t&&t.writable)t.flushHeaders()},mt=async(t,e)=>{let[o,s,l]=t[Z],a=!1;if(!l)l={"content-type":"text/plain; charset=UTF-8"};else if(l instanceof Headers)a=l.has("content-length"),l=j(l);else if(Array.isArray(l)){let r=new Headers(l);a=r.has("content-length"),l=j(r)}else for(let r in l)if(r.length===14&&r.toLowerCase()==="content-length"){a=!0;break}if(!a){if(typeof s==="string")l["Content-Length"]=Buffer.byteLength(s);else if(s instanceof Uint8Array)l["Content-Length"]=s.byteLength;else if(s instanceof Blob)l["Content-Length"]=s.size}if(e.writeHead(o,l),typeof s==="string"||s instanceof Uint8Array)e.end(s);else if(s instanceof Blob)e.end(new Uint8Array(await s.arrayBuffer()));else yt(e),await de(s,e)?.catch((r)=>q(r,e));e[C]?.()},Ye=(t)=>typeof t.then==="function",Be=async(t,e,o={})=>{if(Ye(t))if(o.errorHandler)try{t=await t}catch(l){let a=await o.errorHandler(l);if(!a)return;t=a}else t=await t.catch(it);if(Z in t)return mt(t,e);let s=j(t.headers);if(t.body){let l=t.body.getReader(),a=[],r=!1,u=void 0;if(s["transfer-encoding"]!=="chunked"){let f=2;for(let y=0;y<f;y++){u||=l.read();let w=await Ne(u).catch((i)=>{console.error(i),r=!0});if(!w){if(y===1){await new Promise((i)=>setTimeout(i)),f=3;continue}break}if(u=void 0,w.value)a.push(w.value);if(w.done){r=!0;break}}if(r&&!("content-length"in s))s["content-length"]=a.reduce((y,w)=>y+w.length,0)}if(e.writeHead(t.status,s),a.forEach((f)=>{e.write(f)}),r)e.end();else{if(a.length===0)yt(e);await ft(l,e,u)}}else if(s[ve]);else e.writeHead(t.status,s),e.end();e[C]?.()},Ke=(t,e={})=>{let o=e.autoCleanupIncoming??!0;if(e.overrideGlobalObjects!==!1&&global.Request!==K)Object.defineProperty(global,"Request",{value:K}),Object.defineProperty(global,"Response",{value:W});return async(s,l)=>{let a,r;try{r=Ze(s,e.hostname);let u=!o||s.method==="GET"||s.method==="HEAD";if(!u){if(s[ut]=!0,s.on("end",()=>{u=!0}),s instanceof me)l[C]=()=>{if(!u)setTimeout(()=>{if(!u)setTimeout(()=>{s.destroy(),l.destroy()})})}}if(l.on("close",()=>{if(r[U]){if(s.errored)r[U].abort(s.errored.toString());else if(!l.writableFinished)r[U].abort("Client connection prematurely closed.")}if(!u)setTimeout(()=>{if(!u)setTimeout(()=>{s.destroy()})})}),a=t(r,{incoming:s,outgoing:l}),Z in a)return mt(a,l)}catch(u){if(!a)if(e.errorHandler){if(a=await e.errorHandler(r?u:we(u)),!a)return}else if(!r)a=Oe();else a=it(u);else return q(u,l)}try{return await Be(a,l,e)}catch(u){return q(u,l)}}},We=(t)=>{let e=t.fetch,o=Ke(e,{hostname:t.hostname,overrideGlobalObjects:t.overrideGlobalObjects,autoCleanupIncoming:t.autoCleanupIncoming});return(t.createServer||ye)(t.serverOptions||{},o)},wt=(t,e)=>{let o=We(t);return o.listen(t?.port??3000,t.hostname,()=>{let s=o.address();e&&e(s)}),o};import{writeFileSync as Ge,unlinkSync as Re,existsSync as se,readFileSync as Me,mkdirSync as De}from"node:fs";import{join as le}from"node:path";import{homedir as oe}from"node:os";async function ct(t){let e=(i)=>{return i.stateSchema=ht,i},o={id:"filesystem",name:"filesystem",description:"File and directory operations (read, write, search, glob)",execute:async()=>{return e(new k)}};await t.addMiddleware(o),t.middlewares.registerImplementation(o);let s={id:"terminal",name:"terminal",description:"Terminal command execution (Bash/CMD, background processes)",execute:async()=>{return e(new H)}};await t.addMiddleware(s),t.middlewares.registerImplementation(s);let l={id:"subagents",name:"subagents",description:"Task delegation to specialized agents",execute:async()=>{let{createSubAgentsMiddleware:i}=await import("./chunk-1t3rabge.js");return await i(t)}};await t.addMiddleware(l),t.middlewares.registerImplementation(l);let a={id:"skills",name:"skills",description:"Progressive skills disclosure",execute:async(i)=>{if(i.projectSkillsDir=i.projectSkillsDir||"./.claude/skills",!i.skillsDir){let $=await import("os"),ne=await import("path");i.skillsDir=ne.join($.homedir(),".claude","skills")}let{SkillsMiddleware:x}=await import("./chunk-txnezkkt.js");return new x(i)}};await t.addMiddleware(a),t.middlewares.registerImplementation(a);let r={id:"agents_md",name:"agents_md",description:"Inject agent documentation",execute:async(i)=>{let{AgentsMdMiddleware:x}=await import("./chunk-txnezkkt.js");return new x({projectRoot:i?.projectRoot})}};await t.addMiddleware(r),t.middlewares.registerImplementation(r);let u={id:"interactive",name:"interactive",description:"User interaction for approval and input",execute:async()=>{let{InteractiveMiddleware:i}=await import("./chunk-df36fv24.js");return i}};await t.addMiddleware(u),t.middlewares.registerImplementation(u);let f={id:"task",name:"task",description:"Task management for todo lists",execute:async()=>{let{taskMiddleware:i}=await import("./chunk-s04zfe57.js");return i}};await t.addMiddleware(f),t.middlewares.registerImplementation(f);let y={id:"mcp",name:"mcp",description:"Task management for todo lists",execute:async()=>{let{MCPWithConfigMiddleware:i}=await import("./chunk-p75m7q2h.js");return new i}};await t.addMiddleware(y),t.middlewares.registerImplementation(y);let w={id:"web",name:"web",description:"Fetch and extract readable content from URLs",execute:async()=>{let{WebMiddleware:i}=await import("./chunk-bv28r5cf.js");return i}};await t.addMiddleware(w),t.middlewares.registerImplementation(w)}var xt=`# Manager - 项目经理
|
|
2
|
+
|
|
3
|
+
你是 **Manager**,用户与整个 AI 系统的主要交流窗口。你的职责是理解用户需求、拆解任务、协调子 agent 执行,并汇总结果。
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 核心职责
|
|
8
|
+
|
|
9
|
+
**你做的事**:
|
|
10
|
+
1. **需求澄清** - 与用户深入沟通,确保完全理解需求
|
|
11
|
+
2. **任务拆解** - 将复杂需求分解为清晰、可执行的子任务
|
|
12
|
+
3. **任务派发** - 通过 \`task\` 工具将子任务委派给 \`agents/default\`
|
|
13
|
+
4. **进度追踪** - 使用 \`todo_write\` 追踪任务状态
|
|
14
|
+
5. **决策协调** - 根据子任务返回结果决定下一步行动
|
|
15
|
+
6. **结果汇总** - 向用户报告整体进度和最终结果
|
|
16
|
+
|
|
17
|
+
**你不做的事**:
|
|
18
|
+
- ❌ 不直接编写代码
|
|
19
|
+
- ❌ 不直接读取/修改文件
|
|
20
|
+
- ❌ 不执行终端命令
|
|
21
|
+
- ❌ 不做具体的技术实现
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## 工作流程
|
|
26
|
+
|
|
27
|
+
### 阶段一:需求理解
|
|
28
|
+
|
|
29
|
+
收到用户请求后,评估是否需要澄清:
|
|
30
|
+
|
|
31
|
+
**需要澄清的情况**:
|
|
32
|
+
- 需求模糊或有歧义
|
|
33
|
+
- 技术方案有多个选择
|
|
34
|
+
- 影响范围不清晰
|
|
35
|
+
- 优先级未明确
|
|
36
|
+
|
|
37
|
+
**使用 \`ask_user_questions\` 工具进行澄清**:
|
|
38
|
+
- 一次性提出关键问题,不要逐一追问
|
|
39
|
+
- 问题要具体,提供可选项
|
|
40
|
+
- 充分理解后才开始规划
|
|
41
|
+
|
|
42
|
+
### 阶段二:任务规划
|
|
43
|
+
|
|
44
|
+
根据需求制定执行计划:
|
|
45
|
+
|
|
46
|
+
\`\`\`markdown
|
|
47
|
+
## 任务分析
|
|
48
|
+
|
|
49
|
+
**用户需求**:{用户原始请求}
|
|
50
|
+
|
|
51
|
+
**任务拆解**:
|
|
52
|
+
1. [任务 A] - 描述 + 预期产出
|
|
53
|
+
2. [任务 B] - 描述 + 预期产出(依赖任务 A)
|
|
54
|
+
3. [任务 C] - 描述 + 预期产出
|
|
55
|
+
|
|
56
|
+
**执行顺序**:A → B → C(B 依赖 A 的结果)
|
|
57
|
+
\`\`\`
|
|
58
|
+
|
|
59
|
+
使用 \`todo_write\` 记录任务列表。
|
|
60
|
+
|
|
61
|
+
### 阶段三:任务执行
|
|
62
|
+
|
|
63
|
+
按计划派发任务给 \`agents/default\`:
|
|
64
|
+
|
|
65
|
+
\`\`\`typescript
|
|
66
|
+
// 通过 task 工具派发
|
|
67
|
+
{
|
|
68
|
+
subagent_id: "agents/default",
|
|
69
|
+
subagent_type: "general-purpose",
|
|
70
|
+
task_description: "具体、完整的任务描述",
|
|
71
|
+
data_transfer: {
|
|
72
|
+
// 传递必要的上下文信息
|
|
73
|
+
context: "相关背景",
|
|
74
|
+
requirements: "具体要求",
|
|
75
|
+
constraints: "约束条件"
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
\`\`\`
|
|
79
|
+
|
|
80
|
+
**派发原则**:
|
|
81
|
+
- 任务描述要完整,包含所有必要上下文
|
|
82
|
+
- 明确期望的产出格式
|
|
83
|
+
- 传递前序任务的关键结果
|
|
84
|
+
|
|
85
|
+
### 阶段四:结果决策
|
|
86
|
+
|
|
87
|
+
收到子任务结果后,根据结果决定下一步:
|
|
88
|
+
|
|
89
|
+
| 结果状态 | 处理方式 |
|
|
90
|
+
|---------|---------|
|
|
91
|
+
| ✅ 成功 | 继续派发下一个任务,或进行最终汇总 |
|
|
92
|
+
| ⚠️ 部分完成 | 评估是否需要补充任务 |
|
|
93
|
+
| ❌ 失败 | 分析原因,调整任务描述后重新派发 |
|
|
94
|
+
| \uD83D\uDD04 需要更多信息 | 向用户确认,获取信息后继续 |
|
|
95
|
+
|
|
96
|
+
### 阶段五:结果汇总
|
|
97
|
+
|
|
98
|
+
所有任务完成后向用户报告:
|
|
99
|
+
|
|
100
|
+
\`\`\`markdown
|
|
101
|
+
## 执行结果
|
|
102
|
+
|
|
103
|
+
**已完成**:
|
|
104
|
+
- ✅ 任务 A:{关键产出摘要}
|
|
105
|
+
- ✅ 任务 B:{关键产出摘要}
|
|
106
|
+
|
|
107
|
+
**总结**:{整体结果,用户最关心的信息}
|
|
108
|
+
|
|
109
|
+
**后续建议**:(如有必要)
|
|
110
|
+
\`\`\`
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## 沟通风格
|
|
115
|
+
|
|
116
|
+
- **简洁专业**:直接切入主题,避免冗余
|
|
117
|
+
- **主动澄清**:不确定时及时确认,而非假设
|
|
118
|
+
- **透明进度**:让用户了解当前执行到哪一步
|
|
119
|
+
- **诚实汇报**:如遇问题,客观说明原因和解决方案
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## 任务拆解原则
|
|
124
|
+
|
|
125
|
+
**好的子任务**:
|
|
126
|
+
- 单一职责,边界清晰
|
|
127
|
+
- 产出物明确(代码文件、测试、文档等)
|
|
128
|
+
- 相互独立或依赖关系明确
|
|
129
|
+
- 粒度适中(不过大,不过碎)
|
|
130
|
+
|
|
131
|
+
**拆解示例**:
|
|
132
|
+
|
|
133
|
+
> 用户:重构用户模块并添加完整测试
|
|
134
|
+
|
|
135
|
+
拆解为:
|
|
136
|
+
1. 分析现有用户模块结构 → 输出:分析报告
|
|
137
|
+
2. 重构用户模块代码 → 输出:修改后的文件列表
|
|
138
|
+
3. 为用户模块编写单元测试 → 输出:测试文件
|
|
139
|
+
4. 验证重构后所有测试通过 → 输出:测试执行结果
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## 重要约束
|
|
144
|
+
|
|
145
|
+
1. **需求优先**:充分理解需求后再行动,避免返工
|
|
146
|
+
2. **完整上下文**:给子 agent 的任务必须包含足够的背景信息
|
|
147
|
+
3. **有序执行**:有依赖关系的任务按顺序执行
|
|
148
|
+
4. **保持专注**:每次只追踪一个进行中的任务
|
|
149
|
+
`;var Tt=({cwd:t,env:e})=>`You are an interactive CLI tool that helps users with software engineering tasks. Use the instructions below and the tools available to you to assist the user.
|
|
150
|
+
|
|
151
|
+
IMPORTANT: Assist with defensive security tasks only. Refuse to create, modify, or improve code that may be used maliciously. Allow security analysis, detection rules, vulnerability explanations, defensive tools, and security documentation.
|
|
152
|
+
IMPORTANT: You must NEVER generate or guess URLs for the user unless you are confident that the URLs are for helping the user with programming. You may use URLs provided by the user in their messages or local files.
|
|
153
|
+
|
|
154
|
+
# Tone and style
|
|
155
|
+
You should be concise, direct, and to the point.
|
|
156
|
+
You MUST answer concisely with fewer than 4 lines (not including tool use or code generation), unless user asks for detail.
|
|
157
|
+
IMPORTANT: You should minimize output tokens as much as possible while maintaining helpfulness, quality, and accuracy. Only address the specific query or task at hand, avoiding tangential information unless absolutely critical for completing the request. If you can answer in 1-3 sentences or a short paragraph, please do.
|
|
158
|
+
IMPORTANT: You should NOT answer with unnecessary preamble or postamble (such as explaining your code or summarizing your action), unless the user asks you to.
|
|
159
|
+
Do not add additional code explanation summary unless requested by the user. After working on a file, just stop, rather than providing an explanation of what you did.
|
|
160
|
+
Answer the user's question directly, without elaboration, explanation, or details. One word answers are best. Avoid introductions, conclusions, and explanations. You MUST avoid text before/after your response, such as "The answer is <answer>.", "Here is the content of the file..." or "Based on the information provided, the answer is..." or "Here is what I will do next...". Here are some examples to demonstrate appropriate verbosity:
|
|
161
|
+
|
|
162
|
+
<example>
|
|
163
|
+
user: 2 + 2
|
|
164
|
+
assistant: 4
|
|
165
|
+
</example>
|
|
166
|
+
|
|
167
|
+
<example>
|
|
168
|
+
user: what is 2+2?
|
|
169
|
+
assistant: 4
|
|
170
|
+
</example>
|
|
171
|
+
|
|
172
|
+
<example>
|
|
173
|
+
user: is 11 a prime number?
|
|
174
|
+
assistant: Yes
|
|
175
|
+
</example>
|
|
176
|
+
|
|
177
|
+
<example>
|
|
178
|
+
user: what command should I run to list files in the current directory?
|
|
179
|
+
assistant: ls
|
|
180
|
+
</example>
|
|
181
|
+
|
|
182
|
+
<example>
|
|
183
|
+
user: what command should I run to watch files in the current directory?
|
|
184
|
+
assistant: [runs ls to list the files in the current directory, then read docs/commands in the relevant file to find out how to watch files]
|
|
185
|
+
npm run dev
|
|
186
|
+
</example>
|
|
187
|
+
|
|
188
|
+
<example>
|
|
189
|
+
user: How many golf balls fit inside a jetta?
|
|
190
|
+
assistant: 150000
|
|
191
|
+
</example>
|
|
192
|
+
|
|
193
|
+
<example>
|
|
194
|
+
user: what files are in the directory src/?
|
|
195
|
+
assistant: [runs ls and sees foo.c, bar.c, baz.c]
|
|
196
|
+
user: which file contains the implementation of foo?
|
|
197
|
+
assistant: src/foo.c
|
|
198
|
+
</example>
|
|
199
|
+
|
|
200
|
+
When you run a non-trivial bash command, you should explain what the command does and why you are running it, to make sure the user understands what you are doing (this is especially important when you are running a command that will make changes to the user's system).
|
|
201
|
+
|
|
202
|
+
Remember that your output will be displayed on a command line interface. Your responses can use Github-flavored markdown for formatting, and will be rendered in a monospace font using the CommonMark specification.
|
|
203
|
+
|
|
204
|
+
Output text to communicate with the user; all text you output outside of tool use is displayed to the user. Only use tools to complete tasks. Never use tools like Bash or code comments as means to communicate with the user during the session.
|
|
205
|
+
|
|
206
|
+
If you cannot or will not help the user with something, please do not say why or what it could lead to, since this comes across as preachy and annoying. Please offer helpful alternatives if possible, and otherwise keep your response to 1-2 sentences.
|
|
207
|
+
|
|
208
|
+
Only use emojis if the user explicitly requests it. Avoid using emojis in all communication unless asked.
|
|
209
|
+
|
|
210
|
+
IMPORTANT: Keep your responses short, since they will be displayed on a command line interface.
|
|
211
|
+
|
|
212
|
+
# Proactiveness
|
|
213
|
+
You are allowed to be proactive, but only when the user asks you to do something. You should strive to strike a balance between:
|
|
214
|
+
- Doing the right thing when asked, including taking actions and follow-up actions
|
|
215
|
+
- Not surprising the user with actions you take without asking
|
|
216
|
+
For example, if the user asks you how to approach something, you should do your best to answer their question first, and not immediately jump into taking actions.
|
|
217
|
+
|
|
218
|
+
# Following conventions
|
|
219
|
+
When making changes to files, first understand the file's code conventions. Mimic code style, use existing libraries and utilities, and follow existing patterns.
|
|
220
|
+
- NEVER assume that a given library is available, even if it is well known. Whenever you write code that uses a library or framework, first check that this codebase already uses the given library. For example, you might look at neighboring files, or check the package.json (or cargo.toml, and so on depending on the language).
|
|
221
|
+
- When you create a new component, first look at existing components to see how they're written; then consider framework choice, naming conventions, typing, and other conventions.
|
|
222
|
+
- When you edit a piece of code, first look at the code's surrounding context (especially its imports) to understand the code's choice of frameworks and libraries. Then consider how to make the given change in a way that is most idiomatic.
|
|
223
|
+
- Always follow security best practices. Never introduce code that exposes or logs secrets and keys. Never commit secrets or keys to the repository.
|
|
224
|
+
|
|
225
|
+
# Doing tasks
|
|
226
|
+
The user will primarily request you perform software engineering tasks. This includes solving bugs, adding new functionality, refactoring code, explaining code, and more. For these tasks the following steps are recommended:
|
|
227
|
+
- Use the TodoWrite tool to plan the task if required
|
|
228
|
+
- Use the available search tools to understand the codebase and the user's query. You are encouraged to use the search tools extensively both in parallel and sequentially.
|
|
229
|
+
- Implement the solution using all tools available to you
|
|
230
|
+
- Verify the solution if possible with tests. NEVER assume specific test framework or test script. Check the README or search codebase to determine the testing approach.
|
|
231
|
+
- VERY IMPORTANT: When you have completed a task, you MUST run the lint and typecheck commands (eg. npm run lint, npm run typecheck, ruff, etc.) with Bash if they were provided to you to ensure your code is correct. If you are unable to find the correct command, ask the user for the command to run and if they supply it, proactively suggest writing it to CLAUDE.md so that you will know to run it next time.
|
|
232
|
+
NEVER commit changes unless the user explicitly asks you to. It is VERY IMPORTANT to only commit when explicitly asked, otherwise the user will feel that you are being too proactive.
|
|
233
|
+
|
|
234
|
+
# Tool usage policy
|
|
235
|
+
- When doing file search, prefer to use the Task tool in order to reduce context usage.
|
|
236
|
+
- You should proactively use the Task tool with specialized agents when the task at hand matches the agent's description.
|
|
237
|
+
- When WebFetch returns a message about a redirect to a different host, you should immediately make a new WebFetch request with the redirect URL provided in the response.
|
|
238
|
+
- You have the capability to call multiple tools in a single response. When multiple independent pieces of information are requested, batch your tool calls together for optimal performance. When making multiple bash tool calls, you MUST send a single message with multiple tools calls to run the calls in parallel. For example, if you need to run "git status" and "git diff", send a single message with two tool calls to run the calls in parallel.
|
|
239
|
+
|
|
240
|
+
Here is useful information about the environment you are running in:
|
|
241
|
+
|
|
242
|
+
<env>
|
|
243
|
+
Working directory: ${t}
|
|
244
|
+
Is directory a git repo: ${e.isGitRepo?"Yes":"No"}
|
|
245
|
+
Platform: ${e.platform}
|
|
246
|
+
OS Version: ${e.osVersion}
|
|
247
|
+
Today's date: ${e.date}
|
|
248
|
+
</env>
|
|
249
|
+
|
|
250
|
+
# Code References
|
|
251
|
+
|
|
252
|
+
When referencing specific functions or pieces of code include the pattern \`file_path:line_number\` to allow the user to easily navigate to the source code location.
|
|
253
|
+
|
|
254
|
+
<example>
|
|
255
|
+
user: Where are errors from the client handled?
|
|
256
|
+
assistant: Clients are marked as failed in the \`connectToServer\` function in src/services/process.ts:712.
|
|
257
|
+
</example>
|
|
258
|
+
`;var Ve={filesystem:!0,terminal:!0,agents_md:!0,skills:!0,subagents:!0,interactive:!0,task:!0,mcp:!0,web:!0};async function b(){let t=new $t,e=new V(t);await e.addModel({id:"glm-4.7",model_name:"glm-4.7",provider_id:process.env.MODEL_PROVIDER||"openai",stream_usage:!0,enable_thinking:!0,temperature:0.7,max_tokens:4096,top_p:1,frequency_penalty:0,presence_penalty:0}),await ct(e);let s=await new At().loadAllAgents(process.cwd()),l=new Set(s.map((a)=>`agents/${a.name}`));for(let a of s){let r=`agents/${a.name}`,u=`prompts/${a.name}`;await e.addPrompt({id:u,name:a.name},a.systemPrompt),await e.addAgent({id:r,name:a.name,description:a.description,system_prompt:u,model:"glm-4.7",middlewares:Ve})}if(await e.addPrompt({id:"prompts/default",name:"default"},Tt({cwd:process.cwd(),env:{isGitRepo:!0,platform:process.platform,osVersion:process.version,date:new Date().toISOString().split("T")[0]}})),await e.addPrompt({id:"prompts/manager",name:"manager"},xt),!l.has("agents/default"))await e.addAgent({id:"agents/default",name:"Jarvis",description:"代码实现助手",system_prompt:"prompts/default",model:"glm-4.7",middlewares:{filesystem:!0,terminal:!0,agents_md:!0,skills:!0,subagents:!0,interactive:!0,task:!0,mcp:!0,web:!0}});if(!l.has("agents/manager"))await e.addAgent({id:"agents/manager",name:"Manager",description:"任务管理员",system_prompt:"prompts/manager",model:"glm-4.7",middlewares:{filesystem:!1,terminal:!1,agents_md:!0,skills:!0,subagents:!0,interactive:!0,task:!0,mcp:!1,web:!1}});return e}var be=await b(),Zt=be;async function Fe(t,e,o,s,l){let a=await I(t,o,{pkg:e,providerResolver:l?.providerResolver,initModel:p,stateSchema:L,enhanceSystemPrompt:async(u,f)=>{return u+`
|
|
259
|
+
|
|
260
|
+
`+await Ot(f)}});o.thread_id=Ut(s);let r=await a.invoke(o,{recursionLimit:500,configurable:s.configurable,context:s.context});return{active_agent:"",task_store:r.task_store,messages:r.messages}}await Nt();function S(t,e){return new vt(L).addNode("graph",async(o,s)=>{let{active_agent:l}=o,a=t??Zt,r=await _(a),u=(l&&l!=="default"?l:null)??o.agent_id??"agents/default";if(!r.includes(u))throw Error(`Unknown agent: ${u}. Available: ${r.join(", ")}`);return await Fe(u,a,o,s,e)}).addEdge(dt,"graph").compile()}var R=null;async function Kt(){if(R)return R;let t=await b(),e=await V.fromStorage(t.storage);for(let l of t.middlewares.listImplementations())e.middlewares.registerImplementation(l);let o=await Yt(),s=new Bt(process.cwd());return await s.initialize(),R={agentPackage:e,configManager:o,taskStore:s},R}var Vt=Wt.context().create(),c=Vt.router,m=Vt.procedure;var bt=c({get:m.query(async({ctx:t})=>{return await t.configManager.getConfig()}),update:m.input(n.record(n.string(),n.unknown())).mutation(async({ctx:t,input:e})=>{return await t.configManager.updateConfig(e),await t.configManager.getConfig()})});var Ft=30000;async function Qe(t){let e=new AbortController,o=setTimeout(()=>e.abort(),Ft);try{if(t.type==="openai"||t.type==="deepseek"||t.type==="moonshot"||t.type==="zhipu"||t.type==="custom"){let s=await fetch(`${t.baseUrl}/models`,{method:"GET",headers:{Authorization:`Bearer ${t.apiKey}`,"Content-Type":"application/json"},signal:e.signal});if(!s.ok)throw Error(`API error (${s.status}): ${s.statusText}`);return((await s.json()).data||[]).map((a)=>({id:a.id,name:a.id,provider:t.type}))}else if(t.type==="anthropic"){let s=await fetch(`${t.baseUrl}/v1/models`,{method:"GET",headers:{"x-api-key":t.apiKey,"anthropic-version":"2023-06-01","Content-Type":"application/json"},signal:e.signal});if(!s.ok)throw Error(`Anthropic API error (${s.status}): ${s.statusText}`);return((await s.json()).data||[]).map((a)=>({id:a.id,name:a.display_name||a.id,provider:"anthropic"}))}else if(t.type==="gemini"){let s=await fetch(`${t.baseUrl}/v1beta/models`,{method:"GET",headers:{Authorization:`Bearer ${t.apiKey}`},signal:e.signal});if(!s.ok)throw Error(`Gemini API error (${s.status}): Invalid API key`);return((await s.json()).models||[]).map((a)=>({id:a.name,name:a.displayName||a.name,provider:"gemini"}))}return[]}catch(s){if(s.name==="AbortError")throw Error(`API request timeout (${Ft/1000}s)`);throw s}finally{clearTimeout(o)}}var Qt=c({list:m.input(n.object({providerId:n.string()})).query(async({ctx:t,input:e})=>{let s=((await t.configManager.getConfig()).providers||[]).find((l)=>l.id===e.providerId);if(!s||!s.apiKey||!s.baseUrl)return[];return await Qe(s)})});var Jt=c({list:m.query(async({ctx:t})=>{return await t.configManager.listSkills()}),get:m.input(n.object({name:n.string()})).query(async({ctx:t,input:e})=>{return await t.configManager.getSkill(e.name)}),save:m.input(n.object({name:n.string(),content:n.object({frontmatter:n.record(n.string(),n.unknown()).optional(),body:n.string()})})).mutation(async({ctx:t,input:e})=>{return await t.configManager.saveSkill(e.name,e.content),{success:!0}}),delete:m.input(n.object({name:n.string()})).mutation(async({ctx:t,input:e})=>{return await t.configManager.deleteSkill(e.name),{success:!0}})});var zt=c({list:m.input(n.object({filter:n.string().optional(),cwd:n.string().optional()}).optional()).query(async({ctx:t,input:e})=>{if(e?.filter)return await t.taskStore.getTasksByStatus(e.filter);return await t.taskStore.getAllTasks()}),get:m.input(n.object({id:n.string(),cwd:n.string().optional()})).query(async({ctx:t,input:e})=>{return await t.taskStore.getTask(e.id)}),updateStatus:m.input(n.object({id:n.string(),status:n.string(),cwd:n.string().optional()})).mutation(async({ctx:t,input:e})=>{return await t.taskStore.updateTask(e.id,{status:e.status})}),delete:m.input(n.object({id:n.string(),cwd:n.string().optional()})).mutation(async({ctx:t,input:e})=>{return await t.taskStore.deleteTask(e.id)})});import{join as Xt}from"path";import{homedir as Je}from"os";var Mt=c({list:m.input(n.object({type:n.enum(["memories","skills"]),cwd:n.string().optional()})).query(async({input:t})=>{let e=t.cwd||process.cwd(),o=Xt(e,".claude",t.type),s=Xt(Je(),".claude",t.type);try{if(t.type==="memories")return Rt(s,o).map((a)=>({...a,type:"memory"}));else return Gt(s,o).map((a)=>({...a,type:"skill"}))}catch(l){return console.warn(`Failed to load ${t.type}:`,l),[]}})});ze();var Xe=new Map;async function qt(t){let{command:e,cwd:o,timeout:s}=t,l=Dt();try{let a=process.platform==="win32",f=Et(a?"cmd.exe":"/bin/bash",[...a?["/d","/s","/c"]:["-c"],e],{cwd:o,detached:!0,reject:!1,windowsVerbatimArguments:a,timeout:s});if(!f.pid)return{id:l,pid:0,output:"Error: Failed to start command",status:"failed",exitCode:-1};let y={process:f,stdout:[],stderr:[],command:e,startTime:Date.now()};jt.set(f.pid,y),Xe.set(l,f.pid);let w=[];f.stdout?.on("data",(x)=>{let $=x.toString();w.push($),y.stdout.push($)}),f.stderr?.on("data",(x)=>{let $=x.toString();w.push($),y.stderr.push($)}),f.on("close",(x)=>{y.status=x===0?"completed":"failed",y.exitCode=x}),await new Promise((x)=>setTimeout(x,100));let i=y.status||"running";return{id:l,pid:f.pid,output:w.join(""),status:i,exitCode:y.exitCode}}catch(a){let r=a instanceof Error?a.message:"Unknown error";return{id:l,pid:0,output:`Error: ${r}`,status:"failed",exitCode:-1}}}var F=new Map,Pt=c({list:m.query(async()=>{return Array.from(F.values())}),get:m.input(n.object({id:n.string()})).query(async({input:t})=>{let e=F.get(t.id);if(!e)throw Error(`Process '${t.id}' not found`);return e}),exec:m.input(n.object({command:n.string(),cwd:n.string().optional()})).mutation(async({input:t})=>{let e=await qt({command:t.command,cwd:t.cwd||process.cwd()});return F.set(e.id,{id:e.id,name:t.command,pid:e.pid,status:e.status==="running"?"running":e.exitCode===0?"stopped":"error",startedAt:Date.now()}),{id:e.id,pid:e.pid,stdout:e.output,stderr:"",exitCode:e.exitCode??0,status:e.status}}),kill:m.input(n.object({id:n.string()})).mutation(async({input:t})=>{let e=F.get(t.id);if(!e)throw Error(`Process '${t.id}' not found`);if(e.pid)try{process.kill(e.pid,"SIGTERM")}catch{}return e.status="stopped",F.set(t.id,e),{success:!0}})});var Ct=c({config:bt,models:Qt,skills:Jt,tasks:zt,knowledge:Mt,processes:Pt});function kt(t){return{...t}}var N=(t,e)=>t.constructor.name===e.name,h=new Map;h.set(n.ZodBoolean.name,()=>!1),h.set(n.ZodNumber.name,()=>0),h.set(n.ZodString.name,()=>""),h.set(n.ZodArray.name,()=>[]),h.set(n.ZodRecord.name,()=>({})),h.set(n.ZodDefault.name,(t)=>t.def.defaultValue),h.set(n.ZodPipe.name,(t)=>Q(t.def.in)),h.set(n.ZodOptional.name,(t)=>N(t.def.innerType,n.ZodDefault)?t.def.innerType.def.defaultValue:void 0),h.set(n.ZodTuple.name,(t)=>{let e=[];for(let o of t.def.items)e.push(Q(o));return e}),h.set(n.ZodPipe.name,(t)=>Q(t.def.in)),h.set(n.ZodUnion.name,(t)=>Q(t.def.options[0])),h.set(n.ZodObject.name,(t)=>d(t)),h.set(n.ZodRecord.name,(t)=>d(t)),h.set(n.ZodIntersection.name,(t)=>d(t));function Q(t){let e=t.constructor.name;if(!h.has(e)){console.warn("getSchemaDefaultForField: Unhandled type",t.constructor.name);return}return h.get(e)(t)}function d(t){if(N(t,n.ZodRecord))return{};if(N(t,n.ZodPipe))return d(t.def.in);if(N(t,n.ZodIntersection))return{...d(t.def.left),...d(t.def.right)};if(N(t,n.ZodUnion)){for(let e of t.def.options)if(N(e,n.ZodObject))return d(e);return console.warn("getSchemaDefaultObject: No object found in union, returning empty object"),{}}return N(t,n.ZodObject)?Object.fromEntries(Object.entries(t.shape).map(([e,o])=>[e,Q(o)]).filter((e)=>e[1]!==void 0)):(console.warn(`getSchemaDefaultObject: Expected object schema, got ${t.constructor.name}`),{})}var pl=n.object({task_store:n.record(n.string(),n.any()).default({})}),Sl=n.object({task_id:n.string().optional().describe("The task id to ask the subagent, if not provided, will use the tool call id"),subagent_id:n.string(),task_description:n.string().describe("Describe the user state and what you want the subagent to do."),data_transfer:n.any().optional().describe("Data to transfer to the subagent.")});class tt{agentPackage;baseUrl;constructor(t,e){this.agentPackage=t;this.baseUrl=e||process.env.ZEN_SWARM_URL||"http://127.0.0.1:8124"}async resolve(t){try{let e=`${this.baseUrl}/api/trpc/providers.resolveForAgent?input=${encodeURIComponent(JSON.stringify({json:{id:t}}))}`,o=await fetch(e,{signal:AbortSignal.timeout(3000)});if(!o.ok)return null;let l=(await o.json())?.result?.data?.json;if(!l?.apiKey)return null;return{id:l.id,type:l.type,name:l.name,baseUrl:l.baseUrl,apiKey:l.apiKey}}catch{return null}}async resolveByModel(t){let e=await this.agentPackage.getModel(t);if(!e?.provider_id)return null;return this.resolve(e.provider_id)}}async function Ht(t){let e=new tt(t.agentPackage),o=S(t.agentPackage,{providerResolver:e});g("code",o),console.log('LangGraph graph "code" registered at /api/langgraph')}function Lt(t){return(e)=>e.json({status:"ok",version:"1.0.0",service:"zen-core",port:Number(process.env.ZEN_CORE_PORT||8125),graphs:["code"],timestamp:Date.now()})}var J=It(_t(),1),et=(t)=>{return t=t.startsWith("/")?t.slice(1):t,t=t.endsWith("/")?t.slice(0,-1):t,t};async function St(t){let e=new Headers,o=async(u)=>{var f;return(f=t.createContext)===null||f===void 0?void 0:f.call(t,(0,J.default)({req:t.req,resHeaders:e},u))},s=new URL(t.req.url),l=et(s.pathname),a=et(t.endpoint),r=et(l.slice(a.length));return await pt((0,J.default)((0,J.default)({},t),{},{req:t.req,createContext:o,path:r,error:null,onError(u){var f;t===null||t===void 0||(f=t.onError)===null||f===void 0||f.call(t,(0,J.default)((0,J.default)({},u),{},{req:t.req}))},responseMeta(u){var f;let y=(f=t.responseMeta)===null||f===void 0?void 0:f.call(t,u);if(y===null||y===void 0?void 0:y.headers){if(y.headers instanceof Headers)for(let[w,i]of y.headers.entries())e.append(w,i);else for(let[w,i]of Object.entries(y.headers))if(Array.isArray(i))for(let x of i)e.append(w,x);else if(typeof i==="string")e.set(w,i)}return{headers:e,status:y===null||y===void 0?void 0:y.status}}}))}var M={};function gt(t){t.post("/api/mcp-sync",async(e)=>{try{let o=await e.req.json();return M=o.servers??o??{},console.log(`[mcp-sync] Received ${Object.keys(M).length} MCP server(s)`),e.json({ok:!0,count:Object.keys(M).length})}catch(o){return console.error("[mcp-sync] Failed to parse request body:",o),e.json({ok:!1,error:String(o)},400)}}),t.get("/api/mcp-sync",(e)=>{return e.json({servers:M})})}var Y=Number(process.env.ZEN_CORE_PORT||8125),D=le(oe(),".zen-code","zen-core.pid"),te=le(oe(),".zen-code");if(!se(te))De(te,{recursive:!0});if(se(D)){let t=parseInt(Me(D,"utf8").trim());if(!isNaN(t))try{process.kill(t,"SIGTERM"),console.log(`Terminated old zen-core process (PID: ${t})`),await new Promise((e)=>setTimeout(e,500))}catch{}}Ge(D,String(process.pid));process.on("exit",()=>{try{Re(D)}catch{}});console.log("Bootstrapping zen-core services...");var st=await Kt();await Ht(st);var B=new ee;B.use(at());B.get("/health",Lt(st));gt(B);B.all("/api/trpc/*",async(t)=>{return St({req:t.req.raw,router:Ct,createContext:()=>kt(st),endpoint:"/api/trpc"})});var{default:Ee}=await import("./chunk-rr7h6wdp.js");B.route("/api/langgraph",Ee);wt({fetch(t,e){return B.fetch(t,e)},port:Y});console.log(`zen-core running on http://127.0.0.1:${Y}`);console.log(` Health: http://127.0.0.1:${Y}/health`);console.log(` LangGraph: http://127.0.0.1:${Y}/api/langgraph`);console.log(` tRPC: http://127.0.0.1:${Y}/api/trpc`);console.log(` Terminal: ws://127.0.0.1:${Y}/ws/terminal`);async function ae(t){console.log(`
|
|
261
|
+
[zen-core] Received ${t}, shutting down...`),process.exit(0)}process.on("SIGTERM",()=>ae("SIGTERM"));process.on("SIGINT",()=>ae("SIGINT"));
|
package/dist/zen-keyboard.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{U as h,Y as s,Z as i,fa as u,ga as p}from"./chunk-bqkrynm6.js";import{Rl as n}from"./chunk-x17jyjan.js";var f=n(h(),1);var r=n(u(),1);i(r.jsxDEV(O,{},void 0,!1,void 0,this));function O(){let[m,l]=f.useState(`Press any key...
|
|
2
2
|
`);return p((y,c,g)=>{let t=["\x1B[2J\x1B[H","input:",JSON.stringify(y),"","key:"],o=Object.entries(c).filter(([,e])=>e===!0);for(let[e]of o)t.push(` ${e}: true`);if(o.length===0)t.push(" (no true values)");t.push(JSON.stringify(g,null,2)),l(t.join(`
|
|
3
3
|
`))}),r.jsxDEV(s,{children:m},void 0,!1,void 0,this)}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zen-code",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/cli.js",
|
|
6
6
|
"bin": "./dist/cli.js",
|
|
@@ -21,7 +21,6 @@
|
|
|
21
21
|
"dependencies": {},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@anthropic-ai/sdk": "^0.71.2",
|
|
24
|
-
"@codegraph/agent": "^1.0.0",
|
|
25
24
|
"@codegraph/config": "^1.0.0",
|
|
26
25
|
"@codegraph/union-client": "^1.0.0",
|
|
27
26
|
"@google/generative-ai": "^0.24.1",
|
|
@@ -33,8 +32,9 @@
|
|
|
33
32
|
"@langchain/mcp-adapters": "^1.1.1",
|
|
34
33
|
"@langchain/openai": "^1.2.12",
|
|
35
34
|
"@langgraph-js/agent-middlewares": "^0.1.0",
|
|
35
|
+
"@langgraph-js/web-fetch": "^1.1.0",
|
|
36
36
|
"@langgraph-js/pure-graph": "^3.3.0",
|
|
37
|
-
"@langgraph-js/sdk": "^4.6.
|
|
37
|
+
"@langgraph-js/sdk": "^4.6.6",
|
|
38
38
|
"@langgraph-js/standard-agent": "^1.3.1",
|
|
39
39
|
"@nanostores/react": "^1.0.0",
|
|
40
40
|
"@tanstack/react-query": "^5.90.21",
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"@vitejs/plugin-react": "^5.1.2",
|
|
48
48
|
"ansi-escapes": "^7.3.0",
|
|
49
49
|
"chalk": "^5.6.2",
|
|
50
|
+
"clipboardy": "^5.3.1",
|
|
50
51
|
"diff-match-patch": "^1.0.5",
|
|
51
52
|
"execa": "^9.6.1",
|
|
52
53
|
"extract-zip": "^2.0.1",
|
|
@@ -82,6 +83,7 @@
|
|
|
82
83
|
"vitest": "^4.0.18",
|
|
83
84
|
"xdg-basedir": "^5.1.0",
|
|
84
85
|
"yaml": "^2.8.2",
|
|
86
|
+
"zen-core": "^1.0.0",
|
|
85
87
|
"zod": "^4.3.5"
|
|
86
88
|
},
|
|
87
89
|
"babel": {
|
package/dist/chunk-0ddrb30y.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{if as a,jf as b}from"./chunk-qxebn3jw.js";import"./chunk-q1cxrg0x.js";import"./chunk-tjg2e8v3.js";import"./chunk-y8qhrx11.js";export{a as createFSManager,b as createCustomManager};
|
package/dist/chunk-215an3fz.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as k}from"./chunk-h8fdexm4.js";import"./chunk-4wnmk2tj.js";import{Ae as r,Ie as B,Je as b,we as R,ze as g}from"./chunk-c7kd2qrp.js";import"./chunk-a9tw6d68.js";import"./chunk-k4q8j7pg.js";import"./chunk-spx7nn8t.js";import"./chunk-vfxjbdz4.js";import"./chunk-qxebn3jw.js";import"./chunk-e8kxa5vj.js";import"./chunk-q1cxrg0x.js";import"./chunk-tjg2e8v3.js";import{Dl as m}from"./chunk-y8qhrx11.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};
|
package/dist/chunk-4z0w0ng1.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{C as r}from"./chunk-pzb224c5.js";import{lg as c,mg as h}from"./chunk-pe8mzxwn.js";import{$g as o,Dg as u,Fg as S,Vg as l,Xg as i,Yg as s,_g as n,ah as d}from"./chunk-hp2jzn9x.js";import{ii as g,ij as p}from"./chunk-nk62q95g.js";import{Al as N,Cl as WY}from"./chunk-hve2a279.js";import{Il as L}from"./chunk-y8qhrx11.js";WY();var PY=(Y)=>{let Z=Y.goto!=null&&!Array.isArray(Y.goto)?[Y.goto]:Y.goto;return new h({goto:Z?.map(($)=>{if(typeof $!=="string")return new c($.node,$.input);return $}),update:Y.update??void 0,resume:Y.resume})},I="[...]",QY="[Circular]",G=[],x=[];function zY(){return{depthLimit:Number.MAX_SAFE_INTEGER,edgesLimit:Number.MAX_SAFE_INTEGER}}function OY(Y,Z,$,J){if(typeof J>"u")J=zY();f(Y,"",0,[],void 0,0,J);var H;try{if(x.length===0)H=JSON.stringify(Y,Z,$);else H=JSON.stringify(Y,KY(Z),$)}catch(U){return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]")}finally{while(G.length!==0){var X=G.pop();if(X.length===4)Object.defineProperty(X[0],X[1],X[3]);else X[0][X[1]]=X[2]}}return H}function w(Y,Z,$,J){var H=Object.getOwnPropertyDescriptor(J,$);if(H.get!==void 0)if(H.configurable)Object.defineProperty(J,$,{value:Y}),G.push([J,$,Z,H]);else x.push([Z,$,Y]);else J[$]=Y,G.push([J,$,Z])}function f(Y,Z,$,J,H,X,U){X+=1;var W;if(typeof Y==="object"&&Y!==null){for(W=0;W<J.length;W++)if(J[W]===Y){w(QY,Y,Z,H);return}if(typeof U.depthLimit<"u"&&X>U.depthLimit){w(I,Y,Z,H);return}if(typeof U.edgesLimit<"u"&&$+1>U.edgesLimit){w(I,Y,Z,H);return}if(J.push(Y),Array.isArray(Y))for(W=0;W<Y.length;W++)f(Y[W],W,W,J,Y,X,U);else{var P=Object.keys(Y);for(W=0;W<P.length;W++){var z=P[W];f(Y[z],z,W,J,Y,X,U)}}J.pop()}}function KY(Y){return Y=typeof Y<"u"?Y:function(Z,$){return $},function(Z,$){if(x.length>0)for(var J=0;J<x.length;J++){var H=x[J];if(H[1]===Z&&H[0]===$){$=H[2],x.splice(J,1);break}}return Y.call(this,Z,$)}}function VY(Y){return Y!==null&&Y.lc===1&&Y.type==="constructor"&&Array.isArray(Y.id)}async function q(Y){if(Y&&typeof Y==="object")if(Array.isArray(Y))return await Promise.all(Y.map(($)=>q($)));else{let Z={};for(let[$,J]of Object.entries(Y))Z[$]=await q(J);if(Z.lc===2&&Z.type==="undefined")return;else if(Z.lc===2&&Z.type==="constructor"&&Array.isArray(Z.id))try{let $=Z.id[Z.id.length-1],J;switch($){case"Set":J=Set;break;case"Map":J=Map;break;case"RegExp":J=RegExp;break;case"Error":J=Error;break;default:return Z}if(Z.method)return J[Z.method](...Z.args||[]);else return new J(...Z.args||[])}catch($){return Z}else if(VY(Z))return l(JSON.stringify(Z));return Z}return Y}function M(Y,Z,$,J){return{lc:2,type:"constructor",id:[Y.name],method:Z??null,args:$??[],kwargs:J??{}}}function FY(Y){if(Y===void 0)return{lc:2,type:"undefined"};else if(Y instanceof Set||Y instanceof Map)return M(Y.constructor,void 0,[Array.from(Y)]);else if(Y instanceof RegExp)return M(RegExp,void 0,[Y.source,Y.flags]);else if(Y instanceof Error)return M(Y.constructor,void 0,[Y.message]);else if(Y?.lg_name==="Send")return{node:Y.node,args:Y.args};else return Y}class t{_dumps(Y){return new TextEncoder().encode(OY(Y,($,J)=>{return FY(J)}))}async dumpsTyped(Y){if(Y instanceof Uint8Array)return["bytes",Y];else return["json",this._dumps(Y)]}async _loads(Y){let Z=JSON.parse(Y);return q(Z)}async loadsTyped(Y,Z){if(Y==="bytes")return typeof Z==="string"?new TextEncoder().encode(Z):Z;else if(Y==="json")return this._loads(typeof Z==="string"?Z:new TextDecoder().decode(Z));else throw Error(`Unknown serialization type: ${Y}`)}}class a extends r.default{constructor(Y,Z=!0,$=300){super();this.id=Y,this.compressMessages=Z,this.ttl=$}serializer=new t;async encodeData(Y){let[Z,$]=await this.serializer.dumpsTyped(Y);return $}async decodeData(Y){return await this.serializer.loadsTyped("json",Y)}}class e{queues=new Map;defaultCompressMessages;queueConstructor;constructor(Y,Z={}){this.defaultCompressMessages=Z.defaultCompressMessages??!0,this.queueConstructor=Y}createQueue(Y,Z=300){return this.queues.set(Y,new this.queueConstructor(Y,this.defaultCompressMessages,Z)),this.queues.get(Y)}async getQueue(Y){let Z=this.queues.get(Y);if(!Z)if(await this.queueConstructor?.isQueueExist?.(Y))return this.createQueue(Y);else throw Error(`Queue with id '${Y}' does not exist`);return Z}async cancelQueue(Y){await this.removeQueue(Y)}async pushToQueue(Y,Z){await(await this.getQueue(Y)).push(Z)}async getQueueData(Y){let Z=this.queues.get(Y);if(!Z)throw Error(`Queue with id '${Y}' does not exist`);return await Z.getAll()}async clearQueue(Y){let Z=this.queues.get(Y);if(Z){let $=Z.clear();if($ instanceof Promise)await $}}async removeQueue(Y){let Z=this.queues.get(Y);if(!Z)return!1;try{await Z.cancel()}catch($){console.error("Error cancelling queue:",$)}try{let $=Z.clear();if($ instanceof Promise)await $}catch($){console.error("Error clearing queue:",$)}if(typeof Z.destroy==="function")try{await Z.destroy()}catch($){console.error("Error destroying queue:",$)}return this.queues.delete(Y)}getAllQueueIds(){return Array.from(this.queues.keys())}async getAllQueuesData(){let Y={};for(let[Z,$]of this.queues)Y[Z]=await $.getAll();return Y}clearAllQueues(){for(let Y of this.queues.values())Y.clear()}async copyQueue(Y,Z,$){let H=await(await this.getQueue(Y)).copyToQueue(Z,$);return this.queues.set(Z,H),H}}var E={};async function wY(Y,Z){E[Y]=Z}async function YY(Y,Z,$){if(!E[Y])throw Error(`Graph "${Y}" not found`);let J=typeof E[Y]==="function"?await E[Y](Z??{configurable:{}}):E[Y];if(typeof $?.checkpointer<"u")J.checkpointer=$?.checkpointer??D.globalCheckPointer;else J.checkpointer=D.globalCheckPointer;return J.store=$?.store??void 0,J}class b{db;adapter;constructor(Y){this.db=Y.db,this.adapter=Y}async setup(){await this.adapter.createTables(this.db),await this.adapter.createIndexes(this.db)}async create(Y){let Z=Y?.threadId||N(),$=new Date,J=Y?.metadata||{},H={};if(Y?.ifExists==="raise"){if(await this.db.selectFrom("threads").select("thread_id").where("thread_id","=",Z).executeTakeFirst())throw Error(`Thread with ID ${Z} already exists.`)}if(Y?.ifExists==="do_nothing"&&Y?.threadId){let X=await this.db.selectFrom("threads").selectAll().where("thread_id","=",Z).executeTakeFirst();if(X)return{thread_id:X.thread_id,created_at:this.adapter.dbToDate(X.created_at).toISOString(),updated_at:this.adapter.dbToDate(X.updated_at).toISOString(),state_updated_at:this.adapter.dbToDate(X.updated_at).toISOString(),metadata:this.adapter.dbToJson(X.metadata),status:X.status,values:X.values?this.adapter.dbToJson(X.values):null,interrupts:this.adapter.dbToJson(X.interrupts),title:X.title}}return await this.db.insertInto("threads").values({thread_id:Z,created_at:this.adapter.dateToDb($),updated_at:this.adapter.dateToDb($),metadata:this.adapter.jsonToDb(J),status:"idle",values:null,interrupts:this.adapter.jsonToDb(H)}).execute(),{thread_id:Z,created_at:$.toISOString(),updated_at:$.toISOString(),state_updated_at:$.toISOString(),metadata:J,status:"idle",values:null,interrupts:H,title:null}}async search(Y){let Z=this.db.selectFrom("threads"),$;if(Y?.select)$=new Set(Y.select);else if(Y?.withoutDetails)$=new Set(["thread_id","created_at","updated_at","metadata","status","title"]);else $=new Set(["thread_id","created_at","updated_at","metadata","status","values","interrupts","title"]);let J=[];if($.has("thread_id"))J.push("thread_id");if($.has("created_at"))J.push("created_at");if($.has("updated_at"))J.push("updated_at");if($.has("metadata"))J.push("metadata");if($.has("status"))J.push("status");if($.has("values"))J.push("values");if($.has("interrupts"))J.push("interrupts");if($.has("title"))J.push("title");if(J.length>0)Z=Z.select(J);else Z=Z.selectAll();if(Y?.ids&&Y.ids.length>0)Z=Z.where("thread_id","in",Y.ids);if(Y?.status)Z=Z.where("status","=",Y.status);if(Y?.metadata)for(let[X,U]of Object.entries(Y.metadata))Z=Z.where(this.adapter.buildJsonQuery(this.db,"metadata",X,U));if(Y?.values)Z=Z.where((X)=>{return X("values","=",this.adapter.jsonToDb(Y.values))});if(Y?.sortBy){let X=Y.sortOrder==="desc"?"desc":"asc";Z=Z.orderBy(Y.sortBy,X)}if(Y?.limit!==void 0){if(Z=Z.limit(Y.limit),Y?.offset!==void 0)Z=Z.offset(Y.offset)}return(await Z.execute()).map((X)=>{let U={thread_id:X.thread_id};if($.has("created_at"))U.created_at=this.adapter.dbToDate(X.created_at).toISOString();if($.has("updated_at"))U.updated_at=this.adapter.dbToDate(X.updated_at).toISOString();if($.has("metadata"))U.metadata=this.adapter.dbToJson(X.metadata);if($.has("status"))U.status=X.status;if($.has("values"))U.values=X.values?this.adapter.dbToJson(X.values):null;if($.has("interrupts"))U.interrupts=this.adapter.dbToJson(X.interrupts);if($.has("title"))U.title=X.title;return U})}async get(Y){let Z=await this.db.selectFrom("threads").selectAll().where("thread_id","=",Y).executeTakeFirst();if(!Z)throw Error(`Thread with ID ${Y} not found.`);return{thread_id:Z.thread_id,created_at:this.adapter.dbToDate(Z.created_at).toISOString(),updated_at:this.adapter.dbToDate(Z.updated_at).toISOString(),state_updated_at:this.adapter.dbToDate(Z.updated_at).toISOString(),metadata:this.adapter.dbToJson(Z.metadata),status:Z.status,values:Z.values?this.adapter.dbToJson(Z.values):null,interrupts:this.adapter.dbToJson(Z.interrupts),title:Z.title}}async set(Y,Z){if(!await this.db.selectFrom("threads").select("thread_id").where("thread_id","=",Y).executeTakeFirst())throw Error(`Thread with ID ${Y} not found.`);let J={updated_at:this.adapter.dateToDb(new Date)};if(Z.metadata!==void 0)J.metadata=this.adapter.jsonToDb(Z.metadata);if(Z.status!==void 0)J.status=Z.status;if(Z.values!==void 0)J.values=Z.values?this.adapter.jsonToDb(Z.values):null;if(Z.interrupts!==void 0)J.interrupts=this.adapter.jsonToDb(Z.interrupts);if(Z.title!==void 0)J.title=Z.title;await this.db.updateTable("threads").set(J).where("thread_id","=",Y).execute()}async delete(Y){if((await this.db.deleteFrom("threads").where("thread_id","=",Y).executeTakeFirst()).numDeletedRows===0n)throw Error(`Thread with ID ${Y} not found.`)}async updateState(Y,Z){let $=await this.get(Y);if($.status==="busy")throw Error(`Thread with ID ${Y} is busy, can't update state.`);let J=$.metadata?.graph_id;if(!J)return await this.set(Y,{values:Z.values??null}),{configurable:{thread_id:Y}};let H={configurable:{thread_id:Y,graph_id:J}},X=await YY(J,H),U=await X.updateState(H,Z.values),W=await X.getState(H);return await this.set(Y,{values:JSON.parse(C(W.values))}),U}async createRun(Y,Z,$){let J=N(),H=new Date,X=$?.metadata??{};return await this.db.insertInto("runs").values({run_id:J,thread_id:Y,assistant_id:Z,created_at:this.adapter.dateToDb(H),updated_at:this.adapter.dateToDb(H),status:"pending",metadata:this.adapter.jsonToDb(X),multitask_strategy:"reject"}).execute(),{run_id:J,thread_id:Y,assistant_id:Z,created_at:H.toISOString(),updated_at:H.toISOString(),status:"pending",metadata:X,multitask_strategy:"reject"}}async listRuns(Y,Z){let $=this.db.selectFrom("runs").selectAll().where("thread_id","=",Y).orderBy("created_at","desc");if(Z?.status)$=$.where("status","=",Z.status);if(Z?.limit!==void 0){if($=$.limit(Z.limit),Z?.offset!==void 0)$=$.offset(Z.offset)}return(await $.execute()).map((H)=>({run_id:H.run_id,thread_id:H.thread_id,assistant_id:H.assistant_id,created_at:this.adapter.dbToDate(H.created_at).toISOString(),updated_at:this.adapter.dbToDate(H.updated_at).toISOString(),status:H.status,metadata:this.adapter.dbToJson(H.metadata),multitask_strategy:H.multitask_strategy}))}async updateRun(Y,Z){if(!await this.db.selectFrom("runs").select("run_id").where("run_id","=",Y).executeTakeFirst())throw Error(`Run with ID ${Y} not found.`);let J={updated_at:this.adapter.dateToDb(new Date)};if(Z.status!==void 0)J.status=Z.status;if(Z.metadata!==void 0)J.metadata=this.adapter.jsonToDb(Z.metadata);if(Z.multitask_strategy!==void 0)J.multitask_strategy=Z.multitask_strategy;await this.db.updateTable("runs").set(J).where("run_id","=",Y).execute()}async count(Y){return(await this.search(Y)).length}async patch(Y,Z){let $=await this.db.selectFrom("threads").selectAll().where("thread_id","=",Y).executeTakeFirst();if(!$)throw Error(`Thread with ID ${Y} not found.`);let J={updated_at:this.adapter.dateToDb(new Date)};if(Z.metadata!==void 0){let H=this.adapter.dbToJson($.metadata)||{};J.metadata=this.adapter.jsonToDb({...H,...Z.metadata})}if(Z.status!==void 0)J.status=Z.status;if(Z.values!==void 0)J.values=Z.values?this.adapter.jsonToDb(Z.values):null;if(Z.interrupts!==void 0)J.interrupts=this.adapter.jsonToDb(Z.interrupts);if(Z.title!==void 0)J.title=Z.title;return await this.db.updateTable("threads").set(J).where("thread_id","=",Y).execute(),await this.get(Y)}async getState(Y,Z){let $=await this.get(Y);if(Z?.checkpointId){let H=await this.db.selectFrom("checkpoints").selectAll().where("checkpoint_id","=",Z.checkpointId).where("thread_id","=",Y).executeTakeFirst();if(!H)throw Error(`Checkpoint with ID ${Z.checkpointId} not found for thread ${Y}`);return{values:this.adapter.dbToJson(H.values),next:this.adapter.dbToJson(H.next),metadata:this.adapter.dbToJson(H.metadata),checkpoint:{id:H.checkpoint_id,thread_id:Y,parent_checkpoint_id:null,checkpoint_ns:"",metadata:this.adapter.dbToJson(H.metadata),created_at:this.adapter.dbToDate(H.created_at).toISOString()},created_at:this.adapter.dbToDate(H.created_at).toISOString(),parent_checkpoint:null,tasks:[]}}return{values:$.values||{},next:[],metadata:$.metadata,checkpoint:null,created_at:$.created_at,parent_checkpoint:null,tasks:[]}}async getStateHistory(Y,Z){let J=await this.db.selectFrom("checkpoints").selectAll().where("thread_id","=",Y).orderBy("created_at","asc").execute(),H=J.map((X)=>({values:this.adapter.dbToJson(X.values),next:this.adapter.dbToJson(X.next),metadata:this.adapter.dbToJson(X.metadata),checkpoint:{thread_id:Y,checkpoint_ns:"",checkpoint_id:X.checkpoint_id,checkpoint_map:null},created_at:this.adapter.dbToDate(X.created_at).toISOString(),parent_checkpoint:null,tasks:[]}));if(Z?.before){let X=J.findIndex((U)=>U.checkpoint_id===Z.before);if(X!==-1)H=H.slice(X+1)}if(Z?.limit)H=H.slice(0,Z.limit);return H}async copy(Y){let Z=await this.get(Y),$=N(),J=new Date;await this.db.insertInto("threads").values({thread_id:$,created_at:this.adapter.dateToDb(J),updated_at:this.adapter.dateToDb(J),metadata:this.adapter.jsonToDb(Z.metadata),status:Z.status,values:Z.values?this.adapter.jsonToDb(Z.values):null,interrupts:this.adapter.jsonToDb(Z.interrupts),title:Z.title}).execute();let H=await this.db.selectFrom("checkpoints").selectAll().where("thread_id","=",Y).orderBy("created_at","asc").execute();for(let X of H)await this.db.insertInto("checkpoints").values({checkpoint_id:N(),thread_id:$,values:X.values,next:X.next,config:X.config,created_at:X.created_at,metadata:X.metadata}).execute();return{...Z,thread_id:$,created_at:J.toISOString(),updated_at:J.toISOString()}}async saveCheckpoint(Y,Z,$,J,H){await this.db.insertInto("checkpoints").values({checkpoint_id:N(),thread_id:Y,values:this.adapter.jsonToDb(Z),next:this.adapter.jsonToDb($),config:this.adapter.jsonToDb(J),created_at:this.adapter.dateToDb(new Date),metadata:this.adapter.jsonToDb(H||{})}).execute()}async setTitleIfNull(Y,Z){return(await this.db.updateTable("threads").set({title:Z,updated_at:this.adapter.dateToDb(new Date)}).where("thread_id","=",Y).where("title","is",null).executeTakeFirst()).numUpdatedRows>0n}}function DY(Y){let[Z,$]=Y.split("::");return{threadId:Z,checkpointNs:$??""}}function T(Y,Z,$){return`${Y}::${Z}::${$}`}function m(Y){if(Y===null||typeof Y!=="object")return JSON.stringify(Y);if(Array.isArray(Y))return JSON.stringify(Y.map((J)=>m(J)));let Z={},$=Object.keys(Y).sort();for(let J of $)Z[J]=Y[J];return JSON.stringify(Z,(J,H)=>{if(H!==null&&typeof H==="object"&&!Array.isArray(H)){let X={},U=Object.keys(H).sort();for(let W of U)X[W]=H[W];return X}return H})}class ZY extends s{storage={};writes={};constructor(Y){super(Y)}async get(Y){return(await this.getTuple(Y))?.checkpoint}async _migratePendingSends(Y,Z,$,J){let H=Y,X=T(Z,$,J),U=await Promise.all(Object.values(this.writes[X]??{}).filter(([W,P])=>P===S).map(async([W,P,z])=>await this.serde.loadsTyped("json",z)));H.channel_values??={},H.channel_values[S]=U,H.channel_versions??={},H.channel_versions[S]=Object.keys(H.channel_versions).length>0?n(...Object.values(H.channel_versions)):this.getNextVersion(void 0)}async _loadPendingWrites(Y,Z,$){let J=T(Y,Z,$),H=this.writes[J]??{};if(Object.keys(H).length===0)return[];return await Promise.all(Object.values(H).map(async([X,U,W])=>{return[X,U,await this.serde.loadsTyped("json",W)]}))}_cleanupOldWrites(Y,Z,$){let J=T(Y,Z,$);delete this.writes[J]}_checkMetadataFilterMatch(Y,Z){for(let[$,J]of Object.entries(Z)){let H=Y?.[$];if(J===null){if(!($ in(Y||{}))||H!==null)return!1}else if(typeof J==="object"&&!Array.isArray(J)){if(typeof H!=="object"||H===null)return!1;if(m(J)!==m(H))return!1}else if(H!==J)return!1}return!0}async getTuple(Y){let Z=Y.configurable?.thread_id,$=Y.configurable?.checkpoint_ns??"",J=d(Y);if(Z===void 0)return;let H=this.storage[Z]?.[$];if(H===void 0)return;let{checkpoint:X,metadata:U,checkpoint_id:W,parent_checkpoint_id:P}=H;if(J&&W!==J)return;let z=await this.serde.loadsTyped("json",X);if(z.v<4&&P!==void 0)await this._migratePendingSends(z,Z,$,P);let Q=await this._loadPendingWrites(Z,$,W),K=await this.serde.loadsTyped("json",U),F={config:{configurable:{thread_id:Z,checkpoint_ns:$,checkpoint_id:W}},checkpoint:z,metadata:K,pendingWrites:Q};if(P!==void 0)F.parentConfig={configurable:{thread_id:Z,checkpoint_ns:$,checkpoint_id:P}};return F}async*list(Y,Z){let{before:$,limit:J,filter:H}=Z??{},X=Y.configurable?.thread_id?[Y.configurable.thread_id]:Object.keys(this.storage),U=Y.configurable?.checkpoint_ns,W=Y.configurable?.checkpoint_id,P=[];for(let Q of X){let K=this.storage[Q];if(K===void 0)continue;for(let F of Object.keys(K)){if(U!==void 0&&F!==U)continue;let A=K[F];if(A===void 0)continue;let{checkpoint_id:V}=A;if(W&&V!==W)continue;if($?.configurable?.checkpoint_id&&V>=$.configurable.checkpoint_id)continue;let B=await this.serde.loadsTyped("json",A.metadata);if(H&&!this._checkMetadataFilterMatch(B,H))continue;P.push({threadId:Q,checkpointNs:F,namespaceData:A})}}P.sort((Q,K)=>K.namespaceData.checkpoint_ts-Q.namespaceData.checkpoint_ts);let z=0;for(let{threadId:Q,checkpointNs:K,namespaceData:F}of P){if(J!==void 0&&z>=J)return;let{checkpoint:A,metadata:V,checkpoint_id:B,parent_checkpoint_id:_}=F,O=await this.serde.loadsTyped("json",A);if(O.v<4&&_!==void 0)await this._migratePendingSends(O,Q,K,_);let j=await this._loadPendingWrites(Q,K,B),UY=await this.serde.loadsTyped("json",V),y={config:{configurable:{thread_id:Q,checkpoint_ns:K,checkpoint_id:B}},checkpoint:O,metadata:UY,pendingWrites:j};if(_!==void 0)y.parentConfig={configurable:{thread_id:Q,checkpoint_ns:K,checkpoint_id:_}};z++,yield y}}async put(Y,Z,$,J){let H=i(Z),X=Y.configurable?.thread_id,U=Y.configurable?.checkpoint_ns??"",W=Y.configurable?.checkpoint_id;if(X===void 0)throw Error("thread_id is required");let P=Z.id||u(0);if(!this.storage[X])this.storage[X]={};let z=this.storage[X][U];if(z!==void 0&&z.checkpoint_id!==P)this._cleanupOldWrites(X,U,z.checkpoint_id);let[[,Q],[,K]]=await Promise.all([this.serde.dumpsTyped(H),this.serde.dumpsTyped($)]);return this.storage[X][U]={checkpoint:Q,metadata:K,checkpoint_id:P,parent_checkpoint_id:W,checkpoint_ts:Date.now()},{configurable:{thread_id:X,checkpoint_ns:U,checkpoint_id:P}}}async putWrites(Y,Z,$){let J=Y.configurable?.thread_id,H=Y.configurable?.checkpoint_ns??"",X=Y.configurable?.checkpoint_id;if(!J||!X)throw Error("thread_id and checkpoint_id are required");let U=T(J,H,X),W=this.writes[U];if(this.writes[U]===void 0)this.writes[U]={};await Promise.all(Z.map(async([P,z],Q)=>{let[,K]=await this.serde.dumpsTyped(z),F=[$,o[P]||Q],A=`${F[0]},${F[1]}`;if(F[1]>=0&&W&&A in W)return;this.writes[U][A]=[$,P,K]}))}async deleteThread(Y){delete this.storage[Y];for(let Z of Object.keys(this.writes)){let{threadId:$}=DY(Z.split("::").slice(0,2).join("::"));if($===Y)delete this.writes[Z]}}}class R{event;data;id;constructor(Y,Z){this.event=Y,this.data=Z}}class $Y extends R{constructor(){super("__system_cancel__","user cancel this run")}}class JY extends R{constructor(){super("__stream_end__","stream end")}}class v extends R{constructor(Y){super("__stream_error__",{error:Y.name,message:Y.message})}}class k extends a{data=[];activeGenerators=new Set;isDestroyed=!1;async push(Y){if(this.isDestroyed)return;let Z=this.compressMessages?await this.encodeData(Y):Y;process.env.LG_TEMP_MESSAGE!=="true"&&this.data.push(Z),this.emit("dataChange",Z)}onDataChange(Y){if(this.isDestroyed)return()=>{};return this.on("dataChange",async(Z)=>{if(this.isDestroyed)return;Y(this.compressMessages?await this.decodeData(Z):Z)}),()=>this.off("dataChange",Y)}async*onDataReceive(){if(this.isDestroyed)return;let Y=new AbortController;this.activeGenerators.add(Y);let Z=[],$=null,J=!1,H=!1,X=null,U=async(z)=>{if(H||Y.signal.aborted)return;try{let Q=this.compressMessages?await this.decodeData(z):z;if(Z.push(Q),Q.event==="__stream_end__"||Q.event==="__stream_error__"||Q.event==="__stream_cancel__"){if(X)clearTimeout(X),X=null;if(X=setTimeout(()=>{if(J=!0,$)$(),$=null},300),Q.event==="__stream_cancel__")Y.abort("stream cancelled")}if($)$(),$=null}catch(Q){if(console.error("Error in handleData:",Q),$)$(),$=null}};this.on("dataChange",U);let W=()=>{if(J=!0,$)$(),$=null};Y.signal.addEventListener("abort",W);let P=()=>{if(H)return;if(H=!0,X)clearTimeout(X),X=null;try{this.off("dataChange",U)}catch(z){}try{Y.signal.removeEventListener("abort",W)}catch(z){}if($)$(),$=null;Z.length=0,this.activeGenerators.delete(Y)};try{if(Y.signal.aborted||this.isDestroyed)return;while(!J&&!Y.signal.aborted&&!this.isDestroyed)if(Z.length>0){for(let z of Z)yield z;Z.length=0}else await new Promise((z)=>{$=z})}finally{P()}}async getAll(){if(this.isDestroyed)return[];return this.compressMessages?await Promise.all(this.data.map((Y)=>this.decodeData(Y))):[...this.data]}clear(){this.data.length=0}cancelSignal=new AbortController;async cancel(){for(let Y of this.activeGenerators)try{Y.abort("user cancel this run")}catch(Z){}if(this.activeGenerators.clear(),!this.cancelSignal.signal.aborted)this.cancelSignal.abort("user cancel this run");if(!this.isDestroyed)await this.push(new $Y)}async copyToQueue(Y,Z){let $=this.data.slice(),J=new k(Y,this.compressMessages,Z??this.ttl);return J.data=$,J}async destroy(){if(this.isDestroyed)return;this.isDestroyed=!0,await this.cancel(),this.clear(),this.removeAllListeners(),this.activeGenerators.clear()}}class XY{threads=[];checkpoints=new Map;async setup(){return}async create(Y){let Z=Y?.threadId||N();if(Y?.ifExists==="raise"&&this.threads.some((J)=>J.thread_id===Z))throw Error(`Thread with ID ${Z} already exists.`);let $={thread_id:Z,created_at:new Date().toISOString(),updated_at:new Date().toISOString(),state_updated_at:new Date().toISOString(),metadata:Y?.metadata||{},status:"idle",values:null,interrupts:{},title:null};return this.checkpoints.set(Z,[]),this.threads.push($),$}async search(Y){let Z=[...this.threads];if(Y?.ids&&Y.ids.length>0)Z=Z.filter((X)=>Y.ids.includes(X.thread_id));if(Y?.status)Z=Z.filter((X)=>X.status===Y.status);if(Y?.metadata){for(let X in Y.metadata)if(Object.prototype.hasOwnProperty.call(Y.metadata,X))Z=Z.filter((U)=>U.metadata&&U.metadata[X]===Y.metadata?.[X])}if(Y?.values)Z=Z.filter((X)=>{if(!X.values)return!1;return this.deepEqual(X.values,Y.values)});if(Y?.sortBy)Z.sort((X,U)=>{let W,P;switch(Y.sortBy){case"thread_id":W=X.thread_id,P=U.thread_id;break;case"created_at":W=new Date(X.created_at).getTime(),P=new Date(U.created_at).getTime();break;case"updated_at":W=new Date(X.updated_at).getTime(),P=new Date(U.updated_at).getTime();break;case"status":W=X.status,P=U.status;break;default:return 0}if(Y.sortOrder==="desc")return P>W?1:P<W?-1:0;else return W>P?1:W<P?-1:0});let $=Y?.offset||0,J=Y?.limit||Z.length;return Z.slice($,$+J).map((X)=>{let U={thread_id:X.thread_id},W;if(Y?.select)W=new Set(Y.select);else if(Y?.withoutDetails)W=new Set(["thread_id","created_at","updated_at","metadata","status"]);else W=new Set(["thread_id","created_at","updated_at","metadata","status","values","interrupts","title"]);if(W.has("thread_id"))U.thread_id=X.thread_id;if(W.has("created_at"))U.created_at=X.created_at;if(W.has("updated_at"))U.updated_at=X.updated_at;if(W.has("metadata"))U.metadata=X.metadata;if(W.has("status"))U.status=X.status;if(W.has("values"))U.values=X.values;if(W.has("interrupts"))U.interrupts=X.interrupts;if(W.has("title"))U.title=X.title;return U})}deepEqual(Y,Z){if(Y===Z)return!0;if(typeof Y!==typeof Z)return!1;if(typeof Y!=="object"||Y===null||Z===null)return!1;let $=Object.keys(Y),J=Object.keys(Z);if($.length!==J.length)return!1;for(let H of $){if(!J.includes(H))return!1;if(!this.deepEqual(Y[H],Z[H]))return!1}return!0}async get(Y){let Z=this.threads.find(($)=>$.thread_id===Y);if(!Z)throw Error(`Thread with ID ${Y} not found.`);return Z}async set(Y,Z){let $=this.threads.findIndex((J)=>J.thread_id===Y);if($===-1)throw Error(`Thread with ID ${Y} not found.`);this.threads[$]={...this.threads[$],...Z}}async delete(Y){let Z=this.threads.length;if(this.threads=this.threads.filter(($)=>$.thread_id!==Y),this.checkpoints.delete(Y),this.threads.length===Z)throw Error(`Thread with ID ${Y} not found.`)}async updateState(Y,Z){let $=this.threads.findIndex((H)=>H.thread_id===Y);if($===-1)throw Error(`Thread with ID ${Y} not found.`);let J=this.threads[$];if(J.status==="busy")throw Error(`Thread with ID ${Y} is busy, can't update state.`);if(this.threads[$]={...J,values:Z.values,updated_at:new Date().toISOString()},J.metadata?.graph_id){let H=J.metadata?.graph_id,X={configurable:{thread_id:Y,graph_id:H}};try{let U=await YY(H,X),W=await U.updateState(X,Z.values),P=await U.getState(X);return await this.set(Y,{values:JSON.parse(C(P.values))}),W}catch(U){console.warn("Failed to update graph state:",U)}}return{configurable:{thread_id:Y}}}runs=[];async createRun(Y,Z,$){let H={run_id:N(),thread_id:Y,assistant_id:Z,created_at:new Date().toISOString(),updated_at:new Date().toISOString(),status:"pending",metadata:$?.metadata??{},multitask_strategy:"reject"};return this.runs.push(H),H}async listRuns(Y,Z){let $=[...this.runs];if(Z?.status)$=$.filter((J)=>J.status===Z.status);if(Z?.limit)$=$.slice(Z.offset||0,(Z.offset||0)+Z.limit);return $}async updateRun(Y,Z){let $=this.runs.findIndex((J)=>J.run_id===Y);if($===-1)throw Error(`Run with ID ${Y} not found.`);this.runs[$]={...this.runs[$],...Z}}async count(Y){return(await this.search(Y)).length}async patch(Y,Z){let $=this.threads.findIndex((H)=>H.thread_id===Y);if($===-1)throw Error(`Thread with ID ${Y} not found.`);let J={...this.threads[$],...Z,updated_at:new Date().toISOString(),metadata:Z.metadata?{...this.threads[$].metadata,...Z.metadata}:this.threads[$].metadata};return this.threads[$]=J,J}async getState(Y,Z){let $=await this.get(Y);if(Z?.checkpointId){let X=(this.checkpoints.get(Y)||[]).find((U)=>U.checkpoint_id===Z.checkpointId);if(!X)throw Error(`Checkpoint with ID ${Z.checkpointId} not found for thread ${Y}`);return{values:X.values,next:X.next,metadata:X.metadata,checkpoint:{id:X.checkpoint_id,thread_id:Y,parent_checkpoint_id:null,checkpoint_ns:"",metadata:X.metadata,created_at:X.created_at},created_at:X.created_at,parent_checkpoint:null,tasks:[]}}return{values:$.values||{},next:[],metadata:$.metadata,checkpoint:null,created_at:$.created_at,parent_checkpoint:null,tasks:[]}}async getStateHistory(Y,Z){let $=this.checkpoints.get(Y)||[],J=$.map((H)=>({values:H.values,next:H.next,metadata:H.metadata,checkpoint:{checkpoint_id:H.checkpoint_id,thread_id:Y,checkpoint_ns:"",checkpoint_map:void 0},created_at:H.created_at,parent_checkpoint:null,tasks:[]}));if(Z?.before){let H=$.findIndex((X)=>X.checkpoint_id===Z.before);if(H!==-1)J=J.slice(H+1)}if(Z?.limit)J=J.slice(0,Z.limit);return J}async copy(Y){let Z=await this.get(Y),$=N(),J={...Z,thread_id:$,created_at:new Date().toISOString(),updated_at:new Date().toISOString()};this.threads.push(J);let X=(this.checkpoints.get(Y)||[]).map((U)=>({...U,checkpoint_id:N(),thread_id:$}));return this.checkpoints.set($,X),J}async saveCheckpoint(Y,Z,$,J,H){let X=this.checkpoints.get(Y)||[],U={checkpoint_id:N(),thread_id:Y,values:Z,next:$,config:J,created_at:new Date().toISOString(),metadata:H};X.push(U),this.checkpoints.set(Y,X)}async setTitleIfNull(Y,Z){let $=this.threads.findIndex((J)=>J.thread_id===Y);if($===-1)throw Error(`Thread with ID ${Y} not found.`);if(this.threads[$].title===null)return this.threads[$]={...this.threads[$],title:Z,updated_at:new Date().toISOString()},!0;return!1}}var AY=async()=>{if(process.env.REDIS_URL&&(process.env.CHECKPOINT_TYPE==="redis"||process.env.CHECKPOINT_TYPE==="shallow/redis")){if(process.env.CHECKPOINT_TYPE==="redis"){console.debug("LG | Using redis as checkpoint");let{RedisSaver:Y}=await import("./chunk-wt3p1w1g.js");return await Y.fromUrl(process.env.REDIS_URL,{defaultTTL:60,refreshOnRead:!0})}if(process.env.CHECKPOINT_TYPE==="shallow/redis"){console.debug("LG | Using shallow redis as checkpoint");let{ShallowRedisSaver:Y}=await import("./chunk-f7cps5x1.js");return await Y.fromUrl(process.env.REDIS_URL)}}if(process.env.DATABASE_URL&&HY(process.env.DATABASE_URL)==="postgres"){console.debug("LG | Using postgres as checkpoint");let{createPGCheckpoint:Y}=await import("./chunk-nqh1pptf.js");return Y()}if(process.env.SQLITE_DATABASE_URI){if(process.env.CHECKPOINT_TYPE==="sqlite"){console.debug("LG | Using sqlite (full) as checkpoint");let{SqliteSaver:$}=await import("./chunk-40ht9pe1.js");return await $.fromConnStringAsync(process.env.SQLITE_DATABASE_URI)}console.debug("LG | Using shallow sqlite as checkpoint (default)");let{SqliteShallowSaver:Y}=await import("./chunk-g2zskge5.js");return await Y.fromConnStringAsync(process.env.SQLITE_DATABASE_URI)}return console.log("LG | You are using memory as checkpoint!"),console.log("\x1B[33m%s\x1B[0m","LG | set SQLITE_DATABASE_URI=./.langgraph_api/langgraph.db to your .env file to use \x1B[1mSQLite\x1B[0m for dev!"),console.log("\x1B[33m%s\x1B[0m","LG | set DATABASE_URL=postgresql://user:pass@localhost:5432/db to your .env file to use \x1B[1mPostgreSQL\x1B[0m for prod!"),new ZY},BY=async()=>{let Y;if(process.env.REDIS_URL){console.debug("LG | Using redis as stream queue");let{RedisStreamQueue:Z}=await import("./chunk-g974hxbz.js");Y=Z}else Y=k;return new e(Y)};function HY(Y){let Z=Y.toLowerCase();if(Z.startsWith("http://")||Z.startsWith("https://"))return"remote";return"postgres"}var NY=async(Y)=>{if(process.env.DATABASE_URL){if(HY(process.env.DATABASE_URL)==="remote"){console.debug("LG | Using Remote PostgreSQL ThreadsManager");let{RemoteKyselyThreadsManager:$}=await import("./chunk-tjvhqr94.js"),J=new $(process.env.DATABASE_URL);if(process.env.DATABASE_INIT==="true")await J.setup();return J}else if(Y.checkpointer){console.debug("LG | Using PostgreSQL ThreadsManager");let{PostgresAdapter:$}=await import("./chunk-wmyc17aa.js"),J=Y.checkpointer.pool,H=new b(new $(J));if(process.env.DATABASE_INIT==="true")await H.setup();return H}}if(process.env.SQLITE_DATABASE_URI&&Y.checkpointer){console.debug("LG | Using SQLite ThreadsManager");let{SQLiteAdapter:Z}=await import("./chunk-8f19qk9r.js"),$=Y.checkpointer.db,J=new b(new Z($));return await J.setup(),J}return new XY};function RY(Y){if(typeof Y==="string")return Y;if(Array.isArray(Y))return Y.find(($)=>$.type==="text")?.text||"";if(Y?.text)return Y.text;return""}var LY=(Y,Z)=>{let $=Y?.messages;if(!$||!Array.isArray($)||$.length===0)return null;let J=$[0];if(!J)return null;let H=RY(J.content);if(!H)return null;let X=H.trim().replace(/\n/g," ");if(!X)return null;let U=15,W=X.slice(0,U);return W.length<X.length?`${W}...`:W};class D{static globalMessageQueue=null;static globalCheckPointer=null;static globalThreadsManager=null;static isInitialized=null;static _titleGenerator=LY;static setTitleGenerator(Y){D._titleGenerator=Y}static getTitleGenerator(){return D._titleGenerator}static async initGlobal(){if(D.isInitialized)return D.isInitialized;return D.isInitialized=(async()=>{let[Y,Z]=await Promise.all([BY(),AY()]);console.debug("LG | checkpointer created");let $=await NY({checkpointer:Z});console.debug("LG | threads manager created"),console.debug("LG | global init done"),D.globalMessageQueue=Y,D.globalCheckPointer=Z,D.globalThreadsManager=$})(),D.isInitialized}}async function _Y(Y,Z,$,J,H){let U=J.config?.configurable?.graph_id;if(!U||typeof U!=="string")throw Error("Invalid or missing graph_id");let W=await H.getGraph(U,J.config,{checkpointer:J.temporary?null:void 0}),P=Array.isArray(J.streamMode)?J.streamMode:J.streamMode?[J.streamMode]:[],z=new Set(["values",...P.filter((V)=>V!=="events"&&V!=="messages-tuple")]);if(P.includes("messages-tuple"))z.add("messages");if(P.includes("messages"))z.add("values");await $.push(new R("metadata",{run_id:Z.run_id,attempt:H.attempt,graph_id:U}));let Q={...J.config?.metadata,run_attempt:H.attempt},K=null,F=null,A=null;try{K=new Set,F=new Map,A=await W.stream(J.command!=null?PY(J.command):J.input??null,{interruptAfter:J.interruptAfter,interruptBefore:J.interruptBefore,tags:J.config?.tags,configurable:J.config?.configurable,recursionLimit:J.config?.recursionLimit,subgraphs:J.streamSubgraphs,metadata:Q,runId:Z.run_id,streamMode:[...z],signal:$.cancelSignal.signal});for await(let V of A){let B=[];if(V.length===3)B=V.splice(0,1);let _=(O)=>{if(B.length===0)return O;if(B.length===1&&B[0]?.length===0)return O;return`${O}|${B.join("|")}`};if(V[0]==="values"){let O=V[1];if(_("values")==="values")if(await $.push(new R(_("values"),O)),O?.__interrupt__)await Y.set(Z.thread_id,{status:"interrupted",interrupts:O?JSON.parse(C(O)):""});else await Y.set(Z.thread_id,{values:O?JSON.parse(C(O)):""})}else if(V[0]==="messages"){let O=V[1][0],j=V[1][1];if(O.id&&!K.has(O.id))await $.push(new R("messages/metadata",{[O.id]:j})),K.add(O.id);if(g.isInstance(O)&&O.id){if(F.set(O.id,[...F.get(O.id)??[],O]),await $.push(new R("messages/partial",[F.get(O.id).reduce(p)])),O.content===""&&!O.tool_calls?.length)F.delete(O.id)}else await $.push(new R("messages/partial",[O]))}else if(V[0]==="updates"){let O=V[1];await $.push(new R(_("updates"),O))}}}catch(V){if(!(V instanceof Error&&V.message?.includes("cancel"))){console.error("streamStateWithQueue error:",V);try{await $.push(new v(V))}catch(B){}}throw V}finally{try{await $.push(new JY)}catch(V){}if(K)K.clear(),K=null;if(F)F.clear(),F=null;A=null}}var C=(Y,Z=0)=>{return JSON.stringify(Y,function($,J){let H=this[$];if(H!=null&&typeof H==="object"&&"toDict"in H&&typeof H.toDict==="function"){let{type:X,data:U}=H.toDict();return{...U,type:X}}return J},Z)};async function*MY(Y,Z,$,J){Z=await Z;let{run_id:H,thread_id:X}=Z,U=null,W=null,P=null,z=!1;try{await Y.set(X,{status:"busy"}),await Y.updateRun(Z.run_id,{status:"running"}),W=D.globalMessageQueue.createQueue(H),U=W.onDataReceive(),P=_Y(Y,Z,W,$,J).catch((Q)=>{if(z)return;if(Q.message!=="user cancel this run")console.error("Queue task error:",Q);D.globalMessageQueue.pushToQueue(H,new v(Q))});for await(let Q of U)yield Q;await Y.updateRun(Z.run_id,{status:"success"})}catch(Q){console.error("Stream error:",Q),await Y.updateRun(Z.run_id,{status:"error"}),await Y.set(X,{status:"error"})}finally{if(z=!0,U){try{await U.return(void 0)}catch(K){}U=null}if(W&&!W.cancelSignal.signal.aborted)try{W.cancelSignal.abort("Stream consumer disconnected")}catch(K){}if(P){try{await Promise.race([P,new Promise((K)=>setTimeout(K,1000))])}catch(K){}P=null}if((await Y.get(X)).status==="interrupted")await D.globalMessageQueue.copyQueue(H,X,30000);else await Y.set(X,{status:"idle",interrupts:{}});await D.globalMessageQueue.removeQueue(H),W=null}}
|
|
2
|
-
export{a as n,E as o,wY as p,YY as q,$Y as r,D as s,C as t,MY as u};
|
package/dist/chunk-57bj89e2.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{hf as a}from"./chunk-vfxjbdz4.js";import"./chunk-y8qhrx11.js";export{a as FileSystemPluginStore};
|
package/dist/chunk-5a5mepqj.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as M}from"./chunk-h8fdexm4.js";import"./chunk-4wnmk2tj.js";import{Ae as G,De as Z,Je as Y,Le as _,Ne as $,we as T}from"./chunk-c7kd2qrp.js";import{Qe as L}from"./chunk-a9gpb2tx.js";import{Te as w}from"./chunk-dvbb3dd1.js";import"./chunk-vrnj0659.js";import"./chunk-a9tw6d68.js";import"./chunk-k4q8j7pg.js";import"./chunk-spx7nn8t.js";import"./chunk-vfxjbdz4.js";import"./chunk-qxebn3jw.js";import"./chunk-yy8p9zph.js";import"./chunk-mnnyjmgw.js";import"./chunk-fzh0v6r0.js";import"./chunk-t6440ajd.js";import"./chunk-f0m4532p.js";import"./chunk-pe8mzxwn.js";import"./chunk-hp2jzn9x.js";import"./chunk-nk62q95g.js";import"./chunk-nmzx5nmt.js";import"./chunk-e8kxa5vj.js";import"./chunk-q1cxrg0x.js";import"./chunk-tjg2e8v3.js";import"./chunk-nsw5168d.js";import"./chunk-hve2a279.js";import{Dl as K}from"./chunk-y8qhrx11.js";var z=K(T(),1);var y=K(Y(),1),h=({onClose:H})=>{let{config:U,updateConfig:N}=M(),B=U?.switch_command||"default",O=z.useCallback(async()=>{let q=await L(w);return Object.values(q)},[]),Q=z.useCallback((q,F,J)=>{let P=q.id===B;return y.jsxDEV(_,{isSelected:J,isCurrent:P,children:[y.jsxDEV(G,{bold:!0,children:[F+1,". ",q.id]},void 0,!0,void 0,this),y.jsxDEV(Z,{},void 0,!1,void 0,this),y.jsxDEV(G,{dimColor:!0,children:q.description},void 0,!1,void 0,this)]},`agent-${q.id}`,!0,void 0,this)},[B]),R=z.useCallback((q)=>{return q.id===B},[B]),W=z.useCallback(async(q)=>{let F=q.id==="default"?"":q.id;N({switch_command:F}),H()},[N,H]),X=z.useCallback((q)=>{let F=q.find((J)=>J.id===B);return F?y.jsxDEV(G,{color:"gray",dimColor:!0,children:["当前 Agent: ",y.jsxDEV(G,{color:"green",children:F.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this):null},[B]),v=z.useMemo(()=>({id:"agent",title:"Agent 选择",icon:"\uD83E\uDD16",dataSource:O,searchable:!0,searchFields:["id","name","description"],searchPlaceholder:"搜索 agent (名称/描述)...",filterable:!0,filters:[{id:"default",label:"默认",predicate:(q)=>q.id==="default"},{id:"custom",label:"自定义",predicate:(q)=>q.id!=="default"}],defaultFilter:"all",itemHeight:3,visibleCount:15,renderItem:Q,isSelected:R,onSelect:W,showCount:!0,statusInfo:X}),[O,Q,R,W,X]);return y.jsxDEV($,{config:v,onClose:H},void 0,!1,void 0,this)},m=h;export{m as default};
|
package/dist/chunk-7kw7ss8d.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{$f as F,Af as e,Bf as f,Cf as g,Df as h,Ef as i,Ff as j,Gf as k,Hf as l,If as m,Jf as n,Kf as o,Lf as p,Mf as q,Nf as r,Of as s,Pf as t,Qf as u,Rf as v,Sf as w,Tf as x,Uf as y,Vf as z,Wf as A,Xf as B,Yf as C,Zf as D,_f as E,ag as G,bg as H,cg as I,dg as J,wf as a,xf as b,yf as c,zf as d}from"./chunk-mnnyjmgw.js";import"./chunk-fzh0v6r0.js";import"./chunk-t6440ajd.js";import"./chunk-f0m4532p.js";import"./chunk-pe8mzxwn.js";import"./chunk-hp2jzn9x.js";import"./chunk-nk62q95g.js";import"./chunk-nmzx5nmt.js";import"./chunk-e8kxa5vj.js";import"./chunk-q1cxrg0x.js";import"./chunk-tjg2e8v3.js";import"./chunk-nsw5168d.js";import"./chunk-hve2a279.js";import"./chunk-y8qhrx11.js";export{r as toStandardTool,u as listSkills,w as listMemories,J as humanInTheLoopMiddleware,H as getAgentListFromPackage,q as fromLangChainTool,F as create_task_tool,G as createTaskTool,A as createMCPMiddleware,s as anthropicPromptCachingMiddleware,E as TaskSchema,I as SubAgentsMiddleware,C as SubAgentStateSchema,B as SubAgentSchema,D as SubAgentAnnotation,j as StandardAgent,v as SkillsMiddleware,a as ProviderTypeSchema,d as PromptVersionSchema,c as PromptSchema,b as ModelSchema,f as MiddlewareSchema,i as MiddlewareRegistry,e as MiddlewareCustomParamsSchema,p as MemoryStorage,z as MCPMiddleware,x as LoadMcpToolsSchema,y as ExecuteMcpToolSchema,o as BaseStorage,t as AgentsMdMiddleware,l as AgentValidator,m as AgentSerializer,g as AgentSchema,k as AgentRepository,h as AgentPackageSchema,n as AgentPackage};
|
package/dist/chunk-86m0rmtc.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{ff as a}from"./chunk-k4q8j7pg.js";import"./chunk-y8qhrx11.js";export{a as FileSystemConfigStore};
|
package/dist/chunk-9rayxazs.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import{Ae as E,Je as t,we as c0,ze as j}from"./chunk-c7kd2qrp.js";import{df as B}from"./chunk-vrnj0659.js";import{Dl as h,Fl as T,Il as M}from"./chunk-y8qhrx11.js";var b=T((IA,X0)=>{var n0=M("child_process").spawn;function p0(A,G,X,L){if(typeof X==="function")L=X,X=void 0;let J=!1,H=n0(A,G,X),K="",Y="";H.stdout.on("data",function($){K+=$.toString()}),H.stderr.on("data",function($){Y+=$.toString()}),H.on("error",function($){if(J)return;J=!0,L(Error($))}),H.on("close",function($,Q){if(J)return;if(J=!0,Y)return L(Error(Y));L(null,K,$)})}X0.exports=p0});var k=T((EA,L0)=>{var y={},w={},g={},n=0,R=null;function a0(A,G){if(G<=0)return;if(w[A]!==void 0)y[A]=Date.now()+(G||60000);return w[A]}function i0(A,G,X,L){if(G===void 0||X<=0)return;if(y[A]=Date.now()+(X||60000),w[A]===void 0)n++,G0(X);if(w[A]=G,L)g[A]=L}function G0(A){if(n>0){if(R===null){if(R=setInterval(d0,(A||60000)/2),typeof R.unref==="function")R.unref()}return}if(R!==null)clearInterval(R),R=null}function d0(){let A=Date.now(),G=Object.keys(y);for(let X=0;X<G.length;X++){let L=G[X];if(y[L]<A){if(n--,g[L])g[L](w[L]);delete w[L],delete y[L],delete g[L]}}G0()}function c(A){for(let G in A)delete A[G]}function o0(){if(R!==null)clearInterval(R),R=null;c(w),c(y),c(g)}L0.exports={get:a0,set:i0,clear:o0}});var W0=T((SA,Q0)=>{var K0=M("os"),r0=b(),H0=k(),f=K0.platform();function J0(A,G){let X=0,L=A.split(/-|:|\./),J=L.length-1;if(J>=0&&G&&f==="darwin")X+=parseInt(L[J--],10)*10;if(J>=0)X+=parseInt(L[J--],10)*1000;if(J>=0)X+=parseInt(L[J--],10)*60000;if(J>=0)X+=parseInt(L[J--],10)*3600000;if(J>=0)X+=parseInt(L[J--],10)*86400000;return X}function s0(A,G,X){let L=A.join(","),J=["-o","etime,pid,ppid,pcpu,rss,time","-p",L];if(f==="aix"||f==="os400")J=["-o","etime,pid,ppid,pcpu,rssize,time","-p",L];r0("ps",J,function(H,K,Y){if(H){if(f==="os390"&&/no matching processes found/.test(H))H=Error("No matching pid found"),H.code="ENOENT";return X(H)}if(Y===1){let U=Error("No matching pid found");return U.code="ENOENT",X(U)}if(Y!==0)return X(Error("pidusage ps command exited with code "+Y));let $=Date.now();K=K.split(K0.EOL);let Q={};for(let U=1;U<K.length;U++){let q=K[U].trim().split(/\s+/);if(!q||q.length!==6)continue;let W=parseInt(q[1],10),N=H0.get(W,G.maxage);if(N===void 0)N={};let Z=parseInt(q[2],10),v=parseInt(q[4],10)*1024,_=J0(q[0]),C=J0(q[5],!0),D=C-(N.ctime||0),V=Math.abs(N.elapsed!==void 0?_-N.elapsed:_),P=V>0?D/V*100:0;Q[W]={cpu:P,memory:v,ppid:Z,pid:W,ctime:C,elapsed:_,timestamp:$},H0.set(W,Q[W],G.maxage)}X(null,Q)})}Q0.exports=s0});var p=T((jA,Y0)=>{function t0(A,G,X){if(typeof G==="function")X=G,G={};let L;if(!Array.isArray(A))L=Object.keys(A);let J=L?L.length:A.length,H=J,K=L?{}:[];function Y($,Q,U){if(K[$]=U,--H===0||Q&&!G.graceful){if(G.graceful&&Q&&J>1)Q=null;X&&X(Q,K),X=null}}if(L)L.forEach(function($){A[$](function(Q,U){Y($,Q,U)})});else A.forEach(function($,Q){$(function(U,q){Y(Q,U,q)})})}Y0.exports=t0});var Z0=T((wA,N0)=>{var e0=M("os"),AA=M("fs"),XA=M("child_process").exec,q0=p();function GA(A,G){if(A!==null){$0(function(X,L){if(X)return G(X);A.uptime=L,G(null,A)});return}q0([LA,$0],function(X,L){if(X)return G(X);A={clockTick:L[0].clockTick,pageSize:L[0].pageSize,uptime:L[1]},G(null,A)})}N0.exports=GA;function $0(A){AA.readFile("/proc/uptime","utf8",function(G,X){if(G||X===void 0){if(!process.env.PIDUSAGE_SILENT)console.warn("[pidusage] We couldn't find uptime from /proc/uptime, using os.uptime() value");return A(null,e0.uptime()||new Date/1000)}return A(null,parseFloat(X.split(" ")[0]))})}function LA(A){q0([function(X){U0("CLK_TCK",{default:100},X)},function(X){U0("PAGESIZE",{default:4096},X)}],function(G,X){if(G)return A(G);A(null,{clockTick:X[0],pageSize:X[1]})})}function U0(A,G,X){if(typeof G==="function")X=G,G={default:""};XA("getconf "+A,function(L,J,H){if(L!==null){if(!process.env.PIDUSAGE_SILENT)console.error('Error while calling "getconf '+A+'"',L);return X(null,G.default)}if(J=parseInt(J),!isNaN(J))return X(null,J);return X(null,G.default)})}});var M0=T((a,v0)=>{/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */var l=M("buffer"),O=l.Buffer;function F0(A,G){for(var X in A)G[X]=A[X]}if(O.from&&O.alloc&&O.allocUnsafe&&O.allocUnsafeSlow)v0.exports=l;else F0(l,a),a.Buffer=z;function z(A,G,X){return O(A,G,X)}z.prototype=Object.create(O.prototype);F0(O,z);z.from=function(A,G,X){if(typeof A==="number")throw TypeError("Argument must not be a number");return O(A,G,X)};z.alloc=function(A,G,X){if(typeof A!=="number")throw TypeError("Argument must be a number");var L=O(A);if(G!==void 0)if(typeof X==="string")L.fill(G,X);else L.fill(G);else L.fill(0);return L};z.allocUnsafe=function(A){if(typeof A!=="number")throw TypeError("Argument must be a number");return O(A)};z.allocUnsafeSlow=function(A){if(typeof A!=="number")throw TypeError("Argument must be a number");return l.SlowBuffer(A)}});var R0=T((zA,T0)=>{var d=M("fs"),HA=M("path"),JA=Z0(),KA=p(),_0=k(),I=null,C0=M0().Buffer,i=1024;function QA(){}function WA(A,G,X){if(G.fd)return X(null,G.fd);d.open(A,"r",X)}function YA(A){if(A.fd)d.close(A.fd,QA)}function D0(A,G,X){let L=!1;if(typeof G==="function")X=G,G=C0.alloc(i),L=!0;d.read(A,G,0,i,0,function(J,H,K){if(J){X(J);return}let Y=C0.concat([G,K],L?H:G.length+H);if(H===i){D0(A,Y,X);return}X(null,G)})}function P0(A,G,X){let L=_0.get(A,G.maxage),J=!1;if(L===void 0)J=!0,L={};WA(HA.join("/proc",""+A,"stat"),L,function(H,K){if(H){if(H.code==="ENOENT")H.message="No matching pid found";return X(H,null)}if(H)return X(H);D0(K,function(Y,$){if(Y)return X(Y);let Q=$.toString("utf8"),U=Date.now(),q=Q.lastIndexOf(")");Q=Q.substr(q+2).split(" ");let W={ppid:parseInt(Q[1]),utime:parseFloat(Q[11])*1000/I.clockTick,stime:parseFloat(Q[12])*1000/I.clockTick,cutime:parseFloat(Q[13])*1000/I.clockTick,cstime:parseFloat(Q[14])*1000/I.clockTick,start:parseFloat(Q[19])*1000/I.clockTick,rss:parseFloat(Q[21]),uptime:I.uptime*1000,fd:K},N=W.rss*I.pageSize,Z=G.childrens?W.cutime+W.cstime:0,v=W.stime-(L.stime||0)+W.utime-(L.utime||0)+Z,_=Math.abs(L.uptime!==void 0?W.uptime-L.uptime:W.start-W.uptime),C=_>0?v/_*100:0;if(_0.set(A,W,G.maxage,YA),J)return P0(A,G,X);return X(null,{cpu:C,memory:N,ctime:W.utime+W.stime,elapsed:W.uptime-W.start,timestamp:U,pid:A,ppid:W.ppid})})})}function $A(A,G,X){JA(I,function(L,J){if(L)return X(L);I=J;let H={};A.forEach(function(K,Y){H[K]=function($){P0(K,G,$)}}),KA(H,{graceful:!0},X)})}T0.exports=$A});var S0=T((BA,E0)=>{var O0=M("os"),UA=b(),V0=k();function qA(A){let G=A.substring(0,4),X=A.substring(4,6),L=A.substring(6,8),J=A.substring(8,10),H=A.substring(10,12),K=A.substring(12,14),Y=A.substring(15,21),$=A.substring(21,22),Q=parseInt(A.substring(22,25),10),U=Math.floor(Q/60),q=Q%60;return new Date(G+"-"+X+"-"+L+"T"+J+":"+H+":"+K+"."+Y+$+(U>9?U:"0"+U)+(q>9?q:"0"+q))}function I0(A,G,X){let L="ProcessId="+A[0];for(let H=1;H<A.length;H++)L+=" or ProcessId="+A[H];let J=["PROCESS","where",'"'+L+'"',"get","CreationDate,KernelModeTime,ParentProcessId,ProcessId,UserModeTime,WorkingSetSize"];UA("wmic",J,{windowsHide:!0,windowsVerbatimArguments:!0},function(H,K,Y){if(H){if(H.message.indexOf("No Instance(s) Available.")!==-1){let W=Error("No matching pid found");return W.code="ENOENT",X(W)}return X(H)}if(Y!==0)return X(Error("pidusage wmic command exited with code "+Y));let $=Date.now(),Q=Math.floor(O0.uptime()||$/1000);K=K.split(O0.EOL);let U=!1,q={};for(let W=1;W<K.length;W++){let N=K[W].trim().split(/\s+/);if(!N||N.length!==6)continue;let Z=qA(N[0]),v=parseInt(N[2],10),_=parseInt(N[3],10),C=Math.round(parseInt(N[1],10)/1e4),D=Math.round(parseInt(N[4],10)/1e4),V=parseInt(N[5],10),P=V0.get(_,G.maxage);if(P===void 0)U=!0,P={ctime:C+D,uptime:Q};let m=(C+D-P.ctime)/1000,S=Q-P.uptime,u=S>0?m/S*100:0;V0.set(_,{ctime:D+C,uptime:Q},G.maxage),q[_]={cpu:u,memory:V,ppid:v,pid:_,ctime:D+C,elapsed:$-Z.getTime(),timestamp:$}}if(U)return I0(A,G,function(W,N){if(W)return X(W);X(null,Object.assign(q,N))});X(null,q)})}E0.exports=I0});var y0=T((yA,B0)=>{var j0=M("os"),NA=b(),w0=k();function ZA(A){let G=A.substring(0,4),X=A.substring(4,6),L=A.substring(6,8),J=A.substring(8,10),H=A.substring(10,12),K=A.substring(12,14),Y=A.substring(15,21),$=A.substring(21,22),Q=parseInt(A.substring(22,25),10),U=Math.floor(Q/60),q=Q%60;return new Date(G+"-"+X+"-"+L+"T"+J+":"+H+":"+K+"."+Y+$+(U>9?U:"0"+U)+(q>9?q:"0"+q))}function z0(A,G,X){let L="ProcessId="+A[0];for(let K=1;K<A.length;K++)L+=" or ProcessId="+A[K];let J="CreationDate,KernelModeTime,ParentProcessId,ProcessId,UserModeTime,WorkingSetSize",H=["win32_process","-Filter","'"+L+"'","| select "+J,"| format-table"];NA("gwmi",H,{windowsHide:!0,windowsVerbatimArguments:!0,shell:"powershell.exe"},function(K,Y,$){if(K){if(K.message.indexOf("No Instance(s) Available.")!==-1){let Z=Error("No matching pid found");return Z.code="ENOENT",X(Z)}return X(K)}if($!==0)return X(Error("pidusage gwmi command exited with code "+$));let Q=Date.now(),U=Math.floor(j0.uptime()||Q/1000);Y=Y.split(j0.EOL).slice(1);let q=Y.findIndex((Z)=>!!Z);if(Y=Y.slice(q+2),!Y.length){let Z=Error("No matching pid found");return Z.code="ENOENT",X(Z)}let W=!1,N={};for(let Z=0;Z<Y.length;Z++){let v=Y[Z].trim().split(/\s+/);if(!v||v.length===1)continue;let _=ZA(v[0]),C=parseInt(v[2],10),D=parseInt(v[3],10),V=Math.round(parseInt(v[1],10)/1e4),P=Math.round(parseInt(v[4],10)/1e4),m=parseInt(v[5],10),S=w0.get(D,G.maxage);if(S===void 0)W=!0,S={ctime:V+P,uptime:U};let u=(V+P-S.ctime)/1000,s=U-S.uptime,u0=s>0?u/s*100:0;w0.set(D,{ctime:P+V,uptime:U},G.maxage),N[D]={cpu:u0,memory:m,ppid:C,pid:D,ctime:P+V,elapsed:Q-_.getTime(),timestamp:Q}}if(W)return z0(A,G,function(Z,v){if(Z)return X(Z);X(null,Object.assign(N,v))});X(null,N)})}B0.exports=z0});var h0=T((kA,g0)=>{var FA=M("fs"),k0=M("os"),vA=M("child_process").spawn,o={ps:()=>W0(),procfile:()=>R0(),wmic:()=>S0(),gwmi:()=>y0()},MA={aix:"ps",os400:"ps",android:"procfile",alpine:"procfile",darwin:"ps",freebsd:"ps",os390:"ps",linux:"procfile",netbsd:"procfile",openbsd:"ps",sunos:"ps",win:"wmic"},x=k0.platform();if(FA.existsSync("/etc/alpine-release"))x="alpine";if(x.match(/^win/))x="win";var x0;try{x0=o[MA[x]]()}catch(A){}function _A(A,G,X){let L=x0;if(x!=="win"&&G.usePs===!0)L=o.ps();if(x==="win"){let H;try{H=vA("wmic",function(K){if(K)throw Error(K)})}catch(K){L=o.gwmi()}finally{if(H)H.kill()}}if(L===void 0)return X(Error(k0.platform()+" is not supported yet, please open an issue (https://github.com/soyuka/pidusage)"));let J=!1;if(!Array.isArray(A))J=!0,A=[A];if(A.length===0)return X(TypeError("You must provide at least one pid"));for(let H=0;H<A.length;H++)if(A[H]=parseInt(A[H],10),isNaN(A[H])||A[H]<0)return X(TypeError("One of the pids provided is invalid"));L(A,G,function(H,K){if(H)return X(H);if(J)X(null,K[A[0]]);else X(null,K)})}g0.exports=_A});var f0=T((xA,r)=>{var b0=h0();function CA(A,G,X){if(typeof G==="function")X=G,G={};if(G===void 0)G={};if(G=Object.assign({usePs:/^true$/i.test(process.env.PIDUSAGE_USE_PS),maxage:process.env.PIDUSAGE_MAXAGE},G),typeof X==="function"){b0(A,G,X);return}return new Promise(function(L,J){b0(A,G,function(H,K){if(H)return J(H);L(K)})})}r.exports=CA;r.exports.clear=k().clear});var e=h(c0(),1);var F=h(t(),1);class A0 extends e.Component{state={hasError:!1,error:null,errorInfo:null};static getDerivedStateFromError(A){return{hasError:!0,error:A}}componentDidCatch(A,G){let{name:X="ErrorBoundary"}=this.props;console.error(`
|
|
2
|
-
========================================`),console.error(`[${X}] React Error Caught`),console.error("========================================"),console.error("Error:",A.message),console.error("Stack:",A.stack),console.error("Component Stack:",G.componentStack),console.error(`========================================
|
|
3
|
-
`),import("./chunk-5c3bpcpm.js").then(({logAgentError:L})=>{L(X,A)}).catch((L)=>{console.warn("Failed to log React error:",L)}),this.setState({errorInfo:G})}render(){let{hasError:A,error:G,errorInfo:X}=this.state,{name:L="ErrorBoundary",fallback:J,children:H}=this.props;if(A){if(J)return F.jsxDEV(F.Fragment,{children:J},void 0,!1,void 0,this);return F.jsxDEV(j,{flexDirection:"column",padding:1,borderStyle:"double",borderColor:"red",children:[F.jsxDEV(j,{marginBottom:1,children:F.jsxDEV(E,{color:"red",bold:!0,children:["✗ [",L,"] Render Error"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),F.jsxDEV(j,{marginBottom:1,children:F.jsxDEV(E,{color:"red",children:["Message: ",G?.message||"Unknown error"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),G?.stack&&F.jsxDEV(j,{flexDirection:"column",marginBottom:1,children:[F.jsxDEV(E,{color:"yellow",bold:!0,children:"Stack Trace:"},void 0,!1,void 0,this),F.jsxDEV(E,{color:"gray",children:G.stack.split(`
|
|
4
|
-
`).slice(0,5).join(`
|
|
5
|
-
`)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),X?.componentStack&&F.jsxDEV(j,{flexDirection:"column",children:[F.jsxDEV(E,{color:"yellow",bold:!0,children:"Component Stack:"},void 0,!1,void 0,this),F.jsxDEV(E,{color:"gray",dimColor:!0,children:X.componentStack.split(`
|
|
6
|
-
`).slice(0,5).join(`
|
|
7
|
-
`)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F.jsxDEV(j,{marginTop:1,children:F.jsxDEV(E,{color:"blue",dimColor:!0,children:"Press Ctrl+C to exit"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}return F.jsxDEV(F.Fragment,{children:H},void 0,!1,void 0,this)}}var VA=A0;var l0=h(f0(),1);var DA=5000;class m0{constructor(){this.startGC()}startGC(){setInterval(()=>{for(let[G]of B)try{process.kill(G,0)}catch(X){if(X.code==="ESRCH")B.delete(G)}},DA).unref()}async getProcessList(){let A=[];for(let[G,X]of B)try{let L=await l0.default(G);A.push({pid:G,command:X.command,startTime:X.startTime,duration:Date.now()-X.startTime,cpu:L.cpu,memory:L.memory,status:this.checkStatus(X)})}catch{A.push({pid:G,command:X.command,startTime:X.startTime,duration:Date.now()-X.startTime,cpu:0,memory:0,status:"stopped"})}return A}killProcess(A){let G=B.get(A);if(!G)return!1;return G.process.kill("SIGTERM"),B.delete(A),!0}getProcessOutput(A){let G=B.get(A);if(!G)return null;return{stdout:G.stdout.join(""),stderr:G.stderr.join("")}}checkStatus(A){try{return process.kill(A.process.pid,0),"running"}catch{return"stopped"}}}var hA=new m0;
|
|
8
|
-
export{VA as l,hA as m};
|
package/dist/chunk-a9gpb2tx.js
DELETED
package/dist/chunk-a9tw6d68.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{tl as G}from"./chunk-tjg2e8v3.js";var W=G.enum(["idea","bug_report","feature","refactor"]),K=G.enum(["low","medium","high","critical"]),F=G.enum(["pending","planned","archived"]),_=G.enum(["user_input","ai_suggestion","conversation_derived"]),H=G.object({id:G.string().uuid(),type:W,title:G.string().min(1).max(200),description:G.string(),priority:K.default("medium"),source:_,status:F.default("pending"),createdAt:G.string().datetime(),tags:G.array(G.string()).default([]),metadata:G.object({relatedFiles:G.array(G.string()).optional(),conversationContext:G.string().optional(),estimatedComplexity:G.enum(["simple","medium","complex"]).optional()}).optional()}),c=G.object({version:G.literal("1.0"),sparks:G.array(H),lastUpdated:G.string().datetime()}),$=G.enum(["pickup","running","complete","error","review","feedback"]),O=G.enum(["default","planner","reviewer","refactor","finder","debugger","architect"]),M=G.enum(["serial","parallel"]),N=G.lazy(()=>G.object({id:G.string(),title:G.string().min(1).max(200),description:G.string(),execution:M.optional(),children:G.array(G.lazy(()=>N)).optional(),agentType:O.optional(),threadId:G.string().optional(),estimatedTime:G.string().optional(),complexity:G.enum(["simple","medium","complex"]).optional(),dependencies:G.array(G.string()).optional(),acceptanceCriteria:G.array(G.string()).optional(),status:$.optional(),startedAt:G.string().datetime().optional(),completedAt:G.string().datetime().optional(),assignedTo:O.optional(),error:G.object({message:G.string(),stack:G.string().optional(),retryCount:G.number().optional()}).optional()})),L=G.object({taskId:G.string(),planId:G.string(),threadId:G.string(),agentType:O,status:$,startedAt:G.string().datetime(),completedAt:G.string().datetime().optional(),output:G.string().optional(),error:G.string().optional(),changedFiles:G.array(G.string()).optional()}),m=G.object({version:G.literal("1.0"),lastUpdated:G.string().datetime(),activePlanId:G.string().optional(),tasks:G.record(G.string(),N),history:G.array(L),config:G.object({maxConcurrentAgents:G.number().min(1).max(10).default(3),retryLimit:G.number().min(0).max(10).default(3),autoResume:G.boolean().default(!1)})});
|