pikiloom 0.4.8 → 0.4.10
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-Cpmeho1T.js +1 -0
- package/dashboard/dist/assets/{DirBrowser-MOD5cAPf.js → DirBrowser-DP0PmqYk.js} +1 -1
- package/dashboard/dist/assets/{ExtensionsTab-B9X_3L3B.js → ExtensionsTab-CAsex0fD.js} +1 -1
- package/dashboard/dist/assets/{IMAccessTab-CytKG9TY.js → IMAccessTab-CKRgP8fO.js} +1 -1
- package/dashboard/dist/assets/{Modal-ZOB1qJrT.js → Modal-e5zVwIox.js} +1 -1
- package/dashboard/dist/assets/{Modals-DLsZa6vC.js → Modals-B2k-gnZH.js} +1 -1
- package/dashboard/dist/assets/{Select-DMKejUbS.js → Select-BBP3aON8.js} +1 -1
- package/dashboard/dist/assets/{SessionPanel-DXdnwcvU.js → SessionPanel-b2PrnaOi.js} +1 -1
- package/dashboard/dist/assets/{SystemTab-YPeM7KNA.js → SystemTab-BDPugAG9.js} +1 -1
- package/dashboard/dist/assets/{index-gXOsku2L.js → index-BJL-XxHY.js} +2 -2
- package/dashboard/dist/assets/{index-DnZulXm9.js → index-C4JSCVlv.js} +3 -3
- package/dashboard/dist/assets/{shared-vtx3AxNk.js → shared-DxKugyn4.js} +1 -1
- package/dashboard/dist/index.html +1 -1
- package/dist/agent/drivers/claude-tui.js +59 -3
- package/dist/core/config/runtime-config.js +4 -1
- package/package.json +1 -1
- package/dashboard/dist/assets/AgentTab-B87z-S00.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as s,j as e,a as H}from"./react-vendor-C7Sl8SE7.js";import{c}from"./index-
|
|
1
|
+
import{r as s,j as e,a as H}from"./react-vendor-C7Sl8SE7.js";import{c}from"./index-BJL-XxHY.js";function y(u,h){return!!(u&&h instanceof Node&&u.contains(h))}function M({value:u,options:h,onChange:j,className:g,placeholder:l="—",disabled:x=!1,readOnly:f=!1}){const p=h.find(t=>t.value===u),w=f||h.length<=1,[a,m]=s.useState(!1),[n,i]=s.useState(null),o=s.useRef(null),_=s.useRef(null);if(s.useEffect(()=>{if(!a)return;const t=d=>{y(o.current,d.target)||y(_.current,d.target)||m(!1)},r=d=>{d.key==="Escape"&&m(!1)};return document.addEventListener("mousedown",t),document.addEventListener("keydown",r),()=>{document.removeEventListener("mousedown",t),document.removeEventListener("keydown",r)}},[a]),s.useLayoutEffect(()=>{if(!a)return;const t=()=>{const r=o.current;if(!r)return;const d=r.getBoundingClientRect(),k=window.innerHeight-d.bottom-12,E=d.top-12,N=k<220&&E>k,L=Math.max(140,Math.min(260,N?E:k));i({left:d.left,top:N?Math.max(12,d.top-L-8):d.bottom+8,width:d.width,maxHeight:L})};return t(),window.addEventListener("resize",t),window.addEventListener("scroll",t,!0),()=>{window.removeEventListener("resize",t),window.removeEventListener("scroll",t,!0)}},[a]),w)return e.jsx("div",{className:c("flex h-9 w-full items-center rounded-md border border-edge bg-panel-alt px-3 text-[13px] text-fg-5 shadow-none",x&&"cursor-not-allowed",g),children:e.jsx("span",{className:c("truncate",!p&&"text-fg-6"),children:p?.label||l})});const b=t=>{x||(j(t),m(!1))},v=a&&n?H.createPortal(e.jsx("div",{ref:_,role:"listbox",className:"fixed z-[220] overflow-hidden rounded-xl border border-edge-h bg-[var(--th-dropdown)] p-1.5 shadow-[0_24px_64px_rgba(2,6,23,0.22)] backdrop-blur-xl",style:{left:n.left,top:n.top,width:n.width},children:e.jsx("div",{className:"overflow-y-auto",style:{maxHeight:n.maxHeight},children:h.map(t=>{const r=t.value===u;return e.jsxs("button",{type:"button",role:"option","aria-selected":r,onClick:()=>b(t.value),className:c("flex w-full items-start gap-2 rounded-lg px-3 py-2 text-left text-[13px] transition-colors duration-200",r?"bg-panel text-fg shadow-[inset_0_1px_0_rgba(255,255,255,0.03)]":"text-fg-3 hover:bg-panel-alt hover:text-fg-2"),children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-baseline gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate",children:t.label}),t.meta&&e.jsx("span",{className:"shrink-0 font-mono text-[10px] text-fg-5",children:t.meta})]}),t.description&&e.jsx("div",{className:"mt-0.5 truncate font-mono text-[10px] leading-relaxed text-fg-5",children:t.description})]}),r&&e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"mt-0.5 shrink-0 text-fg-4",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})})]},t.value)})})}),document.body):null;return e.jsxs("div",{ref:o,className:c("relative",g),children:[e.jsxs("button",{type:"button",disabled:x,"aria-haspopup":"listbox","aria-expanded":a,onClick:()=>m(t=>!t),className:c("flex h-9 w-full items-center rounded-md border border-control-border bg-control px-3 pr-8 text-left text-[13px] text-fg shadow-sm","transition-[border-color,box-shadow,background] duration-200 outline-none","hover:border-control-border-h hover:bg-control-h","focus-visible:border-control-border-h focus-visible:shadow-[0_0_0_4px_var(--th-glow-a)]","disabled:cursor-not-allowed disabled:bg-panel-alt disabled:border-edge disabled:text-fg-5","disabled:shadow-none disabled:hover:border-edge disabled:hover:bg-panel-alt",a&&"border-control-border-h bg-control-h shadow-[0_0_0_4px_var(--th-glow-a)]"),children:[e.jsx("span",{className:c("min-w-0 flex-1 truncate",!p&&"text-fg-5"),children:p?.label||l}),e.jsx("span",{className:c("pointer-events-none absolute inset-y-0 right-3 flex items-center text-fg-4 transition-transform duration-200",a&&"rotate-180"),children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})})]}),v]})}function B({value:u,options:h,onChange:j,renderIcon:g}){const[l,x]=s.useState(!1),[f,p]=s.useState(null),w=s.useRef(null),a=s.useRef(null);s.useEffect(()=>{if(!l)return;const n=o=>{y(w.current,o.target)||y(a.current,o.target)||x(!1)},i=o=>{o.key==="Escape"&&x(!1)};return document.addEventListener("mousedown",n),document.addEventListener("keydown",i),()=>{document.removeEventListener("mousedown",n),document.removeEventListener("keydown",i)}},[l]),s.useLayoutEffect(()=>{if(!l)return;const n=()=>{const i=w.current;if(!i)return;const o=i.getBoundingClientRect(),b=window.innerHeight-o.bottom-12,v=o.top-12,t=b<220&&v>b,r=Math.max(140,Math.min(260,t?v:b));p({left:o.left,top:t?Math.max(12,o.top-r-8):o.bottom+8,width:Math.max(o.width,160),maxHeight:r})};return n(),window.addEventListener("resize",n),window.addEventListener("scroll",n,!0),()=>{window.removeEventListener("resize",n),window.removeEventListener("scroll",n,!0)}},[l]);const m=l&&f?H.createPortal(e.jsx("div",{ref:a,role:"listbox",className:"fixed z-[220] overflow-hidden rounded-xl border border-edge-h bg-[var(--th-dropdown)] p-1.5 shadow-[0_24px_64px_rgba(2,6,23,0.22)] backdrop-blur-xl",style:{left:f.left,top:f.top,width:f.width},children:e.jsx("div",{className:"overflow-y-auto",style:{maxHeight:f.maxHeight},children:h.map(n=>{const i=n.value===u;return e.jsxs("button",{type:"button",role:"option","aria-selected":i,onClick:()=>{j(n.value),x(!1)},className:c("flex w-full items-center gap-2.5 rounded-lg px-2.5 py-2 text-left text-[13px] transition-colors duration-200",i?"bg-panel text-fg shadow-[inset_0_1px_0_rgba(255,255,255,0.03)]":"text-fg-3 hover:bg-panel-alt hover:text-fg-2"),children:[g(n.value),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:n.label}),i&&e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"shrink-0 text-fg-4",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})})]},n.value)})})}),document.body):null;return e.jsxs("div",{ref:w,className:"relative shrink-0",children:[e.jsxs("button",{type:"button","aria-haspopup":"listbox","aria-expanded":l,onClick:()=>x(n=>!n),className:c("inline-flex items-center gap-1.5 rounded-lg border border-edge bg-inset px-2 py-1.5","transition-[border-color,box-shadow,background] duration-200 outline-none","hover:border-edge-h hover:bg-panel","focus-visible:border-edge-h focus-visible:shadow-[0_0_0_4px_var(--th-glow-a)]",l&&"border-edge-h bg-panel shadow-[0_0_0_4px_var(--th-glow-a)]"),children:[g(u),e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:c("text-fg-5 transition-transform duration-200",l&&"rotate-180"),children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),m]})}export{B as I,M as S};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as t,j as n}from"./react-vendor-C7Sl8SE7.js";import{c as mt,I as gt,S as ke,i as Se,a as T,u as We,d as ht,g as pt,h as xt,s as kt,K as St}from"./index-gXOsku2L.js";import{l as bt,n as Xe,m as vt,a as yt,b as It,p as Tt,u as jt,c as Rt,T as wt,R as Nt,U as Ot,d as Lt,e as Mt,f as Ct,L as Et,I as At}from"./index-DnZulXm9.js";import{M as Ge,a as Ye}from"./Modal-ZOB1qJrT.js";import"./router-DHISdpPk.js";import"./Select-DMKejUbS.js";import"./DirBrowser-MOD5cAPf.js";import"./markdown-DxQYQFeH.js";import"./ExtensionsTab-B9X_3L3B.js";function Ft({snapshot:i}){const[r,p]=t.useState(i.currentIndex??0),[M,j]=t.useState(""),[x,h]=t.useState(!1),[W,k]=t.useState(null);t.useEffect(()=>{p(i.currentIndex??0),j(""),k(null)},[i.promptId,i.currentIndex]);const C=i.questions||[],b=C[r]||null,X=C.length,w=!!(b?.options&&b.options.length),d=w?!!b?.allowFreeform:!0,H=a=>{a&&(p(m=>m+1),j(""))},ne=async a=>{if(!x){h(!0),k(null);try{const m=await T.interactionSelectOption(i.promptId,a);if(!m.ok){k(m.error||"Failed to submit selection.");return}H(m.advanced)}catch(m){k(m?.message||"Network error.")}finally{h(!1)}}},N=async()=>{if(x)return;const a=M.trim();if(!a&&!b?.allowEmpty){k("Please enter a response.");return}h(!0),k(null);try{const m=await T.interactionSubmitText(i.promptId,a);if(!m.ok){k(m.error||"Failed to submit answer.");return}H(m.advanced)}catch(m){k(m?.message||"Network error.")}finally{h(!1)}},f=async()=>{if(!x){h(!0),k(null);try{const a=await T.interactionSkip(i.promptId);if(!a.ok){k(a.error||"Failed to skip.");return}H(a.advanced)}catch(a){k(a?.message||"Network error.")}finally{h(!1)}}},P=async()=>{if(!x){h(!0);try{await T.interactionCancel(i.promptId)}catch{}}},V=t.useMemo(()=>{const a=[];return i.hint&&a.push(i.hint),X>1&&a.push(`Question ${r+1} of ${X}`),a.join(" · ")||void 0},[i.hint,r,X]);return n.jsxs(Ge,{open:!0,onClose:P,wide:w&&(b?.options?.length||0)>3,children:[n.jsx(Ye,{title:i.title||"Pikiloom needs your input",description:V,onClose:P}),b?n.jsxs("div",{className:"space-y-4",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-xs font-medium uppercase tracking-wide text-fg-5",children:b.header||"Question"}),n.jsx("div",{className:"mt-1 whitespace-pre-wrap text-sm leading-relaxed text-fg",children:b.prompt})]}),w&&n.jsx("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2",children:(b.options||[]).map(a=>n.jsxs("button",{type:"button",disabled:x,onClick:()=>ne(a.value||a.label),className:mt("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:[n.jsx("div",{className:"font-medium text-fg group-hover:text-fg",children:a.label}),a.description&&n.jsx("div",{className:"mt-0.5 text-xs leading-snug text-fg-4",children:a.description})]},a.value||a.label))}),d&&n.jsx("div",{children:n.jsx(gt,{value:M,onChange:a=>j(a.target.value),onKeyDown:a=>{a.key==="Enter"&&!a.shiftKey&&!x&&(a.preventDefault(),N())},placeholder:w?"Or type a custom answer…":"Type your answer…",disabled:x,autoFocus:!w})}),W&&n.jsx("div",{className:"rounded-md border border-red-300/40 bg-red-500/10 px-3 py-2 text-xs text-red-600",children:W}),n.jsxs("div",{className:"flex items-center justify-between gap-3",children:[n.jsx("div",{className:"text-xs text-fg-5",children:x?n.jsxs("span",{className:"inline-flex items-center gap-2",children:[n.jsx(ke,{})," Submitting…"]}):n.jsxs("span",{children:["Press ",n.jsx("kbd",{className:"rounded border border-edge bg-panel-alt px-1.5 py-0.5 text-[10px] uppercase",children:"Enter"})," to send"]})}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(Se,{variant:"ghost",size:"sm",onClick:f,disabled:x,children:"Skip"}),d&&n.jsx(Se,{variant:"primary",size:"sm",onClick:N,disabled:x||!M.trim()&&!b.allowEmpty,children:"Submit"})]})]})]}):n.jsxs("div",{className:"py-6 text-center text-sm text-fg-5",children:[n.jsx(ke,{className:"mr-2 inline-block"})," Waiting for the agent…"]})]})}const Fe=12,Ve=160,Ht=96,Pt=20,z=new Map;function qt(i,r){return`${i}:${r}`}function Dt(i,r){for(z.delete(i),z.set(i,r);z.size>Pt;)z.delete(z.keys().next().value)}const Vt=t.memo(function({session:r,workdir:p,active:M=!0,onSessionChange:j,initialPendingPrompt:x,initialPendingImageUrls:h,onPendingPromptConsumed:W}){const k=We(e=>e.locale),C=We(e=>e.agentStatus?.agents?.find(s=>s.agent===r.agent)??null),b=C?.selectedEffort??null,X=C?.selectedModel??null,w=C?.byokProviderName??null,d=t.useMemo(()=>ht(k),[k]),H=pt(r.agent||""),ne=xt(r),N=!!x||!!(h&&h.length),[f,P]=t.useState(null),[V,a]=t.useState(!N),[m,He]=t.useState(!1),[g,q]=t.useState(null),[G,Y]=t.useState(!1),[se,be]=t.useState(null),[Je,Pe]=t.useState(0),[Ze,ve]=t.useState(null),[le,ae]=t.useState([]),[et,oe]=t.useState([]),[J,ye]=t.useState([]),[S,ue]=t.useState(x||null),[O,ce]=t.useState(h||[]),[tt,ie]=t.useState(null),Ie=t.useRef(null);Ie.current=tt;const[qe,D]=t.useState([]),De=t.useRef([]);De.current=qe;const Z=t.useRef(null),[rt,Ue]=t.useState(null),[de,ee]=t.useState(null),[te,Te]=t.useState(""),[E,je]=t.useState(!1),nt=!!C?.capabilities?.fork,Re=t.useRef(null),U=t.useRef(h||[]),L=t.useRef(g),$e=t.useRef(G);L.current=g,$e.current=G;const A=t.useRef(null),fe=t.useRef(null),$=t.useRef(!0),B=t.useRef(!1),me=t.useRef(null),we=t.useRef(!1),Q=t.useRef(N),re=t.useRef(!1),F=t.useRef(!1),Ne=t.useRef(!1),Oe=t.useRef(!1),Be=t.useRef({model:null,effort:null}),st=t.useCallback(e=>{Be.current=e},[]);t.useEffect(()=>{Ne.current||!N||(Ne.current=!0,x&&!S&&ue(x),h&&h.length&&!O.length&&(ce(h),U.current=h),a(!1),Pe(e=>e+1),W?.())},[N,W]);const v=t.useCallback(()=>{ue(null),ce(e=>{for(const s of e)URL.revokeObjectURL(s);return[]}),U.current=[],ie(null)},[]),K=t.useCallback(()=>{D(e=>{if(!e.length)return e;for(const s of e)for(const l of s.imageUrls)URL.revokeObjectURL(l);return[]}),Z.current=null},[]),Qe=t.useCallback((e,s)=>{const l=!!L.current||$e.current,o=s||[];if(l){const u=`local-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`;Z.current=u,D(c=>[...c,{localId:u,taskId:null,prompt:e||"",imageUrls:o}]);return}for(const u of U.current)URL.revokeObjectURL(u);Z.current=null,ue(e||null),ce(o),U.current=o,ie(null)},[]),lt=t.useCallback(e=>{const s=Z.current;if(s){Z.current=null,D(l=>{const o=l.findIndex(c=>c.localId===s);if(o<0)return l;const u=l.slice();return u[o]={...u[o],taskId:e},u});return}ie(e)},[]),at=t.useCallback(async()=>{if(!de)return;const e=te.trim();if(e){je(!0);try{const s=await T.forkSession(p,r.agent||"",r.sessionId,de.atTurn,e,{});if(!s.ok||!s.sessionKey){je(!1);return}const[l,o]=s.sessionKey.split(":");ee(null),Te(""),j?.({agent:l,sessionId:o,workdir:p})}finally{je(!1)}}},[de,te,p,r.agent,r.sessionId,j]);Re.current=at;const ge=t.useCallback(async(e,s={})=>{try{const l=await bt({workdir:p,agent:r.agent||"",sessionId:r.sessionId,rich:!0,turnOffset:e.turnOffset,turnLimit:e.turnLimit,lastNTurns:e.lastNTurns},{force:s.force});return l.ok?Xe(l):null}catch{return null}},[p,r.agent,r.sessionId]),y=t.useCallback(async({keepOlder:e,force:s=!1,scrollToBottom:l=!1})=>{const o=r.sessionId;if(me.current===o)return!1;me.current=o;try{const u=await ge({turnOffset:0,turnLimit:Fe},{force:s});if(!u||r.sessionId!==o)return!1;if(l&&(B.current=!0),P(c=>!c||!e?u:vt(c,u)),a(!1),re.current&&(re.current=!1,v()),F.current){const c=F.current;F.current=!1;const I=c!==!0?c.taskId:null;L.current&&(c===!0||L.current.taskId===I)&&q(null)}return!0}finally{me.current===o&&(me.current=null)}},[ge,v,r.sessionId]),he=t.useCallback(async()=>{if(!f?.hasOlder||we.current)return;const e=A.current;e&&(fe.current={scrollHeight:e.scrollHeight,scrollTop:e.scrollTop}),we.current=!0,He(!0);try{const s=await ge({turnOffset:Math.max(0,f.totalTurns-f.startTurn),turnLimit:Fe});s?P(l=>l?yt(l,s):s):fe.current=null}finally{we.current=!1,He(!1)}},[ge,f]),pe=t.useRef(null),_=t.useCallback(e=>{if(e?.sessionId&&e.sessionId!==r.sessionId&&(Oe.current=!0,Le.current=`${r.agent}:${e.sessionId}`,j?.({agent:r.agent||"",sessionId:e.sessionId,workdir:p})),!e){const l=pe.current;Y(!1),l==="streaming"?(re.current=!0,F.current=!0,y({keepOlder:!0,force:!0,scrollToBottom:$.current})):q(null),l==="done"?(v(),K()):l===null&&Q.current&&y({keepOlder:!0,force:!0}),l!==null&&(Q.current=!1),ve(null),be(null),ae([]),oe([]),ye([]),pe.current=null;return}if(be(e.phase),ve(e.taskId||null),ae(e.queuedTaskIds&&e.queuedTaskIds.length?e.queuedTaskIds:[]),oe(e.queuedTasks&&e.queuedTasks.length?e.queuedTasks:[]),ye(Array.isArray(e.interactions)&&e.interactions.length?e.interactions:[]),e.phase==="streaming"){if(F.current&&L.current&&L.current.taskId!==null&&L.current.taskId!==(e.taskId||null)&&!(e.text||"").trim()||q({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,startedAt:typeof e.startedAt=="number"?e.startedAt:null,error:null}),Y(!0),e.taskId&&e.taskId!==Ie.current){const o=De.current,u=o.findIndex(c=>c.taskId===e.taskId);if(u>=0){const c=o[u];for(const I of U.current)URL.revokeObjectURL(I);ue(c.prompt||null),ce(c.imageUrls),U.current=c.imageUrls,ie(e.taskId),D(I=>I.filter((dt,ft)=>ft!==u))}}$.current&&(B.current=!0)}else if(e.phase==="queued")q(null),Y(!1);else if(e.phase==="done"){Y(!1),q(I=>I?{...I,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,error:e.error}:I);const l=!!e.queuedTaskIds?.length,o=L.current,u=!!o&&It(o),c=!!e.incomplete&&u&&!l;pe.current!=="done"&&(l||(re.current=!0),F.current=c?!1:{taskId:e.taskId||null},y({keepOlder:!0,force:!0,scrollToBottom:$.current})),l||(Q.current=!1)}const s=new Set;if(e.taskId&&s.add(e.taskId),Array.isArray(e.queuedTaskIds))for(const l of e.queuedTaskIds)s.add(l);D(l=>{let o=!1;const u=[];for(const c of l)if(!c.taskId||s.has(c.taskId))u.push(c);else{for(const I of c.imageUrls)URL.revokeObjectURL(I);o=!0}return o?u:l}),pe.current=e.phase},[v,K,y,r.sessionId,r.agent,j,p]),Ke=t.useCallback(()=>{Q.current=!0,Pe(e=>e+1)},[]),ot=t.useCallback(async e=>{try{await T.recallSessionMessage(e),Ie.current===e&&v(),D(s=>{let l=!1;const o=[];for(const u of s)if(u.taskId===e){for(const c of u.imageUrls)URL.revokeObjectURL(c);l=!0}else o.push(u);return l?o:s}),ae(s=>s.filter(l=>l!==e)),oe(s=>s.filter(l=>l.taskId!==e)),ve(s=>s===e?null:s)}catch{}},[v]),ut=t.useCallback(async e=>{try{await T.steerSession(e)}catch{}},[]),ct=t.useCallback(async()=>{try{await T.stopSession(r.agent||"",r.sessionId)}catch{}},[r.agent,r.sessionId]),xe=qt(r.agent||"",r.sessionId);t.useEffect(()=>{if(Oe.current){Oe.current=!1;let u=!1;return y({keepOlder:!0,force:!0}).finally(()=>{u||a(!1)}),()=>{u=!0}}let e=!1;const s=Tt({workdir:p,agent:r.agent||"",sessionId:r.sessionId,rich:!0,turnOffset:0,turnLimit:Fe},{allowStale:!0}),l=N&&!Ne.current,o=s?.ok?Xe(s):z.get(xe)||null;return a(l?!1:!o),P(o),q(null),Y(!1),be(null),ae([]),oe([]),ye([]),l||(v(),K(),Q.current=!1,re.current=!1,F.current=!1),$.current=!0,B.current=!0,l||y({keepOlder:!1,force:!0}).finally(()=>{e||a(!1)}),()=>{e=!0}},[y,r.agent,r.sessionId,p,xe,v,K]),t.useEffect(()=>{f&&f.turns.length>0&&Dt(xe,f)},[xe,f]),t.useEffect(()=>{M&&y({keepOlder:!0,force:!0})},[M,y]);const Le=t.useRef(`${r.agent}:${r.sessionId}`);Le.current=`${r.agent}:${r.sessionId}`,jt("stream-update",t.useCallback(e=>{e.key===Le.current&&_(e.snapshot??null)},[_])),t.useEffect(()=>{let e=!0;return T.getSessionStreamState(r.agent||"",r.sessionId).then(s=>{e&&_(s.state)}).catch(()=>{}),()=>{e=!1}},[_,r.agent,r.sessionId,Je]),Rt(t.useCallback(()=>{T.getSessionStreamState(r.agent||"",r.sessionId).then(e=>{_(e.state)}).catch(()=>{}),y({keepOlder:!0,force:!0})},[_,r.agent,r.sessionId,y])),t.useEffect(()=>{!Q.current&&ne!=="running"&&!G&&!g&&!se&&le.length===0&&(v(),K())},[ne,G,g,se,le.length,v,K]),t.useLayoutEffect(()=>{const e=fe.current,s=A.current;!e||!s||(fe.current=null,s.scrollTop=e.scrollTop+(s.scrollHeight-e.scrollHeight))},[f?.turns.length]),t.useLayoutEffect(()=>{if(!B.current)return;const e=A.current;e&&(B.current=!1,e.scrollTop=e.scrollHeight,requestAnimationFrame(()=>{$.current&&(e.scrollTop=e.scrollHeight)}))},[f,g]),t.useLayoutEffect(()=>{if(!S)return;const e=A.current;e&&(e.scrollTop=e.scrollHeight)},[S]),t.useEffect(()=>{if(!f?.hasOlder||V||m)return;const e=A.current;e&&e.scrollHeight<=e.clientHeight+Ve&&he()},[f?.hasOlder,f?.turns.length,he,V,m]);const it=t.useCallback(()=>{const e=A.current;if(!e)return;const s=e.scrollHeight-e.scrollTop-e.clientHeight;$.current=s<=Ht,e.scrollTop<=Ve&&he()},[he]),Me=g?.model||r.model||X||null,Ce=g?.effort||r.thinkingEffort||b||null,_e=Me?kt(Me):null,Ee=St(r,{streaming:G,hasLiveStream:!!g,streamPhase:se,queuedTaskCount:le.length}),R=f?.turns||[],Ae=t.useMemo(()=>{if(!O.length||!R.length)return!1;const e=R[R.length-1];return!e.user||(e.user.text?.trim()||"")!==(S||"").trim()?!1:e.user.blocks.filter(l=>l.type==="image").length<O.length},[R,S,O.length]),ze=t.useMemo(()=>{let e=R;if(Ae){const l=e[e.length-1];e=[...e.slice(0,-1),{...l,user:null}]}if(!g||!e.length)return e;const s=e[e.length-1];return!s.assistant||S&&s.user?.text?.trim()!==S.trim()?e:[...e.slice(0,-1),{...s,assistant:null}]},[R,g,S,Ae]);return n.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[n.jsx("div",{ref:A,onScroll:it,className:"flex-1 overflow-y-auto overscroll-contain",children:V&&!S&&!O.length&&!g?n.jsx("div",{className:"flex items-center justify-center py-20",children:n.jsx(ke,{className:"h-5 w-5 text-fg-4"})}):ze.length===0&&!S&&!O.length&&!g&&!Ee?n.jsx("div",{className:"py-20 text-center text-[13px] text-fg-5",children:d("hub.noMessages")}):n.jsxs("div",{className:"max-w-[900px] mx-auto px-6 py-6 space-y-0",children:[(f?.hasOlder||m)&&n.jsxs("div",{className:"mb-4 flex items-center justify-center gap-2 text-[11px] text-fg-5",children:[m?n.jsx(ke,{className:"h-3 w-3 text-fg-5"}):n.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-fg-5/35"}),n.jsx("span",{children:d(m?"hub.loadingOlderTurns":"hub.loadOlderTurnsHint")})]}),r.migratedFrom?.kind==="fork"&&r.migratedFrom.sessionId&&n.jsxs("button",{type:"button",onClick:()=>j?.({agent:r.migratedFrom.agent||r.agent||"",sessionId:r.migratedFrom.sessionId,workdir:p}),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:`#${r.migratedFrom.sessionId.slice(0,8)}`,children:[n.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[n.jsx("circle",{cx:"6",cy:"6",r:"2"}),n.jsx("circle",{cx:"18",cy:"6",r:"2"}),n.jsx("circle",{cx:"12",cy:"20",r:"2"}),n.jsx("path",{d:"M6 8v3a3 3 0 0 0 3 3h6a3 3 0 0 0 3-3V8"}),n.jsx("path",{d:"M12 14v4"})]}),n.jsx("span",{children:d("hub.forkBadge")}),n.jsxs("span",{className:"font-mono",children:["#",r.migratedFrom.sessionId.slice(0,8)]}),typeof r.migratedFrom.forkedAtTurn=="number"&&n.jsxs("span",{className:"text-fg-5/70",children:["· ",d("hub.forkBadgeAt").replace("{turn}",String(r.migratedFrom.forkedAtTurn+1))]})]}),ze.map((e,s)=>{const l=(f?.startTurn||0)+s;return n.jsx(wt,{turn:e,turnIndex:l,agent:r.agent||"",meta:H,model:_e,effort:Ce,providerName:w,t:d,onResend:o=>{B.current=!0,Qe(o);const u=Be.current;T.sendSessionMessage(p,r.agent||"",r.sessionId,o,{model:u.model||Me||void 0,effort:u.effort||Ce||void 0}).then(c=>{c.ok&&Ke()}).catch(()=>{v()})},onEdit:o=>Ue(o),onFork:nt?o=>{Te(""),ee({atTurn:o})}:void 0},`${f?.startTurn||0}:${s}`)}),Ee&&n.jsx("div",{className:"mb-5 animate-in",children:n.jsx(Nt,{detail:Ee,t:d})}),(S||O.length>0)&&(Ae||!(S&&R.length>0&&R[R.length-1]?.user?.text?.trim()===S.trim()))&&n.jsxs("div",{className:"session-turn",children:[n.jsx(Ot,{text:S||"",blocks:O.map(e=>({type:"image",content:e})),t:d}),!g&&n.jsx("div",{className:"mt-3 mb-5 animate-in",children:n.jsx(Lt,{className:"text-fg-5"})})]}),g&&Mt(g)&&n.jsxs("div",{className:"mb-6",children:[n.jsx(Ct,{agent:r.agent||"",meta:H,model:_e,effort:Ce,providerName:w,previewMeta:g.previewMeta,liveStartedAt:g.phase==="streaming"?g.startedAt??null:null}),n.jsx(Et,{stream:g,t:d})]}),n.jsx("div",{className:"h-4"})]})}),n.jsx(At,{session:r,workdir:p,onStreamQueued:Ke,onSendStart:Qe,onSendTaskAssigned:lt,onSessionChange:j,t:d,streamPhase:se,streamTaskId:Ze,queuedTaskIds:le,queuedTasks:et,pendingQueuedSends:qe,onRecall:ot,onSteer:ut,onStopAll:ct,editDraft:rt,onEditDraftConsumed:()=>Ue(null),onSelectionChange:st}),de&&n.jsxs(Ge,{open:!0,onClose:()=>{E||ee(null)},children:[n.jsx(Ye,{title:d("hub.forkPromptTitle"),description:d("hub.forkPromptHint"),onClose:()=>{E||ee(null)}}),n.jsx("textarea",{autoFocus:!0,value:te,disabled:E,onChange:e=>Te(e.target.value),onKeyDown:e=>{e.key==="Enter"&&(e.metaKey||e.ctrlKey)&&te.trim()&&!E&&(e.preventDefault(),Re.current?.())},placeholder:d("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"}),n.jsxs("div",{className:"mt-4 flex items-center justify-end gap-2",children:[n.jsx(Se,{variant:"ghost",disabled:E,onClick:()=>ee(null),children:d("modal.cancel")}),n.jsx(Se,{variant:"primary",disabled:E||!te.trim(),onClick:()=>{Re.current?.()},children:d(E?"hub.forkSubmitting":"hub.forkSubmit")})]})]}),M&&J.length>0&&n.jsx(Ft,{snapshot:J[J.length-1]},J[J.length-1].promptId)]})});export{Vt as SessionPanel};
|
|
1
|
+
import{r as t,j as n}from"./react-vendor-C7Sl8SE7.js";import{c as mt,I as gt,S as ke,i as Se,a as T,u as We,d as ht,g as pt,h as xt,s as kt,K as St}from"./index-BJL-XxHY.js";import{l as bt,n as Xe,m as vt,a as yt,b as It,p as Tt,u as jt,c as Rt,T as wt,R as Nt,U as Ot,d as Lt,e as Mt,f as Ct,L as Et,I as At}from"./index-C4JSCVlv.js";import{M as Ge,a as Ye}from"./Modal-e5zVwIox.js";import"./router-DHISdpPk.js";import"./Select-BBP3aON8.js";import"./DirBrowser-DP0PmqYk.js";import"./markdown-DxQYQFeH.js";import"./ExtensionsTab-CAsex0fD.js";function Ft({snapshot:i}){const[r,p]=t.useState(i.currentIndex??0),[M,j]=t.useState(""),[x,h]=t.useState(!1),[W,k]=t.useState(null);t.useEffect(()=>{p(i.currentIndex??0),j(""),k(null)},[i.promptId,i.currentIndex]);const C=i.questions||[],b=C[r]||null,X=C.length,w=!!(b?.options&&b.options.length),d=w?!!b?.allowFreeform:!0,H=a=>{a&&(p(m=>m+1),j(""))},ne=async a=>{if(!x){h(!0),k(null);try{const m=await T.interactionSelectOption(i.promptId,a);if(!m.ok){k(m.error||"Failed to submit selection.");return}H(m.advanced)}catch(m){k(m?.message||"Network error.")}finally{h(!1)}}},N=async()=>{if(x)return;const a=M.trim();if(!a&&!b?.allowEmpty){k("Please enter a response.");return}h(!0),k(null);try{const m=await T.interactionSubmitText(i.promptId,a);if(!m.ok){k(m.error||"Failed to submit answer.");return}H(m.advanced)}catch(m){k(m?.message||"Network error.")}finally{h(!1)}},f=async()=>{if(!x){h(!0),k(null);try{const a=await T.interactionSkip(i.promptId);if(!a.ok){k(a.error||"Failed to skip.");return}H(a.advanced)}catch(a){k(a?.message||"Network error.")}finally{h(!1)}}},P=async()=>{if(!x){h(!0);try{await T.interactionCancel(i.promptId)}catch{}}},V=t.useMemo(()=>{const a=[];return i.hint&&a.push(i.hint),X>1&&a.push(`Question ${r+1} of ${X}`),a.join(" · ")||void 0},[i.hint,r,X]);return n.jsxs(Ge,{open:!0,onClose:P,wide:w&&(b?.options?.length||0)>3,children:[n.jsx(Ye,{title:i.title||"Pikiloom needs your input",description:V,onClose:P}),b?n.jsxs("div",{className:"space-y-4",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-xs font-medium uppercase tracking-wide text-fg-5",children:b.header||"Question"}),n.jsx("div",{className:"mt-1 whitespace-pre-wrap text-sm leading-relaxed text-fg",children:b.prompt})]}),w&&n.jsx("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2",children:(b.options||[]).map(a=>n.jsxs("button",{type:"button",disabled:x,onClick:()=>ne(a.value||a.label),className:mt("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:[n.jsx("div",{className:"font-medium text-fg group-hover:text-fg",children:a.label}),a.description&&n.jsx("div",{className:"mt-0.5 text-xs leading-snug text-fg-4",children:a.description})]},a.value||a.label))}),d&&n.jsx("div",{children:n.jsx(gt,{value:M,onChange:a=>j(a.target.value),onKeyDown:a=>{a.key==="Enter"&&!a.shiftKey&&!x&&(a.preventDefault(),N())},placeholder:w?"Or type a custom answer…":"Type your answer…",disabled:x,autoFocus:!w})}),W&&n.jsx("div",{className:"rounded-md border border-red-300/40 bg-red-500/10 px-3 py-2 text-xs text-red-600",children:W}),n.jsxs("div",{className:"flex items-center justify-between gap-3",children:[n.jsx("div",{className:"text-xs text-fg-5",children:x?n.jsxs("span",{className:"inline-flex items-center gap-2",children:[n.jsx(ke,{})," Submitting…"]}):n.jsxs("span",{children:["Press ",n.jsx("kbd",{className:"rounded border border-edge bg-panel-alt px-1.5 py-0.5 text-[10px] uppercase",children:"Enter"})," to send"]})}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(Se,{variant:"ghost",size:"sm",onClick:f,disabled:x,children:"Skip"}),d&&n.jsx(Se,{variant:"primary",size:"sm",onClick:N,disabled:x||!M.trim()&&!b.allowEmpty,children:"Submit"})]})]})]}):n.jsxs("div",{className:"py-6 text-center text-sm text-fg-5",children:[n.jsx(ke,{className:"mr-2 inline-block"})," Waiting for the agent…"]})]})}const Fe=12,Ve=160,Ht=96,Pt=20,z=new Map;function qt(i,r){return`${i}:${r}`}function Dt(i,r){for(z.delete(i),z.set(i,r);z.size>Pt;)z.delete(z.keys().next().value)}const Vt=t.memo(function({session:r,workdir:p,active:M=!0,onSessionChange:j,initialPendingPrompt:x,initialPendingImageUrls:h,onPendingPromptConsumed:W}){const k=We(e=>e.locale),C=We(e=>e.agentStatus?.agents?.find(s=>s.agent===r.agent)??null),b=C?.selectedEffort??null,X=C?.selectedModel??null,w=C?.byokProviderName??null,d=t.useMemo(()=>ht(k),[k]),H=pt(r.agent||""),ne=xt(r),N=!!x||!!(h&&h.length),[f,P]=t.useState(null),[V,a]=t.useState(!N),[m,He]=t.useState(!1),[g,q]=t.useState(null),[G,Y]=t.useState(!1),[se,be]=t.useState(null),[Je,Pe]=t.useState(0),[Ze,ve]=t.useState(null),[le,ae]=t.useState([]),[et,oe]=t.useState([]),[J,ye]=t.useState([]),[S,ue]=t.useState(x||null),[O,ce]=t.useState(h||[]),[tt,ie]=t.useState(null),Ie=t.useRef(null);Ie.current=tt;const[qe,D]=t.useState([]),De=t.useRef([]);De.current=qe;const Z=t.useRef(null),[rt,Ue]=t.useState(null),[de,ee]=t.useState(null),[te,Te]=t.useState(""),[E,je]=t.useState(!1),nt=!!C?.capabilities?.fork,Re=t.useRef(null),U=t.useRef(h||[]),L=t.useRef(g),$e=t.useRef(G);L.current=g,$e.current=G;const A=t.useRef(null),fe=t.useRef(null),$=t.useRef(!0),B=t.useRef(!1),me=t.useRef(null),we=t.useRef(!1),Q=t.useRef(N),re=t.useRef(!1),F=t.useRef(!1),Ne=t.useRef(!1),Oe=t.useRef(!1),Be=t.useRef({model:null,effort:null}),st=t.useCallback(e=>{Be.current=e},[]);t.useEffect(()=>{Ne.current||!N||(Ne.current=!0,x&&!S&&ue(x),h&&h.length&&!O.length&&(ce(h),U.current=h),a(!1),Pe(e=>e+1),W?.())},[N,W]);const v=t.useCallback(()=>{ue(null),ce(e=>{for(const s of e)URL.revokeObjectURL(s);return[]}),U.current=[],ie(null)},[]),K=t.useCallback(()=>{D(e=>{if(!e.length)return e;for(const s of e)for(const l of s.imageUrls)URL.revokeObjectURL(l);return[]}),Z.current=null},[]),Qe=t.useCallback((e,s)=>{const l=!!L.current||$e.current,o=s||[];if(l){const u=`local-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`;Z.current=u,D(c=>[...c,{localId:u,taskId:null,prompt:e||"",imageUrls:o}]);return}for(const u of U.current)URL.revokeObjectURL(u);Z.current=null,ue(e||null),ce(o),U.current=o,ie(null)},[]),lt=t.useCallback(e=>{const s=Z.current;if(s){Z.current=null,D(l=>{const o=l.findIndex(c=>c.localId===s);if(o<0)return l;const u=l.slice();return u[o]={...u[o],taskId:e},u});return}ie(e)},[]),at=t.useCallback(async()=>{if(!de)return;const e=te.trim();if(e){je(!0);try{const s=await T.forkSession(p,r.agent||"",r.sessionId,de.atTurn,e,{});if(!s.ok||!s.sessionKey){je(!1);return}const[l,o]=s.sessionKey.split(":");ee(null),Te(""),j?.({agent:l,sessionId:o,workdir:p})}finally{je(!1)}}},[de,te,p,r.agent,r.sessionId,j]);Re.current=at;const ge=t.useCallback(async(e,s={})=>{try{const l=await bt({workdir:p,agent:r.agent||"",sessionId:r.sessionId,rich:!0,turnOffset:e.turnOffset,turnLimit:e.turnLimit,lastNTurns:e.lastNTurns},{force:s.force});return l.ok?Xe(l):null}catch{return null}},[p,r.agent,r.sessionId]),y=t.useCallback(async({keepOlder:e,force:s=!1,scrollToBottom:l=!1})=>{const o=r.sessionId;if(me.current===o)return!1;me.current=o;try{const u=await ge({turnOffset:0,turnLimit:Fe},{force:s});if(!u||r.sessionId!==o)return!1;if(l&&(B.current=!0),P(c=>!c||!e?u:vt(c,u)),a(!1),re.current&&(re.current=!1,v()),F.current){const c=F.current;F.current=!1;const I=c!==!0?c.taskId:null;L.current&&(c===!0||L.current.taskId===I)&&q(null)}return!0}finally{me.current===o&&(me.current=null)}},[ge,v,r.sessionId]),he=t.useCallback(async()=>{if(!f?.hasOlder||we.current)return;const e=A.current;e&&(fe.current={scrollHeight:e.scrollHeight,scrollTop:e.scrollTop}),we.current=!0,He(!0);try{const s=await ge({turnOffset:Math.max(0,f.totalTurns-f.startTurn),turnLimit:Fe});s?P(l=>l?yt(l,s):s):fe.current=null}finally{we.current=!1,He(!1)}},[ge,f]),pe=t.useRef(null),_=t.useCallback(e=>{if(e?.sessionId&&e.sessionId!==r.sessionId&&(Oe.current=!0,Le.current=`${r.agent}:${e.sessionId}`,j?.({agent:r.agent||"",sessionId:e.sessionId,workdir:p})),!e){const l=pe.current;Y(!1),l==="streaming"?(re.current=!0,F.current=!0,y({keepOlder:!0,force:!0,scrollToBottom:$.current})):q(null),l==="done"?(v(),K()):l===null&&Q.current&&y({keepOlder:!0,force:!0}),l!==null&&(Q.current=!1),ve(null),be(null),ae([]),oe([]),ye([]),pe.current=null;return}if(be(e.phase),ve(e.taskId||null),ae(e.queuedTaskIds&&e.queuedTaskIds.length?e.queuedTaskIds:[]),oe(e.queuedTasks&&e.queuedTasks.length?e.queuedTasks:[]),ye(Array.isArray(e.interactions)&&e.interactions.length?e.interactions:[]),e.phase==="streaming"){if(F.current&&L.current&&L.current.taskId!==null&&L.current.taskId!==(e.taskId||null)&&!(e.text||"").trim()||q({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,startedAt:typeof e.startedAt=="number"?e.startedAt:null,error:null}),Y(!0),e.taskId&&e.taskId!==Ie.current){const o=De.current,u=o.findIndex(c=>c.taskId===e.taskId);if(u>=0){const c=o[u];for(const I of U.current)URL.revokeObjectURL(I);ue(c.prompt||null),ce(c.imageUrls),U.current=c.imageUrls,ie(e.taskId),D(I=>I.filter((dt,ft)=>ft!==u))}}$.current&&(B.current=!0)}else if(e.phase==="queued")q(null),Y(!1);else if(e.phase==="done"){Y(!1),q(I=>I?{...I,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,error:e.error}:I);const l=!!e.queuedTaskIds?.length,o=L.current,u=!!o&&It(o),c=!!e.incomplete&&u&&!l;pe.current!=="done"&&(l||(re.current=!0),F.current=c?!1:{taskId:e.taskId||null},y({keepOlder:!0,force:!0,scrollToBottom:$.current})),l||(Q.current=!1)}const s=new Set;if(e.taskId&&s.add(e.taskId),Array.isArray(e.queuedTaskIds))for(const l of e.queuedTaskIds)s.add(l);D(l=>{let o=!1;const u=[];for(const c of l)if(!c.taskId||s.has(c.taskId))u.push(c);else{for(const I of c.imageUrls)URL.revokeObjectURL(I);o=!0}return o?u:l}),pe.current=e.phase},[v,K,y,r.sessionId,r.agent,j,p]),Ke=t.useCallback(()=>{Q.current=!0,Pe(e=>e+1)},[]),ot=t.useCallback(async e=>{try{await T.recallSessionMessage(e),Ie.current===e&&v(),D(s=>{let l=!1;const o=[];for(const u of s)if(u.taskId===e){for(const c of u.imageUrls)URL.revokeObjectURL(c);l=!0}else o.push(u);return l?o:s}),ae(s=>s.filter(l=>l!==e)),oe(s=>s.filter(l=>l.taskId!==e)),ve(s=>s===e?null:s)}catch{}},[v]),ut=t.useCallback(async e=>{try{await T.steerSession(e)}catch{}},[]),ct=t.useCallback(async()=>{try{await T.stopSession(r.agent||"",r.sessionId)}catch{}},[r.agent,r.sessionId]),xe=qt(r.agent||"",r.sessionId);t.useEffect(()=>{if(Oe.current){Oe.current=!1;let u=!1;return y({keepOlder:!0,force:!0}).finally(()=>{u||a(!1)}),()=>{u=!0}}let e=!1;const s=Tt({workdir:p,agent:r.agent||"",sessionId:r.sessionId,rich:!0,turnOffset:0,turnLimit:Fe},{allowStale:!0}),l=N&&!Ne.current,o=s?.ok?Xe(s):z.get(xe)||null;return a(l?!1:!o),P(o),q(null),Y(!1),be(null),ae([]),oe([]),ye([]),l||(v(),K(),Q.current=!1,re.current=!1,F.current=!1),$.current=!0,B.current=!0,l||y({keepOlder:!1,force:!0}).finally(()=>{e||a(!1)}),()=>{e=!0}},[y,r.agent,r.sessionId,p,xe,v,K]),t.useEffect(()=>{f&&f.turns.length>0&&Dt(xe,f)},[xe,f]),t.useEffect(()=>{M&&y({keepOlder:!0,force:!0})},[M,y]);const Le=t.useRef(`${r.agent}:${r.sessionId}`);Le.current=`${r.agent}:${r.sessionId}`,jt("stream-update",t.useCallback(e=>{e.key===Le.current&&_(e.snapshot??null)},[_])),t.useEffect(()=>{let e=!0;return T.getSessionStreamState(r.agent||"",r.sessionId).then(s=>{e&&_(s.state)}).catch(()=>{}),()=>{e=!1}},[_,r.agent,r.sessionId,Je]),Rt(t.useCallback(()=>{T.getSessionStreamState(r.agent||"",r.sessionId).then(e=>{_(e.state)}).catch(()=>{}),y({keepOlder:!0,force:!0})},[_,r.agent,r.sessionId,y])),t.useEffect(()=>{!Q.current&&ne!=="running"&&!G&&!g&&!se&&le.length===0&&(v(),K())},[ne,G,g,se,le.length,v,K]),t.useLayoutEffect(()=>{const e=fe.current,s=A.current;!e||!s||(fe.current=null,s.scrollTop=e.scrollTop+(s.scrollHeight-e.scrollHeight))},[f?.turns.length]),t.useLayoutEffect(()=>{if(!B.current)return;const e=A.current;e&&(B.current=!1,e.scrollTop=e.scrollHeight,requestAnimationFrame(()=>{$.current&&(e.scrollTop=e.scrollHeight)}))},[f,g]),t.useLayoutEffect(()=>{if(!S)return;const e=A.current;e&&(e.scrollTop=e.scrollHeight)},[S]),t.useEffect(()=>{if(!f?.hasOlder||V||m)return;const e=A.current;e&&e.scrollHeight<=e.clientHeight+Ve&&he()},[f?.hasOlder,f?.turns.length,he,V,m]);const it=t.useCallback(()=>{const e=A.current;if(!e)return;const s=e.scrollHeight-e.scrollTop-e.clientHeight;$.current=s<=Ht,e.scrollTop<=Ve&&he()},[he]),Me=g?.model||r.model||X||null,Ce=g?.effort||r.thinkingEffort||b||null,_e=Me?kt(Me):null,Ee=St(r,{streaming:G,hasLiveStream:!!g,streamPhase:se,queuedTaskCount:le.length}),R=f?.turns||[],Ae=t.useMemo(()=>{if(!O.length||!R.length)return!1;const e=R[R.length-1];return!e.user||(e.user.text?.trim()||"")!==(S||"").trim()?!1:e.user.blocks.filter(l=>l.type==="image").length<O.length},[R,S,O.length]),ze=t.useMemo(()=>{let e=R;if(Ae){const l=e[e.length-1];e=[...e.slice(0,-1),{...l,user:null}]}if(!g||!e.length)return e;const s=e[e.length-1];return!s.assistant||S&&s.user?.text?.trim()!==S.trim()?e:[...e.slice(0,-1),{...s,assistant:null}]},[R,g,S,Ae]);return n.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[n.jsx("div",{ref:A,onScroll:it,className:"flex-1 overflow-y-auto overscroll-contain",children:V&&!S&&!O.length&&!g?n.jsx("div",{className:"flex items-center justify-center py-20",children:n.jsx(ke,{className:"h-5 w-5 text-fg-4"})}):ze.length===0&&!S&&!O.length&&!g&&!Ee?n.jsx("div",{className:"py-20 text-center text-[13px] text-fg-5",children:d("hub.noMessages")}):n.jsxs("div",{className:"max-w-[900px] mx-auto px-6 py-6 space-y-0",children:[(f?.hasOlder||m)&&n.jsxs("div",{className:"mb-4 flex items-center justify-center gap-2 text-[11px] text-fg-5",children:[m?n.jsx(ke,{className:"h-3 w-3 text-fg-5"}):n.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-fg-5/35"}),n.jsx("span",{children:d(m?"hub.loadingOlderTurns":"hub.loadOlderTurnsHint")})]}),r.migratedFrom?.kind==="fork"&&r.migratedFrom.sessionId&&n.jsxs("button",{type:"button",onClick:()=>j?.({agent:r.migratedFrom.agent||r.agent||"",sessionId:r.migratedFrom.sessionId,workdir:p}),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:`#${r.migratedFrom.sessionId.slice(0,8)}`,children:[n.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[n.jsx("circle",{cx:"6",cy:"6",r:"2"}),n.jsx("circle",{cx:"18",cy:"6",r:"2"}),n.jsx("circle",{cx:"12",cy:"20",r:"2"}),n.jsx("path",{d:"M6 8v3a3 3 0 0 0 3 3h6a3 3 0 0 0 3-3V8"}),n.jsx("path",{d:"M12 14v4"})]}),n.jsx("span",{children:d("hub.forkBadge")}),n.jsxs("span",{className:"font-mono",children:["#",r.migratedFrom.sessionId.slice(0,8)]}),typeof r.migratedFrom.forkedAtTurn=="number"&&n.jsxs("span",{className:"text-fg-5/70",children:["· ",d("hub.forkBadgeAt").replace("{turn}",String(r.migratedFrom.forkedAtTurn+1))]})]}),ze.map((e,s)=>{const l=(f?.startTurn||0)+s;return n.jsx(wt,{turn:e,turnIndex:l,agent:r.agent||"",meta:H,model:_e,effort:Ce,providerName:w,t:d,onResend:o=>{B.current=!0,Qe(o);const u=Be.current;T.sendSessionMessage(p,r.agent||"",r.sessionId,o,{model:u.model||Me||void 0,effort:u.effort||Ce||void 0}).then(c=>{c.ok&&Ke()}).catch(()=>{v()})},onEdit:o=>Ue(o),onFork:nt?o=>{Te(""),ee({atTurn:o})}:void 0},`${f?.startTurn||0}:${s}`)}),Ee&&n.jsx("div",{className:"mb-5 animate-in",children:n.jsx(Nt,{detail:Ee,t:d})}),(S||O.length>0)&&(Ae||!(S&&R.length>0&&R[R.length-1]?.user?.text?.trim()===S.trim()))&&n.jsxs("div",{className:"session-turn",children:[n.jsx(Ot,{text:S||"",blocks:O.map(e=>({type:"image",content:e})),t:d}),!g&&n.jsx("div",{className:"mt-3 mb-5 animate-in",children:n.jsx(Lt,{className:"text-fg-5"})})]}),g&&Mt(g)&&n.jsxs("div",{className:"mb-6",children:[n.jsx(Ct,{agent:r.agent||"",meta:H,model:_e,effort:Ce,providerName:w,previewMeta:g.previewMeta,liveStartedAt:g.phase==="streaming"?g.startedAt??null:null}),n.jsx(Et,{stream:g,t:d})]}),n.jsx("div",{className:"h-4"})]})}),n.jsx(At,{session:r,workdir:p,onStreamQueued:Ke,onSendStart:Qe,onSendTaskAssigned:lt,onSessionChange:j,t:d,streamPhase:se,streamTaskId:Ze,queuedTaskIds:le,queuedTasks:et,pendingQueuedSends:qe,onRecall:ot,onSteer:ut,onStopAll:ct,editDraft:rt,onEditDraftConsumed:()=>Ue(null),onSelectionChange:st}),de&&n.jsxs(Ge,{open:!0,onClose:()=>{E||ee(null)},children:[n.jsx(Ye,{title:d("hub.forkPromptTitle"),description:d("hub.forkPromptHint"),onClose:()=>{E||ee(null)}}),n.jsx("textarea",{autoFocus:!0,value:te,disabled:E,onChange:e=>Te(e.target.value),onKeyDown:e=>{e.key==="Enter"&&(e.metaKey||e.ctrlKey)&&te.trim()&&!E&&(e.preventDefault(),Re.current?.())},placeholder:d("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"}),n.jsxs("div",{className:"mt-4 flex items-center justify-end gap-2",children:[n.jsx(Se,{variant:"ghost",disabled:E,onClick:()=>ee(null),children:d("modal.cancel")}),n.jsx(Se,{variant:"primary",disabled:E||!te.trim(),onClick:()=>{Re.current?.()},children:d(E?"hub.forkSubmitting":"hub.forkSubmit")})]})]}),M&&J.length>0&&n.jsx(Ft,{snapshot:J[J.length-1]},J[J.length-1].promptId)]})});export{Vt as SessionPanel};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e,r as f}from"./react-vendor-C7Sl8SE7.js";import{G as v,c as C,H as G,u as x,d as F,a as $,i as w,R as L,v as g,x as O}from"./index-
|
|
1
|
+
import{j as e,r as f}from"./react-vendor-C7Sl8SE7.js";import{G as v,c as C,H as G,u as x,d as F,a as $,i as w,R as L,v as g,x as O}from"./index-BJL-XxHY.js";import{S as N}from"./shared-DxKugyn4.js";import"./router-DHISdpPk.js";function k(s){return Number.isFinite(s??NaN)?Math.max(0,Math.min(100,Number(s))):null}function S(s){return Number.isFinite(s??NaN)?Number(s).toFixed(2):null}function z(s){return s?[s.hostName||"—",s.platform,s.arch].filter(Boolean).join(" · "):""}function E(s,r){if(!s)return[];const o=s.totalMem||0,i=s.memoryUsed||o-(s.freeMem||0),t=k(s.memoryPercent||(o>0?i/o*100:0)),a=k(s.cpuUsage?.usedPercent),d=s.loadAverage||null,c=S(d?.one),p=S(d?.five),u=S(d?.fifteen),h=k(d?d.one/Math.max(s.cpuCount||1,1)*100:null),y=[{key:"cpu",label:r("sessions.cpu"),value:a!=null?`${a.toFixed(0)}%`:`${s.cpuCount} cores`,detail:[`${s.cpuCount} cores`,s.cpuModel||""].filter(Boolean),tone:a!=null&&a>=85?"warn":"ok",progressPercent:a},...c&&p&&u?[{key:"cpu-load",label:r("system.cpuLoad"),value:`1m ${c}`,detail:[`5m ${p}`,`15m ${u}`],tone:h!=null&&h>=85?"warn":"muted",progressPercent:h}]:[],{key:"memory",label:r("sessions.memory"),value:`${G(i)} / ${G(o)}`,detail:t!=null?`${t.toFixed(0)}%`:void 0,tone:t!=null&&t>=85?"warn":"ok",progressPercent:t}];if(s.disk){const m=k(parseFloat(String(s.disk.percent).replace("%","")));y.push({key:"disk",label:r("sessions.disk"),value:`${s.disk.used} / ${s.disk.total}`,detail:s.disk.percent,tone:m!=null&&m>=85?"warn":"muted",progressPercent:m})}else if(s.battery){const m=k(parseFloat(String(s.battery.percent).replace("%","")));y.push({key:"battery",label:r("sessions.battery"),value:s.battery.percent,detail:s.battery.state,tone:m!=null&&m<=20?"warn":"muted",progressPercent:m})}return y}function W(s){return s?Array.isArray(s)?s.join(" · "):s:""}function q({items:s,loading:r,className:o}){return r?e.jsx("div",{className:C("space-y-1",o),children:Array.from({length:4},(i,t)=>e.jsxs("div",{className:"grid grid-cols-[80px_auto_1fr] items-baseline gap-x-4 py-1",children:[e.jsx(v,{className:"h-3 w-12"}),e.jsx(v,{className:"h-3 w-24"}),e.jsx(v,{className:"h-3 w-28"})]},t))}):e.jsx("div",{className:C("flex flex-wrap items-baseline gap-x-5 gap-y-1.5",o),children:s.map(i=>{const t=W(i.detail);return e.jsxs("div",{className:"inline-flex items-baseline gap-1.5 whitespace-nowrap",title:t||void 0,children:[e.jsx("span",{className:"text-[10px] font-medium uppercase tracking-[0.12em] text-fg-5",children:i.label}),e.jsx("span",{className:"font-mono text-[12px] tabular-nums text-fg-2",children:i.value}),t&&e.jsxs("span",{className:"text-[11px] text-fg-5",children:["· ",t]})]},i.key)})})}const B=[{key:"screenRecording",labelKey:"perm.screenRecording",reasonZh:"用于截图与界面分析",reasonEn:"For screenshots and UI inspection",guidePathKey:"perm.pathScreenRecording",icon:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"4",y:"5.5",width:"11.5",height:"10",rx:"2.4"}),e.jsx("path",{d:"m17.5 8.4 2.7-1.5v7.2l-2.7-1.5"}),e.jsx("circle",{cx:"9.75",cy:"10.5",r:"1.1",fill:"currentColor",stroke:"none"})]})},{key:"fullDiskAccess",labelKey:"perm.fullDiskAccess",reasonZh:"访问桌面、下载等受保护目录",reasonEn:"Access to Desktop, Downloads and other protected folders",guidePathKey:"perm.pathFullDiskAccess",icon:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"6.2",y:"10.1",width:"11.6",height:"8.6",rx:"2.6"}),e.jsx("path",{d:"M9 10V7.8a3 3 0 1 1 6 0V10"}),e.jsx("circle",{cx:"12",cy:"13.5",r:"0.9",fill:"currentColor",stroke:"none"}),e.jsx("path",{d:"M12 14.6v1.8"})]})}];function H(s){return s==="zh-CN"?{introWithHost:"请在 macOS 中为 {hostApp} 开启以下权限。",intro:"请在 macOS 中开启以下权限。",status:"状态",summary:"系统位置",loading:"检查中",needsGrant:"需要授权",granted:"已授权",authorize:"授权",openSettings:"前往设置",refreshState:"刷新状态",checking:"检查中...",hostGranted:"{hostApp} 已可直接使用此权限。",hostGrantedFallback:"当前宿主应用已可直接使用此权限。",needsGrantDetail:"尚未授权,可通过右侧按钮发起系统授权。",needsSettingsDetail:"需要在系统设置中手动开启此权限。"}:{introWithHost:"Grant the following permissions to {hostApp} in macOS.",intro:"Grant the following permissions in macOS.",status:"Status",summary:"System path",loading:"Checking",needsGrant:"Needs access",granted:"Granted",authorize:"Authorize",openSettings:"Open settings",refreshState:"Refresh status",checking:"Checking...",hostGranted:"{hostApp} can use this permission now.",hostGrantedFallback:"The current host app can use this permission now.",needsGrantDetail:"Access has not been granted yet. Use the button on the right to trigger the macOS prompt.",needsSettingsDetail:"This permission needs to be enabled manually in System Settings."}}function I(){const s=x(n=>n.state),r=x(n=>n.locale),o=x(n=>n.reload),i=x(n=>n.toast),t=f.useMemo(()=>F(r),[r]),a=H(r),d=s?.permissions||{},c=s?.hostApp||null,p=!s,[u,h]=f.useState(null),y=f.useMemo(()=>B.map(n=>({...n,permission:d[n.key]})),[d]),m=f.useCallback(async n=>{if(!u){h(n);try{const l=await $.requestPermission(n);if(!l.ok){i(l.error||t("perm.requestFailed"),!1);return}l.action==="already_granted"?i(t("perm.alreadyGranted")):l.action==="prompted"?i(t("perm.promptOpened")):i(t("perm.settingsOpened")),await o()}catch(l){i(l instanceof Error?l.message:t("perm.requestFailed"),!1)}finally{h(l=>l===n?null:l)}}},[o,u,t,i]),M=f.useCallback(async()=>{await o()},[o]);return e.jsxs("div",{className:"animate-in space-y-3",children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx("div",{className:"text-[13px] leading-relaxed text-fg-4",children:c?a.introWithHost.replace("{hostApp}",c):a.intro})}),e.jsx(w,{variant:"outline",size:"sm",onClick:()=>{M()},children:a.refreshState})]}),e.jsx(L,{children:y.map(n=>{const l=n.permission,j=!!l?.granted,P=!!l&&l.checkable,A=p?a.loading:j?a.granted:a.needsGrant,D=p?"idle":j?"ok":"warn",b=p?a.loading:j?c?a.hostGranted.replace("{hostApp}",c):a.hostGrantedFallback:P?a.needsGrantDetail:a.needsSettingsDetail,R=p?a.checking:P?a.authorize:a.openSettings;return e.jsxs(g,{children:[e.jsx(g.Lead,{icon:n.icon,title:t(n.labelKey),subtitle:r==="zh-CN"?n.reasonZh:n.reasonEn}),e.jsx(g.Status,{children:e.jsx(O,{state:D,label:A})}),e.jsx(g.Field,{children:t(n.guidePathKey)}),e.jsx(g.Action,{children:!j&&e.jsx(w,{variant:"primary",size:"sm",disabled:p||!!u,onClick:()=>{m(n.key)},children:u===n.key?a.checking:R})}),b&&b!==A&&e.jsx(g.Description,{children:b})]},n.key)})})]})}function _({onOpenWorkdir:s}){const r=x(c=>c.state),o=x(c=>c.host),i=x(c=>c.locale),t=f.useMemo(()=>F(i),[i]),a=r?.bot?.workdir||r?.runtimeWorkdir||r?.config.workdir||"",d=z(o);return e.jsxs("div",{className:"animate-in space-y-3",children:[e.jsx(N,{className:"!p-3.5",children:e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"flex items-baseline gap-2",children:e.jsx("span",{className:"text-[13px] font-semibold tracking-tight text-fg",children:t("config.workdir")})}),e.jsx("div",{className:"mt-0.5 break-all font-mono text-[12px] leading-relaxed text-fg-2",children:a||t("sidebar.notSet")})]}),e.jsx(w,{variant:"outline",size:"sm",onClick:s,children:t("sidebar.switchDir")})]})}),e.jsxs(N,{className:"space-y-2 !p-3.5",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-x-3 gap-y-0.5",children:[e.jsxs("div",{className:"flex items-baseline gap-2 min-w-0",children:[e.jsx("span",{className:"text-[13px] font-semibold tracking-tight text-fg",children:t("app.systemInfo")}),e.jsx("span",{className:"truncate text-[11px] text-fg-5",children:d||t("status.loading")})]}),e.jsxs("div",{className:"text-[11px] text-fg-5",children:[r?.version?`Pikiloom v${r.version}`:"Pikiloom",r?.nodeVersion?` · Node ${r.nodeVersion}`:""]})]}),e.jsx(q,{items:E(o,t),loading:!o})]}),e.jsxs(N,{className:"space-y-2 !p-3.5",children:[e.jsx("div",{className:"text-[13px] font-semibold tracking-tight text-fg",children:t("tab.permissions")}),e.jsx(I,{})]})]})}export{_ as SystemTab};
|