pikiloom 0.4.74 → 0.4.75
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/dashboard/dist/assets/{AgentTab-KSanVg_l.js → AgentTab-mOLTkWO3.js} +1 -1
- package/dashboard/dist/assets/{ConnectionModal-BSoA2mZL.js → ConnectionModal-C_dMkfPp.js} +1 -1
- package/dashboard/dist/assets/{DirBrowser-zKX7wmty.js → DirBrowser-D8CSsHGw.js} +1 -1
- package/dashboard/dist/assets/{ExtensionsTab-DKLjCr4u.js → ExtensionsTab-DoENefbA.js} +1 -1
- package/dashboard/dist/assets/{IMAccessTab-BhvB7Hes.js → IMAccessTab-hGzp1fw8.js} +1 -1
- package/dashboard/dist/assets/{Modal-Qwlap_Fl.js → Modal-Bsippcly.js} +1 -1
- package/dashboard/dist/assets/{Modals-2Zw2FSLo.js → Modals-BgLj51_X.js} +1 -1
- package/dashboard/dist/assets/{Select-dIxoi_TN.js → Select-CaMLVBWh.js} +1 -1
- package/dashboard/dist/assets/SessionPanel-CEoPMHDr.js +1 -0
- package/dashboard/dist/assets/{SystemTab-CtjiZa5s.js → SystemTab-CBrXz_gj.js} +1 -1
- package/dashboard/dist/assets/{index-DN0a6ZnO.js → index-CYDoPd1c.js} +3 -3
- package/dashboard/dist/assets/{index-BDSh0L9U.js → index-D_s24-jk.js} +2 -2
- package/dashboard/dist/assets/{shared-D2sGZJ9f.js → shared-D_xr0ftZ.js} +1 -1
- package/dashboard/dist/index.html +1 -1
- package/package.json +1 -1
- package/dashboard/dist/assets/SessionPanel--D5NGYgd.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as s}from"./react-vendor-C7Sl8SE7.js";import{O as t,m as i,S as a}from"./index-
|
|
1
|
+
import{j as s}from"./react-vendor-C7Sl8SE7.js";import{O as t,m as i,S as a}from"./index-D_s24-jk.js";function o({primary:e,secondary:l,tertiary:n}){return s.jsxs("div",{className:"flex flex-col gap-2 pt-1 sm:flex-row sm:flex-wrap sm:items-center sm:justify-between",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e&&s.jsxs(i,{tone:"primary",onClick:e.onClick,disabled:e.disabled,children:[e.loading&&s.jsx(a,{}),e.label]}),l&&s.jsx(i,{tone:"secondary",onClick:l.onClick,disabled:l.disabled,children:l.label})]}),n&&s.jsx("div",{className:"text-xs leading-relaxed text-fg-4",children:n})]})}function c({children:e,className:l}){return s.jsx(t,{padding:"md",elevation:"flat",className:l,children:e})}export{o as A,c as S};
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
<link rel="icon" type="image/png" href="/logo.png">
|
|
7
7
|
<title>Pikiloom</title>
|
|
8
8
|
<link href="https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&family=Geist+Mono:wght@400;500&display=swap" rel="stylesheet">
|
|
9
|
-
<script type="module" crossorigin src="/assets/index-
|
|
9
|
+
<script type="module" crossorigin src="/assets/index-D_s24-jk.js"></script>
|
|
10
10
|
<link rel="modulepreload" crossorigin href="/assets/react-vendor-C7Sl8SE7.js">
|
|
11
11
|
<link rel="modulepreload" crossorigin href="/assets/router-DHISdpPk.js">
|
|
12
12
|
<link rel="stylesheet" crossorigin href="/assets/index-BO-FYAny.css">
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as n,j as s}from"./react-vendor-C7Sl8SE7.js";import{c as on,I as un,S as Ke,m as ze,a as T,u as pt,d as cn,g as dn,l as fn,e as mn,j as gn,f as pn,s as hn,Y as xn}from"./index-BDSh0L9U.js";import{s as kn,l as Sn,n as Pt,m as bn,a as vn,o as In,d as Tn,b as yn,p as Rn,h as Et,c as Qe,e as jn,f as wn,g as Mt,i as $e,j as ht,k as Nn,q as An,T as Ln,R as On,U as Ct,r as Pn,t as Ut,L as qt,u as En,I as Mn}from"./index-DN0a6ZnO.js";import{M as Ht,a as Ft}from"./Modal-Qwlap_Fl.js";import"./router-DHISdpPk.js";import"./Select-dIxoi_TN.js";import"./DirBrowser-zKX7wmty.js";import"./markdown-DxQYQFeH.js";import"./ExtensionsTab-DKLjCr4u.js";function Cn({snapshot:a}){const[t,f]=n.useState(a.currentIndex??0),[N,y]=n.useState(""),[x,h]=n.useState(!1),[C,S]=n.useState(null);n.useEffect(()=>{f(a.currentIndex??0),y(""),S(null)},[a.promptId,a.currentIndex]);const O=a.questions||[],R=O[t]||null,Z=O.length,U=!!(R?.options&&R.options.length),P=U?!!R?.allowFreeform:!0,de=c=>{c&&(f(i=>i+1),y(""))},fe=async c=>{if(!x){h(!0),S(null);try{const i=await T.interactionSelectOption(a.promptId,c);if(!i.ok){S(i.error||"Failed to submit selection.");return}de(i.advanced)}catch(i){S(i?.message||"Network error.")}finally{h(!1)}}},me=async()=>{if(x)return;const c=N.trim();if(!c&&!R?.allowEmpty){S("Please enter a response.");return}h(!0),S(null);try{const i=await T.interactionSubmitText(a.promptId,c);if(!i.ok){S(i.error||"Failed to submit answer.");return}de(i.advanced)}catch(i){S(i?.message||"Network error.")}finally{h(!1)}},m=async()=>{if(!x){h(!0),S(null);try{const c=await T.interactionSkip(a.promptId);if(!c.ok){S(c.error||"Failed to skip.");return}de(c.advanced)}catch(c){S(c?.message||"Network error.")}finally{h(!1)}}},ee=async()=>{if(!x){h(!0);try{await T.interactionCancel(a.promptId)}catch{}}},te=n.useMemo(()=>{const c=[];return a.hint&&c.push(a.hint),Z>1&&c.push(`Question ${t+1} of ${Z}`),c.join(" · ")||void 0},[a.hint,t,Z]);return s.jsxs(Ht,{open:!0,onClose:ee,wide:U&&(R?.options?.length||0)>3,children:[s.jsx(Ft,{title:a.title||"Pikiloom needs your input",description:te,onClose:ee}),R?s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{children:[s.jsx("div",{className:"text-xs font-medium uppercase tracking-wide text-fg-5",children:R.header||"Question"}),s.jsx("div",{className:"mt-1 whitespace-pre-wrap text-sm leading-relaxed text-fg",children:R.prompt})]}),U&&s.jsx("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2",children:(R.options||[]).map(c=>s.jsxs("button",{type:"button",disabled:x,onClick:()=>fe(c.value||c.label),className:on("group rounded-lg border border-edge bg-panel-alt px-3 py-2 text-left text-sm transition","hover:border-control-border-h hover:bg-control-h hover:shadow-sm","focus:outline-none focus:ring-2 focus:ring-[var(--th-glow-a)]","disabled:cursor-not-allowed disabled:opacity-50"),children:[s.jsx("div",{className:"font-medium text-fg group-hover:text-fg",children:c.label}),c.description&&s.jsx("div",{className:"mt-0.5 text-xs leading-snug text-fg-4",children:c.description})]},c.value||c.label))}),P&&s.jsx("div",{children:s.jsx(un,{value:N,onChange:c=>y(c.target.value),onKeyDown:c=>{c.key==="Enter"&&!c.shiftKey&&!x&&(c.preventDefault(),me())},placeholder:U?"Or type a custom answer…":"Type your answer…",disabled:x,autoFocus:!U})}),C&&s.jsx("div",{className:"rounded-md border border-red-300/40 bg-red-500/10 px-3 py-2 text-xs text-red-600",children:C}),s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsx("div",{className:"text-xs text-fg-5",children:x?s.jsxs("span",{className:"inline-flex items-center gap-2",children:[s.jsx(Ke,{})," Submitting…"]}):s.jsxs("span",{children:["Press ",s.jsx("kbd",{className:"rounded border border-edge bg-panel-alt px-1.5 py-0.5 text-[10px] uppercase",children:"Enter"})," to send"]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ze,{variant:"ghost",size:"sm",onClick:m,disabled:x,children:"Skip"}),P&&s.jsx(ze,{variant:"primary",size:"sm",onClick:me,disabled:x||!N.trim()&&!R.allowEmpty,children:"Submit"})]})]})]}):s.jsxs("div",{className:"py-6 text-center text-sm text-fg-5",children:[s.jsx(Ke,{className:"mr-2 inline-block"})," Waiting for the agent…"]})]})}function Un(a){return a.isNull?(a.localStreamPending||a.holdsActiveState)&&!a.holdExpired?"reject-null":"apply":(typeof a.updatedAt=="number"?a.updatedAt:0)<a.lastAppliedUpdatedAt?"reject-stale":"apply"}function qn(a,t){return typeof t!="number"?a:t>a?t:a}function Dn(a,t){return!a||!a.length?[]:t.size?a.filter(f=>!t.has(f)):a.slice()}function Hn(a,t,f,N){if(!a.size)return a;const y=new Set(t);let x=!1;const h=new Map;for(const[C,S]of a){if(f-S>N||!y.has(C)){x=!0;continue}h.set(C,S)}return x?h:a}const xt=12,Dt=160,Fn=96,Bn=[],_n=[],Qn=[],$n={phase:"streaming",text:"",thinking:""},Kn=20,zn=6e4,Wn=15e3,Yn=7e3,ie=new Map;function Gn(a,t){return`${a}:${t}`}function Vn(a,t){for(ie.delete(a),ie.set(a,t);ie.size>Kn;)ie.delete(ie.keys().next().value)}const or=n.memo(function({session:t,workdir:f,active:N=!0,onSessionChange:y,initialPendingPrompt:x,initialPendingImageUrls:h,onPendingPromptConsumed:C}){const S=pt(e=>e.locale),O=pt(e=>e.agentStatus?.agents?.find(r=>r.agent===t.agent)??null),R=O?.selectedEffort??null,Z=O?.selectedModel??null,U=pt(e=>e.modelLayer),P=t.profileId?U?.profiles.find(e=>e.id===t.profileId)??null:null,de=P?U?.providers.find(e=>e.id===P.providerId)??null:null,fe=t.profileId===void 0?O?.byokProviderName??null:de?.name??null,me=t.profileId===void 0?O?.byokProfileName??null:P&&P.name.trim().toLowerCase()!==P.modelId.trim().toLowerCase()?P.name:null,m=n.useMemo(()=>cn(S),[S]),ee=dn(t.agent||""),te=fn(t),c=!!x||!!(h&&h.length),[i,We]=n.useState(null),[Ye,ge]=n.useState(!c),[pe,kt]=n.useState(!1),[u,F]=n.useState(null),[B,he]=n.useState(!1),[q,Ge]=n.useState(null),[Bt,St]=n.useState(0),[_t,Ve]=n.useState(null),[D,Re]=n.useState([]),[Qt,je]=n.useState([]),[xe,Xe]=n.useState([]),[g,ne]=n.useState(x||null),[E,re]=n.useState(h||[]),[$t,se]=n.useState(null),_=n.useRef(null);_.current=$t;const bt=n.useRef(g);bt.current=g;const[we,H]=n.useState([]),Ne=n.useRef([]);Ne.current=we;const ke=n.useRef(null),[Kt,vt]=n.useState(null),[Ae,Se]=n.useState(null),[be,Je]=n.useState(""),[Q,Ze]=n.useState(!1),zt=!!O?.capabilities?.fork,et=n.useRef(null),L=n.useRef(h||[]),$=n.useRef(u),tt=n.useRef(B);$.current=u,tt.current=B;const nt=n.useRef(D);nt.current=D;const It=n.useRef(q);It.current=q;const K=n.useRef(null),Le=n.useRef(null),z=n.useRef(!0),le=n.useRef(!1),Oe=n.useRef(null),rt=n.useRef(!1),M=n.useRef(c),ae=n.useRef(!1),W=n.useRef(!1),st=n.useRef(!1),lt=n.useRef(!1),Y=n.useRef(null),Pe=n.useRef(0),ve=n.useRef(Date.now()),Ie=n.useRef(new Map),Tt=n.useRef({model:null,effort:null}),Wt=n.useCallback(e=>{Tt.current=e},[]);n.useEffect(()=>{st.current||!c||(st.current=!0,x&&!g&&ne(x),h&&h.length&&!E.length&&(re(h),L.current=h),ge(!1),St(e=>e+1),C?.())},[c,C]);const A=n.useCallback(()=>{ne(null),re(e=>{for(const r of e)URL.revokeObjectURL(r);return[]}),L.current=[],se(null)},[]),G=n.useCallback(()=>{H(e=>{if(!e.length)return e;for(const r of e)for(const l of r.imageUrls)URL.revokeObjectURL(l);return[]}),ke.current=null},[]),yt=n.useCallback((e,r)=>{ve.current=Date.now();const l=kn({streaming:tt.current,liveStreamPhase:$.current?.phase??null,streamPhase:It.current,queuedTaskCount:nt.current.length,pendingQueuedCount:Ne.current.length}),o=r||[];if(l){const d=`local-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`;ke.current=d,H(k=>[...k,{localId:d,taskId:null,prompt:e||"",imageUrls:o}]);return}$.current?.phase==="done"&&F(null);for(const d of L.current)URL.revokeObjectURL(d);ke.current=null,ne(e||null),re(o),L.current=o,se(null)},[]),Yt=n.useCallback(e=>{const r=ke.current;if(r){ke.current=null,H(l=>{const o=l.findIndex(k=>k.localId===r);if(o<0)return l;const d=l.slice();return d[o]={...d[o],taskId:e},d});return}se(e)},[]),Gt=n.useCallback(async()=>{if(!Ae)return;const e=be.trim();if(e){Ze(!0);try{const r=await T.forkSession(f,t.agent||"",t.sessionId,Ae.atTurn,e,{});if(!r.ok||!r.sessionKey){Ze(!1);return}const[l,o]=r.sessionKey.split(":");Se(null),Je(""),y?.({agent:l,sessionId:o,workdir:f})}finally{Ze(!1)}}},[Ae,be,f,t.agent,t.sessionId,y]);et.current=Gt;const Ee=n.useCallback(async(e,r={})=>{try{const l=await Sn({workdir:f,agent:t.agent||"",sessionId:t.sessionId,rich:!0,turnOffset:e.turnOffset,turnLimit:e.turnLimit,lastNTurns:e.lastNTurns},{force:r.force});return l.ok?Pt(l):null}catch{return null}},[f,t.agent,t.sessionId]),j=n.useCallback(async({keepOlder:e,force:r=!1,scrollToBottom:l=!1})=>{const o=t.sessionId;if(Oe.current===o)return!1;Oe.current=o;try{const d=await Ee({turnOffset:0,turnLimit:xt},{force:r});if(!d||t.sessionId!==o)return!1;if(l&&(le.current=!0),We(k=>!k||!e?d:bn(k,d)),ge(!1),ae.current&&(ae.current=!1,A()),W.current){const k=W.current;W.current=!1;const X=k!==!0?k.taskId:null;$.current&&(k===!0||$.current.taskId===X)&&F(null)}return!0}finally{Oe.current===o&&(Oe.current=null)}},[Ee,A,t.sessionId]),Me=n.useCallback(async()=>{if(!i?.hasOlder||rt.current)return;const e=K.current;e&&(Le.current={scrollHeight:e.scrollHeight,scrollTop:e.scrollTop}),rt.current=!0,kt(!0);try{const r=await Ee({turnOffset:Math.max(0,i.totalTurns-i.startTurn),turnLimit:xt});r?We(l=>l?vn(l,r):r):Le.current=null}finally{rt.current=!1,kt(!1)}},[Ee,i]),Ce=n.useRef(null),oe=n.useCallback((e,r="ws")=>{const l=tt.current||nt.current.length>0,o=Date.now()-ve.current>Wn;if(Un({updatedAt:e?.updatedAt,isNull:!e,lastAppliedUpdatedAt:Pe.current,localStreamPending:M.current,holdsActiveState:l,holdExpired:o})!=="apply")return;const k=!e&&o&&(M.current||l);if(e&&(ve.current=Date.now(),Pe.current=qn(Pe.current,e.updatedAt)),e?.sessionId&&e.sessionId!==t.sessionId&&(lt.current=!0,Te.current=`${t.agent}:${e.sessionId}`,y?.({agent:t.agent||"",sessionId:e.sessionId,workdir:f})),!e){const p=Ce.current;he(!1),k?(M.current=!1,ae.current=!0,W.current=!0,G(),j({keepOlder:!0,force:!0,scrollToBottom:z.current})):p==="streaming"?(ae.current=!0,W.current=!0,j({keepOlder:!0,force:!0,scrollToBottom:z.current})):F(null),k||(M.current&&p!=="streaming"?j({keepOlder:!0,force:!0}):(p==="done"&&(A(),G()),p!==null&&(M.current=!1))),Ve(null),Ge(null),Re([]),je([]),Xe([]),Ce.current=null;return}Ge(e.phase),Ve(e.taskId||null);const X=[];e.taskId&&X.push(e.taskId),Array.isArray(e.queuedTaskIds)&&X.push(...e.queuedTaskIds),Ie.current=Hn(Ie.current,X,Date.now(),zn);const ue=Ie.current,mt=Dn(e.queuedTaskIds,ue),Ot=(Array.isArray(e.queuedTasks)?e.queuedTasks:[]).filter(p=>!ue.has(p.taskId));if(Re(mt.length?mt:Bn),je(Ot.length?Ot:_n),Xe(Array.isArray(e.interactions)&&e.interactions.length?e.interactions:Qn),In({pendingTaskId:_.current,streamTaskId:e.taskId||null,queuedTaskIds:e.queuedTaskIds})){const p=_.current,w=bt.current||"",I=L.current;H(v=>v.some(ce=>ce.taskId===p)?v:[...v,{localId:`demote-${p}`,taskId:p,prompt:w,imageUrls:I}]),ne(null),re([]),L.current=[],se(null),_.current=null}if(e.phase==="streaming"){if(F({taskId:e.taskId||null,phase:"streaming",text:e.text||"",thinking:e.thinking||"",activity:e.activity,plan:e.plan??null,model:e.model??null,effort:e.effort??null,previewMeta:e.previewMeta??null,subAgents:e.previewMeta?.subAgents??null,generatingImages:e.previewMeta?.generatingImages??0,artifacts:e.artifacts??null,startedAt:typeof e.startedAt=="number"?e.startedAt:null,error:null,question:e.question??null,questionBlocks:e.questionBlocks??null}),he(!0),e.taskId&&e.taskId!==_.current){const p=Ne.current,w=p.findIndex(I=>I.taskId===e.taskId);if(w>=0){const I=p[w];for(const v of L.current)URL.revokeObjectURL(v);ne(I.prompt||null),re(I.imageUrls),L.current=I.imageUrls,se(e.taskId),H(v=>v.filter((ce,J)=>J!==w))}}z.current&&(le.current=!0)}else if(e.phase==="queued")F(null),he(!1);else if(e.phase==="done"){const p=Tn($.current?.taskId??null,e.taskId||null),w=mt.length>0;if(p){he(!1),F(J=>J?{...J,phase:"done",error:e.error??null}:e.error?{taskId:e.taskId||null,phase:"done",text:"",thinking:"",activity:"",plan:null,model:e.model??null,effort:e.effort??null,previewMeta:e.previewMeta??null,subAgents:e.previewMeta?.subAgents??null,generatingImages:e.previewMeta?.generatingImages??0,artifacts:e.artifacts??null,error:e.error,question:e.question??null,questionBlocks:e.questionBlocks??null}:J);const I=$.current,v=!!I&&yn(I),ce=!!e.incomplete&&v&&!w;if(Ce.current!=="done"){w||(ae.current=!0),W.current=ce?!1:{taskId:e.taskId||null},j({keepOlder:!0,force:!0,scrollToBottom:z.current});const J=t.agent||"",sn=t.sessionId,ln=Te.current;Y.current&&clearTimeout(Y.current),Y.current=setTimeout(()=>{Y.current=null,T.getSessionStreamState(J,sn).then(an=>{Te.current===ln&&Ue.current(an.state,"seed")}).catch(()=>{})},900)}}w||(M.current=!1)}const gt=new Set;if(e.taskId&>.add(e.taskId),Array.isArray(e.queuedTaskIds))for(const p of e.queuedTaskIds)gt.add(p);H(p=>{let w=!1;const I=[];for(const v of p)if(!v.taskId||gt.has(v.taskId))I.push(v);else{for(const ce of v.imageUrls)URL.revokeObjectURL(ce);w=!0}return w?I:p}),Ce.current=e.phase},[A,G,j,t.sessionId,t.agent,y,f]),Ue=n.useRef(oe);Ue.current=oe;const Rt=n.useCallback(()=>{M.current=!0,ve.current=Date.now(),St(e=>e+1)},[]);n.useEffect(()=>()=>{Y.current&&(clearTimeout(Y.current),Y.current=null)},[]);const Vt=n.useCallback(async e=>{try{Ie.current.set(e,Date.now()),await T.recallSessionMessage(e),_.current===e&&A(),H(r=>{let l=!1;const o=[];for(const d of r)if(d.taskId===e){for(const k of d.imageUrls)URL.revokeObjectURL(k);l=!0}else o.push(d);return l?o:r}),Re(r=>r.filter(l=>l!==e)),je(r=>r.filter(l=>l.taskId!==e)),Ve(r=>r===e?null:r)}catch{}},[A]),Xt=n.useCallback(async e=>{const r=Ne.current.find(l=>l.taskId===e)||null;if(r&&r.imageUrls.length>0){for(const l of L.current)URL.revokeObjectURL(l);ne(r.prompt||null),re(r.imageUrls),L.current=r.imageUrls,se(e),_.current=e,H(l=>l.filter(o=>o.taskId!==e))}try{await T.steerSession(e)}catch{}},[]),Jt=n.useCallback(async()=>{try{await T.stopSession(t.agent||"",t.sessionId)}catch{}},[t.agent,t.sessionId]),qe=Gn(t.agent||"",t.sessionId);n.useEffect(()=>{if(lt.current){lt.current=!1;let d=!1;return j({keepOlder:!0,force:!0}).finally(()=>{d||ge(!1)}),()=>{d=!0}}let e=!1;const r=Rn({workdir:f,agent:t.agent||"",sessionId:t.sessionId,rich:!0,turnOffset:0,turnLimit:xt},{allowStale:!0}),l=c&&!st.current,o=r?.ok?Pt(r):ie.get(qe)||null;return ge(l?!1:!o),We(o),F(null),he(!1),Ge(null),Re([]),je([]),Xe([]),Pe.current=0,ve.current=Date.now(),Ie.current=new Map,l||(A(),G(),M.current=!1,ae.current=!1,W.current=!1),z.current=!0,le.current=!0,l||j({keepOlder:!1,force:!0}).finally(()=>{e||ge(!1)}),()=>{e=!0}},[j,t.agent,t.sessionId,f,qe,A,G]),n.useEffect(()=>{i&&i.turns.length>0&&Vn(qe,i)},[qe,i]),n.useEffect(()=>{N&&j({keepOlder:!0,force:!0})},[N,j]);const Te=n.useRef(`${t.agent}:${t.sessionId}`);Te.current=`${t.agent}:${t.sessionId}`,mn("stream-update",n.useCallback(e=>{e.key===Te.current&&oe(e.snapshot??null)},[oe])),n.useEffect(()=>{let e=!0;return T.getSessionStreamState(t.agent||"",t.sessionId).then(r=>{e&&Ue.current(r.state,"seed")}).catch(()=>{}),()=>{e=!1}},[t.agent,t.sessionId,Bt]),gn(n.useCallback(()=>{T.getSessionStreamState(t.agent||"",t.sessionId).then(e=>{oe(e.state,"seed")}).catch(()=>{}),j({keepOlder:!0,force:!0})},[oe,t.agent,t.sessionId,j]));const jt=B||!!q||D.length>0||!!g||we.length>0;n.useEffect(()=>{if(!N||!jt)return;const e=setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||T.getSessionStreamState(t.agent||"",t.sessionId).then(r=>Ue.current(r.state,"seed")).catch(()=>{})},Yn);return()=>clearInterval(e)},[N,jt,t.agent,t.sessionId]),n.useEffect(()=>{!M.current&&te!=="running"&&!B&&!u&&!q&&D.length===0&&(A(),G())},[te,B,u,q,D.length,A,G]),n.useLayoutEffect(()=>{const e=Le.current,r=K.current;!e||!r||(Le.current=null,r.scrollTop=e.scrollTop+(r.scrollHeight-e.scrollHeight))},[i?.turns.length]),n.useLayoutEffect(()=>{if(!le.current)return;const e=K.current;e&&(le.current=!1,e.scrollTop=e.scrollHeight,requestAnimationFrame(()=>{z.current&&(e.scrollTop=e.scrollHeight)}))},[i,u]),n.useLayoutEffect(()=>{if(!g)return;const e=K.current;e&&(e.scrollTop=e.scrollHeight)},[g]),n.useEffect(()=>{if(!i?.hasOlder||Ye||pe)return;const e=K.current;e&&e.scrollHeight<=e.clientHeight+Dt&&Me()},[i?.hasOlder,i?.turns.length,Me,Ye,pe]);const Zt=n.useCallback(()=>{const e=K.current;if(!e)return;const r=e.scrollHeight-e.scrollTop-e.clientHeight;z.current=r<=Fn,e.scrollTop<=Dt&&Me()},[Me]),ye=u?.model||t.model||Z||null,De=pn(t.agent||"",u?.effort||t.thinkingEffort||R||null,t.workflowEnabled??O?.workflowEnabled)||null,at=me&&(!ye||ye===Z)?me:ye?hn(ye):null,ot=xn(t,{streaming:B,hasLiveStream:!!u,streamPhase:q,queuedTaskCount:D.length}),b=i?.turns||[],en=n.useMemo(()=>{for(let e=b.length-1;e>=0;e--){const r=b[e].assistant?.blocks;if(r)for(let l=r.length-1;l>=0;l--){const o=r[l];if(o.type==="plan"&&Et(o.plan))return o.plan}}return null},[b]),He=n.useMemo(()=>{if(!E.length||!b.length)return!1;const e=b[b.length-1];return!e.user||!Qe(e.user.text,g)?!1:e.user.blocks.filter(l=>l.type==="image").length<E.length},[b,g,E.length]),ut=n.useMemo(()=>E.length?E.map(e=>({type:"image",content:e})):!g||!u?.questionBlocks?.length?[]:Qe(g,u.question)?u.questionBlocks:[],[E,g,u]),ct=u?.question||null,Fe=jn(g,ct),wt=u&&Et(u.plan)?u.plan:u&&wn(g,ct)?en:null,it=Mt(ct,g),Nt=b.length>0?b[b.length-1]?.user?.text:null,At=!!Fe&&b.length>0&&$e(Nt,Fe),V=n.useMemo(()=>{let e=b;if(He){const ue=e[e.length-1];e=[...e.slice(0,-1),{...ue,user:null}]}if(!u||!e.length)return e;const r=e[e.length-1],l=Fe;if(!r.assistant)return!!r.user&&!!l&&!Qe(r.user.text,l)&&($e(r.user.text,l)||Mt(l,r.user.text))?[...e.slice(0,-1),{...r,user:{...r.user,text:l}}]:e;const o=(u.text||"").trim(),d=r.assistant.text?.trim()||"";if(!(l!=null?$e(r.user?.text,l):!!d&&!!o&&(o.startsWith(d)||d.startsWith(o))))return e;const X=r.user&&l&&!Qe(r.user.text,l)?{...r.user,text:l}:r.user;return[...e.slice(0,-1),{...r,user:X,assistant:null}]},[b,u,Fe,He]),tn=(!!g||ut.length>0)&&!it&&(He||!At)&&!u,nn=!!u&&ht(u)&&u.phase==="streaming",dt=Nn({sessionRunning:te==="running",streaming:B,streamPhase:q,queuedTaskCount:D.length,pendingQueuedCount:we.length,liveTurnStreaming:nn,pendingBubbleDots:tn}),Be=dt&&V.length>0?V[V.length-1]:null,_e=!!Be?.assistant&&An(Be.assistant),ft=_e?Be.assistant.usage??null:null,rn=_e?Be.assistant.blocks.filter(e=>e.type==="tool_use").length:0,Lt=(()=>{if(!dt||te!=="running")return null;const e=t.runUpdatedAt?Date.parse(t.runUpdatedAt):NaN;return Number.isFinite(e)?e:null})();return s.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[s.jsx("div",{ref:K,onScroll:Zt,className:"flex-1 overflow-y-auto overscroll-contain",children:Ye&&!g&&!E.length&&!u?s.jsx("div",{className:"flex items-center justify-center py-20",children:s.jsx(Ke,{className:"h-5 w-5 text-fg-4"})}):V.length===0&&!g&&!E.length&&!u&&!ot?s.jsx("div",{className:"py-20 text-center text-[13px] text-fg-5",children:m("hub.noMessages")}):s.jsxs("div",{className:"max-w-[900px] mx-auto px-6 py-6 space-y-0",children:[(i?.hasOlder||pe)&&s.jsxs("div",{className:"mb-4 flex items-center justify-center gap-2 text-[11px] text-fg-5",children:[pe?s.jsx(Ke,{className:"h-3 w-3 text-fg-5"}):s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-fg-5/35"}),s.jsx("span",{children:m(pe?"hub.loadingOlderTurns":"hub.loadOlderTurnsHint")})]}),t.migratedFrom?.kind==="fork"&&t.migratedFrom.sessionId&&s.jsxs("button",{type:"button",onClick:()=>y?.({agent:t.migratedFrom.agent||t.agent||"",sessionId:t.migratedFrom.sessionId,workdir:f}),className:"mb-4 inline-flex items-center gap-1.5 rounded-md border border-edge bg-panel-alt px-2.5 py-1 text-[11px] text-fg-5 transition hover:border-edge-h hover:text-fg-2",title:`#${t.migratedFrom.sessionId.slice(0,8)}`,children:[s.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[s.jsx("circle",{cx:"6",cy:"6",r:"2"}),s.jsx("circle",{cx:"18",cy:"6",r:"2"}),s.jsx("circle",{cx:"12",cy:"20",r:"2"}),s.jsx("path",{d:"M6 8v3a3 3 0 0 0 3 3h6a3 3 0 0 0 3-3V8"}),s.jsx("path",{d:"M12 14v4"})]}),s.jsx("span",{children:m("hub.forkBadge")}),s.jsxs("span",{className:"font-mono",children:["#",t.migratedFrom.sessionId.slice(0,8)]}),typeof t.migratedFrom.forkedAtTurn=="number"&&s.jsxs("span",{className:"text-fg-5/70",children:["· ",m("hub.forkBadgeAt").replace("{turn}",String(t.migratedFrom.forkedAtTurn+1))]})]}),V.map((e,r)=>{const l=(i?.startTurn||0)+r;return s.jsx(Ln,{turn:e,turnIndex:l,hideHeaderUsage:_e&&r===V.length-1,isTail:r===V.length-1,agent:t.agent||"",meta:ee,model:at,effort:De,providerName:fe,t:m,workdir:f,onResend:o=>{le.current=!0,yt(o);const d=Tt.current;T.sendSessionMessage(f,t.agent||"",t.sessionId,o,{model:d.model||ye||void 0,effort:d.effort||De||void 0}).then(k=>{k.ok&&Rt()}).catch(()=>{A()})},onEdit:o=>vt(o),onFork:zt?o=>{Je(""),Se({atTurn:o})}:void 0},`${i?.startTurn||0}:${r}`)}),ot&&s.jsx("div",{className:"mb-5 animate-in",children:s.jsx(On,{detail:ot,t:m})}),(g||ut.length>0)&&!it&&(He||!At)&&s.jsxs("div",{className:"session-turn session-turn--live",children:[s.jsx(Ct,{text:g||"",blocks:ut,t:m}),!u&&s.jsx("div",{className:"mt-3 mb-5 animate-in",children:s.jsx(Pn,{className:"text-fg-5"})})]}),u&&ht(u)&&u.question&&(!g||it)&&!(b.length>0&&$e(Nt,u.question))&&s.jsx("div",{className:"session-turn session-turn--live",children:s.jsx(Ct,{text:u.question,blocks:u.questionBlocks||void 0,t:m})}),u&&ht(u)&&s.jsxs("div",{className:"mb-6",children:[s.jsx(Ut,{agent:t.agent||"",meta:ee,model:at,effort:De,providerName:fe,previewMeta:u.previewMeta,hideContextUsage:!0}),s.jsx(qt,{stream:wt===u.plan?u:{...u,plan:wt},t:m,workdir:f})]}),dt&&(_e?s.jsx("div",{className:"-mt-3 mb-6 animate-in",children:s.jsx(En,{toolCount:rn,ctxPct:ft?.contextPercent??null,ctxTokens:ft?.contextUsedTokens??0,turnOutTokens:ft?.turnOutputTokens??0,startedAt:Lt})}):s.jsxs("div",{className:"mb-6",children:[s.jsx(Ut,{agent:t.agent||"",meta:ee,model:at,effort:De,providerName:fe,hideContextUsage:!0}),s.jsx(qt,{stream:{...$n,startedAt:Lt},t:m,workdir:f})]})),s.jsx("div",{className:"h-4"})]})}),s.jsx(Mn,{session:t,workdir:f,onStreamQueued:Rt,onSendStart:yt,onSendTaskAssigned:Yt,onSessionChange:y,t:m,streamPhase:q,streamTaskId:_t,queuedTaskIds:D,queuedTasks:Qt,pendingQueuedSends:we,onRecall:Vt,onSteer:Xt,onStopAll:Jt,editDraft:Kt,onEditDraftConsumed:()=>vt(null),onSelectionChange:Wt}),Ae&&s.jsxs(Ht,{open:!0,onClose:()=>{Q||Se(null)},children:[s.jsx(Ft,{title:m("hub.forkPromptTitle"),description:m("hub.forkPromptHint"),onClose:()=>{Q||Se(null)}}),s.jsx("textarea",{autoFocus:!0,value:be,disabled:Q,onChange:e=>Je(e.target.value),onKeyDown:e=>{e.key==="Enter"&&(e.metaKey||e.ctrlKey)&&be.trim()&&!Q&&(e.preventDefault(),et.current?.())},placeholder:m("hub.forkPromptPlaceholder"),className:"w-full min-h-[120px] resize-y rounded-md border border-edge bg-panel-alt px-3 py-2 text-[13px] leading-relaxed text-fg outline-none focus:border-edge-h"}),s.jsxs("div",{className:"mt-4 flex items-center justify-end gap-2",children:[s.jsx(ze,{variant:"ghost",disabled:Q,onClick:()=>Se(null),children:m("modal.cancel")}),s.jsx(ze,{variant:"primary",disabled:Q||!be.trim(),onClick:()=>{et.current?.()},children:m(Q?"hub.forkSubmitting":"hub.forkSubmit")})]})]}),N&&xe.length>0&&s.jsx(Cn,{snapshot:xe[xe.length-1]},xe[xe.length-1].promptId)]})});export{or as SessionPanel};
|