From 2584c456443f4c23d740ff50f7792c6a327f62a9 Mon Sep 17 00:00:00 2001 From: CatJuly <83827003+CatJuly@users.noreply.github.com> Date: Wed, 5 Aug 2026 17:21:40 +0800 Subject: [PATCH] fix(ui): bind delete-project dialog to theme tokens so paper theme is readable The confirm dialog painted its panel with `var(--bg-surface, #1e1e2e)`, but `--bg-surface` is not defined by any stylesheet in the project. Every theme therefore fell through to the hardcoded dark `#1e1e2e`. That went unnoticed under the six dark themes, whose `--text` is light and so still contrasted against the dark panel. The paper theme is the only light palette: its `--text` is `#1e293b`, which put dark text on the dark panel at roughly 1.05:1 contrast and made the title and body invisible. Point the panel at `--bg-elevated` so it tracks the active palette, and give the title and body explicit `--text` / `--text-secondary` colors instead of relying on inherited color plus `opacity: 0.7`, which is equally unreliable over a light surface. Add a `--border` outline so the now-white panel still reads as a distinct layer above the scrim. Verified by hand across all seven themes. --- .../{index-Dw3OK9za.js => index-Cdi_JV6w.js} | 2 +- .../office_ui/frontend_dist/index.html | 28 +++++++++---------- .../components/ProjectSelector.tsx | 7 +++-- 3 files changed, 19 insertions(+), 18 deletions(-) rename opc/plugins/office_ui/frontend_dist/assets/{index-Dw3OK9za.js => index-Cdi_JV6w.js} (98%) diff --git a/opc/plugins/office_ui/frontend_dist/assets/index-Dw3OK9za.js b/opc/plugins/office_ui/frontend_dist/assets/index-Cdi_JV6w.js similarity index 98% rename from opc/plugins/office_ui/frontend_dist/assets/index-Dw3OK9za.js rename to opc/plugins/office_ui/frontend_dist/assets/index-Cdi_JV6w.js index 2f6ac6d..aa882ed 100644 --- a/opc/plugins/office_ui/frontend_dist/assets/index-Dw3OK9za.js +++ b/opc/plugins/office_ui/frontend_dist/assets/index-Cdi_JV6w.js @@ -174,7 +174,7 @@ Run anyway?`}[b]??b).replace(/\{(\w+)\}/g,(j,N)=>String(w?.[N]??`{${N}}`)));if(e `).trim()}function RC(e){const t=gv(e),n=PV(t),i=n.split(/\n{2,}/).map(r=>r.trim()).filter(Boolean);return i.length>1&&/^Verification:\s/i.test(i[i.length-1])?i.slice(0,-1).join(` `).trim():n}function PV(e){let t=String(e||"").trim();for(;;){const n=t.match(/^\*\*([^\r\n]{8,160}?)\*\*:(?:[ \t]+|\r?\n+)([\s\S]+)$/);if(!n)return t;const i=n[2].trim();if(i.length<80||i===t)return t;t=i}}function BV(e,t,n,i){if(!i)return n.content;const r=gv(e.content),o=gv(t.content);return!r||!o||r===o?n.content:r.endsWith(o)?e.content:o.endsWith(r)?t.content:n.content}function Il(e){const t=Or(e),n=new Set,i=typeof t.checkpoint_type=="string"?t.checkpoint_type.trim():"",r=typeof t.checkpoint_id=="string"?t.checkpoint_id.trim():"";for(const o of[e.id,typeof t.ui_message_id=="string"?t.ui_message_id:"",typeof t.result_delivery_id=="string"&&t.result_delivery_id.trim()?`delivery:${t.result_delivery_id.trim()}`:"",i&&r?`checkpoint:${i}:${r}`:""]){const a=String(o??"").trim();a&&n.add(a)}return n}function ll(e){return new Set([...Il(e)].map(t=>`${e.channelId}\0${t}`))}function $V(e){return e.startsWith("checkpoint:")||e.startsWith("delivery:")}function ci(e){return typeof e.timestamp=="number"?e.timestamp:0}function yv(e){return String(e.id??"").startsWith("msg-")}function JI(e){return!yv(e)}function AC(e){const t={};for(const n of e){if(!JI(n))continue;const i=ci(n);i>(t[n.channelId]??0)&&(t[n.channelId]=i)}return t}function HV(e,t,n){return n<=(e[t]??0)?e:{...e,[t]:n}}function FV(e,t){const n={};for(const i of e){if(!JI(i)||i.sender==="user")continue;const r=t[i.channelId]??0;ci(i)<=r||(n[i.channelId]=(n[i.channelId]??0)+1)}return n}function MC(e){const t=String(e.sender??"").trim().toLowerCase(),n=Or(e),i=typeof n.role=="string"?n.role.trim().toLowerCase():"";return t==="user"||i==="user"?"user":"assistant"}function DC(e){const t=Or(e),n=String(e.sender??"").trim().toLowerCase();let i=0;const r=eT(e);return r&&(i+=1e3+r),t.source==="engine"&&(i+=100),n&&n!=="system"&&(i+=20),n&&!["assistant","system","user"].includes(n)&&(i+=5),e.replyToId&&(i+=2),i+=Math.min(Object.keys(t).length,10),i}function OC(e){return String(Or(e).source??"").trim().toLowerCase()==="engine"}function eT(e){const t=Or(e),n=String(t.transcript_kind??"").trim();if(n)return TC[n]??0;const i=String(t.kind??"").trim();return TC[i]??0}function Tl(e){return eT(e)>0}function tT(e,t){if(e.channelId!==t.channelId)return!1;const n=Il(e),i=Il(t);for(const r of n)if(i.has(r))return!0;return!1}function mm(e,t){if(tT(e,t))return!0;if(e.channelId!==t.channelId||MC(e)!==MC(t)||RC(e.content)!==RC(t.content))return!1;const n=Tl(e)&&Tl(t);if(!n&&String(e.replyToId??"")!==String(t.replyToId??"")||!(OC(e)||OC(t)))return!1;const i=ci(e),r=ci(t);return!(!n&&i&&r&&Math.abs(i-r)>z0)}function pm(e,t,n=!1){let i=e,r=t;const o=yv(e),a=yv(t);o!==a?(i=o?t:e,r=o?e:t):(n||DC(t)>DC(e))&&(i=t,r=e);const c=[];for(const j of[r.mentions,i.mentions])for(const N of j??[])c.includes(N)||c.push(N);const d=Il(e),m=Il(t);let h=!1,p="";for(const j of d)m.has(j)&&($V(j)||(h=!0,p||(p=j)));const g=BV(e,t,i,h),x=String(Or(e).checkpoint_id??"").trim(),v=String(Or(t).checkpoint_id??"").trim(),b=!!x&&x===v,w=Tl(e)&&Tl(t),k=w?String(Or(e).ui_timeline_id??Or(t).ui_timeline_id??Uv(e)).trim():"",S={...Or(r),...Or(i)};return k&&(S.ui_timeline_id=k),{...r,...i,...p?{id:p}:{},content:g,metadata:S,mentions:c,timestamp:b||w?ci(e)||ci(t):ci(i)||ci(r)}}function LC(e){const t=[],n=new Map;for(const i of[...e].sort((r,o)=>ci(r)-ci(o))){const r=ll(i);let o=-1,a=!1;for(const d of r){const m=n.get(d);if(m!==void 0){o=m,a=t[m].id===i.id;break}}if(o===-1){const d=ci(i),m=Tl(i);for(let h=t.length-1;h>=0;h--){const p=ci(t[h]);if(!m&&d>0&&p>0&&d-p>z0)break;if(mm(t[h],i)){o=h;break}}}const c=o===-1?t.length:o;o===-1?t.push(i):t[o]=pm(t[o],i,a);for(const d of ll(t[c]))n.has(d)||n.set(d,c)}return t}function VV(e,t){const n=[...e],i=new Map;n.forEach((r,o)=>{for(const a of ll(r))i.set(a,o)});for(const r of[...t].sort((o,a)=>ci(o)-ci(a))){let o=-1;for(const a of ll(r)){const c=i.get(a);if(c!==void 0){o=c;break}}if(o<0){for(let a=n.length-1;a>=0;a-=1)if(mm(n[a],r)){o=a;break}}if(o<0)o=n.length,n.push(r);else{const a=n[o];n[o]=pm(a,r,a.id===r.id)}for(const a of ll(r))i.set(a,o);for(const a of ll(n[o]))i.set(a,o)}return n.sort((r,o)=>ci(r)===ci(o)?r.id.localeCompare(o.id):ci(r)-ci(o))}function UV(e,t){switch(t.type){case"SET":return t.channels;case"CLEAR":return[];case"ADD":return e.some(n=>n.id===t.channel.id)?e:[...e,t.channel];case"REMOVE":return e.filter(n=>n.id!==t.channelId);case"REMOVE_PARTICIPANT":return e.map(n=>({...n,participants:n.participants.filter(i=>i!==t.agentId)}));default:return e}}function GV(e,t){switch(t.type){case"SET":{const n=LC(t.messages);if(e.length===0)return n;const i=e.filter(r=>typeof r.id=="string"&&r.id.startsWith("msg-")&&!n.some(o=>mm(r,o)));return i.length===0?n:LC([...n,...i])}case"CLEAR":return[];case"ADD":{const n=ci(t.message);Il(t.message);let i=!1;for(let r=e.length-1;r>=0;r--){const o=ci(e[r]);if(!i&&n>0&&o>0&&n-o>z0&&(i=!0),tT(e[r],t.message)){const a=[...e];return a[r]=pm(e[r],t.message,e[r].id===t.message.id),a}if((Tl(t.message)||!i)&&mm(e[r],t.message)){const a=[...e];return a[r]=pm(e[r],t.message),a}}return[...e,t.message]}case"MERGE":return t.messages.length===0?e:VV(e,t.messages);case"MARK_SENDER_DELETED":return e.map(n=>n.sender===t.senderId?{...n,senderDeleted:!0,senderName:"[已删除的 Agent]"}:n);case"REMOVE_BY_CHANNEL":return e.filter(n=>n.channelId!==t.channelId);case"REMOVE_BY_TASK_ID":return e.filter(n=>n.channelId!==`session:${t.taskId}`&&n.metadata?.task_id!==t.taskId);default:return e}}function qV(){const[e,t]=C.useReducer(UV,[]),[n,i]=C.useReducer(GV,[]),[r,o]=C.useState({}),[a,c]=C.useState("default"),d=C.useRef(null),m=C.useMemo(()=>AC(n),[n]),h=C.useRef(m);h.current=m;const p=C.useMemo(()=>{const T={};for(const M of n)T[M.channelId]||(T[M.channelId]=[]),T[M.channelId].push(M);return T},[n]),g=C.useMemo(()=>FV(n,r),[n,r]),x=C.useCallback(T=>{const M={id:`msg-${zV()}`,channelId:T.channelId,sender:T.sender,senderName:T.senderName,content:T.content,timestamp:Date.now(),replyToId:T.replyToId,mentions:[],metadata:T.metadata};return i({type:"ADD",message:M}),M},[]),v=C.useCallback(T=>p[T]??[],[p]),b=C.useCallback(T=>g[T]??0,[g]),w=C.useCallback(T=>{const M=h.current[T]??0;M<=0||o(I=>HV(I,T,M))},[]),k=C.useCallback(T=>{i({type:"MARK_SENDER_DELETED",senderId:T})},[]),S=C.useCallback(T=>{t({type:"REMOVE_PARTICIPANT",agentId:T})},[]),j=C.useCallback(T=>{t({type:"REMOVE",channelId:`session:${T}`}),i({type:"REMOVE_BY_TASK_ID",taskId:T})},[]),N=C.useCallback(()=>{t({type:"CLEAR"}),i({type:"CLEAR"}),d.current=null,o({})},[]),L=C.useCallback((T,M,I)=>{const H=T||"default",Y=H!==a,P=d.current!==H;d.current=H,c(H),t({type:"SET",channels:M}),i(Y?{type:"SET",messages:I}:{type:"MERGE",messages:I}),P&&o(AC(I))},[a]),A=C.useCallback(T=>{i({type:"ADD",message:T})},[]),D=C.useCallback(T=>{i({type:"MERGE",messages:T})},[]),O=C.useCallback(T=>{t({type:"ADD",channel:T})},[]);return C.useMemo(()=>({scopeProjectId:a,channels:e,messages:n,sendMessage:x,getChannelMessages:v,getUnreadCount:b,markRead:w,markSenderDeleted:k,removeParticipant:S,removeSessionData:j,clear:N,initFromBackend:L,addMessageFromBackend:A,mergeMessagesFromBackend:D,addChannelFromBackend:O}),[a,e,n,x,v,b,w,k,S,j,N,L,A,D,O])}const Zm=4e3;function gl(e,t){return e.length>t?e.slice(-t):e}function xv(e,t,n){if(!e)return t;if(!t||e===t)return e;if(t.startsWith(e))return t;if(e.startsWith(t)||e.endsWith(t))return e;if(t.endsWith(e))return t;const i=Math.min(e.length,t.length);for(let r=i;r>0;r-=1)if(e.slice(-r)===t.slice(0,r))return`${e}${t.slice(r)}`;return n==="tool_call"&&/[}\]"]$/.test(e)&&!/^\s/.test(t)?`${e} -${t}`:`${e}${t}`}function WV(e,t){const n=e.trim().replace(/\s+/g," ");return n?n.length>120?`${n.slice(0,120).trimEnd()}...`:n:t||"Thinking"}function YV(e){return{timestamp:Number.isFinite(e.timestamp)?e.timestamp:Date.now(),type:e.type,summary:typeof e.summary=="string"?e.summary:"",detail:typeof e.detail=="string"&&e.detail?e.detail:void 0,turnId:typeof e.turnId=="string"&&e.turnId?e.turnId:void 0,itemId:typeof e.itemId=="string"&&e.itemId?e.itemId:void 0,streamId:typeof e.streamId=="string"&&e.streamId?e.streamId:void 0,toolCallId:typeof e.toolCallId=="string"&&e.toolCallId?e.toolCallId:void 0,permissionGroupKey:typeof e.permissionGroupKey=="string"&&e.permissionGroupKey?e.permissionGroupKey:void 0,seq:typeof e.seq=="number"&&Number.isFinite(e.seq)?e.seq:void 0,executionMode:typeof e.executionMode=="string"&&e.executionMode?e.executionMode:void 0}}function hm(e){const t=e.itemId||e.streamId;return t?`${e.type}:${e.turnId??""}:${t}`:e.toolCallId&&(e.type==="tool_call"||e.type==="autonomy")?`${e.type}:${e.turnId??""}:${e.toolCallId}`:e.permissionGroupKey&&e.type==="autonomy"?`${e.type}:${e.turnId??""}:${e.permissionGroupKey}`:""}function XV(e,t){const n=hm(e),i=hm(t);return n&&i?n===i:t.timestamp-e.timestamp>Zm||e.type!==t.type?!1:e.type==="thinking"||e.type==="assistant"?!0:e.type==="tool_call"?e.summary===t.summary:!1}function KV(e,t){return t.timestamp-e.timestamp<=Zm&&e.type===t.type&&e.summary===t.summary&&(e.detail??"")===(t.detail??"")}function ZV(e,t){if(e.type==="thinking"||e.type==="assistant"){const n=xv(e.detail??"",t.detail??"","thinking");return{timestamp:e.timestamp,type:e.type,summary:WV(n,t.summary||e.summary),detail:n||void 0,turnId:t.turnId??e.turnId,itemId:t.itemId??e.itemId,streamId:t.streamId??e.streamId,toolCallId:t.toolCallId??e.toolCallId,permissionGroupKey:t.permissionGroupKey??e.permissionGroupKey,seq:t.seq??e.seq,executionMode:t.executionMode??e.executionMode}}if(e.type==="tool_call"){const n=xv(e.detail??"",t.detail??"","tool_call");return{timestamp:e.timestamp,type:"tool_call",summary:t.summary||e.summary,detail:n||void 0,turnId:t.turnId??e.turnId,itemId:t.itemId??e.itemId,streamId:t.streamId??e.streamId,toolCallId:t.toolCallId??e.toolCallId,permissionGroupKey:t.permissionGroupKey??e.permissionGroupKey,seq:t.seq??e.seq,executionMode:t.executionMode??e.executionMode}}return t}function nT(e,t,n=100){const i=YV(t),r=hm(i),o=r?[...e].reverse().findIndex(d=>hm(d)===r):-1,a=o>=0?e.length-1-o:e.length-1,c=e[a];return c?r&&o>=0&&typeof c.seq=="number"&&typeof i.seq=="number"&&i.seq<=c.seq?e:KV(c,i)?gl([...e.slice(0,a),c,...e.slice(a+1)],n):XV(c,i)?gl([...e.slice(0,a),ZV(c,i),...e.slice(a+1)],n):gl([...e,i],n):[i]}function iT(e,t=100){return(Array.isArray(e)?e:[]).reduce((n,i)=>nT(n,i,t),[])}function QV(e){return{timestamp:Number.isFinite(e.timestamp)?e.timestamp:Date.now(),type:e.type,workItemProjectionId:typeof e.workItemProjectionId=="string"&&e.workItemProjectionId?e.workItemProjectionId:void 0,workItemTurnType:typeof e.workItemTurnType=="string"&&e.workItemTurnType?e.workItemTurnType:void 0,workItemProjectionTitle:typeof e.workItemProjectionTitle=="string"&&e.workItemProjectionTitle?e.workItemProjectionTitle:void 0,runtimeTaskId:typeof e.runtimeTaskId=="string"&&e.runtimeTaskId?e.runtimeTaskId:void 0,executionTurnId:typeof e.executionTurnId=="string"&&e.executionTurnId?e.executionTurnId:void 0,roleName:typeof e.roleName=="string"&&e.roleName?e.roleName:void 0,detail:typeof e.detail=="string"&&e.detail?e.detail:void 0}}function rT(e,t){return e.type===t.type&&(e.workItemProjectionId??"")===(t.workItemProjectionId??"")&&(e.workItemTurnType??"")===(t.workItemTurnType??"")&&(e.workItemProjectionTitle??"")===(t.workItemProjectionTitle??"")&&(e.executionTurnId??e.runtimeTaskId??"")===(t.executionTurnId??t.runtimeTaskId??"")&&(e.roleName??"")===(t.roleName??"")}function JV(e,t){return t.timestamp-e.timestamp<=Zm&&rT(e,t)&&(e.type==="thinking"||e.type==="tool_call")}function eU(e,t){return rT(e,t)&&(e.detail??"")===(t.detail??"")&&t.timestamp-e.timestamp<=Zm}function tU(e,t){const n=t.type==="tool_call"?"tool_call":"thinking";return{...e,...t,timestamp:t.timestamp,detail:xv(e.detail??"",t.detail??"",n)||void 0}}function sT(e,t,n=100){const i=QV(t),r=e[e.length-1];return r?eU(r,i)?gl([...e.slice(0,-1),{...r,timestamp:i.timestamp}],n):JV(r,i)?gl([...e.slice(0,-1),tU(r,i)],n):gl([...e,i],n):[i]}function oT(e,t=100){return(Array.isArray(e)?e:[]).reduce((n,i)=>sT(n,i,t),[])}function vv(e){const t=String(e??"").trim().toLowerCase();return t==="company"?"company":t==="org"||t==="custom"?"org":"task"}function nU(e){return String(e??"").trim().toLowerCase()==="custom"?"custom":"corporate"}function aT(e){const t=String(e.execMode??"").trim().toLowerCase(),n=String(e.companyProfile??"").trim().toLowerCase(),i=String(e.orgId??"").trim(),o=t.length>0?vv(t):n==="custom"||i?"org":vv(t);return o==="org"?{...e,execMode:"org",companyProfile:"custom",orgId:i||void 0}:o==="company"?{...e,execMode:"company",companyProfile:"corporate",orgId:void 0}:{...e,execMode:"task",companyProfile:void 0,orgId:void 0}}const gf=100,iU=new Set(["done","failed","cancelled"]);function rU(e,t,n){const i=n,r=new Map(t.filter(c=>c.projectId===i).map(c=>[c.taskId,c])),o=new Set,a=[];for(const c of e){if(c.projectId!==i)continue;const d=r.get(c.taskId);d?(a.push(d),o.add(c.taskId)):a.push(c)}for(const c of t)c.projectId!==i||o.has(c.taskId)||(a.push(c),o.add(c.taskId));return a}function sU(e,t){const n=g=>aT({...g,progressLog:iT(g.progressLog??[],gf),workItemLog:oT(g.workItemLog??[],gf)}),i=g=>{const x=String(g.execMode??"").trim().toLowerCase();return x==="company"||x==="org"||x==="custom"||!!g.isCompanyRuntime||!!g.parentSessionId||!!g.workItemProjectionId||!!g.roleWorkItems||!!g.executorRoleWorkItems||!!g.orgId},r=g=>{const x=String(g.execMode??"").trim().toLowerCase(),v=String(g.companyProfile??"").trim().toLowerCase(),b=String(g.orgId??"").trim();return x==="task"&&(!v||v==="corporate")&&!b&&!g.isCompanyRuntime&&!g.parentSessionId&&!g.workItemProjectionId&&!g.workItemRoleId&&!g.roleWorkItems&&!g.executorRoleWorkItems},o=(g,x)=>{const v=g.execMode,b=x.execMode;return!v||v==="task"&&b&&b!=="task"&&!r(g)&&(i(g)||i(x))?b:v},a=(g,x,v)=>{const b=g[v],w=x[v];return!b||b==="native"&&w&&w!=="native"?w:b},c=(g,x)=>Object.prototype.hasOwnProperty.call(g,x),d=(g,x,v)=>c(g,v)?g[v]:x[v],m=(g,x)=>{const v=typeof g.updatedAt=="number"&&Number.isFinite(g.updatedAt)?g.updatedAt:void 0,b=typeof x.updatedAt=="number"&&Number.isFinite(x.updatedAt)?x.updatedAt:void 0;return v===void 0?b??Date.now():b===void 0?v:Math.max(b,v)},h=(g,x)=>g.runtimeControlState==="suspending"&&x.runtimeControlState==="running"?{...x,runtimeControlState:"suspending",canStop:!1,canResume:g.canResume??!1,pendingRuntimeCheckpointId:g.pendingRuntimeCheckpointId??x.pendingRuntimeCheckpointId,stopIntentId:g.stopIntentId??x.stopIntentId}:x,p=(g,x,v)=>{const b=g[v];if(b!=null)return b;if(!(iU.has(g.status)||g.status!=="running"&&g.runtimeControlState!=="running"&&g.runtimeControlState!=="suspending"&&g.runtimeControlState!=="resuming"))return x[v]};switch(t.type){case"SET":{if(t.reset)return t.sessions.map(n);const x=new Map(e.map(v=>[v.taskId,v]));return t.sessions.map(v=>{const b=x.get(v.taskId);if(!b)return n(v);const w=h(b,v);return n({...v,updatedAt:m(v,b),execMode:o(v,b),preferredAgent:a(v,b,"preferredAgent"),draftAssistantText:b.draftAssistantText??v.draftAssistantText,draftUpdatedAt:b.draftUpdatedAt??v.draftUpdatedAt,draftIteration:b.draftIteration??v.draftIteration,draftTurnId:b.draftTurnId??v.draftTurnId,agentStatus:p(v,b,"agentStatus"),currentTool:p(v,b,"currentTool"),displayTool:p(v,b,"displayTool"),toolElapsedMs:p(v,b,"toolElapsedMs"),lastToolSummary:p(v,b,"lastToolSummary"),contextTokens:b.contextTokens??v.contextTokens,contextWindow:b.contextWindow??v.contextWindow,contextRemainingPct:b.contextRemainingPct??v.contextRemainingPct,inputTokens:b.inputTokens??v.inputTokens,outputTokens:b.outputTokens??v.outputTokens,totalTokens:b.totalTokens??v.totalTokens,turnCostUsd:b.turnCostUsd??v.turnCostUsd,sessionCostUsd:b.sessionCostUsd??v.sessionCostUsd,pendingPermissionCount:b.pendingPermissionCount??v.pendingPermissionCount,drainMode:b.drainMode??v.drainMode,workItemProjectionId:v.workItemProjectionId??b.workItemProjectionId,workItemTurnType:v.workItemTurnType??b.workItemTurnType,companyProfile:d(v,b,"companyProfile"),orgId:d(v,b,"orgId"),workItemRoleId:v.workItemRoleId??b.workItemRoleId,workItemRoleName:v.workItemRoleName??b.workItemRoleName,workItemGate:v.workItemGate??b.workItemGate,roleWorkItems:v.roleWorkItems??b.roleWorkItems,executorRoleWorkItems:v.executorRoleWorkItems??b.executorRoleWorkItems,employeeAssignment:v.employeeAssignment??b.employeeAssignment,selectedExecutionAgent:a(v,b,"selectedExecutionAgent"),runtimeControlState:w.runtimeControlState??b.runtimeControlState,canStop:w.canStop??b.canStop,canResume:w.canResume??b.canResume,resumeParentSessionId:v.resumeParentSessionId??b.resumeParentSessionId,pendingRuntimeCheckpointId:w.pendingRuntimeCheckpointId??b.pendingRuntimeCheckpointId,stopIntentId:w.stopIntentId??b.stopIntentId,residentStatus:b.residentStatus??v.residentStatus,actionableInboxCount:b.actionableInboxCount??v.actionableInboxCount,protocolBacklogCount:b.protocolBacklogCount??v.protocolBacklogCount,notificationBacklogCount:b.notificationBacklogCount??v.notificationBacklogCount,latestNotification:b.latestNotification??v.latestNotification,latestPreview:v.latestPreview??b.latestPreview,latestSender:v.latestSender??b.latestSender,latestMessageId:v.latestMessageId??b.latestMessageId,indexLoaded:v.indexLoaded??b.indexLoaded,detailLoaded:b.detailLoaded??v.detailLoaded,fullLoaded:b.fullLoaded??v.fullLoaded,hasMore:v.hasMore??b.hasMore,summaryHasMore:v.summaryHasMore??b.summaryHasMore,fullHasMore:v.fullHasMore??b.fullHasMore,detailLoading:v.detailLoading??b.detailLoading,detailError:v.detailError??b.detailError,viewGeneration:v.viewGeneration??b.viewGeneration,progressLog:b.progressLog&&b.progressLog.length>0?b.progressLog:v.progressLog,workItemLog:b.workItemLog&&b.workItemLog.length>0?b.workItemLog:v.workItemLog,lastRuntimeEventType:b.lastRuntimeEventType??v.lastRuntimeEventType,activeSubagents:b.activeSubagents??v.activeSubagents,permissionRequests:b.permissionRequests??v.permissionRequests,handoffContext:v.handoffContext??b.handoffContext,handoffTo:v.handoffTo??b.handoffTo})})}case"ADD":const g=n(t.session);return e.some(x=>x.taskId===t.session.taskId)?e.map(x=>x.taskId===t.session.taskId?n({...x,...g,progressLog:g.progressLog.length>0?g.progressLog:x.progressLog,workItemLog:(g.workItemLog??[]).length>0?g.workItemLog:x.workItemLog,messageCount:Math.max(x.messageCount??0,g.messageCount??0),updatedAt:Math.max(x.updatedAt??0,g.updatedAt??0),execMode:o(g,x),preferredAgent:a(g,x,"preferredAgent"),workItemProjectionId:g.workItemProjectionId??x.workItemProjectionId,workItemTurnType:g.workItemTurnType??x.workItemTurnType,companyProfile:d(g,x,"companyProfile"),orgId:d(g,x,"orgId"),workItemRoleId:g.workItemRoleId??x.workItemRoleId,workItemRoleName:g.workItemRoleName??x.workItemRoleName,workItemGate:g.workItemGate??x.workItemGate,roleWorkItems:g.roleWorkItems??x.roleWorkItems,executorRoleWorkItems:g.executorRoleWorkItems??x.executorRoleWorkItems,employeeAssignment:g.employeeAssignment??x.employeeAssignment,selectedExecutionAgent:a(g,x,"selectedExecutionAgent"),handoffContext:g.handoffContext??x.handoffContext,handoffTo:g.handoffTo??x.handoffTo,latestPreview:g.latestPreview??x.latestPreview,latestSender:g.latestSender??x.latestSender,latestMessageId:g.latestMessageId??x.latestMessageId,indexLoaded:g.indexLoaded??x.indexLoaded,detailLoaded:g.detailLoaded??x.detailLoaded,fullLoaded:g.fullLoaded??x.fullLoaded,hasMore:g.hasMore??x.hasMore,summaryHasMore:g.summaryHasMore??x.summaryHasMore,fullHasMore:g.fullHasMore??x.fullHasMore,detailLoading:g.detailLoading??x.detailLoading,detailError:g.detailError??x.detailError,viewGeneration:g.viewGeneration??x.viewGeneration}):x):[g,...e];case"UPDATE":return e.map(x=>x.taskId===t.taskId?(()=>{const v=h(x,t.partial);return n({...x,...v,updatedAt:m(v,x),runtimeControlState:v.runtimeControlState??x.runtimeControlState,canStop:v.canStop??x.canStop,canResume:v.canResume??x.canResume,resumeParentSessionId:v.resumeParentSessionId??x.resumeParentSessionId,pendingRuntimeCheckpointId:v.pendingRuntimeCheckpointId??x.pendingRuntimeCheckpointId,stopIntentId:v.stopIntentId??x.stopIntentId,roleWorkItems:v.roleWorkItems??x.roleWorkItems,executorRoleWorkItems:v.executorRoleWorkItems??x.executorRoleWorkItems,execMode:d(v,x,"execMode"),companyProfile:d(v,x,"companyProfile"),orgId:d(v,x,"orgId"),isCompanyRuntime:v.isCompanyRuntime??x.isCompanyRuntime,workItemProjectionId:v.workItemProjectionId??x.workItemProjectionId,workItemTurnType:v.workItemTurnType??x.workItemTurnType,workItemRoleId:v.workItemRoleId??x.workItemRoleId,workItemRoleName:v.workItemRoleName??x.workItemRoleName,workItemGate:v.workItemGate??x.workItemGate,employeeAssignment:v.employeeAssignment??x.employeeAssignment,selectedExecutionAgent:v.selectedExecutionAgent??x.selectedExecutionAgent,activeSubagents:v.activeSubagents??x.activeSubagents,permissionRequests:v.permissionRequests??x.permissionRequests,contextTokens:v.contextTokens??x.contextTokens,contextWindow:v.contextWindow??x.contextWindow,contextRemainingPct:v.contextRemainingPct??x.contextRemainingPct,inputTokens:v.inputTokens??x.inputTokens,outputTokens:v.outputTokens??x.outputTokens,totalTokens:v.totalTokens??x.totalTokens,turnCostUsd:v.turnCostUsd??x.turnCostUsd,sessionCostUsd:v.sessionCostUsd??x.sessionCostUsd,...t.partial.progressLog?{progressLog:t.partial.progressLog}:{},...t.partial.workItemLog?{workItemLog:t.partial.workItemLog}:{}})})():x);case"DELETE":return e.filter(x=>x.taskId!==t.taskId);case"APPEND_PROGRESS":return e.map(x=>x.taskId!==t.taskId?x:{...x,progressLog:nT(x.progressLog,t.entry,gf),updatedAt:Math.max(x.updatedAt,t.entry.timestamp)});case"APPEND_DRAFT":return e.map(x=>{if(x.taskId!==t.taskId)return x;const v=t.turnId??x.draftTurnId,b=!!t.turnId&&!!x.draftTurnId&&t.turnId!==x.draftTurnId;return{...x,draftAssistantText:`${b?"":x.draftAssistantText??""}${t.text}`,draftUpdatedAt:t.timestamp,draftIteration:t.iteration??x.draftIteration,draftTurnId:v,updatedAt:Math.max(x.updatedAt,t.timestamp)}});case"CLEAR_DRAFT":return e.map(x=>x.taskId===t.taskId?{...x,draftAssistantText:void 0,draftUpdatedAt:void 0,draftIteration:void 0,draftTurnId:void 0}:x);case"CLEAR_PROGRESS":return e.map(x=>x.taskId===t.taskId?{...x,progressLog:[]}:x);case"APPEND_WORK_ITEM_PROGRESS":return e.map(x=>x.taskId!==t.taskId?x:{...x,workItemLog:sT(x.workItemLog??[],t.entry,gf)});case"SET_COMPANY_RUNTIME":return e.map(x=>x.taskId===t.taskId?{...x,isCompanyRuntime:t.isCompanyRuntime}:x);default:return e}}function oU(){const[e,t]=C.useReducer(sU,[]),[n,i]=C.useState(null),[r,o]=C.useState("default"),a=C.useMemo(()=>e.find(S=>S.taskId===n)??null,[e,n]),c=C.useCallback(S=>{S.projectId===r&&t({type:"ADD",session:S})},[r]),d=C.useCallback(S=>{t({type:"DELETE",taskId:S})},[]),m=C.useCallback(S=>{i(S)},[]),h=C.useCallback((S,j)=>{t({type:"UPDATE",taskId:S,partial:j})},[]),p=C.useCallback((S,j)=>{t({type:"APPEND_PROGRESS",taskId:S,entry:j})},[]),g=C.useCallback((S,j,N,L)=>{t({type:"APPEND_DRAFT",taskId:S,text:j,iteration:N,turnId:L,timestamp:Date.now()})},[]),x=C.useCallback(S=>{t({type:"CLEAR_DRAFT",taskId:S})},[]),v=C.useCallback(S=>{t({type:"CLEAR_PROGRESS",taskId:S})},[]),b=C.useCallback((S,j)=>{t({type:"APPEND_WORK_ITEM_PROGRESS",taskId:S,entry:j})},[]),w=C.useCallback((S,j)=>{t({type:"SET_COMPANY_RUNTIME",taskId:S,isCompanyRuntime:j})},[]),k=C.useCallback((S,j,N)=>{const L=S||"default",A=L!==r,D=N?.preserveExistingWhenIncomingPartial&&!A?rU(e,j,L):j.filter(O=>O.projectId===L);o(L),t({type:"SET",sessions:D,reset:A}),i(O=>!A&&O&&(D.some(T=>T.taskId===O)||N?.preserveActiveWhenMissing)?O:null)},[r,e]);return C.useMemo(()=>({scopeProjectId:r,sessions:e,activeSessionId:n,activeSession:a,createSession:c,deleteSession:d,setActiveSession:m,updateSession:h,appendProgress:p,appendDraft:g,clearDraft:x,clearProgress:v,appendWorkItemProgress:b,setCompanyRuntime:w,initFromBackend:k}),[r,e,n,a,c,d,m,h,p,g,x,v,b,w,k])}function zC(e){return e.trim()||"default"}function aU(e,t){switch(t.type){case"SET":return{projects:t.projects,activeProjectId:zC(t.activeId)};case"ADD":return e.projects.some(n=>n.id===t.project.id)?e:{...e,projects:[...e.projects,t.project]};case"REMOVE":{const n=e.projects.filter(r=>r.id!==t.id),i=e.activeProjectId===t.id?"default":e.activeProjectId;return{projects:n,activeProjectId:i}}case"SET_ACTIVE":return{...e,activeProjectId:zC(t.id)};default:return e}}function lU(){const[e,t]=C.useReducer(aU,{projects:[{id:"default",name:"default"}],activeProjectId:"default"}),n=C.useCallback((a,c)=>{t({type:"SET",projects:a,activeId:c})},[]),i=C.useCallback(a=>{t({type:"ADD",project:a})},[]),r=C.useCallback(a=>{t({type:"REMOVE",id:a})},[]),o=C.useCallback(a=>{t({type:"SET_ACTIVE",id:a})},[]);return C.useMemo(()=>({projects:e.projects,activeProjectId:e.activeProjectId,initFromBackend:n,addProject:i,removeProject:r,setActiveProject:o}),[e,n,i,r,o])}const PC={active:{label:"Working",cls:"exec-badge-running"},waiting:{label:"Waiting",cls:"exec-badge-idle"},pending:{label:"Pending",cls:"exec-badge-pending"},done:{label:"Done",cls:"exec-badge-done"},failed:{label:"Failed",cls:"exec-badge-failed"}},yf={todo:{label:"To do",cls:"exec-badge-pending"},"in-progress":{label:"In progress",cls:"exec-badge-running"},"in-review":{label:"In review",cls:"exec-badge-idle"},done:{label:"Done",cls:"exec-badge-done"},failed:{label:"Failed",cls:"exec-badge-failed"},cancelled:{label:"Cancelled",cls:"exec-badge-cancelled"}};function cU(e){const t=Math.floor((Date.now()-e)/1e3);if(t<5)return"now";if(t<60)return`${t}s ago`;const n=Math.floor(t/60);if(n<60)return`${n}m ago`;const i=Math.floor(n/60);return i<24?`${i}h ago`:`${Math.floor(i/24)}d ago`}function Sy(e){const t=String(e??"").trim();return t?t.replace(/[_-]/g," ").replace(/\b\w/g,n=>n.toUpperCase()):""}function uU(e){return e.phase==="failed"?yf.failed:e.phase==="cancelled"?yf.cancelled:yf[e.kanbanColumn]??yf.todo}function dU(e){if(e.phase==="failed")return"failed";if(e.phase==="cancelled")return"cancelled";if(e.kanbanColumn==="done")return"done"}function fU(e){const t=e.activitySections??[];return t.length>0?t.reduce((n,i)=>n+(i.entries?.length??0),0):e.progressLog.length}function mU({sections:e,fallbackEntries:t,sessionStatus:n}){const i=(e??[]).filter(r=>(r.entries?.length??0)>0||!!r.runtimeTaskId);return i.length>0?u.jsx("div",{className:"exec-activity-sections",children:i.map((r,o)=>{const a=r.entries??[],c=`${r.runtimeTaskId||r.kind}:${o}`;return u.jsxs("section",{className:"exec-activity-section",children:[u.jsxs("div",{className:"exec-activity-section-head",children:[u.jsx("span",{className:"exec-activity-section-title",children:r.title}),r.roleName&&u.jsx("span",{className:"exec-activity-section-role",children:r.roleName}),a.length>0&&u.jsx("span",{className:"exec-section-count",children:a.length})]}),a.length>0?u.jsx(El,{entries:a,sessionStatus:n,expandedByDefault:!0}):u.jsx("div",{className:"exec-section-empty",children:"No runtime activity yet"})]},c)})}):!t||t.length===0?u.jsx("div",{className:"exec-section-empty",children:"No activity recorded yet"}):u.jsx(El,{entries:t,sessionStatus:n,expandedByDefault:!0})}function BC({role:e,focusedWorkItemId:t,focusedExecutionTurnId:n,agents:i,onClose:r}){const o=C.useMemo(()=>e.workItems.slice().sort((S,j)=>S.createdAt-j.createdAt),[e.workItems]),c=C.useMemo(()=>o.find(S=>!!t&&S.workItemId===t||!!n&&S.executionTurnId===n)??o[o.length-1]??null,[n,t,o])?.workItemId,[d,m]=C.useState(()=>{const S=new Set;return c&&S.add(c),S}),h=C.useRef(new Set);C.useEffect(()=>{!c||h.current.has(c)||(h.current.add(c),m(S=>{if(S.has(c))return S;const j=new Set(S);return j.add(c),j}))},[c]);const p=C.useCallback(S=>{m(j=>{const N=new Set(j);return N.has(S)?N.delete(S):N.add(S),N})},[]),g=C.useRef(null),x=C.useRef(null);C.useEffect(()=>{!c||x.current===c||(x.current=c,g.current?.scrollIntoView({behavior:"smooth",block:"nearest"}))},[c]);const v=C.useCallback(S=>{S.key==="Escape"&&r()},[r]);C.useEffect(()=>(document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)),[v]);const b=i.find(S=>S.agent_id===e.roleId),w=e.roleName||b?.name||Sy(e.roleId)||"Role",k=PC[e.aggregatedStatus]??PC.pending;return u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"exec-panel-backdrop",onClick:r}),u.jsxs("div",{className:"exec-panel",children:[u.jsxs("div",{className:"exec-panel-header",children:[u.jsxs("div",{className:"exec-panel-title-row",children:[u.jsx(bl,{}),u.jsx("h3",{className:"exec-panel-title",children:w}),u.jsx("span",{className:`exec-badge ${k.cls}`,children:k.label}),u.jsxs("span",{className:"exec-panel-task-count",children:[o.length," Work Item",o.length===1?"":"s"]})]}),u.jsx("button",{className:"exec-panel-close",onClick:r,title:"Close (Esc)",children:u.jsx(Dm,{})})]}),u.jsxs("div",{className:"exec-panel-identity",children:[u.jsx("div",{className:"exec-panel-avatar",children:w.charAt(0).toUpperCase()}),u.jsxs("div",{className:"exec-panel-agent-info",children:[u.jsx("span",{className:"exec-panel-agent-name",children:w}),u.jsx("span",{className:"exec-panel-agent-role",children:Sy(e.roleId)}),e.roleSessionId&&u.jsx("span",{className:"exec-panel-employee",children:e.roleSessionId})]})]}),u.jsxs("div",{className:"exec-panel-body",children:[o.length===0&&u.jsx("div",{className:"exec-section-empty",children:"No work items yet"}),o.map((S,j)=>{const N=S.workItemId===c,L=d.has(S.workItemId),A=uU(S),D=fU(S);return u.jsxs("div",{ref:N?g:null,className:`exec-task-card${N?" exec-task-card-focused":""}`,children:[u.jsxs("button",{type:"button",className:"exec-task-card-header",onClick:()=>p(S.workItemId),title:L?"Collapse":"Expand",children:[u.jsxs("span",{className:"exec-task-card-index",children:["Work item #",j+1]}),u.jsx("span",{className:"exec-task-card-title",children:S.title||S.workItemId}),u.jsx("span",{className:`exec-badge ${A.cls}`,children:A.label}),u.jsx("span",{className:"exec-task-card-time",children:cU(S.updatedAt)}),u.jsx("span",{className:`exec-task-card-chevron${L?" open":""}`,"aria-hidden":"true",children:"▸"})]}),L&&u.jsxs("div",{className:"exec-task-card-body",children:[u.jsxs("div",{className:"exec-task-card-projection",children:[u.jsx(Mm,{}),u.jsx("span",{children:Sy(S.kind)||"Work item"}),S.workItemProjectionId&&u.jsx("code",{children:S.workItemProjectionId}),S.executionTurnId&&u.jsx("span",{className:"exec-inline-tag",children:"Execution Turn"}),S.isReviewTarget&&u.jsx("span",{className:"exec-inline-tag",children:"Review target"}),S.executorRoleName&&u.jsx("span",{children:S.executorRoleName})]}),u.jsxs("div",{className:"exec-section",children:[u.jsxs("div",{className:"exec-section-header",children:[u.jsx(bl,{}),u.jsx("span",{children:"Activity"}),u.jsx("span",{className:"exec-section-count",children:D})]}),u.jsx("div",{className:"exec-section-content exec-activity-scroll",children:u.jsx(mU,{sections:S.activitySections,fallbackEntries:S.progressLog,sessionStatus:dU(S)})})]})]})]},S.workItemId)})]})]})]})}function pU({projects:e,activeId:t,onSelect:n,onCreate:i,onDelete:r}){const{t:o}=Vr(),[a,c]=C.useState(!1),[d,m]=C.useState(""),[h,p]=C.useState(null),g=C.useCallback(()=>{const v=d.trim().toLowerCase().replace(/[^a-z0-9_-]+/g,"-").replace(/^-|-$/g,"");v&&(i(v),m(""),c(!1))},[d,i]),x=C.useCallback(()=>{!h||!r||(r(h),p(null))},[h,r]);return u.jsxs("div",{className:"project-selector",style:{display:"flex",alignItems:"center",gap:6},children:[u.jsx("select",{className:"theme-select",value:t,onChange:v=>n(v.target.value),title:o("project.switch"),"aria-label":o("project.switch"),children:e.map(v=>u.jsx("option",{value:v.id,children:v.name},v.id))}),a?u.jsxs("form",{onSubmit:v=>{v.preventDefault(),g()},style:{display:"flex",gap:4},children:[u.jsx("input",{autoFocus:!0,className:"theme-select",value:d,placeholder:o("project.placeholder"),onChange:v=>m(v.target.value),onKeyDown:v=>{v.key==="Escape"&&c(!1)},style:{width:120}}),u.jsx("button",{type:"submit",className:"pill-btn",style:{fontSize:11,padding:"2px 8px"},children:"+"})]}):u.jsx("button",{className:"pill-btn",onClick:()=>c(!0),title:o("project.new"),style:{fontSize:11,padding:"2px 8px"},children:"+"}),r&&t!=="default"&&!h&&u.jsx("button",{className:"pill-btn",onClick:()=>p(t),title:o("project.delete"),style:{fontSize:11,padding:"2px 8px",color:"#ef4444"},children:o("project.deleteButton")}),h&&u.jsx("div",{className:"project-delete-confirm",style:{position:"fixed",inset:0,zIndex:9999,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.5)"},children:u.jsxs("div",{style:{background:"var(--bg-surface, #1e1e2e)",borderRadius:12,padding:"24px 32px",maxWidth:400,boxShadow:"0 8px 32px rgba(0,0,0,0.4)",textAlign:"center"},children:[u.jsx("p",{style:{margin:"0 0 8px",fontWeight:600,fontSize:15},children:o("project.confirmTitle",{name:h})}),u.jsx("p",{style:{margin:"0 0 20px",fontSize:13,opacity:.7},children:o("project.confirmBody")}),u.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"center"},children:[u.jsx("button",{className:"pill-btn",onClick:()=>p(null),style:{padding:"6px 18px",fontSize:13},children:o("common.cancel")}),u.jsx("button",{className:"pill-btn",onClick:x,style:{padding:"6px 18px",fontSize:13,background:"#ef4444",color:"#fff"},children:o("common.delete")})]})]})})]})}const hU=80;function gU(e){const t=Date.now()/1e3,n=Math.max(0,t-e);if(n<60)return"just now";if(n<3600)return`${Math.floor(n/60)}m ago`;if(n<86400)return`${Math.floor(n/3600)}h ago`;if(n<604800)return`${Math.floor(n/86400)}d ago`;try{return new Date(e*1e3).toLocaleDateString()}catch{return""}}function $C(e){return(e.organization_name||e.name).trim()||e.name}function yU(e){const t=e.trim();return t.length>0&&t.length<=hU&&!/[\\/]/.test(t)&&!/[\u0000-\u001f]/.test(t)}function xU(e){return e.normalize("NFKD").replace(/[^\x00-\x7F]/g,"").toLowerCase().trim().replace(/\s+/g,"_").replace(/[^a-z0-9_-]+/g,"_").replace(/_+/g,"_").replace(/^[_-]+|[_-]+$/g,"").slice(0,64)||"org"}function vU({className:e}){return u.jsxs("svg",{className:e,width:"12",height:"12",viewBox:"0 0 16 16",fill:"none","aria-hidden":!0,children:[u.jsx("path",{d:"M8 1.5L1.5 4.5L8 7.5L14.5 4.5L8 1.5Z",stroke:"currentColor",strokeWidth:"1.3",strokeLinejoin:"round"}),u.jsx("path",{d:"M2 8L8 10.8L14 8",stroke:"currentColor",strokeWidth:"1.3",strokeLinejoin:"round",opacity:"0.6"}),u.jsx("path",{d:"M2 11.5L8 14.2L14 11.5",stroke:"currentColor",strokeWidth:"1.3",strokeLinejoin:"round",opacity:"0.35"})]})}function bU({className:e}){return u.jsx("svg",{className:e,width:"10",height:"10",viewBox:"0 0 12 12",fill:"none","aria-hidden":!0,children:u.jsx("path",{d:"M3 4.5L6 7.5L9 4.5",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})})}function _U({className:e}){return u.jsxs("svg",{className:e,width:"11",height:"11",viewBox:"0 0 12 12",fill:"none","aria-hidden":!0,children:[u.jsx("circle",{cx:"5",cy:"5",r:"3.2",stroke:"currentColor",strokeWidth:"1.3"}),u.jsx("path",{d:"M7.5 7.5L10 10",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round"})]})}function kU({savedOrgs:e,activeName:t,isDirty:n,onRefresh:i,onSaveAs:r,onLoad:o,onDelete:a}){const[c,d]=C.useState(!1),[m,h]=C.useState(""),[p,g]=C.useState(0),[x,v]=C.useState(!1),[b,w]=C.useState(""),[k,S]=C.useState(null),[j,N]=C.useState(null),L=C.useRef(null),A=C.useRef(null);C.useEffect(()=>{N(null)},[t,e]);const D=(e??[]).filter(q=>!m.trim()||q.name.toLowerCase().includes(m.trim().toLowerCase())),O=C.useRef(!1);C.useEffect(()=>{c&&!O.current&&(O.current=!0,i())},[c,i]),C.useEffect(()=>{x&&A.current?.focus()},[x]),C.useEffect(()=>{g(q=>Math.min(q,Math.max(0,D.length-1)))},[D.length]),C.useEffect(()=>{if(!c)return;const q=K=>{L.current&&!L.current.contains(K.target)&&T()};return document.addEventListener("mousedown",q),()=>document.removeEventListener("mousedown",q)},[c]);const T=C.useCallback(()=>{d(!1),h(""),g(0),v(!1),w(""),S(null)},[]),M=C.useCallback(q=>{if(q===t){T();return}N(q),o(q),T()},[o,T,t]),I=C.useCallback(q=>{a(q),S(null)},[a]),H=b.trim(),Y=yU(H),P=xU(H),U=(e??[]).some(q=>q.name===P||$C(q).toLowerCase()===H.toLowerCase()),$=C.useCallback(()=>{Y&&(r(H,U),v(!1),w(""),T())},[Y,H,U,r,T]),G=q=>{if(q.key==="Escape"){q.preventDefault(),T();return}if(x){q.key==="Enter"&&(q.preventDefault(),$());return}if(q.key==="ArrowDown")q.preventDefault(),g(K=>Math.min(K+1,Math.max(0,D.length-1)));else if(q.key==="ArrowUp")q.preventDefault(),g(K=>Math.max(0,K-1));else if(q.key==="Enter"){const K=D[p];K&&M(K.name)}else if((q.key==="Backspace"||q.key==="Delete")&&(q.metaKey||q.ctrlKey)){const K=D[p];K&&(q.preventDefault(),S(K.name))}};return u.jsxs("div",{className:"sos-wrap",ref:L,children:[u.jsxs("button",{type:"button",className:"sos-pill","data-open":c?"true":"false",onClick:()=>d(q=>!q),"aria-haspopup":"listbox","aria-expanded":c,title:t?`Active saved architecture: ${t}`:"No saved architecture loaded",children:[u.jsx(vU,{className:"sos-pill-glyph"}),t?u.jsx("span",{className:"sos-pill-name",children:t}):u.jsx("span",{className:"sos-pill-name sos-pill-name--placeholder",children:"draft"}),n&&u.jsx("span",{className:"sos-pill-dirty","aria-label":"Modified since opened"}),u.jsx(bU,{className:"sos-pill-caret"})]}),c&&u.jsxs("div",{className:"sos-popover",role:"listbox",onKeyDown:G,tabIndex:-1,children:[u.jsxs("div",{className:"sos-search-row",children:[u.jsx(_U,{className:"sos-search-glyph"}),u.jsx("input",{type:"text",className:"sos-search-input",placeholder:"Search architectures…",value:m,onChange:q=>{h(q.target.value),g(0)},autoFocus:!0,onKeyDown:G}),u.jsx("kbd",{className:"sos-search-hint",children:"↑↓ ↵"})]}),u.jsx("div",{className:"sos-list",children:e===null?u.jsx("div",{className:"sos-empty",children:"Loading…"}):D.length===0?u.jsx("div",{className:"sos-empty",children:(e??[]).length===0?"No saved architectures.":"No matches."}):D.map((q,K)=>{const W=t===q.name,V=p===K,Q=$C(q);return u.jsxs("div",{className:`sos-row${W?" sos-row--active":""}`,"data-highlighted":V?"true":"false",onMouseEnter:()=>g(K),onClick:()=>M(q.name),role:"option","aria-selected":W,children:[u.jsxs("div",{className:"sos-row-meta",children:[u.jsx("span",{className:"sos-row-name",children:Q}),u.jsxs("span",{className:"sos-row-stats",children:[Q!==q.name&&`${q.name} · `,q.roles_count," ",q.roles_count===1?"role":"roles"," · ",q.employees_count," ",q.employees_count===1?"employee":"employees"," · ",gU(q.saved_at)]})]}),j===q.name?u.jsx("span",{className:"sos-row-loading",children:"loading…"}):W?u.jsx("span",{className:"sos-row-active-chip",children:"active"}):k===q.name?u.jsx("button",{type:"button",className:"sos-row-delete sos-row-delete--confirm",onClick:B=>{B.stopPropagation(),I(q.name)},children:"confirm"}):u.jsx("button",{type:"button",className:"sos-row-delete",onClick:B=>{B.stopPropagation(),S(q.name)},title:"Delete",children:"delete"})]},q.name)})}),u.jsxs("div",{className:"sos-save-as",children:[x?u.jsxs("div",{className:"sos-save-as-form",children:[u.jsx("input",{ref:A,type:"text",className:"sos-save-as-input",placeholder:"Organization name",value:b,onChange:q=>w(q.target.value),onKeyDown:G}),u.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:$,disabled:!Y,children:U?"Overwrite copy":"Save as copy"}),u.jsx("button",{type:"button",className:"btn btn-ghost btn-sm",onClick:()=>{v(!1),w("")},children:"Cancel"})]}):u.jsx("button",{type:"button",className:"sos-save-as-trigger",onClick:()=>v(!0),children:"+ Save as copy..."}),x&&b&&!Y&&u.jsx("div",{className:"sos-save-as-hint sos-save-as-hint--warn",children:"Use up to 80 characters. Slashes are not allowed."}),x&&Y&&U&&u.jsx("div",{className:"sos-save-as-hint sos-save-as-hint--warn",children:"Name exists - this will overwrite that copy."})]})]})]})}const SU=["leader","strategy","target","code","terminal","database","settings","bug","design","pen","layout","marketing","analytics","writing","clipboard","security","support","idea","person","team","camera","calendar","group","ai","generic"],mu={leader:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M5 16L3 5l5.5 5L12 4l3.5 6L21 5l-2 11H5zm0 2h14v2H5v-2z'/%3E%3C/svg%3E",strategy:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M19 22H5v-2h14v2zM17.16 8.26C18.22 9.63 19 10.85 19 12c0 2.21-3.13 4-7 4s-7-1.79-7-4c0-1.15.78-2.37 1.84-3.74C7.83 7.03 9 5.67 9 4.5a2.5 2.5 0 0 1 5 0c0 1.17 1.17 2.53 2.16 3.76zM12 6a.5.5 0 1 1 0-1 .5.5 0 0 1 0 1z'/%3E%3C/svg%3E",target:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8zm0-14c-3.31 0-6 2.69-6 6s2.69 6 6 6 6-2.69 6-6-2.69-6-6-6zm0 10c-2.21 0-4-1.79-4-4s1.79-4 4-4 4 1.79 4 4-1.79 4-4 4zm0-6a2 2 0 1 0 0 4 2 2 0 0 0 0-4z'/%3E%3C/svg%3E",code:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M9.4 16.6L4.8 12l4.6-4.6L8 6l-6 6 6 6 1.4-1.4zm5.2 0L19.2 12l-4.6-4.6L16 6l6 6-6 6-1.4-1.4z'/%3E%3C/svg%3E",terminal:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M20 4H4c-1.11 0-2 .9-2 2v12c0 1.1.89 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 14H4V8h16v10zM13 14h4v2h-4zm-3.41-.82l-2.59 2.59L8.41 17 12 13.41 8.41 9.82 7 11.24l2.59 2.59z'/%3E%3C/svg%3E",database:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M12 2C6.48 2 2 3.79 2 6v12c0 2.21 4.48 4 10 4s10-1.79 10-4V6c0-2.21-4.48-4-10-4zm0 18c-4.42 0-8-1.34-8-3v-2.5c1.74 1.5 4.71 2.5 8 2.5s6.26-1 8-2.5V17c0 1.66-3.58 3-8 3zm0-5c-4.42 0-8-1.34-8-3v-2.5c1.74 1.5 4.71 2.5 8 2.5s6.26-1 8-2.5V12c0 1.66-3.58 3-8 3zm0-5c-4.42 0-8-1.34-8-3s3.58-3 8-3 8 1.34 8 3-3.58 3-8 3z'/%3E%3C/svg%3E",settings:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M19.43 12.98c.04-.32.07-.64.07-.98 0-.34-.03-.66-.07-.98l2.11-1.65c.19-.15.24-.42.12-.64l-2-3.46c-.12-.22-.39-.3-.61-.22l-2.49 1c-.52-.4-1.08-.73-1.69-.98l-.38-2.65C14.46 2.18 14.25 2 14 2h-4c-.25 0-.46.18-.49.42l-.38 2.65c-.61.25-1.17.59-1.69.98l-2.49-1c-.23-.09-.49 0-.61.22l-2 3.46c-.13.22-.07.49.12.64l2.11 1.65c-.04.32-.07.65-.07.98 0 .33.03.66.07.98l-2.11 1.65c-.19.15-.24.42-.12.64l2 3.46c.12.22.39.3.61.22l2.49-1c.52.4 1.08.73 1.69.98l.38 2.65c.03.24.24.42.49.42h4c.25 0 .46-.18.49-.42l.38-2.65c.61-.25 1.17-.59 1.69-.98l2.49 1c.23.09.49 0 .61-.22l2-3.46c.12-.22.07-.49-.12-.64l-2.11-1.65zM12 15.5c-1.93 0-3.5-1.57-3.5-3.5s1.57-3.5 3.5-3.5 3.5 1.57 3.5 3.5-1.57 3.5-3.5 3.5z'/%3E%3C/svg%3E",bug:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M20 8h-2.81c-.45-.78-1.07-1.45-1.82-1.96L17 4.41 15.59 3l-2.17 2.17C12.96 5.06 12.49 5 12 5s-.96.06-1.41.17L8.41 3 7 4.41l1.62 1.63C7.88 6.55 7.26 7.22 6.81 8H4v2h2.09c-.05.33-.09.66-.09 1v1H4v2h2v1c0 .34.04.67.09 1H4v2h2.81c1.04 1.79 2.97 3 5.19 3s4.15-1.21 5.19-3H20v-2h-2.09c.05-.33.09-.66.09-1v-1h2v-2h-2v-1c0-.34-.04-.67-.09-1H20V8zm-6 8h-4v-2h4v2zm0-4h-4v-2h4v2z'/%3E%3C/svg%3E",design:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M12 2C6.49 2 2 6.49 2 12s4.49 10 10 10c1.38 0 2.5-1.12 2.5-2.5 0-.61-.23-1.2-.64-1.67-.08-.1-.13-.21-.13-.33 0-.28.22-.5.5-.5H16c3.31 0 6-2.69 6-6 0-4.96-4.49-9-10-9zm5.5 11c-.83 0-1.5-.67-1.5-1.5s.67-1.5 1.5-1.5 1.5.67 1.5 1.5-.67 1.5-1.5 1.5zm-3-4c-.83 0-1.5-.67-1.5-1.5S13.67 6 14.5 6s1.5.67 1.5 1.5S15.33 9 14.5 9zm-5 0C8.67 9 8 8.33 8 7.5S8.67 6 9.5 6s1.5.67 1.5 1.5S10.33 9 9.5 9zm-3 4c-.83 0-1.5-.67-1.5-1.5s.67-1.5 1.5-1.5 1.5.67 1.5 1.5-.67 1.5-1.5 1.5z'/%3E%3C/svg%3E",pen:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.39-.39-1.02-.39-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z'/%3E%3C/svg%3E",layout:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M3 13h8V3H3v10zm0 8h8v-6H3v6zm10 0h8V11h-8v10zm0-18v6h8V3h-8z'/%3E%3C/svg%3E",marketing:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M18 11v2h4v-2h-4zm-2 6.61c.96.71 2.21 1.65 3.2 2.39.4-.53.8-1.07 1.2-1.6-.99-.74-2.24-1.68-3.2-2.4-.4.54-.8 1.08-1.2 1.61zM20.4 5.6c-.4-.53-.8-1.07-1.2-1.6-.99.74-2.24 1.68-3.2 2.4.4.53.8 1.07 1.2 1.6.96-.72 2.21-1.65 3.2-2.4zM4 9c-1.1 0-2 .9-2 2v2c0 1.1.9 2 2 2h1v4h2v-4h1l5 3V6L8 9H4zm11.5 3c0-1.33-.58-2.53-1.5-3.35v6.69c.92-.81 1.5-2.01 1.5-3.34z'/%3E%3C/svg%3E",analytics:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M3.5 18.49l6-6.01 4 4L22 6.92l-1.41-1.41-7.09 7.97-4-4L2 16.99l1.5 1.5z'/%3E%3C/svg%3E",writing:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.39-.39-1.02-.39-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z'/%3E%3C/svg%3E",clipboard:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M19 3h-4.18C14.4 1.84 13.3 1 12 1c-1.3 0-2.4.84-2.82 2H5c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-7 0c.55 0 1 .45 1 1s-.45 1-1 1-1-.45-1-1 .45-1 1-1zm2 14H7v-2h7v2zm3-4H7v-2h10v2zm0-4H7V7h10v2z'/%3E%3C/svg%3E",security:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M12 1L3 5v6c0 5.55 3.84 10.74 9 12 5.16-1.26 9-6.45 9-12V5l-9-4zm0 10.99h7c-.53 4.12-3.28 7.79-7 8.94V12H5V6.3l7-3.11V11.99z'/%3E%3C/svg%3E",support:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M21 6h-2v9H6v2c0 .55.45 1 1 1h11l4 4V7c0-.55-.45-1-1-1zm-4 6V3c0-.55-.45-1-1-1H3c-.55 0-1 .45-1 1v14l4-4h10c.55 0 1-.45 1-1z'/%3E%3C/svg%3E",idea:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M9 21c0 .55.45 1 1 1h4c.55 0 1-.45 1-1v-1H9v1zm3-19C8.14 2 5 5.14 5 9c0 2.38 1.19 4.47 3 5.74V17c0 .55.45 1 1 1h6c.55 0 1-.45 1-1v-2.26c1.81-1.27 3-3.36 3-5.74 0-3.86-3.14-7-7-7z'/%3E%3C/svg%3E",person:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z'/%3E%3C/svg%3E",team:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M16 11c1.66 0 2.99-1.34 2.99-3S17.66 5 16 5c-1.66 0-3 1.34-3 3s1.34 3 3 3zm-8 0c1.66 0 2.99-1.34 2.99-3S9.66 5 8 5C6.34 5 5 6.34 5 8s1.34 3 3 3zm0 2c-2.33 0-7 1.17-7 3.5V19h14v-2.5c0-2.33-4.67-3.5-7-3.5zm8 0c-.29 0-.62.02-.97.05 1.16.84 1.97 1.97 1.97 3.45V19h6v-2.5c0-2.33-4.67-3.5-7-3.5z'/%3E%3C/svg%3E",camera:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M12 15.2c-1.77 0-3.2-1.43-3.2-3.2s1.43-3.2 3.2-3.2 3.2 1.43 3.2 3.2-1.43 3.2-3.2 3.2zM9 2L7.17 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2h-3.17L15 2H9zm3 15c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5z'/%3E%3C/svg%3E",calendar:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M19 3h-1V1h-2v2H8V1H6v2H5c-1.11 0-1.99.9-1.99 2L3 19c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H5V8h14v11zM7 10h5v5H7z'/%3E%3C/svg%3E",group:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M12 12.75c1.63 0 3.07.39 4.24.9 1.08.48 1.76 1.56 1.76 2.73L18 18H6l.01-1.62c0-1.17.68-2.25 1.76-2.73 1.17-.51 2.6-.9 4.23-.9zM4 13c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm1.13 1.1c-.37-.06-.74-.1-1.13-.1-.99 0-1.93.21-2.78.58C.48 14.9 0 15.62 0 16.43V18h4.5v-1.61c0-.83.23-1.61.63-2.29zM20 13c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm4 3.43c0-.81-.48-1.53-1.22-1.85-.85-.37-1.79-.58-2.78-.58-.39 0-.76.04-1.13.1.4.68.63 1.46.63 2.29V18H24v-1.57zM12 6c1.66 0 3 1.34 3 3s-1.34 3-3 3-3-1.34-3-3 1.34-3 3-3z'/%3E%3C/svg%3E",ai:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M19 9l1.25-2.75L23 5l-2.75-1.25L19 1l-1.25 2.75L15 5l2.75 1.25L19 9zm-7.5.5L9 4 6.5 9.5 1 12l5.5 2.5L9 20l2.5-5.5L17 12l-5.5-2.5zM19 15l-1.25 2.75L15 19l2.75 1.25L19 23l1.25-2.75L23 19l-2.75-1.25L19 15z'/%3E%3C/svg%3E",generic:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z'/%3E%3C/svg%3E"};function Uu(e){return e?e.startsWith("data:")?e:mu[e]??mu.generic:mu.generic}const Xc=["file_read","file_write","file_edit","file_search","list_dir","shell_exec","web_search","web_fetch","todo_read","todo_write","browser_navigate","browser_navigate_back","browser_snapshot","browser_wait_for","browser_scroll","browser_click","browser_type","browser_select_option","browser_take_screenshot","browser_evaluate","browser_close"],wU=[{label:"Files",prefix:"file_",tools:Xc.filter(e=>e.startsWith("file_"))},{label:"Shell",prefix:"shell_",tools:Xc.filter(e=>e==="shell_exec")},{label:"Web",prefix:"web_",tools:Xc.filter(e=>e.startsWith("web_"))},{label:"TODOs",prefix:"todo_",tools:Xc.filter(e=>e.startsWith("todo_"))},{label:"Browser",prefix:"browser_",tools:Xc.filter(e=>e.startsWith("browser_"))}],CU=["codex","cursor","claude_code","opencode"],jU=[{value:"auto",label:"Auto",hint:"System picks native or external based on role config"},{value:"native",label:"Native",hint:"Run directly in-process via LLM"},{value:"external",label:"External",hint:"Delegate to an external agent (codex, cursor, etc.)"}];function EU({role:e,allRoles:t,employees:n,readOnly:i,onUpdateRole:r,onDeleteRole:o,onClose:a}){const[c,d]=C.useState(e.name),[m,h]=C.useState(e.responsibility),[p,g]=C.useState(e.reports_to),[x,v]=C.useState(e.icon??null),[b,w]=C.useState(()=>new Set(e.can_spawn)),[k,S]=C.useState(()=>new Set(e.tools)),[j,N]=C.useState(e.runtime_policy?.execution_strategy??"auto"),[L,A]=C.useState(e.preferred_external_agent??null),[D,O]=C.useState((e.prompt_refs??[]).join(` +${t}`:`${e}${t}`}function WV(e,t){const n=e.trim().replace(/\s+/g," ");return n?n.length>120?`${n.slice(0,120).trimEnd()}...`:n:t||"Thinking"}function YV(e){return{timestamp:Number.isFinite(e.timestamp)?e.timestamp:Date.now(),type:e.type,summary:typeof e.summary=="string"?e.summary:"",detail:typeof e.detail=="string"&&e.detail?e.detail:void 0,turnId:typeof e.turnId=="string"&&e.turnId?e.turnId:void 0,itemId:typeof e.itemId=="string"&&e.itemId?e.itemId:void 0,streamId:typeof e.streamId=="string"&&e.streamId?e.streamId:void 0,toolCallId:typeof e.toolCallId=="string"&&e.toolCallId?e.toolCallId:void 0,permissionGroupKey:typeof e.permissionGroupKey=="string"&&e.permissionGroupKey?e.permissionGroupKey:void 0,seq:typeof e.seq=="number"&&Number.isFinite(e.seq)?e.seq:void 0,executionMode:typeof e.executionMode=="string"&&e.executionMode?e.executionMode:void 0}}function hm(e){const t=e.itemId||e.streamId;return t?`${e.type}:${e.turnId??""}:${t}`:e.toolCallId&&(e.type==="tool_call"||e.type==="autonomy")?`${e.type}:${e.turnId??""}:${e.toolCallId}`:e.permissionGroupKey&&e.type==="autonomy"?`${e.type}:${e.turnId??""}:${e.permissionGroupKey}`:""}function XV(e,t){const n=hm(e),i=hm(t);return n&&i?n===i:t.timestamp-e.timestamp>Zm||e.type!==t.type?!1:e.type==="thinking"||e.type==="assistant"?!0:e.type==="tool_call"?e.summary===t.summary:!1}function KV(e,t){return t.timestamp-e.timestamp<=Zm&&e.type===t.type&&e.summary===t.summary&&(e.detail??"")===(t.detail??"")}function ZV(e,t){if(e.type==="thinking"||e.type==="assistant"){const n=xv(e.detail??"",t.detail??"","thinking");return{timestamp:e.timestamp,type:e.type,summary:WV(n,t.summary||e.summary),detail:n||void 0,turnId:t.turnId??e.turnId,itemId:t.itemId??e.itemId,streamId:t.streamId??e.streamId,toolCallId:t.toolCallId??e.toolCallId,permissionGroupKey:t.permissionGroupKey??e.permissionGroupKey,seq:t.seq??e.seq,executionMode:t.executionMode??e.executionMode}}if(e.type==="tool_call"){const n=xv(e.detail??"",t.detail??"","tool_call");return{timestamp:e.timestamp,type:"tool_call",summary:t.summary||e.summary,detail:n||void 0,turnId:t.turnId??e.turnId,itemId:t.itemId??e.itemId,streamId:t.streamId??e.streamId,toolCallId:t.toolCallId??e.toolCallId,permissionGroupKey:t.permissionGroupKey??e.permissionGroupKey,seq:t.seq??e.seq,executionMode:t.executionMode??e.executionMode}}return t}function nT(e,t,n=100){const i=YV(t),r=hm(i),o=r?[...e].reverse().findIndex(d=>hm(d)===r):-1,a=o>=0?e.length-1-o:e.length-1,c=e[a];return c?r&&o>=0&&typeof c.seq=="number"&&typeof i.seq=="number"&&i.seq<=c.seq?e:KV(c,i)?gl([...e.slice(0,a),c,...e.slice(a+1)],n):XV(c,i)?gl([...e.slice(0,a),ZV(c,i),...e.slice(a+1)],n):gl([...e,i],n):[i]}function iT(e,t=100){return(Array.isArray(e)?e:[]).reduce((n,i)=>nT(n,i,t),[])}function QV(e){return{timestamp:Number.isFinite(e.timestamp)?e.timestamp:Date.now(),type:e.type,workItemProjectionId:typeof e.workItemProjectionId=="string"&&e.workItemProjectionId?e.workItemProjectionId:void 0,workItemTurnType:typeof e.workItemTurnType=="string"&&e.workItemTurnType?e.workItemTurnType:void 0,workItemProjectionTitle:typeof e.workItemProjectionTitle=="string"&&e.workItemProjectionTitle?e.workItemProjectionTitle:void 0,runtimeTaskId:typeof e.runtimeTaskId=="string"&&e.runtimeTaskId?e.runtimeTaskId:void 0,executionTurnId:typeof e.executionTurnId=="string"&&e.executionTurnId?e.executionTurnId:void 0,roleName:typeof e.roleName=="string"&&e.roleName?e.roleName:void 0,detail:typeof e.detail=="string"&&e.detail?e.detail:void 0}}function rT(e,t){return e.type===t.type&&(e.workItemProjectionId??"")===(t.workItemProjectionId??"")&&(e.workItemTurnType??"")===(t.workItemTurnType??"")&&(e.workItemProjectionTitle??"")===(t.workItemProjectionTitle??"")&&(e.executionTurnId??e.runtimeTaskId??"")===(t.executionTurnId??t.runtimeTaskId??"")&&(e.roleName??"")===(t.roleName??"")}function JV(e,t){return t.timestamp-e.timestamp<=Zm&&rT(e,t)&&(e.type==="thinking"||e.type==="tool_call")}function eU(e,t){return rT(e,t)&&(e.detail??"")===(t.detail??"")&&t.timestamp-e.timestamp<=Zm}function tU(e,t){const n=t.type==="tool_call"?"tool_call":"thinking";return{...e,...t,timestamp:t.timestamp,detail:xv(e.detail??"",t.detail??"",n)||void 0}}function sT(e,t,n=100){const i=QV(t),r=e[e.length-1];return r?eU(r,i)?gl([...e.slice(0,-1),{...r,timestamp:i.timestamp}],n):JV(r,i)?gl([...e.slice(0,-1),tU(r,i)],n):gl([...e,i],n):[i]}function oT(e,t=100){return(Array.isArray(e)?e:[]).reduce((n,i)=>sT(n,i,t),[])}function vv(e){const t=String(e??"").trim().toLowerCase();return t==="company"?"company":t==="org"||t==="custom"?"org":"task"}function nU(e){return String(e??"").trim().toLowerCase()==="custom"?"custom":"corporate"}function aT(e){const t=String(e.execMode??"").trim().toLowerCase(),n=String(e.companyProfile??"").trim().toLowerCase(),i=String(e.orgId??"").trim(),o=t.length>0?vv(t):n==="custom"||i?"org":vv(t);return o==="org"?{...e,execMode:"org",companyProfile:"custom",orgId:i||void 0}:o==="company"?{...e,execMode:"company",companyProfile:"corporate",orgId:void 0}:{...e,execMode:"task",companyProfile:void 0,orgId:void 0}}const gf=100,iU=new Set(["done","failed","cancelled"]);function rU(e,t,n){const i=n,r=new Map(t.filter(c=>c.projectId===i).map(c=>[c.taskId,c])),o=new Set,a=[];for(const c of e){if(c.projectId!==i)continue;const d=r.get(c.taskId);d?(a.push(d),o.add(c.taskId)):a.push(c)}for(const c of t)c.projectId!==i||o.has(c.taskId)||(a.push(c),o.add(c.taskId));return a}function sU(e,t){const n=g=>aT({...g,progressLog:iT(g.progressLog??[],gf),workItemLog:oT(g.workItemLog??[],gf)}),i=g=>{const x=String(g.execMode??"").trim().toLowerCase();return x==="company"||x==="org"||x==="custom"||!!g.isCompanyRuntime||!!g.parentSessionId||!!g.workItemProjectionId||!!g.roleWorkItems||!!g.executorRoleWorkItems||!!g.orgId},r=g=>{const x=String(g.execMode??"").trim().toLowerCase(),v=String(g.companyProfile??"").trim().toLowerCase(),b=String(g.orgId??"").trim();return x==="task"&&(!v||v==="corporate")&&!b&&!g.isCompanyRuntime&&!g.parentSessionId&&!g.workItemProjectionId&&!g.workItemRoleId&&!g.roleWorkItems&&!g.executorRoleWorkItems},o=(g,x)=>{const v=g.execMode,b=x.execMode;return!v||v==="task"&&b&&b!=="task"&&!r(g)&&(i(g)||i(x))?b:v},a=(g,x,v)=>{const b=g[v],w=x[v];return!b||b==="native"&&w&&w!=="native"?w:b},c=(g,x)=>Object.prototype.hasOwnProperty.call(g,x),d=(g,x,v)=>c(g,v)?g[v]:x[v],m=(g,x)=>{const v=typeof g.updatedAt=="number"&&Number.isFinite(g.updatedAt)?g.updatedAt:void 0,b=typeof x.updatedAt=="number"&&Number.isFinite(x.updatedAt)?x.updatedAt:void 0;return v===void 0?b??Date.now():b===void 0?v:Math.max(b,v)},h=(g,x)=>g.runtimeControlState==="suspending"&&x.runtimeControlState==="running"?{...x,runtimeControlState:"suspending",canStop:!1,canResume:g.canResume??!1,pendingRuntimeCheckpointId:g.pendingRuntimeCheckpointId??x.pendingRuntimeCheckpointId,stopIntentId:g.stopIntentId??x.stopIntentId}:x,p=(g,x,v)=>{const b=g[v];if(b!=null)return b;if(!(iU.has(g.status)||g.status!=="running"&&g.runtimeControlState!=="running"&&g.runtimeControlState!=="suspending"&&g.runtimeControlState!=="resuming"))return x[v]};switch(t.type){case"SET":{if(t.reset)return t.sessions.map(n);const x=new Map(e.map(v=>[v.taskId,v]));return t.sessions.map(v=>{const b=x.get(v.taskId);if(!b)return n(v);const w=h(b,v);return n({...v,updatedAt:m(v,b),execMode:o(v,b),preferredAgent:a(v,b,"preferredAgent"),draftAssistantText:b.draftAssistantText??v.draftAssistantText,draftUpdatedAt:b.draftUpdatedAt??v.draftUpdatedAt,draftIteration:b.draftIteration??v.draftIteration,draftTurnId:b.draftTurnId??v.draftTurnId,agentStatus:p(v,b,"agentStatus"),currentTool:p(v,b,"currentTool"),displayTool:p(v,b,"displayTool"),toolElapsedMs:p(v,b,"toolElapsedMs"),lastToolSummary:p(v,b,"lastToolSummary"),contextTokens:b.contextTokens??v.contextTokens,contextWindow:b.contextWindow??v.contextWindow,contextRemainingPct:b.contextRemainingPct??v.contextRemainingPct,inputTokens:b.inputTokens??v.inputTokens,outputTokens:b.outputTokens??v.outputTokens,totalTokens:b.totalTokens??v.totalTokens,turnCostUsd:b.turnCostUsd??v.turnCostUsd,sessionCostUsd:b.sessionCostUsd??v.sessionCostUsd,pendingPermissionCount:b.pendingPermissionCount??v.pendingPermissionCount,drainMode:b.drainMode??v.drainMode,workItemProjectionId:v.workItemProjectionId??b.workItemProjectionId,workItemTurnType:v.workItemTurnType??b.workItemTurnType,companyProfile:d(v,b,"companyProfile"),orgId:d(v,b,"orgId"),workItemRoleId:v.workItemRoleId??b.workItemRoleId,workItemRoleName:v.workItemRoleName??b.workItemRoleName,workItemGate:v.workItemGate??b.workItemGate,roleWorkItems:v.roleWorkItems??b.roleWorkItems,executorRoleWorkItems:v.executorRoleWorkItems??b.executorRoleWorkItems,employeeAssignment:v.employeeAssignment??b.employeeAssignment,selectedExecutionAgent:a(v,b,"selectedExecutionAgent"),runtimeControlState:w.runtimeControlState??b.runtimeControlState,canStop:w.canStop??b.canStop,canResume:w.canResume??b.canResume,resumeParentSessionId:v.resumeParentSessionId??b.resumeParentSessionId,pendingRuntimeCheckpointId:w.pendingRuntimeCheckpointId??b.pendingRuntimeCheckpointId,stopIntentId:w.stopIntentId??b.stopIntentId,residentStatus:b.residentStatus??v.residentStatus,actionableInboxCount:b.actionableInboxCount??v.actionableInboxCount,protocolBacklogCount:b.protocolBacklogCount??v.protocolBacklogCount,notificationBacklogCount:b.notificationBacklogCount??v.notificationBacklogCount,latestNotification:b.latestNotification??v.latestNotification,latestPreview:v.latestPreview??b.latestPreview,latestSender:v.latestSender??b.latestSender,latestMessageId:v.latestMessageId??b.latestMessageId,indexLoaded:v.indexLoaded??b.indexLoaded,detailLoaded:b.detailLoaded??v.detailLoaded,fullLoaded:b.fullLoaded??v.fullLoaded,hasMore:v.hasMore??b.hasMore,summaryHasMore:v.summaryHasMore??b.summaryHasMore,fullHasMore:v.fullHasMore??b.fullHasMore,detailLoading:v.detailLoading??b.detailLoading,detailError:v.detailError??b.detailError,viewGeneration:v.viewGeneration??b.viewGeneration,progressLog:b.progressLog&&b.progressLog.length>0?b.progressLog:v.progressLog,workItemLog:b.workItemLog&&b.workItemLog.length>0?b.workItemLog:v.workItemLog,lastRuntimeEventType:b.lastRuntimeEventType??v.lastRuntimeEventType,activeSubagents:b.activeSubagents??v.activeSubagents,permissionRequests:b.permissionRequests??v.permissionRequests,handoffContext:v.handoffContext??b.handoffContext,handoffTo:v.handoffTo??b.handoffTo})})}case"ADD":const g=n(t.session);return e.some(x=>x.taskId===t.session.taskId)?e.map(x=>x.taskId===t.session.taskId?n({...x,...g,progressLog:g.progressLog.length>0?g.progressLog:x.progressLog,workItemLog:(g.workItemLog??[]).length>0?g.workItemLog:x.workItemLog,messageCount:Math.max(x.messageCount??0,g.messageCount??0),updatedAt:Math.max(x.updatedAt??0,g.updatedAt??0),execMode:o(g,x),preferredAgent:a(g,x,"preferredAgent"),workItemProjectionId:g.workItemProjectionId??x.workItemProjectionId,workItemTurnType:g.workItemTurnType??x.workItemTurnType,companyProfile:d(g,x,"companyProfile"),orgId:d(g,x,"orgId"),workItemRoleId:g.workItemRoleId??x.workItemRoleId,workItemRoleName:g.workItemRoleName??x.workItemRoleName,workItemGate:g.workItemGate??x.workItemGate,roleWorkItems:g.roleWorkItems??x.roleWorkItems,executorRoleWorkItems:g.executorRoleWorkItems??x.executorRoleWorkItems,employeeAssignment:g.employeeAssignment??x.employeeAssignment,selectedExecutionAgent:a(g,x,"selectedExecutionAgent"),handoffContext:g.handoffContext??x.handoffContext,handoffTo:g.handoffTo??x.handoffTo,latestPreview:g.latestPreview??x.latestPreview,latestSender:g.latestSender??x.latestSender,latestMessageId:g.latestMessageId??x.latestMessageId,indexLoaded:g.indexLoaded??x.indexLoaded,detailLoaded:g.detailLoaded??x.detailLoaded,fullLoaded:g.fullLoaded??x.fullLoaded,hasMore:g.hasMore??x.hasMore,summaryHasMore:g.summaryHasMore??x.summaryHasMore,fullHasMore:g.fullHasMore??x.fullHasMore,detailLoading:g.detailLoading??x.detailLoading,detailError:g.detailError??x.detailError,viewGeneration:g.viewGeneration??x.viewGeneration}):x):[g,...e];case"UPDATE":return e.map(x=>x.taskId===t.taskId?(()=>{const v=h(x,t.partial);return n({...x,...v,updatedAt:m(v,x),runtimeControlState:v.runtimeControlState??x.runtimeControlState,canStop:v.canStop??x.canStop,canResume:v.canResume??x.canResume,resumeParentSessionId:v.resumeParentSessionId??x.resumeParentSessionId,pendingRuntimeCheckpointId:v.pendingRuntimeCheckpointId??x.pendingRuntimeCheckpointId,stopIntentId:v.stopIntentId??x.stopIntentId,roleWorkItems:v.roleWorkItems??x.roleWorkItems,executorRoleWorkItems:v.executorRoleWorkItems??x.executorRoleWorkItems,execMode:d(v,x,"execMode"),companyProfile:d(v,x,"companyProfile"),orgId:d(v,x,"orgId"),isCompanyRuntime:v.isCompanyRuntime??x.isCompanyRuntime,workItemProjectionId:v.workItemProjectionId??x.workItemProjectionId,workItemTurnType:v.workItemTurnType??x.workItemTurnType,workItemRoleId:v.workItemRoleId??x.workItemRoleId,workItemRoleName:v.workItemRoleName??x.workItemRoleName,workItemGate:v.workItemGate??x.workItemGate,employeeAssignment:v.employeeAssignment??x.employeeAssignment,selectedExecutionAgent:v.selectedExecutionAgent??x.selectedExecutionAgent,activeSubagents:v.activeSubagents??x.activeSubagents,permissionRequests:v.permissionRequests??x.permissionRequests,contextTokens:v.contextTokens??x.contextTokens,contextWindow:v.contextWindow??x.contextWindow,contextRemainingPct:v.contextRemainingPct??x.contextRemainingPct,inputTokens:v.inputTokens??x.inputTokens,outputTokens:v.outputTokens??x.outputTokens,totalTokens:v.totalTokens??x.totalTokens,turnCostUsd:v.turnCostUsd??x.turnCostUsd,sessionCostUsd:v.sessionCostUsd??x.sessionCostUsd,...t.partial.progressLog?{progressLog:t.partial.progressLog}:{},...t.partial.workItemLog?{workItemLog:t.partial.workItemLog}:{}})})():x);case"DELETE":return e.filter(x=>x.taskId!==t.taskId);case"APPEND_PROGRESS":return e.map(x=>x.taskId!==t.taskId?x:{...x,progressLog:nT(x.progressLog,t.entry,gf),updatedAt:Math.max(x.updatedAt,t.entry.timestamp)});case"APPEND_DRAFT":return e.map(x=>{if(x.taskId!==t.taskId)return x;const v=t.turnId??x.draftTurnId,b=!!t.turnId&&!!x.draftTurnId&&t.turnId!==x.draftTurnId;return{...x,draftAssistantText:`${b?"":x.draftAssistantText??""}${t.text}`,draftUpdatedAt:t.timestamp,draftIteration:t.iteration??x.draftIteration,draftTurnId:v,updatedAt:Math.max(x.updatedAt,t.timestamp)}});case"CLEAR_DRAFT":return e.map(x=>x.taskId===t.taskId?{...x,draftAssistantText:void 0,draftUpdatedAt:void 0,draftIteration:void 0,draftTurnId:void 0}:x);case"CLEAR_PROGRESS":return e.map(x=>x.taskId===t.taskId?{...x,progressLog:[]}:x);case"APPEND_WORK_ITEM_PROGRESS":return e.map(x=>x.taskId!==t.taskId?x:{...x,workItemLog:sT(x.workItemLog??[],t.entry,gf)});case"SET_COMPANY_RUNTIME":return e.map(x=>x.taskId===t.taskId?{...x,isCompanyRuntime:t.isCompanyRuntime}:x);default:return e}}function oU(){const[e,t]=C.useReducer(sU,[]),[n,i]=C.useState(null),[r,o]=C.useState("default"),a=C.useMemo(()=>e.find(S=>S.taskId===n)??null,[e,n]),c=C.useCallback(S=>{S.projectId===r&&t({type:"ADD",session:S})},[r]),d=C.useCallback(S=>{t({type:"DELETE",taskId:S})},[]),m=C.useCallback(S=>{i(S)},[]),h=C.useCallback((S,j)=>{t({type:"UPDATE",taskId:S,partial:j})},[]),p=C.useCallback((S,j)=>{t({type:"APPEND_PROGRESS",taskId:S,entry:j})},[]),g=C.useCallback((S,j,N,L)=>{t({type:"APPEND_DRAFT",taskId:S,text:j,iteration:N,turnId:L,timestamp:Date.now()})},[]),x=C.useCallback(S=>{t({type:"CLEAR_DRAFT",taskId:S})},[]),v=C.useCallback(S=>{t({type:"CLEAR_PROGRESS",taskId:S})},[]),b=C.useCallback((S,j)=>{t({type:"APPEND_WORK_ITEM_PROGRESS",taskId:S,entry:j})},[]),w=C.useCallback((S,j)=>{t({type:"SET_COMPANY_RUNTIME",taskId:S,isCompanyRuntime:j})},[]),k=C.useCallback((S,j,N)=>{const L=S||"default",A=L!==r,D=N?.preserveExistingWhenIncomingPartial&&!A?rU(e,j,L):j.filter(O=>O.projectId===L);o(L),t({type:"SET",sessions:D,reset:A}),i(O=>!A&&O&&(D.some(T=>T.taskId===O)||N?.preserveActiveWhenMissing)?O:null)},[r,e]);return C.useMemo(()=>({scopeProjectId:r,sessions:e,activeSessionId:n,activeSession:a,createSession:c,deleteSession:d,setActiveSession:m,updateSession:h,appendProgress:p,appendDraft:g,clearDraft:x,clearProgress:v,appendWorkItemProgress:b,setCompanyRuntime:w,initFromBackend:k}),[r,e,n,a,c,d,m,h,p,g,x,v,b,w,k])}function zC(e){return e.trim()||"default"}function aU(e,t){switch(t.type){case"SET":return{projects:t.projects,activeProjectId:zC(t.activeId)};case"ADD":return e.projects.some(n=>n.id===t.project.id)?e:{...e,projects:[...e.projects,t.project]};case"REMOVE":{const n=e.projects.filter(r=>r.id!==t.id),i=e.activeProjectId===t.id?"default":e.activeProjectId;return{projects:n,activeProjectId:i}}case"SET_ACTIVE":return{...e,activeProjectId:zC(t.id)};default:return e}}function lU(){const[e,t]=C.useReducer(aU,{projects:[{id:"default",name:"default"}],activeProjectId:"default"}),n=C.useCallback((a,c)=>{t({type:"SET",projects:a,activeId:c})},[]),i=C.useCallback(a=>{t({type:"ADD",project:a})},[]),r=C.useCallback(a=>{t({type:"REMOVE",id:a})},[]),o=C.useCallback(a=>{t({type:"SET_ACTIVE",id:a})},[]);return C.useMemo(()=>({projects:e.projects,activeProjectId:e.activeProjectId,initFromBackend:n,addProject:i,removeProject:r,setActiveProject:o}),[e,n,i,r,o])}const PC={active:{label:"Working",cls:"exec-badge-running"},waiting:{label:"Waiting",cls:"exec-badge-idle"},pending:{label:"Pending",cls:"exec-badge-pending"},done:{label:"Done",cls:"exec-badge-done"},failed:{label:"Failed",cls:"exec-badge-failed"}},yf={todo:{label:"To do",cls:"exec-badge-pending"},"in-progress":{label:"In progress",cls:"exec-badge-running"},"in-review":{label:"In review",cls:"exec-badge-idle"},done:{label:"Done",cls:"exec-badge-done"},failed:{label:"Failed",cls:"exec-badge-failed"},cancelled:{label:"Cancelled",cls:"exec-badge-cancelled"}};function cU(e){const t=Math.floor((Date.now()-e)/1e3);if(t<5)return"now";if(t<60)return`${t}s ago`;const n=Math.floor(t/60);if(n<60)return`${n}m ago`;const i=Math.floor(n/60);return i<24?`${i}h ago`:`${Math.floor(i/24)}d ago`}function Sy(e){const t=String(e??"").trim();return t?t.replace(/[_-]/g," ").replace(/\b\w/g,n=>n.toUpperCase()):""}function uU(e){return e.phase==="failed"?yf.failed:e.phase==="cancelled"?yf.cancelled:yf[e.kanbanColumn]??yf.todo}function dU(e){if(e.phase==="failed")return"failed";if(e.phase==="cancelled")return"cancelled";if(e.kanbanColumn==="done")return"done"}function fU(e){const t=e.activitySections??[];return t.length>0?t.reduce((n,i)=>n+(i.entries?.length??0),0):e.progressLog.length}function mU({sections:e,fallbackEntries:t,sessionStatus:n}){const i=(e??[]).filter(r=>(r.entries?.length??0)>0||!!r.runtimeTaskId);return i.length>0?u.jsx("div",{className:"exec-activity-sections",children:i.map((r,o)=>{const a=r.entries??[],c=`${r.runtimeTaskId||r.kind}:${o}`;return u.jsxs("section",{className:"exec-activity-section",children:[u.jsxs("div",{className:"exec-activity-section-head",children:[u.jsx("span",{className:"exec-activity-section-title",children:r.title}),r.roleName&&u.jsx("span",{className:"exec-activity-section-role",children:r.roleName}),a.length>0&&u.jsx("span",{className:"exec-section-count",children:a.length})]}),a.length>0?u.jsx(El,{entries:a,sessionStatus:n,expandedByDefault:!0}):u.jsx("div",{className:"exec-section-empty",children:"No runtime activity yet"})]},c)})}):!t||t.length===0?u.jsx("div",{className:"exec-section-empty",children:"No activity recorded yet"}):u.jsx(El,{entries:t,sessionStatus:n,expandedByDefault:!0})}function BC({role:e,focusedWorkItemId:t,focusedExecutionTurnId:n,agents:i,onClose:r}){const o=C.useMemo(()=>e.workItems.slice().sort((S,j)=>S.createdAt-j.createdAt),[e.workItems]),c=C.useMemo(()=>o.find(S=>!!t&&S.workItemId===t||!!n&&S.executionTurnId===n)??o[o.length-1]??null,[n,t,o])?.workItemId,[d,m]=C.useState(()=>{const S=new Set;return c&&S.add(c),S}),h=C.useRef(new Set);C.useEffect(()=>{!c||h.current.has(c)||(h.current.add(c),m(S=>{if(S.has(c))return S;const j=new Set(S);return j.add(c),j}))},[c]);const p=C.useCallback(S=>{m(j=>{const N=new Set(j);return N.has(S)?N.delete(S):N.add(S),N})},[]),g=C.useRef(null),x=C.useRef(null);C.useEffect(()=>{!c||x.current===c||(x.current=c,g.current?.scrollIntoView({behavior:"smooth",block:"nearest"}))},[c]);const v=C.useCallback(S=>{S.key==="Escape"&&r()},[r]);C.useEffect(()=>(document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)),[v]);const b=i.find(S=>S.agent_id===e.roleId),w=e.roleName||b?.name||Sy(e.roleId)||"Role",k=PC[e.aggregatedStatus]??PC.pending;return u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"exec-panel-backdrop",onClick:r}),u.jsxs("div",{className:"exec-panel",children:[u.jsxs("div",{className:"exec-panel-header",children:[u.jsxs("div",{className:"exec-panel-title-row",children:[u.jsx(bl,{}),u.jsx("h3",{className:"exec-panel-title",children:w}),u.jsx("span",{className:`exec-badge ${k.cls}`,children:k.label}),u.jsxs("span",{className:"exec-panel-task-count",children:[o.length," Work Item",o.length===1?"":"s"]})]}),u.jsx("button",{className:"exec-panel-close",onClick:r,title:"Close (Esc)",children:u.jsx(Dm,{})})]}),u.jsxs("div",{className:"exec-panel-identity",children:[u.jsx("div",{className:"exec-panel-avatar",children:w.charAt(0).toUpperCase()}),u.jsxs("div",{className:"exec-panel-agent-info",children:[u.jsx("span",{className:"exec-panel-agent-name",children:w}),u.jsx("span",{className:"exec-panel-agent-role",children:Sy(e.roleId)}),e.roleSessionId&&u.jsx("span",{className:"exec-panel-employee",children:e.roleSessionId})]})]}),u.jsxs("div",{className:"exec-panel-body",children:[o.length===0&&u.jsx("div",{className:"exec-section-empty",children:"No work items yet"}),o.map((S,j)=>{const N=S.workItemId===c,L=d.has(S.workItemId),A=uU(S),D=fU(S);return u.jsxs("div",{ref:N?g:null,className:`exec-task-card${N?" exec-task-card-focused":""}`,children:[u.jsxs("button",{type:"button",className:"exec-task-card-header",onClick:()=>p(S.workItemId),title:L?"Collapse":"Expand",children:[u.jsxs("span",{className:"exec-task-card-index",children:["Work item #",j+1]}),u.jsx("span",{className:"exec-task-card-title",children:S.title||S.workItemId}),u.jsx("span",{className:`exec-badge ${A.cls}`,children:A.label}),u.jsx("span",{className:"exec-task-card-time",children:cU(S.updatedAt)}),u.jsx("span",{className:`exec-task-card-chevron${L?" open":""}`,"aria-hidden":"true",children:"▸"})]}),L&&u.jsxs("div",{className:"exec-task-card-body",children:[u.jsxs("div",{className:"exec-task-card-projection",children:[u.jsx(Mm,{}),u.jsx("span",{children:Sy(S.kind)||"Work item"}),S.workItemProjectionId&&u.jsx("code",{children:S.workItemProjectionId}),S.executionTurnId&&u.jsx("span",{className:"exec-inline-tag",children:"Execution Turn"}),S.isReviewTarget&&u.jsx("span",{className:"exec-inline-tag",children:"Review target"}),S.executorRoleName&&u.jsx("span",{children:S.executorRoleName})]}),u.jsxs("div",{className:"exec-section",children:[u.jsxs("div",{className:"exec-section-header",children:[u.jsx(bl,{}),u.jsx("span",{children:"Activity"}),u.jsx("span",{className:"exec-section-count",children:D})]}),u.jsx("div",{className:"exec-section-content exec-activity-scroll",children:u.jsx(mU,{sections:S.activitySections,fallbackEntries:S.progressLog,sessionStatus:dU(S)})})]})]})]},S.workItemId)})]})]})]})}function pU({projects:e,activeId:t,onSelect:n,onCreate:i,onDelete:r}){const{t:o}=Vr(),[a,c]=C.useState(!1),[d,m]=C.useState(""),[h,p]=C.useState(null),g=C.useCallback(()=>{const v=d.trim().toLowerCase().replace(/[^a-z0-9_-]+/g,"-").replace(/^-|-$/g,"");v&&(i(v),m(""),c(!1))},[d,i]),x=C.useCallback(()=>{!h||!r||(r(h),p(null))},[h,r]);return u.jsxs("div",{className:"project-selector",style:{display:"flex",alignItems:"center",gap:6},children:[u.jsx("select",{className:"theme-select",value:t,onChange:v=>n(v.target.value),title:o("project.switch"),"aria-label":o("project.switch"),children:e.map(v=>u.jsx("option",{value:v.id,children:v.name},v.id))}),a?u.jsxs("form",{onSubmit:v=>{v.preventDefault(),g()},style:{display:"flex",gap:4},children:[u.jsx("input",{autoFocus:!0,className:"theme-select",value:d,placeholder:o("project.placeholder"),onChange:v=>m(v.target.value),onKeyDown:v=>{v.key==="Escape"&&c(!1)},style:{width:120}}),u.jsx("button",{type:"submit",className:"pill-btn",style:{fontSize:11,padding:"2px 8px"},children:"+"})]}):u.jsx("button",{className:"pill-btn",onClick:()=>c(!0),title:o("project.new"),style:{fontSize:11,padding:"2px 8px"},children:"+"}),r&&t!=="default"&&!h&&u.jsx("button",{className:"pill-btn",onClick:()=>p(t),title:o("project.delete"),style:{fontSize:11,padding:"2px 8px",color:"#ef4444"},children:o("project.deleteButton")}),h&&u.jsx("div",{className:"project-delete-confirm",style:{position:"fixed",inset:0,zIndex:9999,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.5)"},children:u.jsxs("div",{style:{background:"var(--bg-elevated)",borderRadius:12,padding:"24px 32px",border:"1px solid var(--border)",color:"var(--text)",maxWidth:400,boxShadow:"0 8px 32px rgba(0,0,0,0.4)",textAlign:"center"},children:[u.jsx("p",{style:{margin:"0 0 8px",fontWeight:600,fontSize:15,color:"var(--text)"},children:o("project.confirmTitle",{name:h})}),u.jsx("p",{style:{margin:"0 0 20px",fontSize:13,color:"var(--text-secondary)"},children:o("project.confirmBody")}),u.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"center"},children:[u.jsx("button",{className:"pill-btn",onClick:()=>p(null),style:{padding:"6px 18px",fontSize:13},children:o("common.cancel")}),u.jsx("button",{className:"pill-btn",onClick:x,style:{padding:"6px 18px",fontSize:13,background:"#ef4444",color:"#fff"},children:o("common.delete")})]})]})})]})}const hU=80;function gU(e){const t=Date.now()/1e3,n=Math.max(0,t-e);if(n<60)return"just now";if(n<3600)return`${Math.floor(n/60)}m ago`;if(n<86400)return`${Math.floor(n/3600)}h ago`;if(n<604800)return`${Math.floor(n/86400)}d ago`;try{return new Date(e*1e3).toLocaleDateString()}catch{return""}}function $C(e){return(e.organization_name||e.name).trim()||e.name}function yU(e){const t=e.trim();return t.length>0&&t.length<=hU&&!/[\\/]/.test(t)&&!/[\u0000-\u001f]/.test(t)}function xU(e){return e.normalize("NFKD").replace(/[^\x00-\x7F]/g,"").toLowerCase().trim().replace(/\s+/g,"_").replace(/[^a-z0-9_-]+/g,"_").replace(/_+/g,"_").replace(/^[_-]+|[_-]+$/g,"").slice(0,64)||"org"}function vU({className:e}){return u.jsxs("svg",{className:e,width:"12",height:"12",viewBox:"0 0 16 16",fill:"none","aria-hidden":!0,children:[u.jsx("path",{d:"M8 1.5L1.5 4.5L8 7.5L14.5 4.5L8 1.5Z",stroke:"currentColor",strokeWidth:"1.3",strokeLinejoin:"round"}),u.jsx("path",{d:"M2 8L8 10.8L14 8",stroke:"currentColor",strokeWidth:"1.3",strokeLinejoin:"round",opacity:"0.6"}),u.jsx("path",{d:"M2 11.5L8 14.2L14 11.5",stroke:"currentColor",strokeWidth:"1.3",strokeLinejoin:"round",opacity:"0.35"})]})}function bU({className:e}){return u.jsx("svg",{className:e,width:"10",height:"10",viewBox:"0 0 12 12",fill:"none","aria-hidden":!0,children:u.jsx("path",{d:"M3 4.5L6 7.5L9 4.5",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})})}function _U({className:e}){return u.jsxs("svg",{className:e,width:"11",height:"11",viewBox:"0 0 12 12",fill:"none","aria-hidden":!0,children:[u.jsx("circle",{cx:"5",cy:"5",r:"3.2",stroke:"currentColor",strokeWidth:"1.3"}),u.jsx("path",{d:"M7.5 7.5L10 10",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round"})]})}function kU({savedOrgs:e,activeName:t,isDirty:n,onRefresh:i,onSaveAs:r,onLoad:o,onDelete:a}){const[c,d]=C.useState(!1),[m,h]=C.useState(""),[p,g]=C.useState(0),[x,v]=C.useState(!1),[b,w]=C.useState(""),[k,S]=C.useState(null),[j,N]=C.useState(null),L=C.useRef(null),A=C.useRef(null);C.useEffect(()=>{N(null)},[t,e]);const D=(e??[]).filter(q=>!m.trim()||q.name.toLowerCase().includes(m.trim().toLowerCase())),O=C.useRef(!1);C.useEffect(()=>{c&&!O.current&&(O.current=!0,i())},[c,i]),C.useEffect(()=>{x&&A.current?.focus()},[x]),C.useEffect(()=>{g(q=>Math.min(q,Math.max(0,D.length-1)))},[D.length]),C.useEffect(()=>{if(!c)return;const q=K=>{L.current&&!L.current.contains(K.target)&&T()};return document.addEventListener("mousedown",q),()=>document.removeEventListener("mousedown",q)},[c]);const T=C.useCallback(()=>{d(!1),h(""),g(0),v(!1),w(""),S(null)},[]),M=C.useCallback(q=>{if(q===t){T();return}N(q),o(q),T()},[o,T,t]),I=C.useCallback(q=>{a(q),S(null)},[a]),H=b.trim(),Y=yU(H),P=xU(H),U=(e??[]).some(q=>q.name===P||$C(q).toLowerCase()===H.toLowerCase()),$=C.useCallback(()=>{Y&&(r(H,U),v(!1),w(""),T())},[Y,H,U,r,T]),G=q=>{if(q.key==="Escape"){q.preventDefault(),T();return}if(x){q.key==="Enter"&&(q.preventDefault(),$());return}if(q.key==="ArrowDown")q.preventDefault(),g(K=>Math.min(K+1,Math.max(0,D.length-1)));else if(q.key==="ArrowUp")q.preventDefault(),g(K=>Math.max(0,K-1));else if(q.key==="Enter"){const K=D[p];K&&M(K.name)}else if((q.key==="Backspace"||q.key==="Delete")&&(q.metaKey||q.ctrlKey)){const K=D[p];K&&(q.preventDefault(),S(K.name))}};return u.jsxs("div",{className:"sos-wrap",ref:L,children:[u.jsxs("button",{type:"button",className:"sos-pill","data-open":c?"true":"false",onClick:()=>d(q=>!q),"aria-haspopup":"listbox","aria-expanded":c,title:t?`Active saved architecture: ${t}`:"No saved architecture loaded",children:[u.jsx(vU,{className:"sos-pill-glyph"}),t?u.jsx("span",{className:"sos-pill-name",children:t}):u.jsx("span",{className:"sos-pill-name sos-pill-name--placeholder",children:"draft"}),n&&u.jsx("span",{className:"sos-pill-dirty","aria-label":"Modified since opened"}),u.jsx(bU,{className:"sos-pill-caret"})]}),c&&u.jsxs("div",{className:"sos-popover",role:"listbox",onKeyDown:G,tabIndex:-1,children:[u.jsxs("div",{className:"sos-search-row",children:[u.jsx(_U,{className:"sos-search-glyph"}),u.jsx("input",{type:"text",className:"sos-search-input",placeholder:"Search architectures…",value:m,onChange:q=>{h(q.target.value),g(0)},autoFocus:!0,onKeyDown:G}),u.jsx("kbd",{className:"sos-search-hint",children:"↑↓ ↵"})]}),u.jsx("div",{className:"sos-list",children:e===null?u.jsx("div",{className:"sos-empty",children:"Loading…"}):D.length===0?u.jsx("div",{className:"sos-empty",children:(e??[]).length===0?"No saved architectures.":"No matches."}):D.map((q,K)=>{const W=t===q.name,V=p===K,Q=$C(q);return u.jsxs("div",{className:`sos-row${W?" sos-row--active":""}`,"data-highlighted":V?"true":"false",onMouseEnter:()=>g(K),onClick:()=>M(q.name),role:"option","aria-selected":W,children:[u.jsxs("div",{className:"sos-row-meta",children:[u.jsx("span",{className:"sos-row-name",children:Q}),u.jsxs("span",{className:"sos-row-stats",children:[Q!==q.name&&`${q.name} · `,q.roles_count," ",q.roles_count===1?"role":"roles"," · ",q.employees_count," ",q.employees_count===1?"employee":"employees"," · ",gU(q.saved_at)]})]}),j===q.name?u.jsx("span",{className:"sos-row-loading",children:"loading…"}):W?u.jsx("span",{className:"sos-row-active-chip",children:"active"}):k===q.name?u.jsx("button",{type:"button",className:"sos-row-delete sos-row-delete--confirm",onClick:B=>{B.stopPropagation(),I(q.name)},children:"confirm"}):u.jsx("button",{type:"button",className:"sos-row-delete",onClick:B=>{B.stopPropagation(),S(q.name)},title:"Delete",children:"delete"})]},q.name)})}),u.jsxs("div",{className:"sos-save-as",children:[x?u.jsxs("div",{className:"sos-save-as-form",children:[u.jsx("input",{ref:A,type:"text",className:"sos-save-as-input",placeholder:"Organization name",value:b,onChange:q=>w(q.target.value),onKeyDown:G}),u.jsx("button",{type:"button",className:"btn btn-primary btn-sm",onClick:$,disabled:!Y,children:U?"Overwrite copy":"Save as copy"}),u.jsx("button",{type:"button",className:"btn btn-ghost btn-sm",onClick:()=>{v(!1),w("")},children:"Cancel"})]}):u.jsx("button",{type:"button",className:"sos-save-as-trigger",onClick:()=>v(!0),children:"+ Save as copy..."}),x&&b&&!Y&&u.jsx("div",{className:"sos-save-as-hint sos-save-as-hint--warn",children:"Use up to 80 characters. Slashes are not allowed."}),x&&Y&&U&&u.jsx("div",{className:"sos-save-as-hint sos-save-as-hint--warn",children:"Name exists - this will overwrite that copy."})]})]})]})}const SU=["leader","strategy","target","code","terminal","database","settings","bug","design","pen","layout","marketing","analytics","writing","clipboard","security","support","idea","person","team","camera","calendar","group","ai","generic"],mu={leader:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M5 16L3 5l5.5 5L12 4l3.5 6L21 5l-2 11H5zm0 2h14v2H5v-2z'/%3E%3C/svg%3E",strategy:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M19 22H5v-2h14v2zM17.16 8.26C18.22 9.63 19 10.85 19 12c0 2.21-3.13 4-7 4s-7-1.79-7-4c0-1.15.78-2.37 1.84-3.74C7.83 7.03 9 5.67 9 4.5a2.5 2.5 0 0 1 5 0c0 1.17 1.17 2.53 2.16 3.76zM12 6a.5.5 0 1 1 0-1 .5.5 0 0 1 0 1z'/%3E%3C/svg%3E",target:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8zm0-14c-3.31 0-6 2.69-6 6s2.69 6 6 6 6-2.69 6-6-2.69-6-6-6zm0 10c-2.21 0-4-1.79-4-4s1.79-4 4-4 4 1.79 4 4-1.79 4-4 4zm0-6a2 2 0 1 0 0 4 2 2 0 0 0 0-4z'/%3E%3C/svg%3E",code:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M9.4 16.6L4.8 12l4.6-4.6L8 6l-6 6 6 6 1.4-1.4zm5.2 0L19.2 12l-4.6-4.6L16 6l6 6-6 6-1.4-1.4z'/%3E%3C/svg%3E",terminal:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M20 4H4c-1.11 0-2 .9-2 2v12c0 1.1.89 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 14H4V8h16v10zM13 14h4v2h-4zm-3.41-.82l-2.59 2.59L8.41 17 12 13.41 8.41 9.82 7 11.24l2.59 2.59z'/%3E%3C/svg%3E",database:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M12 2C6.48 2 2 3.79 2 6v12c0 2.21 4.48 4 10 4s10-1.79 10-4V6c0-2.21-4.48-4-10-4zm0 18c-4.42 0-8-1.34-8-3v-2.5c1.74 1.5 4.71 2.5 8 2.5s6.26-1 8-2.5V17c0 1.66-3.58 3-8 3zm0-5c-4.42 0-8-1.34-8-3v-2.5c1.74 1.5 4.71 2.5 8 2.5s6.26-1 8-2.5V12c0 1.66-3.58 3-8 3zm0-5c-4.42 0-8-1.34-8-3s3.58-3 8-3 8 1.34 8 3-3.58 3-8 3z'/%3E%3C/svg%3E",settings:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M19.43 12.98c.04-.32.07-.64.07-.98 0-.34-.03-.66-.07-.98l2.11-1.65c.19-.15.24-.42.12-.64l-2-3.46c-.12-.22-.39-.3-.61-.22l-2.49 1c-.52-.4-1.08-.73-1.69-.98l-.38-2.65C14.46 2.18 14.25 2 14 2h-4c-.25 0-.46.18-.49.42l-.38 2.65c-.61.25-1.17.59-1.69.98l-2.49-1c-.23-.09-.49 0-.61.22l-2 3.46c-.13.22-.07.49.12.64l2.11 1.65c-.04.32-.07.65-.07.98 0 .33.03.66.07.98l-2.11 1.65c-.19.15-.24.42-.12.64l2 3.46c.12.22.39.3.61.22l2.49-1c.52.4 1.08.73 1.69.98l.38 2.65c.03.24.24.42.49.42h4c.25 0 .46-.18.49-.42l.38-2.65c.61-.25 1.17-.59 1.69-.98l2.49 1c.23.09.49 0 .61-.22l2-3.46c.12-.22.07-.49-.12-.64l-2.11-1.65zM12 15.5c-1.93 0-3.5-1.57-3.5-3.5s1.57-3.5 3.5-3.5 3.5 1.57 3.5 3.5-1.57 3.5-3.5 3.5z'/%3E%3C/svg%3E",bug:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M20 8h-2.81c-.45-.78-1.07-1.45-1.82-1.96L17 4.41 15.59 3l-2.17 2.17C12.96 5.06 12.49 5 12 5s-.96.06-1.41.17L8.41 3 7 4.41l1.62 1.63C7.88 6.55 7.26 7.22 6.81 8H4v2h2.09c-.05.33-.09.66-.09 1v1H4v2h2v1c0 .34.04.67.09 1H4v2h2.81c1.04 1.79 2.97 3 5.19 3s4.15-1.21 5.19-3H20v-2h-2.09c.05-.33.09-.66.09-1v-1h2v-2h-2v-1c0-.34-.04-.67-.09-1H20V8zm-6 8h-4v-2h4v2zm0-4h-4v-2h4v2z'/%3E%3C/svg%3E",design:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M12 2C6.49 2 2 6.49 2 12s4.49 10 10 10c1.38 0 2.5-1.12 2.5-2.5 0-.61-.23-1.2-.64-1.67-.08-.1-.13-.21-.13-.33 0-.28.22-.5.5-.5H16c3.31 0 6-2.69 6-6 0-4.96-4.49-9-10-9zm5.5 11c-.83 0-1.5-.67-1.5-1.5s.67-1.5 1.5-1.5 1.5.67 1.5 1.5-.67 1.5-1.5 1.5zm-3-4c-.83 0-1.5-.67-1.5-1.5S13.67 6 14.5 6s1.5.67 1.5 1.5S15.33 9 14.5 9zm-5 0C8.67 9 8 8.33 8 7.5S8.67 6 9.5 6s1.5.67 1.5 1.5S10.33 9 9.5 9zm-3 4c-.83 0-1.5-.67-1.5-1.5s.67-1.5 1.5-1.5 1.5.67 1.5 1.5-.67 1.5-1.5 1.5z'/%3E%3C/svg%3E",pen:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.39-.39-1.02-.39-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z'/%3E%3C/svg%3E",layout:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M3 13h8V3H3v10zm0 8h8v-6H3v6zm10 0h8V11h-8v10zm0-18v6h8V3h-8z'/%3E%3C/svg%3E",marketing:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M18 11v2h4v-2h-4zm-2 6.61c.96.71 2.21 1.65 3.2 2.39.4-.53.8-1.07 1.2-1.6-.99-.74-2.24-1.68-3.2-2.4-.4.54-.8 1.08-1.2 1.61zM20.4 5.6c-.4-.53-.8-1.07-1.2-1.6-.99.74-2.24 1.68-3.2 2.4.4.53.8 1.07 1.2 1.6.96-.72 2.21-1.65 3.2-2.4zM4 9c-1.1 0-2 .9-2 2v2c0 1.1.9 2 2 2h1v4h2v-4h1l5 3V6L8 9H4zm11.5 3c0-1.33-.58-2.53-1.5-3.35v6.69c.92-.81 1.5-2.01 1.5-3.34z'/%3E%3C/svg%3E",analytics:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M3.5 18.49l6-6.01 4 4L22 6.92l-1.41-1.41-7.09 7.97-4-4L2 16.99l1.5 1.5z'/%3E%3C/svg%3E",writing:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.39-.39-1.02-.39-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z'/%3E%3C/svg%3E",clipboard:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M19 3h-4.18C14.4 1.84 13.3 1 12 1c-1.3 0-2.4.84-2.82 2H5c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-7 0c.55 0 1 .45 1 1s-.45 1-1 1-1-.45-1-1 .45-1 1-1zm2 14H7v-2h7v2zm3-4H7v-2h10v2zm0-4H7V7h10v2z'/%3E%3C/svg%3E",security:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M12 1L3 5v6c0 5.55 3.84 10.74 9 12 5.16-1.26 9-6.45 9-12V5l-9-4zm0 10.99h7c-.53 4.12-3.28 7.79-7 8.94V12H5V6.3l7-3.11V11.99z'/%3E%3C/svg%3E",support:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M21 6h-2v9H6v2c0 .55.45 1 1 1h11l4 4V7c0-.55-.45-1-1-1zm-4 6V3c0-.55-.45-1-1-1H3c-.55 0-1 .45-1 1v14l4-4h10c.55 0 1-.45 1-1z'/%3E%3C/svg%3E",idea:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M9 21c0 .55.45 1 1 1h4c.55 0 1-.45 1-1v-1H9v1zm3-19C8.14 2 5 5.14 5 9c0 2.38 1.19 4.47 3 5.74V17c0 .55.45 1 1 1h6c.55 0 1-.45 1-1v-2.26c1.81-1.27 3-3.36 3-5.74 0-3.86-3.14-7-7-7z'/%3E%3C/svg%3E",person:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z'/%3E%3C/svg%3E",team:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M16 11c1.66 0 2.99-1.34 2.99-3S17.66 5 16 5c-1.66 0-3 1.34-3 3s1.34 3 3 3zm-8 0c1.66 0 2.99-1.34 2.99-3S9.66 5 8 5C6.34 5 5 6.34 5 8s1.34 3 3 3zm0 2c-2.33 0-7 1.17-7 3.5V19h14v-2.5c0-2.33-4.67-3.5-7-3.5zm8 0c-.29 0-.62.02-.97.05 1.16.84 1.97 1.97 1.97 3.45V19h6v-2.5c0-2.33-4.67-3.5-7-3.5z'/%3E%3C/svg%3E",camera:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M12 15.2c-1.77 0-3.2-1.43-3.2-3.2s1.43-3.2 3.2-3.2 3.2 1.43 3.2 3.2-1.43 3.2-3.2 3.2zM9 2L7.17 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2h-3.17L15 2H9zm3 15c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5z'/%3E%3C/svg%3E",calendar:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M19 3h-1V1h-2v2H8V1H6v2H5c-1.11 0-1.99.9-1.99 2L3 19c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H5V8h14v11zM7 10h5v5H7z'/%3E%3C/svg%3E",group:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M12 12.75c1.63 0 3.07.39 4.24.9 1.08.48 1.76 1.56 1.76 2.73L18 18H6l.01-1.62c0-1.17.68-2.25 1.76-2.73 1.17-.51 2.6-.9 4.23-.9zM4 13c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm1.13 1.1c-.37-.06-.74-.1-1.13-.1-.99 0-1.93.21-2.78.58C.48 14.9 0 15.62 0 16.43V18h4.5v-1.61c0-.83.23-1.61.63-2.29zM20 13c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm4 3.43c0-.81-.48-1.53-1.22-1.85-.85-.37-1.79-.58-2.78-.58-.39 0-.76.04-1.13.1.4.68.63 1.46.63 2.29V18H24v-1.57zM12 6c1.66 0 3 1.34 3 3s-1.34 3-3 3-3-1.34-3-3 1.34-3 3-3z'/%3E%3C/svg%3E",ai:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M19 9l1.25-2.75L23 5l-2.75-1.25L19 1l-1.25 2.75L15 5l2.75 1.25L19 9zm-7.5.5L9 4 6.5 9.5 1 12l5.5 2.5L9 20l2.5-5.5L17 12l-5.5-2.5zM19 15l-1.25 2.75L15 19l2.75 1.25L19 23l1.25-2.75L23 19l-2.75-1.25L19 15z'/%3E%3C/svg%3E",generic:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23888' d='M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z'/%3E%3C/svg%3E"};function Uu(e){return e?e.startsWith("data:")?e:mu[e]??mu.generic:mu.generic}const Xc=["file_read","file_write","file_edit","file_search","list_dir","shell_exec","web_search","web_fetch","todo_read","todo_write","browser_navigate","browser_navigate_back","browser_snapshot","browser_wait_for","browser_scroll","browser_click","browser_type","browser_select_option","browser_take_screenshot","browser_evaluate","browser_close"],wU=[{label:"Files",prefix:"file_",tools:Xc.filter(e=>e.startsWith("file_"))},{label:"Shell",prefix:"shell_",tools:Xc.filter(e=>e==="shell_exec")},{label:"Web",prefix:"web_",tools:Xc.filter(e=>e.startsWith("web_"))},{label:"TODOs",prefix:"todo_",tools:Xc.filter(e=>e.startsWith("todo_"))},{label:"Browser",prefix:"browser_",tools:Xc.filter(e=>e.startsWith("browser_"))}],CU=["codex","cursor","claude_code","opencode"],jU=[{value:"auto",label:"Auto",hint:"System picks native or external based on role config"},{value:"native",label:"Native",hint:"Run directly in-process via LLM"},{value:"external",label:"External",hint:"Delegate to an external agent (codex, cursor, etc.)"}];function EU({role:e,allRoles:t,employees:n,readOnly:i,onUpdateRole:r,onDeleteRole:o,onClose:a}){const[c,d]=C.useState(e.name),[m,h]=C.useState(e.responsibility),[p,g]=C.useState(e.reports_to),[x,v]=C.useState(e.icon??null),[b,w]=C.useState(()=>new Set(e.can_spawn)),[k,S]=C.useState(()=>new Set(e.tools)),[j,N]=C.useState(e.runtime_policy?.execution_strategy??"auto"),[L,A]=C.useState(e.preferred_external_agent??null),[D,O]=C.useState((e.prompt_refs??[]).join(` `)),[T,M]=C.useState(!1),I=C.useRef(e.role_id);C.useEffect(()=>{I.current!==e.role_id&&(I.current=e.role_id,d(e.name),h(e.responsibility),g(e.reports_to),v(e.icon??null),w(new Set(e.can_spawn)),S(new Set(e.tools)),N(e.runtime_policy?.execution_strategy??"auto"),A(e.preferred_external_agent??null),O((e.prompt_refs??[]).join(` `)),M(!1))},[e]);const H=C.useRef({}),Y=C.useRef(null),P=C.useRef(e.role_id);C.useEffect(()=>{P.current=e.role_id},[e.role_id]);const U=C.useCallback(()=>{Y.current&&(clearTimeout(Y.current),Y.current=null);const ie=H.current;H.current={},Object.keys(ie).length!==0&&r(P.current,ie)},[r]),$=C.useCallback(ie=>{i||(H.current={...H.current,...ie},Y.current&&clearTimeout(Y.current),Y.current=setTimeout(U,500))},[U,i]);C.useEffect(()=>()=>{Y.current&&(clearTimeout(Y.current),Y.current=null);const ie=H.current;Object.keys(ie).length>0&&(H.current={},r(P.current,ie))},[r]);const G=ie=>{d(ie),$({name:ie})},q=ie=>{h(ie),$({responsibility:ie})},K=ie=>{g(ie),$({reports_to:ie})},W=ie=>{v(ie),$({icon:ie})},V=ie=>{N(ie),$({execution_strategy:ie})},Q=ie=>{A(ie),$({preferred_external_agent:ie})},B=ie=>{O(ie);const je=ie.split(` `).map(we=>we.trim()).filter(Boolean);$({prompt_refs:je})},Z=ie=>{const je=new Set(b);je.has(ie)?je.delete(ie):je.add(ie),w(je),$({can_spawn:Array.from(je)})},te=ie=>{const je=new Set(k);je.has(ie)?je.delete(ie):je.add(ie),S(je),$({tools:Array.from(je)})},ee=C.useMemo(()=>t.filter(ie=>ie.role_id!==e.role_id),[t,e.role_id]),se=C.useMemo(()=>n.filter(ie=>(ie.role_ids?.length?ie.role_ids:[ie.role_id]).includes(e.role_id)).length,[n,e.role_id]),ae=C.useMemo(()=>D.split(` diff --git a/opc/plugins/office_ui/frontend_dist/index.html b/opc/plugins/office_ui/frontend_dist/index.html index 11f3195..9945e3b 100644 --- a/opc/plugins/office_ui/frontend_dist/index.html +++ b/opc/plugins/office_ui/frontend_dist/index.html @@ -1,16 +1,16 @@ - - -
- - - -+
{t('project.confirmTitle', { name: confirmDelete })}
-+
{t('project.confirmBody')}