zen-code 4.9.2 → 4.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app.js +94 -128
- package/dist/chunk-075hks9v.js +1 -0
- package/dist/chunk-0fj768k4.js +112 -0
- package/dist/chunk-19mf2aa7.js +1 -0
- package/dist/chunk-1mq2jmfy.js +2 -0
- package/dist/chunk-1v863afn.js +278 -0
- package/dist/chunk-1vn8d8b8.js +1 -0
- package/dist/{chunk-hfypkhky.js → chunk-1w19w1bm.js} +1 -1
- package/dist/chunk-3dnayvgx.js +224 -0
- package/dist/chunk-4hg13vwj.js +1 -0
- package/dist/chunk-4scrkcqv.js +1 -0
- package/dist/chunk-54cdhhqm.js +1 -0
- package/dist/chunk-5m4yb9av.js +91 -0
- package/dist/chunk-5yd4ntp6.js +8 -0
- package/dist/{chunk-dxec2q4t.js → chunk-6scjjkn3.js} +1 -1
- package/dist/{chunk-hmemx3cw.js → chunk-7jatn15w.js} +2 -2
- package/dist/{chunk-0pss3s5r.js → chunk-7w9y11hj.js} +1 -1
- package/dist/chunk-7yzv6385.js +1 -0
- package/dist/{chunk-ce53j63y.js → chunk-875hayaj.js} +3 -3
- package/dist/chunk-8bs8r50r.js +1 -0
- package/dist/{chunk-x552nspp.js → chunk-8waww0j9.js} +2 -2
- package/dist/chunk-8ysg0rga.js +1 -0
- package/dist/chunk-9czhw5k6.js +4 -0
- package/dist/chunk-9tgp14v7.js +16 -0
- package/dist/{chunk-yndex7hs.js → chunk-a239dn0b.js} +1 -1
- package/dist/chunk-arv4h3h1.js +2 -0
- package/dist/chunk-b2551zfb.js +2 -0
- package/dist/chunk-b9emn03n.js +1 -0
- package/dist/chunk-bm7578sn.js +1 -0
- package/dist/{chunk-62zh99t6.js → chunk-bytq4kd1.js} +3 -125
- package/dist/chunk-c2wfgbj6.js +1 -0
- package/dist/{chunk-0zk0m93z.js → chunk-cef4vbtb.js} +1 -1
- package/dist/{chunk-hsev32dg.js → chunk-cnzhxgn5.js} +2 -2
- package/dist/chunk-d2770b2z.js +1 -0
- package/dist/chunk-d72063sm.js +2 -0
- package/dist/{chunk-6nfpdtn6.js → chunk-d988tv30.js} +1 -1
- package/dist/{chunk-55nx49pj.js → chunk-dx9k6sdd.js} +3 -3
- package/dist/chunk-e6ggkg36.js +2 -0
- package/dist/{chunk-x90r4sje.js → chunk-fjqtrakn.js} +1 -1
- package/dist/chunk-gbfpab0j.js +1 -0
- package/dist/chunk-gkvx829z.js +1 -0
- package/dist/{chunk-94jawhw7.js → chunk-gwf8b14k.js} +1 -1
- package/dist/chunk-gz7fz9fg.js +1 -0
- package/dist/{chunk-48vkm1yn.js → chunk-h0q3dvnv.js} +2 -2
- package/dist/chunk-h0qb9jk1.js +1 -0
- package/dist/chunk-h9y136h8.js +1 -0
- package/dist/chunk-hrcxdj3c.js +54 -0
- package/dist/chunk-hz9yw7cs.js +166 -0
- package/dist/{chunk-98wjxsna.js → chunk-j4y5rjne.js} +1 -1
- package/dist/chunk-k12y05c3.js +3 -0
- package/dist/{chunk-fkrydbn4.js → chunk-k6fxqssr.js} +3 -3
- package/dist/{chunk-vfwbx331.js → chunk-kmxdq21k.js} +2 -2
- package/dist/chunk-mcb8rewr.js +213 -0
- package/dist/{chunk-9k64296h.js → chunk-mm9w91rj.js} +1 -1
- package/dist/chunk-mv0xzmq8.js +2 -0
- package/dist/{chunk-rztre6k0.js → chunk-n849zsd3.js} +1 -1
- package/dist/chunk-nm253hhf.js +81 -0
- package/dist/{chunk-gyhxdxb4.js → chunk-prg6489q.js} +1 -1
- package/dist/{chunk-pwrscdkf.js → chunk-pxdgy0vr.js} +1 -1
- package/dist/{chunk-frhhpxxy.js → chunk-qhzm2qw9.js} +2 -2
- package/dist/{chunk-8f2zh5h6.js → chunk-qmxtys9q.js} +2 -2
- package/dist/chunk-r0cfe5c1.js +294 -0
- package/dist/chunk-rtjytfhh.js +1 -0
- package/dist/chunk-s7ttf0pm.js +2 -0
- package/dist/{chunk-k38fjqj7.js → chunk-t01t72t2.js} +2 -2
- package/dist/{chunk-fw3nrwpf.js → chunk-t0f66x64.js} +1 -1
- package/dist/chunk-tn356gwf.js +93 -0
- package/dist/chunk-vd8kwzra.js +41 -0
- package/dist/chunk-vhn13anh.js +233 -0
- package/dist/chunk-vnewbtjy.js +1 -0
- package/dist/{chunk-hfegb4pr.js → chunk-wbm7rn9w.js} +2 -2
- package/dist/chunk-wd3gkd45.js +3 -0
- package/dist/chunk-whdf0vbb.js +1 -0
- package/dist/{chunk-r019959h.js → chunk-ws232ksq.js} +2 -2
- package/dist/{chunk-rt5mpgbg.js → chunk-yerf10k7.js} +2 -2
- package/dist/{chunk-pndhbee8.js → chunk-yzv3n8mw.js} +2 -2
- package/dist/chunk-z3e4c424.js +2 -0
- package/dist/{chunk-jb4yt88g.js → chunk-znw7fpep.js} +2 -2
- package/dist/chunk-zq2g4rfd.js +1 -0
- package/dist/cli.js +1 -1
- package/dist/nonInteractive.js +314 -4
- package/dist/zen-keyboard.js +1 -1
- package/package.json +37 -37
- package/dist/chunk-0sxrk9sx.js +0 -1
- package/dist/chunk-178yjjsx.js +0 -1
- package/dist/chunk-1p9xzvpt.js +0 -3
- package/dist/chunk-2eh0sv3s.js +0 -2
- package/dist/chunk-43xrz4wp.js +0 -2
- package/dist/chunk-48ce2wt0.js +0 -1
- package/dist/chunk-578m1dhj.js +0 -2
- package/dist/chunk-5dsevrtz.js +0 -91
- package/dist/chunk-66890qd3.js +0 -2
- package/dist/chunk-738m8242.js +0 -53
- package/dist/chunk-8ty2zfve.js +0 -3
- package/dist/chunk-9b7nj74j.js +0 -1
- package/dist/chunk-9x562s6p.js +0 -1
- package/dist/chunk-a90fm6gz.js +0 -278
- package/dist/chunk-ac5t2ywn.js +0 -100
- package/dist/chunk-ad2hbq42.js +0 -1
- package/dist/chunk-afhxxkmv.js +0 -16
- package/dist/chunk-b4vvgbav.js +0 -1
- package/dist/chunk-b9pcntkv.js +0 -253
- package/dist/chunk-c7y5efa0.js +0 -1
- package/dist/chunk-cbjnwrt7.js +0 -2
- package/dist/chunk-dcs1r9as.js +0 -2
- package/dist/chunk-dcwnpdtk.js +0 -9
- package/dist/chunk-e3tyc24s.js +0 -310
- package/dist/chunk-e8hp8d68.js +0 -81
- package/dist/chunk-h1enhch1.js +0 -2
- package/dist/chunk-hcnx1j2z.js +0 -1
- package/dist/chunk-hra0748z.js +0 -2
- package/dist/chunk-hyf24r36.js +0 -2
- package/dist/chunk-jjcmm167.js +0 -1
- package/dist/chunk-jrepjpft.js +0 -2
- package/dist/chunk-kym9tb01.js +0 -1
- package/dist/chunk-mt1g6g89.js +0 -1
- package/dist/chunk-p0vzbr7s.js +0 -585
- package/dist/chunk-r10bn684.js +0 -1
- package/dist/chunk-r3pe49q4.js +0 -8
- package/dist/chunk-r4tq44hr.js +0 -1
- package/dist/chunk-rjrnaka2.js +0 -1
- package/dist/chunk-s77qbhtz.js +0 -3
- package/dist/chunk-t7rwtc17.js +0 -1
- package/dist/chunk-v8g52kan.js +0 -1
- package/dist/chunk-vd6c87cm.js +0 -2
- package/dist/chunk-vh9zd1v3.js +0 -5
- package/dist/chunk-w2hbsa9j.js +0 -86
- package/dist/chunk-wabmqprd.js +0 -184
- package/dist/chunk-wpy5r9ma.js +0 -40
- package/dist/chunk-yqwxbcc7.js +0 -31
- package/dist/chunk-z8n7y37k.js +0 -1
- package/dist/chunk-zr7sx9hd.js +0 -1
- package/dist/chunk-zxqmghzf.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{M as A,O as q,R as c}from"./chunk-kmxdq21k.js";import{Le as w,ye as R}from"./chunk-1v863afn.js";import{Fl as K}from"./chunk-z3e4c424.js";function ZP(G){return G?.replace(process.cwd(),".")||G||""}var v=K(R(),1);var r=()=>{return process.env.TERM?.includes("256color")||process.env.TERM==="xterm-256color"||process.env.WT_SESSION!==void 0||process.platform==="darwin"||process.env.TERM_PROGRAM==="vscode"||process.env.TERM_PROGRAM==="iTerm.app"};var m={success:{hex:"#4fd6be",fallback:"green"},warning:{hex:"#ffdb95",fallback:"yellow"},error:{hex:"#f7768e",fallback:"red"},info:{hex:"#7dcfff",fallback:"cyan"},muted:{hex:"#565f89",fallback:"gray"},highlight:{hex:"#7dcfff",fallback:"cyanBright"},accent:{hex:"#bb9af7",fallback:"magentaBright"},border:{hex:"#414868",fallback:"gray"},primary:{hex:"#7aa2f7",fallback:"cyan"},secondary:{hex:"#bb9af7",fallback:"magenta"},keyword:{hex:"#bb9af7",fallback:"magenta"},function:{hex:"#7aa2f7",fallback:"blue"},string:{hex:"#9ece6a",fallback:"green"},number:{hex:"#ff9e64",fallback:"yellow"},comment:{hex:"#565f89",fallback:"gray"},variable:{hex:"#c0caf5",fallback:"white"},type:{hex:"#0db9d7",fallback:"cyan"},constant:{hex:"#e0af68",fallback:"yellow"},textPrimary:{hex:"#c0caf5",fallback:"white"},textSecondary:{hex:"#9aa5ce",fallback:"whiteBright"},textMuted:{hex:"#565f89",fallback:"gray"},bg:{hex:"#1a1b26",fallback:"black"},bgCard:{hex:"#24283b",fallback:"black"},indigo:{hex:"#6366f1",fallback:"blue"},purple:{hex:"#a855f7",fallback:"magenta"},pink:{hex:"#ec4899",fallback:"redBright"},rose:{hex:"#f43f5e",fallback:"red"},orange:{hex:"#f97316",fallback:"yellowBright"},amber:{hex:"#f59e0b",fallback:"yellow"},emerald:{hex:"#10b981",fallback:"green"},teal:{hex:"#14b8a6",fallback:"cyan"},sky:{hex:"#0ea5e9",fallback:"blue"}},VP=(G)=>{if(!(G in m))G="sky";return r()?m[G].hex:m[G].fallback};import o from"os";function BP(){try{return o.userInfo().username}catch(G){return process.env.USER||process.env.USERNAME||"User"}}var $=K(R(),1);var p=K(w(),1),n=50,a=1800000,t=300000,e=$.createContext(null);var CP=({children:G})=>{let[X,J]=$.useState([]),[Q,D]=$.useState(null),y=$.useCallback(async(Z)=>{let z=Z.tool;if(!z)return;let{status:W,editedArgs:F}=Z;if(W==="approved")z.sendResumeData({type:"approve"});else if(W==="edited"){let H={name:z.message.name,args:F};z.sendResumeData({type:"edit",edited_action:H})}else if(W==="rejected")z.sendResumeData({type:"reject",message:"User rejected to run this tool"});else console.error("[ChatWrapper] Unknown approval status:",W)},[]),V=$.useCallback(()=>{return`approval_${Date.now()}_${Math.random().toString(36).substring(2,9)}`},[]),j=$.useCallback((Z)=>{let z={...Z,id:V(),status:"pending",createdAt:new Date};return J((W)=>{let F=[...W,z];if(F.length>n){let H=F.filter((P)=>P.status!=="pending");if(H.length>0)return F.filter((P)=>P.id!==H[0].id)}if(W.length===0)D(z.id);return F}),z.id},[V]),N=$.useCallback((Z,z)=>{J((W)=>W.map((F)=>F.id===Z?{...F,...z}:F))},[]),S=$.useCallback((Z)=>{J((z)=>{let W=z.filter((F)=>F.id!==Z);if(Q===Z)D(W.length>0?W[0].id:null);return W})},[Q]),_=$.useCallback(()=>{J((Z)=>{let z=Z.filter((W)=>W.status==="pending");if(z.length===0)D(null);else if(Q&&!z.find((W)=>W.id===Q))D(z[0].id);return z})},[Q]),L=$.useCallback(async()=>{let Z=X.filter((z)=>z.status==="approved"||z.status==="edited"||z.status==="rejected");if(Z.length===0)return;for(let z of Z)try{await y(z)}catch(W){console.error(`[ApprovalContext] Execute approval request failed: ${z.id}`,W)}_()},[X,y,_]),h=$.useCallback(async(Z)=>{await y(Z)},[y]),B=$.useMemo(()=>X.some((Z)=>Z.status==="pending"),[X]),x=$.useMemo(()=>X.length>0&&!B,[X.length,B]),f=$.useCallback(()=>{let Z=Date.now();J((z)=>z.filter((W)=>W.createdAt.getTime()>Z-a))},[]);A(()=>{f()},t),q(()=>{J((Z)=>Z.map((z)=>({...z,tool:void 0})))}),$.useEffect(()=>{if(x)L()},[x,L]);let M=$.useMemo(()=>({requests:X,addApprovalRequest:j,updateApprovalRequest:N,removeApprovalRequest:S,clearCompletedApprovals:_,executeRequest:h,executeApproved:L,hasPendingRequests:B,allRequestsProcessed:x}),[X,j,N,S,_,h,L,B,x]);return p.jsxDEV(e.Provider,{value:M,children:G},void 0,!1,void 0,this)};var O=K(R(),1);var d=K(w(),1),PP=1800000,HP=300000,g=O.createContext(null),lP=({children:G})=>{let[X,J]=O.useState(""),Q=O.useRef(Date.now()),D=O.useCallback(()=>{J("")},[]),y=O.useCallback((j)=>{Q.current=Date.now(),J(j)},[]);A(()=>{if(Date.now()-Q.current>PP)D()},HP);let V={bufferedMessage:X,setBufferedMessage:y,clearBuffer:D};return d.jsxDEV(g.Provider,{value:V,children:G},void 0,!1,void 0,this)},iP=()=>{let G=O.useContext(g);if(!G)throw Error("useChatInputBuffer must be used within ChatInputBufferProvider");return G};var T=K(R(),1);var zP=K(w(),1),sP=T.createContext(void 0);var Y=K(R(),1);var l=K(w(),1),JP=100,WP=1800000,YP=300000,u=Y.createContext(null),zH=()=>{let G=Y.useContext(u);if(!G)throw Error("useInteractionContext must be used within InteractionProvider");return G},JH=({children:G,onInteractionSubmit:X})=>{let[J,Q]=Y.useState([]),[D,y]=Y.useState(0),V=Y.useCallback(()=>{return`interaction_${Date.now()}_${Math.random().toString(36).substring(2,9)}`},[]),j=Y.useCallback((H,P)=>{let U=new Date,E={id:V(),category:"panel",state:"idle",metadata:{title:P?.metadata?.title,description:P?.metadata?.description,icon:P?.metadata?.icon,priority:P?.metadata?.priority??"medium",groupKey:P?.metadata?.groupKey,messageIndex:P?.metadata?.messageIndex},tool:P?.tool,config:{layout:{border:!0,padding:1,...P?.config?.layout},interaction:{autoSubmit:!1,allowSkip:!1,showPreview:!0,...P?.config?.interaction},style:P?.config?.style??{}},content:H,createdAt:U,updatedAt:U};return Q((I)=>{let k=[...I,E];if(k.length>JP){let C=k.filter((b)=>b.state==="submitted"||b.state==="edited"||b.state==="cancelled");if(C.length>0){let b=C[0].id;return k.filter((i)=>i.id!==b)}}return k}),y((I)=>I+1),E},[V]),N=Y.useCallback((H,P)=>{Q((U)=>U.map((E)=>E.id===H?{...E,...P,updatedAt:new Date}:E)),y((U)=>U+1)},[]),S=Y.useCallback((H)=>{Q((P)=>P.filter((U)=>U.id!==H)),y((P)=>P+1)},[]),_=Y.useCallback(()=>{Q([]),y((H)=>H+1)},[]),L=Y.useCallback((H)=>{return J.find((P)=>P.id===H)},[J]),h=Y.useCallback(()=>{return[...J]},[J]),B=Y.useCallback((H)=>{return J.filter((P)=>P.state===H)},[J]),x=Y.useCallback((H)=>{return J.filter((P)=>P.content.type===H)},[J]),f=Y.useCallback(async()=>{let H=J.filter((P)=>P.state==="submitted"||P.state==="edited"||P.state==="cancelled");for(let P of H)if(!P.resultSent&&X)await X(P),N(P.id,{resultSent:!0})},[J,X,N]),M=Y.useCallback(()=>{Q((H)=>H.filter((P)=>P.state==="idle"||P.state==="active")),y((H)=>H+1)},[]),Z=Y.useCallback(()=>{let H=Date.now();Q((P)=>P.filter((U)=>U.updatedAt.getTime()>H-WP))},[]);A(()=>{Z()},YP),q(()=>{Q((H)=>H.map((P)=>({...P,tool:void 0})))});let z=Y.useMemo(()=>J.some((H)=>H.state==="idle"||H.state==="active"),[J]),W=Y.useMemo(()=>J.length>0&&J.every((H)=>H.state==="submitted"||H.state==="edited"||H.state==="cancelled"),[J]);c(()=>{M()},W&&z===!1?100:null),Y.useEffect(()=>{if(W&&z===!1)f()},[W,z,f]);let F=Y.useMemo(()=>({addInteraction:j,updateInteraction:N,removeInteraction:S,clearAll:_,getInteraction:L,getInteractions:h,getInteractionsByState:B,getInteractionsByContent:x,submitInteractions:f,clearCompleted:M,interactions:J,updateCount:D,hasPendingInteractions:z,allInteractionsProcessed:W}),[j,N,S,_,L,h,B,x,f,M,J,D,z,W]);return l.jsxDEV(u.Provider,{value:F,children:G},void 0,!1,void 0,this)};export{ZP as D,VP as E,BP as F,CP as G,lP as H,iP as I,zH as J,JH as K};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{h as d,i as e}from"./chunk-ws232ksq.js";import{j as u}from"./chunk-d72063sm.js";import{R as o}from"./chunk-kmxdq21k.js";import"./chunk-dx9k6sdd.js";import{Be as N,Ce as J,Fe as c,Ke as x,Le as f,Me as s,Ne as i,Pe as t,ye as l}from"./chunk-1v863afn.js";import"./chunk-d2770b2z.js";import"./chunk-mv0xzmq8.js";import"./chunk-znw7fpep.js";import"./chunk-pxdgy0vr.js";import"./chunk-k6fxqssr.js";import"./chunk-t01t72t2.js";import"./chunk-b2551zfb.js";import"./chunk-vd8kwzra.js";import{Fl as S}from"./chunk-z3e4c424.js";var zq=S(l(),1);var U=S(l(),1);var H=S(f(),1),a={openai:"\uD83E\uDD16",anthropic:"\uD83E\uDDE0",gemini:"✨",default:"\uD83D\uDD2E"};var Jq=({defaultValue:O,onSubmit:F,onSwitchProvider:X})=>{let[_,W]=U.useState(O),B=U.useCallback((G)=>{if(!G.trim())return;F(G.trim())},[F]),R=U.useCallback((G,K)=>{if(K.tab)return X?.(K.shift?"left":"right"),!1;if(K.leftArrow)return X?.("left"),!1;if(K.rightArrow)return X?.("right"),!1;return!0},[X]);return H.jsxDEV(N,{paddingX:2,paddingY:1,flexDirection:"column",gap:1,children:[H.jsxDEV(J,{color:"gray",children:"请输入模型名称(Enter 确认):"},void 0,!1,void 0,this),H.jsxDEV(s,{value:_,onChange:W,onSubmit:B,onHotKey:R,maxVisibleLines:1,placeholder:"例如:gpt-4o"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},Qq=({onClose:O})=>{let{extraParams:F,config:X,updateConfig:_}=u(),[W,B]=U.useState(""),R=U.useRef([]),G=U.useMemo(()=>{if(!X?.providers||X.providers.length===0)return[];return X.providers.map((q)=>{let $=q.type||"default";return{id:q.id,label:q.id,icon:a[$]||a.default,config:q}})},[X?.providers]);U.useMemo(()=>{if(G.length>0&&!W){let q=G.find(($)=>$.id===F.provider_id);B(q?.id||G[0].id)}},[G,F.provider_id,W]);let K=G.find((q)=>q.id===W),{data:V,isLoading:y,error:v}=d({provider:K?.config||null,enabled:!!W}),b=U.useMemo(()=>{let q=(V||[]).map(($)=>({id:$.id,name:$.name}));return R.current=q,q},[V]),D=U.useCallback(async()=>{return R.current},[]),j=U.useCallback((q,$,C)=>{let M=q.id===F.provider_id+"-"+q.id;return H.jsxDEV(i,{isSelected:C,isCurrent:M,children:[H.jsxDEV(J,{bold:!0,children:[$+1,". ",q.id]},void 0,!0,void 0,this),H.jsxDEV(J,{dimColor:!0,children:[" ",q.name!==q.id?`(${q.name})`:""]},void 0,!0,void 0,this)]},`model-${$}-${q.id}`,!0,void 0,this)},[F.provider_id]),P=U.useCallback((q)=>{return q.id===F.provider_id+"-"+q.id},[F.provider_id]),g=U.useCallback(async(q)=>{await _({model_id:q}),O()},[_,O]),E=U.useCallback(async(q)=>{let C=G.find((M)=>M.id===W)?.config.type||"openai";await _({provider_id:W,provider_type:C,model_id:q.id}),O()},[_,W,O,G]),k=U.useCallback(async(q)=>{if(G.length<=1)return;let $=G.findIndex((p)=>p.id===W),C=q==="left"?($-1+G.length)%G.length:($+1)%G.length,M=G[C];B(M.id),await _({provider_id:M.id,provider_type:M.config.type})},[W,G,_]),m=U.useMemo(()=>{let q=K?.label||"加载中...";return{id:`model-${W}`,title:`模型选择 - ${q}`,icon:K?.icon||"\uD83D\uDD2E",dataSource:D,searchable:!0,searchFields:["id","name"],searchPlaceholder:"搜索模型...",itemHeight:1,visibleCount:10,renderItem:j,isSelected:P,onSelect:E,showCount:!0,keyMap:{leftArrow:($)=>{k("left")},rightArrow:($)=>{k("right")}}}},[W,K,D,j,P,E,k]);if(G.length===0)return H.jsxDEV(N,{flexDirection:"column",paddingX:2,paddingY:1,children:[H.jsxDEV(J,{color:"yellow",children:"⚠️ 未配置任何 Provider"},void 0,!1,void 0,this),H.jsxDEV(J,{color:"gray",dimColor:!0,children:"请先配置 Provider 后再查看模型列表"},void 0,!1,void 0,this)]},void 0,!0,void 0,this);let T=K?.config.apiKey;return H.jsxDEV(N,{flexDirection:"column",children:[H.jsxDEV(N,{gap:1,paddingX:1,paddingY:1,children:G.map((q,$)=>H.jsxDEV(J,{bold:q.id===W,color:q.id===W?"cyan":"gray",children:[q.icon," ",q.label,q.id===W&&" [当前]",q.id===W&&!T&&" (未配置 API Key)"]},`provider-tab-${$}-${q.id}`,!0,void 0,this))},void 0,!1,void 0,this),y?H.jsxDEV(N,{paddingX:2,paddingY:1,children:H.jsxDEV(J,{color:"gray",children:"加载模型列表中..."},void 0,!1,void 0,this)},void 0,!1,void 0,this):v||b.length===0?H.jsxDEV(Jq,{defaultValue:X?.model_id||"",onSubmit:g,onSwitchProvider:k},void 0,!1,void 0,this):!T?H.jsxDEV(N,{paddingX:2,paddingY:1,children:H.jsxDEV(J,{color:"yellow",children:"请先配置 API Key"},void 0,!1,void 0,this)},void 0,!1,void 0,this):H.jsxDEV(t,{config:m,onClose:O},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},r=Qq;var z=S(l(),1);var Z=S(f(),1),Wq=({onClose:O})=>{let{config:F,updateConfig:X}=u(),[_,W]=z.useState("list"),[B,R]=z.useState(null),[G,K]=z.useState(0),[V,y]=z.useState(null),v=z.useCallback(()=>y(null),[]);o(v,V?3000:null);let b=z.useRef(_),D=z.useRef(G),j=z.useRef([]),P=z.useRef(!0);z.useEffect(()=>{b.current=_},[_]),z.useEffect(()=>{D.current=G},[G]);let g=F?.providers||[];z.useEffect(()=>{j.current=g},[g]);let E=z.useCallback(()=>{P.current=!0,R(null),W("form"),y(null)},[]),k=z.useCallback(()=>{let Q=j.current,Y=D.current,L=Q[Y];if(!L)return;P.current=!1,R(L),W("form"),y(null)},[]),m=z.useCallback(()=>{W("list"),R(null),y(null)},[]),T=z.useCallback(async(Q)=>{let Y=j.current,L=P.current,A=L?[...Y,Q]:Y.map((w)=>w.id===Q.id?Q:w);if(await X({providers:A}),y(L?`已添加 Provider: ${Q.id}`:`已更新 Provider: ${Q.id}`),L){let w=A.findIndex((I)=>I.id===Q.id);K(w>=0?w:0)}W("list"),R(null),y(null)},[X]),q=z.useCallback(async()=>{let Q=j.current,Y=D.current,L=Q[Y];if(!L)return;if(Q.length<=1){y("无法删除最后一个 Provider");return}let A=Q.filter((I)=>I.id!==L.id);await X({providers:A});let w=Math.min(Y,A.length-1);K(w>=0?w:0),y(`已删除 Provider: ${L.id}`)},[X]),$=z.useRef(E),C=z.useRef(k),M=z.useRef(q),p=z.useRef(m),n=z.useRef(O);z.useEffect(()=>{$.current=E},[E]),z.useEffect(()=>{C.current=k},[k]),z.useEffect(()=>{M.current=q},[q]),z.useEffect(()=>{p.current=m},[m]),z.useEffect(()=>{n.current=O},[O]),x((Q,Y)=>{let L=b.current,A=j.current,w=D.current;if(L==="form"){if(Y.escape)p.current();return}if(Y.upArrow)K((I)=>I>0?I-1:A.length-1);else if(Y.downArrow)K((I)=>I<A.length-1?I+1:0);else if(Q==="n"||Q==="N")$.current();else if((Q==="e"||Q==="E"||Y.return)&&A[w])C.current();else if((Q==="d"||Q==="D")&&A[w])M.current();else if(Y.escape)n.current()},{isActive:!0});let Gq=z.useMemo(()=>{if(g.length===0)return Z.jsxDEV(N,{paddingX:2,paddingY:1,children:Z.jsxDEV(J,{color:"yellow",children:"未配置任何 Provider"},void 0,!1,void 0,this)},void 0,!1,void 0,this);return Z.jsxDEV(N,{flexDirection:"column",paddingX:2,gap:1,children:[g.map((Q,Y)=>{let L=!!Q.apiKey,A=L?"green":"yellow";return Z.jsxDEV(N,{marginBottom:0,gap:1,children:[Z.jsxDEV(J,{color:Y===G?"cyan":"gray",bold:Y===G,children:Y===G?">":" "},void 0,!1,void 0,this),Z.jsxDEV(J,{bold:Y===G,color:Y===G?"cyan":void 0,children:Q.id},void 0,!1,void 0,this),Z.jsxDEV(c,{},void 0,!1,void 0,this),Z.jsxDEV(J,{color:"gray",dimColor:Y!==G,children:[" ",Q.type]},void 0,!0,void 0,this),Z.jsxDEV(J,{color:A,dimColor:Y!==G,children:[" ","[",L?"已配置":"未配置","]"]},void 0,!0,void 0,this)]},`provider-${Y}-${Q.id}`,!0,void 0,this)}),Z.jsxDEV(N,{marginTop:1,children:Z.jsxDEV(J,{color:"gray",dimColor:!0,children:[Z.jsxDEV(J,{color:"cyan",children:"↑↓"},void 0,!1,void 0,this)," 导航 ",Z.jsxDEV(J,{color:"cyan",children:"n"},void 0,!1,void 0,this)," 新增 ",Z.jsxDEV(J,{color:"cyan",children:"d"},void 0,!1,void 0,this)," ","删除 ",Z.jsxDEV(J,{color:"cyan",children:"Esc"},void 0,!1,void 0,this)," 关闭"]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},[g,G]);return Z.jsxDEV(N,{flexDirection:"column",children:[Z.jsxDEV(N,{paddingX:2,paddingY:1,children:Z.jsxDEV(J,{bold:!0,color:"cyan",children:"Providers"},void 0,!1,void 0,this)},void 0,!1,void 0,this),_==="list"?Gq:Z.jsxDEV(e,{provider:B||void 0,onCancel:m,onSave:T},void 0,!1,void 0,this),V&&Z.jsxDEV(N,{paddingX:2,paddingY:0,children:Z.jsxDEV(J,{color:"green",children:V},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},qq=Wq;var h=S(f(),1),Xq=({onClose:O,initialTab:F="model"})=>{let[X,_]=zq.useState(F);return x((W,B)=>{if(B.leftArrow&&B.alt)_("model");else if(B.rightArrow&&B.alt)_("provider");else if(B.escape)O()},{isActive:!0}),h.jsxDEV(N,{flexDirection:"column",width:"100%",borderStyle:"single",borderDimColor:!0,children:[h.jsxDEV(N,{flexDirection:"column",paddingX:0,paddingY:0,children:[X==="model"&&h.jsxDEV(r,{onClose:O},void 0,!1,void 0,this),X==="provider"&&h.jsxDEV(qq,{onClose:O},void 0,!1,void 0,this)]},void 0,!0,void 0,this),h.jsxDEV(N,{flexDirection:"row",gap:2,paddingX:2,paddingY:1,borderTop:!0,borderBottom:!1,borderLeft:!1,borderRight:!1,borderStyle:"single",borderColor:"gray",children:[h.jsxDEV(J,{bold:X==="model",color:X==="model"?"cyan":"gray",children:"\uD83E\uDD16 Model"},void 0,!1,void 0,this),h.jsxDEV(J,{bold:X==="provider",color:X==="provider"?"cyan":"gray",children:"\uD83D\uDD0C Provider"},void 0,!1,void 0,this),h.jsxDEV(c,{},void 0,!1,void 0,this),h.jsxDEV(J,{dimColor:!0,children:"Alt+ < >"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},jq=Xq;export{jq as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as M}from"./chunk-d72063sm.js";import"./chunk-dx9k6sdd.js";import{Ce as G,Fe as Z,Le as Y,Ne as _,Pe as $,ye as T}from"./chunk-1v863afn.js";import{Se as L}from"./chunk-1w19w1bm.js";import{Ve as w}from"./chunk-vhn13anh.js";import"./chunk-mcb8rewr.js";import"./chunk-d2770b2z.js";import"./chunk-mv0xzmq8.js";import"./chunk-znw7fpep.js";import"./chunk-pxdgy0vr.js";import"./chunk-k6fxqssr.js";import"./chunk-1mq2jmfy.js";import"./chunk-3dnayvgx.js";import"./chunk-8waww0j9.js";import"./chunk-h0q3dvnv.js";import"./chunk-hrcxdj3c.js";import"./chunk-9tgp14v7.js";import"./chunk-hz9yw7cs.js";import"./chunk-tn356gwf.js";import"./chunk-n849zsd3.js";import"./chunk-t01t72t2.js";import"./chunk-b2551zfb.js";import"./chunk-vd8kwzra.js";import"./chunk-qhzm2qw9.js";import"./chunk-arv4h3h1.js";import{Fl as K}from"./chunk-z3e4c424.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};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import{Gd as D,xd as L}from"./chunk-cnzhxgn5.js";import{Hg as z,Zg as P,_g as K,ah as O}from"./chunk-hz9yw7cs.js";import"./chunk-tn356gwf.js";import"./chunk-n849zsd3.js";import"./chunk-vd8kwzra.js";import"./chunk-arv4h3h1.js";import{Fl as R,Kl as b}from"./chunk-z3e4c424.js";var G={maxRetries:3,baseDelayMs:100,nonRetryablePatterns:["database disk image is malformed","database is malformed","cannot rollback","no transaction is active","database or disk is full"],isRetryableError:(J)=>{let $=J?.message?.toLowerCase()||"";for(let Z of G.nonRetryablePatterns)if($.includes(Z.toLowerCase()))return!1;return $.includes("sqlite_busy")||$.includes("database is locked")||$==="sqlite_busy"||$==="database is locked"}};async function F(J,$){let Z=null;for(let H=0;H<G.maxRetries;H++)try{return await J()}catch(U){Z=U;let j=U?.message?.toLowerCase()||"";if(!G.isRetryableError(U)){if(j.includes("malformed")){let V=Error(`SQLite database is corrupted: ${U.message}
|
|
2
|
+
|
|
3
|
+
Context: ${$||"unknown"}
|
|
4
|
+
|
|
5
|
+
Possible causes:
|
|
6
|
+
1. Database file was manually deleted or modified
|
|
7
|
+
2. Disk I/O errors during write operations
|
|
8
|
+
3. Concurrent access without proper locking
|
|
9
|
+
|
|
10
|
+
Recovery options:
|
|
11
|
+
- Delete the database file to start fresh (data will be lost)
|
|
12
|
+
- Use SQLite recovery tools: sqlite3 <db> ".recover" > recover.sql
|
|
13
|
+
- Switch to PostgreSQL/Redis for production use`);throw V.name="SQLiteCorruptError",V.cause=U,V}throw U}if(H<G.maxRetries-1){let V=G.baseDelayMs*Math.pow(2,H);console.warn(`SQLite lock detected${$?` (${$})`:""}, retrying in ${V}ms (attempt ${H+1}/${G.maxRetries})`),await new Promise((X)=>setTimeout(X,V))}}throw Z}var x=["source","step","parents"];function E(J){return J}var T=E(x);class N extends K{db;isSetup;constructor(J,$){super($);this.db=new L({dialect:J}),this.isSetup=!1}static async fromConnStringAsync(J){let $;if(globalThis.Bun&&!process.env.DISABLE_BUN_SQLITE){console.log("LG | Using BunWorkerDialect "+J);let{BunSqliteDialect:Z}=await import("./chunk-prg6489q.js");$=new N(new Z({url:J}))}else{console.log("LG | Using NodeWasmDialect");let{default:Z}=await import("./chunk-fjqtrakn.js").then((m)=>R(m.default,1)),{NodeWasmDialect:H}=await import("./chunk-a239dn0b.js");console.log(J);let U=new H({database:new Z.Database(J)});$=new N(U)}return await $.setup(),$}async setup(){if(this.isSetup)return;await D`PRAGMA busy_timeout = 5000`.execute(this.db),await D`PRAGMA journal_mode = WAL`.execute(this.db),await D`PRAGMA synchronous = NORMAL`.execute(this.db),await D`PRAGMA wal_autocheckpoint = 1000`.execute(this.db),await D`
|
|
14
|
+
CREATE TABLE IF NOT EXISTS checkpoints (
|
|
15
|
+
thread_id TEXT NOT NULL,
|
|
16
|
+
checkpoint_ns TEXT NOT NULL DEFAULT '',
|
|
17
|
+
checkpoint_id TEXT NOT NULL,
|
|
18
|
+
parent_checkpoint_id TEXT,
|
|
19
|
+
type TEXT,
|
|
20
|
+
checkpoint BLOB,
|
|
21
|
+
metadata BLOB,
|
|
22
|
+
PRIMARY KEY (thread_id, checkpoint_ns, checkpoint_id)
|
|
23
|
+
)`.execute(this.db),await D`
|
|
24
|
+
CREATE TABLE IF NOT EXISTS writes (
|
|
25
|
+
thread_id TEXT NOT NULL,
|
|
26
|
+
checkpoint_ns TEXT NOT NULL DEFAULT '',
|
|
27
|
+
checkpoint_id TEXT NOT NULL,
|
|
28
|
+
task_id TEXT NOT NULL,
|
|
29
|
+
idx INTEGER NOT NULL,
|
|
30
|
+
channel TEXT NOT NULL,
|
|
31
|
+
type TEXT,
|
|
32
|
+
value BLOB,
|
|
33
|
+
PRIMARY KEY (thread_id, checkpoint_ns, checkpoint_id, task_id, idx)
|
|
34
|
+
)`.execute(this.db),this.isSetup=!0}async getTuple(J){await this.setup();let{thread_id:$,checkpoint_ns:Z="",checkpoint_id:H}=J.configurable??{},U=this.db.selectFrom("checkpoints").select(["thread_id","checkpoint_ns","checkpoint_id","parent_checkpoint_id","type","checkpoint","metadata",D`(
|
|
35
|
+
SELECT json_group_array(
|
|
36
|
+
json_object(
|
|
37
|
+
'task_id', pw.task_id,
|
|
38
|
+
'channel', pw.channel,
|
|
39
|
+
'type', pw.type,
|
|
40
|
+
'value', CAST(pw.value AS TEXT)
|
|
41
|
+
)
|
|
42
|
+
)
|
|
43
|
+
FROM writes as pw
|
|
44
|
+
WHERE pw.thread_id = checkpoints.thread_id
|
|
45
|
+
AND pw.checkpoint_ns = checkpoints.checkpoint_ns
|
|
46
|
+
AND pw.checkpoint_id = checkpoints.checkpoint_id
|
|
47
|
+
)`.as("pending_writes"),D`(
|
|
48
|
+
SELECT json_group_array(
|
|
49
|
+
json_object(
|
|
50
|
+
'type', ps.type,
|
|
51
|
+
'value', CAST(ps.value AS TEXT)
|
|
52
|
+
)
|
|
53
|
+
)
|
|
54
|
+
FROM writes as ps
|
|
55
|
+
WHERE ps.thread_id = checkpoints.thread_id
|
|
56
|
+
AND ps.checkpoint_ns = checkpoints.checkpoint_ns
|
|
57
|
+
AND ps.checkpoint_id = checkpoints.parent_checkpoint_id
|
|
58
|
+
AND ps.channel = ${z}
|
|
59
|
+
ORDER BY ps.idx
|
|
60
|
+
)`.as("pending_sends")]).where("thread_id","=",$).where("checkpoint_ns","=",Z);if(H)U=U.where("checkpoint_id","=",H);else U=U.orderBy("checkpoint_id","desc").limit(1);let j=await U.executeTakeFirst();if(!j)return;let V=J;if(!H)V={configurable:{thread_id:j.thread_id,checkpoint_ns:Z,checkpoint_id:j.checkpoint_id}};if(V.configurable?.thread_id===void 0||V.configurable?.checkpoint_id===void 0)throw Error("Missing thread_id or checkpoint_id");let X=await Promise.all(JSON.parse(j.pending_writes).map(async(A)=>{return[A.task_id,A.channel,await this.serde.loadsTyped(A.type??"json",A.value??"")]})),W=await this.serde.loadsTyped(j.type??"json",new TextDecoder().decode(j.checkpoint));if(W.v<4&&j.parent_checkpoint_id!=null)await this.migratePendingSends(W,j.thread_id,j.parent_checkpoint_id);return{checkpoint:W,config:V,metadata:await this.serde.loadsTyped(j.type??"json",new TextDecoder().decode(j.metadata)),parentConfig:j.parent_checkpoint_id?{configurable:{thread_id:j.thread_id,checkpoint_ns:Z,checkpoint_id:j.parent_checkpoint_id}}:void 0,pendingWrites:X}}async*list(J,$){let{limit:Z,before:H,filter:U}=$??{};await this.setup();let j=J.configurable?.thread_id,V=J.configurable?.checkpoint_ns,X=this.db.selectFrom("checkpoints").select(["thread_id","checkpoint_ns","checkpoint_id","parent_checkpoint_id","type","checkpoint","metadata",D`(
|
|
61
|
+
SELECT json_group_array(
|
|
62
|
+
json_object(
|
|
63
|
+
'task_id', pw.task_id,
|
|
64
|
+
'channel', pw.channel,
|
|
65
|
+
'type', pw.type,
|
|
66
|
+
'value', CAST(pw.value AS TEXT)
|
|
67
|
+
)
|
|
68
|
+
)
|
|
69
|
+
FROM writes as pw
|
|
70
|
+
WHERE pw.thread_id = checkpoints.thread_id
|
|
71
|
+
AND pw.checkpoint_ns = checkpoints.checkpoint_ns
|
|
72
|
+
AND pw.checkpoint_id = checkpoints.checkpoint_id
|
|
73
|
+
)`.as("pending_writes"),D`(
|
|
74
|
+
SELECT json_group_array(
|
|
75
|
+
json_object(
|
|
76
|
+
'type', ps.type,
|
|
77
|
+
'value', CAST(ps.value AS TEXT)
|
|
78
|
+
)
|
|
79
|
+
)
|
|
80
|
+
FROM writes as ps
|
|
81
|
+
WHERE ps.thread_id = checkpoints.thread_id
|
|
82
|
+
AND ps.checkpoint_ns = checkpoints.checkpoint_ns
|
|
83
|
+
AND ps.checkpoint_id = checkpoints.parent_checkpoint_id
|
|
84
|
+
AND ps.channel = ${z}
|
|
85
|
+
ORDER BY ps.idx
|
|
86
|
+
)`.as("pending_sends")]);if(j)X=X.where("thread_id","=",j);if(V!==void 0&&V!==null)X=X.where("checkpoint_ns","=",V);if(H?.configurable?.checkpoint_id!==void 0)X=X.where("checkpoint_id","<",H.configurable.checkpoint_id);let W=Object.fromEntries(Object.entries(U??{}).filter(([B,M])=>M!==void 0&&T.includes(B)));for(let[B,M]of Object.entries(W))X=X.where(D`json_extract(CAST(metadata AS TEXT), ${D.lit("$."+B)})`,"=",D.lit(JSON.stringify(M)));if(X=X.orderBy("checkpoint_id","desc"),Z)X=X.limit(parseInt(Z,10));let A=await X.execute();for(let B of A){let M=await Promise.all(JSON.parse(B.pending_writes).map(async(Q)=>{return[Q.task_id,Q.channel,await this.serde.loadsTyped(Q.type??"json",Q.value??"")]})),Y=await this.serde.loadsTyped(B.type??"json",new TextDecoder().decode(B.checkpoint));if(Y.v<4&&B.parent_checkpoint_id!=null)await this.migratePendingSends(Y,B.thread_id,B.parent_checkpoint_id);yield{config:{configurable:{thread_id:B.thread_id,checkpoint_ns:B.checkpoint_ns,checkpoint_id:B.checkpoint_id}},checkpoint:Y,metadata:await this.serde.loadsTyped(B.type??"json",new TextDecoder().decode(B.metadata)),parentConfig:B.parent_checkpoint_id?{configurable:{thread_id:B.thread_id,checkpoint_ns:B.checkpoint_ns,checkpoint_id:B.parent_checkpoint_id}}:void 0,pendingWrites:M}}}async put(J,$,Z){if(await this.setup(),!J.configurable)throw Error("Empty configuration supplied.");let H=J.configurable?.thread_id,U=J.configurable?.checkpoint_ns??"",j=J.configurable?.checkpoint_id;if(!H)throw Error('Missing "thread_id" field in passed "config.configurable".');let V=P($),[[X,W],[A,B]]=await Promise.all([this.serde.dumpsTyped(V),this.serde.dumpsTyped(Z)]);if(X!==A)throw Error("Failed to serialized checkpoint and metadata to the same type.");return await F(async()=>{await this.db.insertInto("checkpoints").values({thread_id:H,checkpoint_ns:U,checkpoint_id:$.id,parent_checkpoint_id:j??null,type:X,checkpoint:new Uint8Array(Buffer.from(W)),metadata:new Uint8Array(Buffer.from(B))}).onConflict((M)=>M.columns(["thread_id","checkpoint_ns","checkpoint_id"]).doUpdateSet({parent_checkpoint_id:j??null,type:X,checkpoint:new Uint8Array(Buffer.from(W)),metadata:new Uint8Array(Buffer.from(B))})).execute()},`put(${H}/${$.id})`),{configurable:{thread_id:H,checkpoint_ns:U,checkpoint_id:$.id}}}async putWrites(J,$,Z){if(await this.setup(),!J.configurable)throw Error("Empty configuration supplied.");if(!J.configurable?.thread_id)throw Error("Missing thread_id field in config.configurable.");if(!J.configurable?.checkpoint_id)throw Error("Missing checkpoint_id field in config.configurable.");let H=await Promise.all($.map(async(V,X)=>{let[W,A]=await this.serde.dumpsTyped(V[1]);return{thread_id:J.configurable.thread_id,checkpoint_ns:J.configurable.checkpoint_ns??"",checkpoint_id:J.configurable.checkpoint_id,task_id:Z,idx:X,channel:V[0],type:W,value:new Uint8Array(Buffer.from(A))}}));if(H.length===0)return;let U=J.configurable.thread_id,j=J.configurable.checkpoint_id;await F(async()=>{await this.db.transaction().execute(async(V)=>{await V.deleteFrom("writes").where("thread_id","=",U).where("checkpoint_ns","=",H[0].checkpoint_ns).where("checkpoint_id","=",j).where("task_id","=",Z).execute();for(let X of H)await V.insertInto("writes").values(X).execute()})},`putWrites(${U}/${j}/${Z})`)}async deleteThread(J){await F(async()=>{await this.db.transaction().execute(async($)=>{await $.deleteFrom("checkpoints").where("thread_id","=",J).execute(),await $.deleteFrom("writes").where("thread_id","=",J).execute()})},`deleteThread(${J})`)}async migratePendingSends(J,$,Z){let H=await this.db.selectFrom("writes as ps").select(["ps.checkpoint_id",D`json_group_array(
|
|
87
|
+
json_object(
|
|
88
|
+
'type', ps.type,
|
|
89
|
+
'value', CAST(ps.value AS TEXT)
|
|
90
|
+
)
|
|
91
|
+
)`.as("pending_sends")]).where("ps.thread_id","=",$).where("ps.checkpoint_id","=",Z).where("ps.channel","=",z).orderBy("ps.idx").executeTakeFirst();if(!H)return;let U=J;U.channel_values??={},U.channel_values[z]=await Promise.all(JSON.parse(H.pending_sends).map(({type:j,value:V})=>this.serde.loadsTyped(j,V))),U.channel_versions[z]=Object.keys(J.channel_versions).length>0?O(...Object.values(J.channel_versions)):this.getNextVersion(void 0)}}export{N as SqliteSaver};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import{Be as j,Ce as E,Le as t,ye as c0}from"./chunk-1v863afn.js";import{ff as B}from"./chunk-mcb8rewr.js";import{Fl as h,Hl as T,Kl as M}from"./chunk-z3e4c424.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-t0f66x64.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};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{Gd as w,ee as z,xd as x}from"./chunk-cnzhxgn5.js";import"./chunk-z3e4c424.js";class J{constructor(h){this.pool=h,this.db=new x({dialect:new z({pool:h})})}db;dateToDb(h){return h}dbToDate(h){return h instanceof Date?h:new Date(h)}jsonToDb(h){return h}dbToJson(h){return h}buildJsonQuery(h,C,H,I){return w`${w.ref(C)}->>${w.lit(H)} = ${w.lit(JSON.stringify(I))}`}now(){return new Date}async createTables(h){await w`
|
|
2
2
|
CREATE TABLE IF NOT EXISTS threads (
|
|
3
3
|
thread_id TEXT PRIMARY KEY,
|
|
4
4
|
created_at TIMESTAMP NOT NULL,
|