@yeaft/webchat-agent 1.0.572 → 1.0.573

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":"1.0.572"}
1
+ {"version":"1.0.573"}
@@ -6879,7 +6879,7 @@ ${String(e||"").trim()}
6879
6879
  </div>
6880
6880
  `}});function $r(e){return typeof e=="string"?e.trim():""}function LC(e){try{let t=new URL(e);return t.protocol==="http:"||t.protocol==="https:"?t.href:""}catch{return""}}function sy(e){let t=$r(e).replace(/\\/g,"/"),s=t.match(/^[A-Za-z]:/)?.[0]||"",n=t.startsWith("/")||!!s,r=t.slice(s.length).split("/"),i=[];for(let o of r)if(!(!o||o==="."))if(o===".."){if(!i.length)return"";i.pop()}else i.push(o);return`${s}${n&&!s||s?"/":""}${i.join("/")}`}function Wd(e,t){let s=$r(e?.ref);if(!s)return null;let n=LC(s);if(e?.kind==="link"||e?.kind==="pr"||n)return n?{type:"url",url:n}:null;if(e?.kind!=="file"||!/^(?:[A-Za-z]:[\\/]|[\\/])/.test($r(t)))return null;let r=sy(t),i=/^(?:[A-Za-z]:[\\/]|[\\/])/.test(s),o=sy(i?s:`${r}/${s}`);if(!r||!o)return null;let a=/^[A-Za-z]:/.test(r)?r.toLowerCase():r,l=/^[A-Za-z]:/.test(o)?o.toLowerCase():o,c=a.endsWith("/")?a:`${a}/`;return l!==a&&!l.startsWith(c)?null:{type:"file",filePath:o}}function ny({agentId:e,workItem:t,routeProtocolSupported:s=!1,hasAgentCapability:n=()=>!1}={}){let r=$r(t?.id),i=$r(t?.workbench?.workDir),o={runtimeProvider:"work-center",agentId:$r(e),workItemId:r},a=lt(o),l=$C.filter(u=>!n(o.agentId,u)),c=s===!0&&!!(a&&i)&&l.length===0,d=c?Ds(a,i):"";return{available:c,browserAvailable:!1,missingCapabilities:l,ownerRoute:o,ownerWorkDir:i,routeKey:a,workspaceGeneration:d,openOutput(u){if(!c)return!1;let g=Wd(u,i);return g?.type!=="file"?!1:(window.dispatchEvent(new CustomEvent("open-file-in-explorer",{detail:{filePath:g.filePath,agentId:o.agentId,conversationId:$n(a),workbenchRoute:o,workbenchRouteKey:a,workspaceGeneration:d}})),!0)}}}var $C,ry=F(()=>{gs();$C=Object.freeze(["workbench_session_routes","workbench_request_correlation","workbench_terminal_cleanup_fence","work_center_workbench"])});function OC(){try{let e=Number(localStorage.getItem("work-center-actions-width"));if(Number.isFinite(e)&&e>=280&&e<=1e4)return e}catch{}return 400}function Ga(e){let t=(Number(e?.workCenterUrlRestoreGeneration)||0)+1;return e&&(e.workCenterUrlRestoreGeneration=t),t}var Ya,Ud=F(()=>{xi();Dr();Zc();It();Ua();Lv();qv();Nv();cd();la();aa();La();Vn();_a();Uv();Kv();ty();Nd();ry();Ai();tn();Mi();$o();Ya={name:"WorkCenterPage",components:{FolderPickerDialog:rn,NavigationIcon:ks,MessageComposer:wa,UserTurnBlock:kr,VpTurnBlock:wr,WorkCenterActionDetail:$v,WorkCenterActionReference:Er,WorkCenterSettingsModal:Hv,AgentSettingsPanel:_r,ModernSelect:Wt,WorkCenterResourceControl:Fv,WorkbenchPanel:Mr,PaneResizeHandle:Wv,WorkCenterSidebar:jv,WorkCenterScheduleEditor:ey},mixins:[Xo],data(){return{sidebarExpanded:window.innerWidth>1100,mobileNavigation:window.innerWidth<=1100,selectedId:null,infoTab:"requirement",workbenchExpanded:!1,selectedActionId:null,narrowPane:"items",contentPanelOpen:!1,actionsPaneWidth:OC(),contentStack:[{type:"action-list"}],staleComposerTarget:null,composerTargetValue:"coordinator",actionInputRequestGeneration:0,workCenterUrlRestoreGeneration:0,workItemMessage:"",workItemMessageQuote:null,workItemMessageAttachments:[],workItemMessageAttachmentUploadCount:0,workItemMessageAttachmentsUploading:!1,workItemMessageSending:!1,workItemMessageError:"",workItemComposerGeneration:0,preserveComposerOnEnvelopeClear:!1,detailLoading:!1,detailError:"",createOpen:!1,settingsOpen:!1,saving:!1,createError:"",scheduleSaving:!1,scheduleDraftStarted:!1,scheduleError:"",createGeneration:0,llmConfigOpen:!1,agentSettingsOpen:!1,agentSettingsTargetId:null,unavailableAgentStateGeneration:0,unavailableAgentStateLoading:!1,unavailableAgentStateError:"",search:"",filtersOpen:!1,createAgentSelection:null,boardVpId:"",boardWorkItemType:"",boardUpdatedRange:"week",mobileBoardLane:"active",deletingWorkItemIds:{},deleteWorkItemError:"",boardQueryTimer:null,actionNowMs:Date.now(),workDirTouched:!1,startTouched:!1,createAttachments:[],createAttachmentUploadCount:0,attachmentsUploading:!1,createAttachmentError:"",deliveryInstructionOptions:[],customDeliveryTarget:!1,deliveryInstructionsGeneration:0,previewingAttachmentId:null,attachmentPreviewError:"",attachmentPreviewGeneration:0,form:{requirement:"",workDir:"",deliveryTarget:"",deliveryInstructions:"",start:!0,scheduled:!1,scheduleDraft:Qi()}}},computed:{store(){return Pinia.useChatStore()},chat(){return this.store},agents(){return this.store.agents||[]},onlineAgents(){return this.agents.filter(e=>e?.online&&Array.isArray(e.capabilities)&&e.capabilities.includes("work_center"))},configurableDisabledAgents(){return this.agents.filter(e=>{let t=this.store.workCenterFeatureSettingsByAgent?.[e?.id];return e?.online&&Array.isArray(e.capabilities)&&e.capabilities.includes("work_center_feature_settings")&&!e.capabilities.includes("work_center")&&t?.loaded===!0&&!t.error&&t.enabled!==!0})},configurableUnavailableAgents(){return this.agents.filter(e=>{let t=this.store.workCenterFeatureSettingsByAgent?.[e?.id];return e?.online&&Array.isArray(e.capabilities)&&e.capabilities.includes("work_center_feature_settings")&&!e.capabilities.includes("work_center")&&t?.loaded===!0&&!t.error&&t.enabled===!0})},configurableAgentSettingsLoading(){return this.unavailableAgentStateLoading},configurableAgentSettingsFailed(){return!!this.unavailableAgentStateError},hasConfigurableOnlineAgents(){return this.agents.some(e=>e?.online&&e.capabilities?.includes("work_center_feature_settings"))},hasOnlineAgents(){return this.agents.some(e=>e?.online)},agentId(){let e=this.store.workCenterAgentId;return this.onlineAgents.some(t=>t.id===e)?e:this.onlineAgents[0]?.id||null},sidebarAgents(){return this.agents.filter(e=>e.capabilities?.includes("work_center"))},createAgentOptions(){return this.sidebarAgents.map(e=>({value:e.id,label:e.name||e.id,badge:e.online?"":this.$t("workCenter.offline"),disabled:!e.online}))},deliveryTargetOptions(){return["","response","workspace_files","pull_request","merge"].map(e=>({value:e,label:this.deliveryTargetLabel(e)})).concat({value:"custom",label:this.$t("workCenter.deliveryTargetCustom")},this.deliveryInstructionOptions.map(e=>({value:`history:${e}`,label:e})))},deliveryTargetChoice:{get(){return this.customDeliveryTarget?"custom":this.form.deliveryTarget},set(e){let t=e.startsWith("history:");this.customDeliveryTarget=e==="custom"||t,this.form.deliveryTarget=this.customDeliveryTarget?"":e,this.form.deliveryInstructions=t?e.slice(8):this.customDeliveryTarget?this.form.deliveryInstructions:""}},watcher(){return this.store.workCenterWatcherByAgent[this.agentId]||null},boardNextCursor(){return this.store.workCenterListPageByAgent[this.agentId]?.nextCursor||null},boardLoadingMore(){return!!this.store.workCenterListMoreLoadingByAgent[this.agentId]},settings(){return this.store.workCenterSettingsByAgent[this.agentId]||null},runtime(){return this.store.workCenterRuntimeByAgent[this.agentId]||null},recurringSchedulesSupported(){return this.runtime?.recurringSchedules===!0},createScheduleResult(){return this.form.scheduled?Xi(this.form.scheduleDraft,this.actionNowMs):{}},executionMode(){return this.form.scheduled?"scheduled":this.form.start?"now":"draft"},workItemTypes(){return Array.isArray(this.runtime?.workItemTypes)?this.runtime.workItemTypes:[]},workItemAttachmentsSupported(){let e=this.agents.find(t=>t?.id===this.agentId);return e?.capabilityMetadataProvided===!0?e.capabilities?.includes("work_item_attachments")===!0:this.runtime?.workItemAttachments===!0},canonicalMessageWireSupported(){return this.agents.find(e=>e?.id===this.agentId)?.capabilities?.includes("work_center_message_v2")===!0},createDefaultWorkDir(){return this.settings?.defaultWorkDir||this.runtime?.defaultWorkDir||""},createDefaultStart(){return this.settings?.startImmediately!==!1},folderPickerAgentId(){return this.agentId||""},defaultWorkDir(){return this.createDefaultWorkDir},items(){return this.store.workCenterItemsByAgent[this.agentId]||[]},loading(){return!!this.store.workCenterLoadingByAgent[this.agentId]},loaded(){return!!this.store.workCenterLoadedByAgent[this.agentId]},error(){return this.store.workCenterErrorByAgent[this.agentId]||null},detail(){return this.store.workCenterDetailByAgent[this.agentId]||null},selected(){return this.detail?.id===this.selectedId?this.detail:this.items.find(e=>e.id===this.selectedId)||null},workbenchContext(){return ny({agentId:this.agentId,workItem:this.narrowPane!=="items"?this.selected:null,routeProtocolSupported:this.store.workCenterWorkbenchProtocolSupported===!0&&this.store.workbenchRouteProtocolSupported===!0,hasAgentCapability:(e,t)=>this.store.hasAgentCapability(e,t)})},infoTabs(){return["requirement","progress","outputs","goals","usage"].map(e=>({id:e,label:this.$t(`workCenter.infoTab.${e}`)}))},requirementText(){return this.selected?.requirement||this.selected?.goal||""},goalProgress(){let e=this.selected?.goalProgress;return Array.isArray(e?.criteria)?e:null},finalResponses(){let e=this.selected?.finalResult?.responses;return Array.isArray(e)?e.filter(t=>typeof t?.summary=="string"&&t.summary.trim()):[]},selectedAction(){return(Array.isArray(this.selected?.actions)?this.selected.actions:[]).find(t=>t.id===this.selectedActionId)||null},contentRef(){return this.contentStack[this.contentStack.length-1]||{type:"action-list"}},contentIsActionList(){return this.contentRef.type==="action-list"},waitingPrompt(){if(this.selected?.status!=="waiting")return null;let e=this.selected.messages?.findLast(r=>r.role==="assistant"&&r.decision),t=this.selected.actions||[];if(e?.role==="assistant"&&e.decision?.kind==="request_human"){let r=t.find(i=>i.id===e.recovery?.actionId&&i.generation===e.recovery?.actionGeneration&&i.status==="waiting");return{question:e.decision.question||this.selected.waitingReason||e.text,action:r||null}}let s=t.find(r=>r.id===this.selected.currentActionId&&r.status==="waiting"),n=s?.canonicalResult?.waitingReason||this.selected.waitingReason;return n?{question:n,action:s||null}:null},replyEntryDisabled(){return this.coordinatorReadOnly||this.detailLoading||!!this.detailError||this.workItemMessageSending||this.workItemMessageAttachmentsUploading||!!this.pendingMessageEnvelope},composerTargetIsCoordinator(){return this.composerTargetValue==="coordinator"},composerTargetAction(){if(!this.composerTargetValue.startsWith("action:"))return null;let[,e,t]=this.composerTargetValue.split(":"),s=Number(t);return(Array.isArray(this.selected?.actions)?this.selected.actions:[]).find(r=>r.id===e&&Number(r.generation)===s)||null},composerTargetIsStale(){return this.composerTargetValue!=="coordinator"&&!this.composerTargetAction},composerTargetOptions(){let e=Array.isArray(this.selected?.actions)?this.selected.actions:[],t=this.tr("workCenter.coordinator","Coordinator"),s=[{value:"coordinator",label:this.$t("workCenter.sendToTarget",{target:t}),sublabel:this.tr("workCenter.coordinatorTargetHint","Work Item planning and coordination"),disabled:!1},...e.map(n=>{let r=this.$t("workCenter.actionNumber",{number:this.actionSequence(n)});return{value:`action:${n.id}:${n.generation}`,label:this.$t("workCenter.sendToTarget",{target:r}),sublabel:n.brief?.objective||this.actionLabel(n.type),badge:this.statusLabel(n.status),disabled:!this.canMessageAction(n)}})];return this.composerTargetIsStale?[{value:this.composerTargetValue,label:this.tr("workCenter.targetUnavailable","Selected Action is no longer available"),sublabel:this.tr("workCenter.targetUnavailableHelp","Choose another target before sending. This draft was not redirected."),disabled:!0},...s]:s},composerTargetLabel(){return this.composerTargetAction?this.composerTargetAction.brief?.objective||this.actionLabel(this.composerTargetAction.type):this.tr("workCenter.coordinator","Coordinator")},composerPlaceholder(){return this.composerTargetAction?this.$t("workCenter.actionChatPlaceholder",{name:this.composerTargetLabel}):this.tr("workCenter.conversationPlaceholder","Message about this work item")},composerTargetUnavailable(){return this.coordinatorReadOnly?!0:this.composerTargetIsCoordinator?this.coordinatorThinking:this.composerTargetAction?!this.canMessageAction(this.composerTargetAction):!0},composerCanSend(){return!this.workItemMessageSending&&!this.workItemMessageAttachmentsUploading&&!this.composerTargetUnavailable&&(!!this.workItemMessage.trim()||this.workItemMessageAttachments.length>0)},pendingMessageEnvelope(){return this.selected?.id?this.store.loadWorkCenterMessageEnvelope(this.agentId,this.selected.id):null},composerDraftLocked(){return!!this.pendingMessageEnvelope&&!this.composerTargetIsStale},pendingEnvelopeHasAttachments(){return Array.isArray(this.pendingMessageEnvelope?.attachments)&&this.pendingMessageEnvelope.attachments.length>0},pendingEnvelopeAttachmentRecovery(){return this.composerDraftLocked&&this.pendingEnvelopeHasAttachments},actionMessageKey(){return this.selected?.id&&this.selectedAction?.id?dr(this.agentId,this.selected.id,this.selectedAction.id,this.selectedAction.generation):""},workItemComposerScope(){return this.selected?.id?`${this.agentId}:${this.selected.id}:${this.workItemComposerGeneration}`:""},conversationBlocks(){return(Array.isArray(this.selected?.messages)?this.selected.messages:[]).map(e=>{let t=Number(e?.updatedAt||e?.createdAt)||0;if(e?.role==="user")return{key:e.id,kind:"user",message:{id:e.id,messageId:e.id,type:"user",content:e.text||"",attachments:Array.isArray(e.attachments)?e.attachments:[],quote:Mt(e.quote),timestamp:t}};if(e?.role==="assistant"){let s=e.speaker||{},n=this.workItemMessageSpeaker(e),r=s.id||`work-center-coordinator:${this.selected?.id||"unknown"}`,i=e.status==="thinking"?this.tr("workCenter.conversationThinking","Working\u2026"):e.error||"",o=e.decision?.kind&&e.decision.kind!=="answer"?this.tr(`workCenter.coordinatorDecision.${e.decision.kind}`,e.decision.kind):"",a=[e.text,i,o].filter(Boolean);return{key:e.id,kind:"assistant",speakerName:n,turn:{id:e.id,messageId:e.id,atMessageId:e.id,turnId:e.turnId||e.id,textContent:a.join(`
6881
6881
 
6882
- `),textSegments:a.map((l,c)=>({key:`${e.id}:${c}`,content:l,kind:e.status==="thinking"?"progress":"result",isStreaming:e.status==="thinking"})),isStreaming:e.status==="thinking",speakerVpId:r,speakerTimestamp:t,showSpeakerHeader:!0,timestamp:t,createdAt:t,todoMsg:null,toolMsgs:[],toolSummaryCount:0,imageMsgs:[],askMsg:null,attachments:Array.isArray(e.attachments)?e.attachments:[]}}}return{key:e.id,kind:"system",message:e}})},coordinatorThinking(){return(this.selected?.messages||[]).some(e=>e?.role==="assistant"&&e.status==="thinking")},coordinatorReadOnly(){return!!this.selected?.schedule?.recurrence||["done","cancelled"].includes(this.selected?.status)},actionMessages(){let e=Array.isArray(this.selectedAction?.messages)?this.selectedAction.messages:[],t=(Array.isArray(this.selectedAction?.thread)?this.selectedAction.thread:[]).flatMap(o=>Array.isArray(o?.messages)?o.messages:[]),s=this.store.workCenterActionMessages[this.actionMessageKey]?.messages||[],n=gi(t,s,e),r=this.selectedAction?.liveMessage,i=r&&n.some(o=>o.role==="assistant"&&o.runId!=null&&o.runId===r.runId&&(r.status==="running"?o.text===r.text:o.status!=="running"));return gi(n,i?null:r)},actionMessagesNextCursor(){let e=this.store.workCenterActionMessages[this.actionMessageKey];return e?e.nextCursor:this.selectedAction?.messageCursor},actionMessagesLoading(){return!!this.store.workCenterActionMessagesLoading[this.actionMessageKey]},actionMessagesError(){return this.store.workCenterActionMessagesError[this.actionMessageKey]||""},orderedActions(){let e=Array.isArray(this.selected?.actions)?this.selected.actions:[];return Ql(e)},boardLanes(){return[{id:"active",title:this.tr("workCenter.board.active","Active")},{id:"needs_attention",title:this.tr("workCenter.board.needsAttention","Needs attention")},{id:"closed",title:this.tr("workCenter.board.closed","Closed")}].map(e=>({...e,items:this.items.filter(t=>t.boardLane===e.id)}))},boardExecutorOptions(){let e=new Map;for(let t of this.items)for(let s of Array.isArray(t.executors)?t.executors:[])s?.id&&e.set(s.id,s.name||s.id);return[...e.entries()].map(([t,s])=>({id:t,name:s}))},boardTypeOptions(){return[...new Set(this.items.map(e=>e.workItemType).filter(Boolean))].sort()},emptyState(){return{title:this.search.trim()?this.tr("workCenter.noMatchesTitle","No matching work items"):this.tr("workCenter.emptyTitle","No work items yet"),body:this.search.trim()?this.tr("workCenter.noMatchesBody","Try a different search or filter."):this.tr("workCenter.emptyBody","Create a persistent task when work must continue beyond one conversation turn."),canCreate:!this.search.trim()}}},watch:{selectedId(){this.infoTab="requirement",this.scheduleError=""},"workbenchContext.workspaceGeneration"(){this.workbenchExpanded=!1},agents:{immediate:!0,deep:!0,handler(){this.loadUnavailableAgentStates()}},agentId:{immediate:!0,handler(e,t){if(Ga(this),this.createGeneration=(Number(this.createGeneration)||0)+1,this.createAttachmentUploadCount=0,this.attachmentsUploading=!1,this.deliveryInstructionOptions=[],this.deliveryInstructionsGeneration+=1,this.saving=!1,this.selectedId=null,this.selectedActionId=null,this.contentPanelOpen=!1,this.resetWorkItemComposer?.(),this.resetContentStack?.(),this.composerTargetValue="coordinator",this.narrowPane="items",this.filtersOpen=!1,this.previewingAttachmentId=null,this.attachmentPreviewError="",this.attachmentPreviewGeneration=(Number(this.attachmentPreviewGeneration)||0)+1,t&&e!==t&&(this.closeFolderPicker(),this.resetCreateExecutionContext(e,{keepOpen:!!e&&this.createAgentSelection===e})),this.createAgentSelection=null,this.store.workCenterAgentId!==e){this.store.enterWorkCenter(e);return}e&&((typeof this.boardFilters=="function"?this.store.listWorkItems(e,this.boardFilters()):this.store.listWorkItems(e)).catch(()=>{}),this.store.loadWorkCenterSettings(e).catch(()=>{}),this.createOpen&&this.loadDeliveryInstructionOptions())}},actionsPaneWidth(e){try{localStorage.setItem("work-center-actions-width",String(e))}catch{}},createDefaultWorkDir(){this.applyCreateDefaults()},createDefaultStart(){this.applyCreateDefaults()},search(){this.scheduleBoardQuery()},boardVpId(){this.scheduleBoardQuery()},boardWorkItemType(){this.scheduleBoardQuery()},boardUpdatedRange(){this.scheduleBoardQuery()},"detail.coordinatorRevision"(){this.$nextTick(()=>{let e=this.$el?.querySelector?.(".work-center-conversation-scroll");e&&(e.scrollTop=e.scrollHeight)})},pendingMessageEnvelope(e,t){if(!(!t||e||t.workItemId!==this.selectedId)){if(this.preserveComposerOnEnvelopeClear){this.preserveComposerOnEnvelopeClear=!1,this.workItemMessageError="",this.workItemMessageSending=!1;return}this.workItemMessage="",this.workItemMessageQuote=null,this.workItemMessageAttachments=[],this.workItemMessageError="",this.workItemMessageSending=!1}},detail:{deep:!0,handler(e){if(!e||e.id!==this.selectedId)return;let t=Array.isArray(e.actions)?e.actions:[];this.selectedActionId&&!t.some(s=>s.id===this.selectedActionId)&&(this.selectedActionId=null,this.contentPanelOpen=!1,this.resetContentStack(),this.syncWorkCenterUrl(!0),this.previewingAttachmentId=null,this.attachmentPreviewError="",this.attachmentPreviewGeneration=(Number(this.attachmentPreviewGeneration)||0)+1),this.composerTargetAction==null&&this.composerTargetValue!=="coordinator"?this.staleComposerTarget=this.composerTargetValue:this.staleComposerTarget=null}}},beforeUnmount(){Ga(this),this.createGeneration=(Number(this.createGeneration)||0)+1,this.workItemComposerGeneration+=1,this.unavailableAgentStateGeneration+=1,this.deliveryInstructionsGeneration+=1,this.boardQueryTimer&&clearTimeout(this.boardQueryTimer),clearInterval(this.actionClockTimer),window.removeEventListener("popstate",this.restoreWorkCenterUrl),document.removeEventListener("click",this.closeHeaderPopovers),this.navigationMedia?.removeEventListener("change",this.onNavigationResize)},mounted(){this.actionClockTimer=setInterval(()=>{this.actionNowMs=Date.now()},1e3),this.returnFocusElement=document.activeElement,this.navigationMedia=window.matchMedia("(max-width: 1100px)"),this.navigationMedia.addEventListener("change",this.onNavigationResize),this.$nextTick(()=>this.focusNavigationReturn()),window.addEventListener("popstate",this.restoreWorkCenterUrl),document.addEventListener("click",this.closeHeaderPopovers),this.restoreWorkCenterUrl();let e=this.store.workCenterCreateDraft;e&&(this.form={requirement:e.requirement||e.goal||e.title||"",workDir:e.workDir||"",deliveryTarget:e.deliveryTarget||"",deliveryInstructions:e.deliveryInstructions||"",start:this.settings?.startImmediately!==!1},this.customDeliveryTarget=!!this.form.deliveryInstructions.trim(),this.createOpen=!0,this.workDirTouched=!!String(e.workDir||"").trim(),this.startTouched=!1,this.applyCreateDefaults())},methods:{selectInfoTab(e){this.infoTab=e,this.$nextTick(()=>{let t=this.$refs.shell?.querySelector(`#work-item-info-panel-${e}`);t&&(t.scrollTop=0)})},onInfoTabKeydown(e,t){let s=this.infoTabs.map(r=>r.id),n=s.indexOf(t);if(e.key==="ArrowRight")n=(n+1)%s.length;else if(e.key==="ArrowLeft")n=(n+s.length-1)%s.length;else if(e.key==="Home")n=0;else if(e.key==="End")n=s.length-1;else return;e.preventDefault(),this.selectInfoTab(s[n]),this.$nextTick(()=>this.$refs.shell?.querySelector(`#work-item-info-tab-${s[n]}`)?.focus())},onNavigationResize(e){this.mobileNavigation=e.matches,this.sidebarExpanded=!e.matches},toggleNavigation(){this.sidebarExpanded=!this.sidebarExpanded,this.$nextTick(()=>this.sidebarExpanded&&this.mobileNavigation?this.$refs.navigation?.focusReturn():this.focusNavigationReturn())},focusNavigationReturn(){this.mobileNavigation?[...this.$refs.header?.querySelectorAll(".work-center-navigation-toggle")||[]].find(e=>e.getClientRects().length)?.focus({preventScroll:!0}):this.$refs.navigation?.focusReturn()},async selectActivity({item:e,actionId:t}){let s=this.agentId;if(await this.selectItem(e),!(this.agentId!==s||this.selectedId!==e.id||this.detailError)&&t){let n=this.selected?.actions?.find(r=>r.id===t);n&&this.selectAction(n)}},toggleWorkbench(){this.$refs.workbench?.toggle()},canOpenOutput(e){return this.workbenchContext.available&&this.store.hasAgentCapability(this.agentId,"file_editor")&&Wd(e,this.workbenchContext.ownerWorkDir)?.type==="file"},openOutput(e){this.canOpenOutput(e)&&this.workbenchContext.openOutput(e)},closeHeaderPopovers(e){e?.target?.closest?.(".work-center-filter-menu, .work-center-search")||(this.filtersOpen=!1)},backToChat(){this.store.leaveWorkCenter(),this.$nextTick(()=>{let e=this.returnFocusElement,t=n=>n?.isConnected&&n.getClientRects().length&&getComputedStyle(n).visibility!=="hidden"&&n.getBoundingClientRect().right>0;(t(e)&&e!==document.body?e:[...document.querySelectorAll(".sidebar-work-center-trigger, .header-sidebar-toggle, .yeaft-topbar-sidebar-toggle")].find(t))?.focus({preventScroll:!0})})},tr(e,t){let s=this.$t?this.$t(e):e;return s&&s!==e?s:t},async loadUnavailableAgentStates(){let e=++this.unavailableAgentStateGeneration,t=this.agents.filter(r=>r?.online&&r.capabilities?.includes("work_center_feature_settings")&&!r.capabilities.includes("work_center")&&(this.store.workCenterFeatureSettingsByAgent?.[r.id]?.loaded!==!0||this.store.workCenterFeatureSettingsByAgent?.[r.id]?.error));if(this.unavailableAgentStateLoading=t.length>0,this.unavailableAgentStateError="",t.length===0)return;let s=await Promise.allSettled(t.map(r=>this.store.loadWorkCenterFeatureSettings(r.id)));if(e!==this.unavailableAgentStateGeneration)return;let n=s.filter(r=>r.status==="rejected");this.unavailableAgentStateError=n.length?n[0].reason?.message||this.tr("workCenter.agentStatusLoadFailed","Could not check Work Center status."):"",this.unavailableAgentStateLoading=!1},openWorkCenterAgentSettings(){let e=this.configurableDisabledAgents[0]||this.configurableUnavailableAgents[0]||this.agents.find(t=>t?.online)||null;this.agentSettingsTargetId=e?.id||null,this.agentSettingsOpen=!0},closeWorkCenterAgentSettings({focusBack:e=!1}={}){this.agentSettingsOpen=!1,e&&this.$nextTick(()=>this.focusNavigationReturn())},selectWorkCenterAgent(e){if(this.mobileNavigation&&(this.sidebarExpanded=!1),!e||e===this.agentId){this.showItemsPane();return}this.saveComposerDraft(),this.showItemsPane(),this.store.enterWorkCenter(e)},statusLabel(e){return this.tr(`workCenter.status.${e}`,String(e||"").replace("_"," "))},goalStatusLabel(e){return this.tr(`workCenter.goalStatus.${e}`,this.statusLabel(e))},deliveryTargetLabel(e){let t={response:"Response",workspace_files:"Files",pull_request:"Pr",merge:"Merge"};return t[e]?this.tr(`workCenter.deliveryTarget${t[e]}`,e):e||this.tr("workCenter.deliveryTargetAsk","Ask me before delivery")},actionLabel(e){return this.tr(`workCenter.action.${e}`,e||"\u2014")},messageSpeakerRole(e,t){return e?this.$t("workCenter.messageSpeakerRole",{name:e,role:t}):t},workItemMessageSpeaker(e){if(e?.role==="user")return this.tr("workCenter.you","You");if(e?.role==="legacy_instruction")return this.tr("workCenter.originalRequest","Original request");let t=e?.speaker?.name||e?.speaker?.id||"";return this.messageSpeakerRole(t,this.tr("workCenter.coordinator","Coordinator"))},quoteWorkItemMessage(e){if(this.coordinatorReadOnly)return;let t=Mt(e);t&&(this.workItemMessageQuote=t,this.saveComposerDraft(),this.$nextTick(()=>this.$refs.workItemComposer?.getTextarea?.()?.focus?.()))},removeWorkItemMessageQuote(){this.workItemMessageQuote=null,this.saveComposerDraft()},editWorkItemMessageAsNew(e){this.coordinatorReadOnly||(this.workItemMessageQuote=null,this.workItemMessage=String(e||""),this.saveComposerDraft(),this.$nextTick(()=>{let t=this.$refs.workItemComposer?.getTextarea?.();t?.focus?.();let s=t?.value?.length||0;t?.setSelectionRange?.(s,s)}))},openConversationAttachment(e){return this.previewAttachment(e?.attachment||e,e?.trigger||null)},actionSequence(e){let t=Number(e?.sequence);if(Number.isFinite(t)&&t>0)return t;let n=(Array.isArray(this.selected?.actions)?this.selected.actions:[]).findIndex(r=>r?.id===e?.id);return n>=0?n+1:1},actionBreadcrumbDescription(e){return String(e?.brief?.objective||e?.objective||this.actionContentSummary(e)||"").trim().replace(/\s+/g," ")||this.tr("workCenter.untitledAction","Untitled Action")},itemActionProgress(e){let t=Math.max(0,Number(e?.actionCount)||0),s=Math.min(t,Math.max(0,Number(e?.completedActionCount)||0));return this.$t("workCenter.actionProgress",{completed:s,total:t})},actionDuration(e){let t=e?.executionDurationMs;if(!Number.isFinite(t)||t<0)return"\u2014";let s=e.executionStartedAt,n=e.status==="running"&&Number.isFinite(s)&&s>0?Math.max(0,this.actionNowMs-s):0;return Ei(t+n)||"\u2014"},time(e){if(!e)return"";try{return new Date(Number(e)).toLocaleString()}catch{return""}},onWorkItemMessageInput(){this.saveComposerDraft()},onWorkItemMessageKeydown(e){e.key!=="Enter"||e.shiftKey||e.isComposing||(e.preventDefault(),this.sendSelectedWorkItemMessage())},boardFilters(){let e=Date.now(),t=this.boardUpdatedRange==="day"?e-1440*60*1e3:this.boardUpdatedRange==="week"?e-10080*60*1e3:this.boardUpdatedRange==="month"?e-720*60*60*1e3:null;return{keyword:this.search.trim(),vpId:this.boardVpId,workItemType:this.boardWorkItemType,updatedFrom:t,limit:200}},scheduleBoardQuery(){this.boardQueryTimer&&clearTimeout(this.boardQueryTimer),this.boardQueryTimer=setTimeout(()=>{this.boardQueryTimer=null,this.agentId&&this.refresh()},180)},refresh(){return this.agentId?this.store.listWorkItems(this.agentId,this.boardFilters()).catch(()=>{}):Promise.resolve([])},refreshWorkCenterRuntime(e){if(!(!e||e!==this.agentId))return this.store.refreshWorkCenterRuntime(e).catch(()=>{})},loadMoreBoardItems(){return this.store.loadMoreWorkItems(this.agentId).catch(()=>{})},boardAction(e){return e.attentionAction||e.activeAction||e.currentAction||null},boardActionCountLabel(e){let t=e.actionCounts||{},s=[];for(let n of["running","failed","waiting","ready"])Number(t[n])>0&&s.push(`${t[n]} ${this.statusLabel(n)}`);return s.join(" \xB7 ")||this.itemActionProgress(e)},boardExecutorLabel(e){let t=Array.isArray(e.executors)?e.executors:[];if(t.length>0)return t.map(n=>n.name||n.id).join(", ");let s=this.boardAction(e);return s?.assignedVp?.name||s?.assignedVp?.id||this.tr("workCenter.assignment.planned","Planned assignment")},sameContentRef(e,t){return e?.type===t?.type&&e?.actionId===t?.actionId&&e?.runId===t?.runId&&e?.resourceId===t?.resourceId},resetContentStack(e=[{type:"action-list"}]){let t=Array.isArray(e)?e:[e],s=t[0]?.type==="action-list"?t:[{type:"action-list"},...t];this.contentStack=s.length>0?s:[{type:"action-list"}];let n=[...this.contentStack].reverse().find(r=>r.type==="action");this.selectedActionId=this.contentRef.actionId||n?.actionId||null},openContentPanel({syncUrl:e=!0}={}){this.contentPanelOpen=!0,e&&this.syncWorkCenterUrl(),this.$nextTick(()=>{this.$refs.actionsButton?.getClientRects().length||this.$refs.contentClose?.focus({preventScroll:!0})})},closeContentPanel({syncUrl:e=!0}={}){this.contentPanelOpen=!1,this.resetContentStack(),e&&this.syncWorkCenterUrl(),this.$nextTick(()=>this.$refs.actionsButton?.focus?.())},pushContentRef(e,{replace:t=!1,syncUrl:s=!0}={}){let n=this.contentRef;if(this.contentPanelOpen=!0,this.sameContentRef(n,e)){s&&this.syncWorkCenterUrl(t);return}this.contentStack=e.type==="action-list"?[{type:"action-list"}]:[...this.contentStack,e],this.selectedActionId=e.actionId||this.selectedActionId,s&&this.syncWorkCenterUrl(t)},popContentRef(){if(this.contentStack.length<=1)return;this.contentStack=this.contentStack.slice(0,-1);let e=[...this.contentStack].reverse().find(t=>t.type==="action");this.selectedActionId=e?.actionId||null,this.syncWorkCenterUrl()},contentRefParam(e){return e.type==="action"&&e.actionId?`action:${e.actionId}`:e.type==="run"&&e.actionId&&e.runId?`run:${e.actionId}:${e.runId}`:e.type==="attachment"&&e.resourceId?`attachment:${e.actionId||"-"}:${e.resourceId}`:"action-list"},contentStackParam(){return this.contentStack.map(e=>this.contentRefParam(e)).join("/")},parseContentRef(e){let t=String(e||"");if(t==="action-list")return{type:"action-list"};if(t.startsWith("action:"))return{type:"action",actionId:t.slice(7)};if(t.startsWith("run:")){let[,s,n]=t.split(":");return{type:"run",actionId:s,runId:n}}if(t.startsWith("attachment:")){let[,s,n]=t.split(":");return{type:"attachment",actionId:s==="-"?null:s,resourceId:n}}return{type:"action-list"}},parseContentStack(e){let s=[...String(e||"").split("/").filter(Boolean).map(n=>this.parseContentRef(n))].reverse().find(n=>n.actionId&&["action","run","attachment"].includes(n.type));return s?[{type:"action-list"},{type:"action",actionId:s.actionId}]:[{type:"action-list"}]},workCenterUrlRoute(){let e=new URLSearchParams(window.location.search);return{agentId:e.get("workAgentId"),itemId:e.get("workItemId"),content:e.has("workContent")?e.get("workContent"):null}},sameWorkCenterUrlRoute(e,t){return e?.agentId===t?.agentId&&e?.itemId===t?.itemId&&e?.content===t?.content},syncWorkCenterUrl(e=!1){Ga(this);let t=new URL(window.location.href);this.selectedId?(t.searchParams.set("workAgentId",this.agentId||""),t.searchParams.set("workItemId",this.selectedId),t.searchParams.set("workContent",this.contentPanelOpen?this.contentStackParam():"none")):(t.searchParams.delete("workAgentId"),t.searchParams.delete("workItemId"),t.searchParams.delete("workContent"));let s=`${t.pathname}${t.search}${t.hash}`;if(`${window.location.pathname}${window.location.search}${window.location.hash}`===s)return;let n={...window.history.state,workCenter:!!this.selectedId,workCenterContent:!!this.selectedId&&this.contentPanelOpen};window.history[e?"replaceState":"pushState"](n,"",s)},async restoreWorkCenterUrl(){let e=Ga(this),t=this.workCenterUrlRoute(),s=()=>e===this.workCenterUrlRestoreGeneration&&this.sameWorkCenterUrlRoute(t,this.workCenterUrlRoute()),n=t.agentId,r=t.itemId;if(!r||n&&n!==this.agentId){this.selectedId&&this.showItemsPane({syncUrl:!1});return}let i=t.content==null?(this.$refs.shell?.clientWidth||window.innerWidth)>900:t.content!=="none",o=this.parseContentStack(t.content),a=o.at(-1);if(this.selectedId!==r||this.detail?.id!==r){this.openWorkItem(r,{syncUrl:!1,contentRefs:o,contentOpen:i}),this.detailLoading=!0;try{await this.store.getWorkItem(r,this.agentId)}catch(c){s()&&(this.detailError=c?.message||String(c))}finally{s()&&(this.detailLoading=!1)}}if(!s())return;let l=a.actionId||[...o].reverse().find(c=>c.type==="action")?.actionId;if(l&&!this.selected?.actions?.some(c=>c.id===l)){this.resetContentStack(),this.syncWorkCenterUrl(!0);return}this.resetContentStack(o),this.contentPanelOpen=i,this.narrowPane="work-item",i&&l&&this.loadLatestActionMessages(this.selectedAction),i&&t.content!==this.contentStackParam()&&this.syncWorkCenterUrl(!0)},resetWorkItemComposer(){this.workItemComposerGeneration+=1,this.workItemMessage="",this.workItemMessageQuote=null,this.workItemMessageAttachments=[],this.workItemMessageAttachmentUploadCount=0,this.workItemMessageAttachmentsUploading=!1,this.workItemMessageError="",this.workItemMessageSending=!1},draftTarget(){let e=this.composerTargetAction;return e?{kind:"action",actionId:e.id,generation:Number(e.generation)}:this.composerTargetValue==="coordinator"?{kind:"coordinator"}:(()=>{let[,t="",s="0"]=this.composerTargetValue.split(":");return{kind:"action",actionId:t,generation:Number(s)||0}})()},targetValue(e){return typeof e=="string"&&e.startsWith("action:")?e:e?.kind==="action"?`action:${e.actionId}:${e.generation}`:"coordinator"},saveComposerDraft(){!this.selectedId||!this.agentId||this.store.saveWorkCenterComposerDraft(this.agentId,this.selectedId,{text:this.workItemMessage,quote:this.workItemMessageQuote,attachments:[...this.workItemMessageAttachments],target:this.draftTarget(),error:this.workItemMessageError})},restoreComposerDraft(e){let s=this.store.loadWorkCenterMessageEnvelope(this.agentId,e)||this.store.loadWorkCenterComposerDraft(this.agentId,e);this.workItemMessage=s?.text||"",this.workItemMessageQuote=Mt(s?.quote),this.workItemMessageAttachments=[...s?.attachments||[]],this.composerTargetValue=this.targetValue(s?.target),this.workItemMessageError=s?.error||"",this.staleComposerTarget=null,this.workItemMessageSending=!1,this.workItemMessageAttachmentUploadCount=0,this.workItemMessageAttachmentsUploading=!1,this.workItemComposerGeneration+=1},openWorkItem(e,{syncUrl:t=!0,contentRefs:s=[{type:"action-list"}],contentOpen:n=(this.$refs.shell?.clientWidth||window.innerWidth)>900}={}){this.saveComposerDraft(),this.selectedId=e,this.narrowPane="work-item",this.contentPanelOpen=n,this.resetContentStack(s),this.restoreComposerDraft(e),this.detailError="",this.detailLoading=!1,this.previewingAttachmentId=null,this.attachmentPreviewError="",this.attachmentPreviewGeneration=(Number(this.attachmentPreviewGeneration)||0)+1,t&&this.syncWorkCenterUrl()},async selectItem(e){this.mobileNavigation&&(this.sidebarExpanded=!1),this.openWorkItem(e.id),this.detailLoading=!0;try{await this.store.getWorkItem(e.id,this.agentId)}catch(t){this.selectedId===e.id&&(this.detailError=t?.message||String(t))}finally{this.selectedId===e.id&&(this.detailLoading=!1)}},selectAction(e){this.selectedActionId!==e.id&&(this.previewingAttachmentId=null,this.attachmentPreviewError="",this.attachmentPreviewGeneration=(Number(this.attachmentPreviewGeneration)||0)+1),this.pushContentRef({type:"action",actionId:e.id}),this.loadLatestActionMessages(e),this.$nextTick(()=>this.$refs.actionBack?.focus({preventScroll:!0}))},loadLatestActionMessages(e=this.selectedAction){if(!this.selected?.id||!e?.id||Array.isArray(e.messages))return null;let t=dr(this.agentId,this.selected.id,e.id,e.generation);return this.store.workCenterActionMessages[t]?null:this.store.loadWorkItemActionMessages(this.selected.id,e.id,e.generation,null,this.agentId).catch(()=>null)},showItemsPane({syncUrl:e=!0}={}){this.saveComposerDraft(),this.narrowPane="items",this.selectedId=null,this.contentPanelOpen=!1,this.resetContentStack(),this.composerTargetValue="coordinator",this.resetWorkItemComposer(),e&&this.syncWorkCenterUrl()},showActionsPane(){this.contentPanelOpen=!0,this.contentIsActionList?this.syncWorkCenterUrl():this.popContentRef(),this.$nextTick(()=>this.$refs.contentClose?.focus({preventScroll:!0}))},canMessageAction(e){return!e||["done","cancelled"].includes(this.selected?.status)?!1:["idle","ready","running","paused","waiting","failed","completed","stopped"].includes(e.status)&&e.admissionStatus!=="blocked"},clearPendingMessageEnvelope({preserveAttachments:e=!1}={}){return!this.selectedId||!this.pendingMessageEnvelope?!1:(this.actionInputRequestGeneration=(Number(this.actionInputRequestGeneration)||0)+1,this.preserveComposerOnEnvelopeClear=!0,this.store.discardWorkCenterMessageEnvelope(this.agentId,this.selectedId)?(e||(this.workItemMessageAttachments=[]),this.workItemMessageError="",this.workItemMessageSending=!1,!0):(this.preserveComposerOnEnvelopeClear=!1,!1))},replyToWaitingPrompt(e=null){this.replyEntryDisabled||e&&!this.canMessageAction(e)||!e&&this.coordinatorThinking||(this.composerTargetValue=e?`action:${e.id}:${e.generation}`:"coordinator",this.staleComposerTarget=null,this.workItemMessageError="",this.saveComposerDraft(),(this.$refs.shell?.clientWidth||window.innerWidth)<=900&&this.closeContentPanel(),this.$nextTick(()=>{let t=this.$refs.workItemComposer?.getTextarea?.();t?.scrollIntoView?.({block:"nearest"}),t?.focus?.()}))},chooseCoordinatorTarget(){this.pendingMessageEnvelope&&!this.clearPendingMessageEnvelope({preserveAttachments:!0})||(this.composerTargetValue="coordinator",this.staleComposerTarget=null,this.saveComposerDraft())},onComposerTargetChange(){this.pendingMessageEnvelope&&!this.clearPendingMessageEnvelope({preserveAttachments:!0})||(this.staleComposerTarget=this.composerTargetAction==null&&this.composerTargetValue!=="coordinator"?this.composerTargetValue:null,this.saveComposerDraft())},loadEarlierActionMessages(){return!this.selected?.id||!this.selectedAction?.id||this.actionMessagesNextCursor==null?null:this.store.loadWorkItemActionMessages(this.selected.id,this.selectedAction.id,this.selectedAction.generation,this.actionMessagesNextCursor,this.agentId).catch(()=>null)},actionExecutor(e){return e?.assignedVp?.name||e?.assignedVp?.id||e?.requiredRole||e?.assignmentPolicy?.fixedVpId||e?.assignmentPolicy?.capability||this.tr("workCenter.assignment.auto","Auto")},actionContentSummary(e){return String(e?.contentSummary||e?.response||e?.brief?.objective||"").trim()},executionStats(e){return e?.executionStats||{}},formatCount(e){return new Intl.NumberFormat().format(Math.max(0,Number(e)||0))},formatTokens(e){let t=Math.max(0,Number(e)||0);return t>=1e6?`${(t/1e6).toFixed(1)}m`:t>=1e3?`${(t/1e3).toFixed(1)}k`:String(t)},resetCreateExecutionContext(e,{keepOpen:t=!1}={}){let s=this.workDirTouched||this.startTouched,n=this.store.workCenterCreateDraft;n&&(this.store.workCenterCreateDraft={sourceAgentId:e||null,requirement:n.requirement||n.goal||n.title||"",workDir:"",deliveryTarget:n.deliveryTarget||"",deliveryInstructions:n.deliveryInstructions||"",origin:null,linkedSessionIds:[]}),this.createAttachments=[],this.createAttachmentError="",this.form.workDir="",this.form.start=!0,this.form.scheduled=!1,this.form.scheduleDraft=Qi(),this.scheduleDraftStarted=!1,this.createError="",this.workDirTouched=!1,this.startTouched=!1,s&&!t&&(this.createOpen=!1),this.applyCreateDefaults()},applyCreateDefaults(){this.createOpen&&(!this.workDirTouched&&!this.form.workDir.trim()&&(this.form.workDir=this.createDefaultWorkDir),this.startTouched||(this.form.start=this.createDefaultStart))},folderPickerInitialDir(){return this.form.workDir.trim()||this.createDefaultWorkDir},folderPickerSetWorkDir(e){this.form.workDir=e,this.workDirTouched=!0},onCreateWorkDirInput(){this.workDirTouched=!0},setExecutionMode(e){e==="scheduled"&&!this.scheduleDraftStarted&&(this.form.scheduleDraft=Qi(),this.scheduleDraftStarted=!0),this.form.scheduled=e==="scheduled",this.form.start=e==="now",this.startTouched=!0},scheduleStatusLabel(e){return this.$t("workCenter.scheduling.status."+(e?.status||"scheduled"))},scheduleSummary(e){if(!e)return"";let t=[this.scheduleStatusLabel(e)];if(e.lastError&&e.status==="scheduled"&&t.push(this.$t("workCenter.scheduling.retrying")),e.recurrence&&t.push(this.$t("workCenter.scheduling."+e.recurrence.frequency)),e.scheduledFor&&!["completed","cancelled"].includes(e.status)){let s=e.recurrence?.timeZone;t.push(new Intl.DateTimeFormat(this.$locale?.value||this.$locale||"en",{timeZone:s,dateStyle:"medium",timeStyle:"short",hour12:!1}).format(e.scheduledFor)),s&&t.push(s.replaceAll("_"," "))}return t.join(" \xB7 ")},async setSelectedScheduleEnabled(e){let t=this.selected?.schedule;if(!this.selected||!t||this.selected.status!=="draft"||this.scheduleSaving)return;let s=this.agentId,n=this.selected.id;this.scheduleSaving=!0,this.scheduleError="";try{await this.store.updateWorkItemSchedule(n,{enabled:e,revision:this.selected.revision},s)}catch(r){this.agentId===s&&this.selectedId===n&&(this.scheduleError=r?.message||String(r))}finally{this.scheduleSaving=!1}},clipboardFiles(e){return Array.from(e?.clipboardData?.items||[]).filter(t=>t?.kind==="file").map(t=>t.getAsFile?.()).filter(Boolean)},clipboardIncludesText(e){return Array.from(e?.clipboardData?.types||[]).some(t=>String(t).toLowerCase().startsWith("text/"))},attachmentUploadName(e,t){let s=String(e?.name||"").trim();if(s)return s;let n={"image/png":".png","image/jpeg":".jpg","image/gif":".gif","image/webp":".webp","application/pdf":".pdf","application/json":".json","text/plain":".txt"};return`${String(e?.type||"").startsWith("image/")?"pasted-image":"pasted-file"}-${Date.now()}-${t+1}${n[e?.type]||""}`},async uploadPendingAttachments(e){let t=new FormData;e.forEach((a,l)=>{t.append("files",a,this.attachmentUploadName(a,l))});let s=Pinia.useAuthStore(),n=s.getActiveToken?.()||s.token||null,r=n?{Authorization:`Bearer ${n}`}:{},i=await fetch("/api/upload",{method:"POST",headers:r,body:t});if(!i.ok)throw new Error(this.tr("workCenter.attachmentsUploadFailed","Attachment upload failed"));let o=await i.json();return Array.isArray(o.files)?o.files:[]},async addCreateAttachments(e){if(!this.workItemAttachmentsSupported){this.createAttachmentError=this.tr("workCenter.attachmentsUnsupported","The selected Agent does not support Work Item attachments.");return}let t=Math.max(0,10-this.createAttachments.length),s=Array.from(e||[]).slice(0,t);if(s.length===0)return;let n=this.createGeneration;this.createAttachmentUploadCount+=1,this.attachmentsUploading=!0,this.createAttachmentError="";try{let r=await this.uploadPendingAttachments(s);if(!this.createOpen||this.createGeneration!==n)return;this.createAttachments=[...this.createAttachments,...r].slice(0,10)}catch(r){this.createOpen&&this.createGeneration===n&&(this.createAttachmentError=r?.message||String(r))}finally{this.createGeneration===n&&(this.createAttachmentUploadCount=Math.max(0,this.createAttachmentUploadCount-1),this.attachmentsUploading=this.createAttachmentUploadCount>0)}},async onCreateAttachmentInput(e){let t=Array.from(e.target.files||[]);e.target.value="",await this.addCreateAttachments(t)},async onCreateRequirementPaste(e){let t=this.clipboardFiles(e);t.length!==0&&(this.clipboardIncludesText(e)||e.preventDefault(),await this.addCreateAttachments(t))},removeCreateAttachment(e){this.createAttachments=this.createAttachments.filter((t,s)=>s!==e)},discardPendingMessageEnvelope(){this.clearPendingMessageEnvelope()&&this.saveComposerDraft()},async addWorkItemMessageAttachments(e){if(!this.workItemAttachmentsSupported){this.workItemMessageError=this.tr("workCenter.attachmentsUnsupported","The selected Agent does not support Work Item attachments.");return}if(!e.length)return;let t=this.workItemComposerScope;if(!t)return;let s=this.pendingEnvelopeAttachmentRecovery,n=Array.isArray(this.selected?.attachments)?this.selected.attachments.length:0,r=Math.max(0,10-n-(s?0:this.workItemMessageAttachments.length)),i=Array.from(e).slice(0,r);if(i.length===0)return;let o=this.workItemComposerGeneration;this.workItemMessageAttachmentUploadCount+=1,this.workItemMessageAttachmentsUploading=!0,this.workItemMessageError="";try{let a=(await this.uploadPendingAttachments(i)).slice(0,Math.max(0,10-n));if(this.workItemComposerScope!==t||this.workItemComposerGeneration!==o)return;if(s){let l=this.store.replaceWorkCenterMessageEnvelopeAttachments(this.agentId,this.selectedId,a);if(!l)throw new Error(this.tr("workCenter.pendingEnvelopeChanged","The pending request changed; reopen this Work Item and try again."));this.workItemMessageAttachments=[...l.attachments],this.workItemMessageError=""}else this.workItemMessageAttachments=[...this.workItemMessageAttachments,...a].slice(0,Math.max(0,10-n)),this.saveComposerDraft()}catch(a){this.workItemComposerScope===t&&this.workItemComposerGeneration===o&&(this.workItemMessageError=a?.message||String(a))}finally{this.workItemComposerScope===t&&this.workItemComposerGeneration===o&&(this.workItemMessageAttachmentUploadCount=Math.max(0,this.workItemMessageAttachmentUploadCount-1),this.workItemMessageAttachmentsUploading=this.workItemMessageAttachmentUploadCount>0)}},async onWorkItemMessageAttachmentInput(e){let t=Array.from(e.target.files||[]);e.target.value="",await this.addWorkItemMessageAttachments(t)},async onWorkItemMessagePaste(e){let t=this.clipboardFiles(e);t.length!==0&&(this.clipboardIncludesText(e)||e.preventDefault(),await this.addWorkItemMessageAttachments(t))},removeWorkItemMessageAttachment(e){this.workItemMessageAttachments=this.workItemMessageAttachments.filter((t,s)=>s!==e),this.saveComposerDraft()},async previewAttachment(e,t=null){if(!this.selected?.id||!e?.id||this.previewingAttachmentId)return;let s=this.agentId,n=this.selected.id,r=this.selectedActionId||"",i=`${s}:${n}:${r}`,o=(Number(this.attachmentPreviewGeneration)||0)+1;this.attachmentPreviewGeneration=o;let a=()=>this.attachmentPreviewGeneration===o&&`${this.agentId}:${this.selected?.id||""}:${this.selectedActionId||""}`===i,l=e.isImage?null:window.open("","_blank");if(!e.isImage&&!l){this.attachmentPreviewError=this.tr("workCenter.attachmentOpenBlocked","The browser blocked the attachment window. Allow pop-ups and try again.");return}l&&(l.opener=null),this.previewingAttachmentId=e.id,this.attachmentPreviewError="";try{let c=await this.store.previewWorkItemAttachment(n,e.id,s);if(!a()){l?.close();return}c?.preview&&c.attachment?.isImage?Fs(c.preview,{alt:e.name||this.tr("workCenter.previewAttachment","Open attachment"),closeLabel:this.tr("common.close","Close"),trigger:t}):c?.preview&&l?l.location.replace(c.preview):l?.close()}catch(c){l?.close(),a()&&(this.attachmentPreviewError=c?.message||this.tr("workCenter.attachmentPreviewFailed","Could not open the attachment. Try again."))}finally{a()&&(this.previewingAttachmentId=null)}},isExternalOutput(e){return["link","pr"].includes(e?.kind)&&/^https?:\/\//i.test(String(e?.ref||""))},formatAttachmentSize(e){let t=Math.max(0,Number(e)||0);return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/1024/1024).toFixed(1)} MB`},async focusCustomDeliveryInput(){await this.$nextTick(),await this.$nextTick(),this.createOpen&&this.customDeliveryTarget&&this.$refs.customDeliveryInput?.focus()},async loadDeliveryInstructionOptions(){let e=this.agentId,t=++this.deliveryInstructionsGeneration;if(e)try{let s=await this.store.loadWorkCenterDeliveryInstructions(e);this.agentId===e&&this.deliveryInstructionsGeneration===t&&(this.deliveryInstructionOptions=s)}catch{this.agentId===e&&this.deliveryInstructionsGeneration===t&&(this.deliveryInstructionOptions=[])}},selectCreateAgent(e){this.saving||e===this.agentId||!this.onlineAgents.some(t=>t.id===e)||(this.createAgentSelection=e,this.selectWorkCenterAgent(e))},openCreate(){this.agentId&&(this.mobileNavigation&&(this.sidebarExpanded=!1),this.createGeneration=(Number(this.createGeneration)||0)+1,this.createAttachmentUploadCount=0,this.attachmentsUploading=!1,this.createOpen=!0,this.workDirTouched=!1,this.startTouched=!1,this.createAttachmentError="",this.applyCreateDefaults(),this.loadDeliveryInstructionOptions(),this.$nextTick(()=>this.$refs.createRequirement?.focus()))},closeCreate(){this.saving||(this.createGeneration=(Number(this.createGeneration)||0)+1,this.createAttachmentUploadCount=0,this.attachmentsUploading=!1,this.closeFolderPicker(),this.createOpen=!1,this.createAttachments=[],this.createAttachmentError="",this.createError="",this.store.workCenterCreateDraft=null)},async submitCreate(){let e=String(this.form.requirement||this.form.goal||this.form.title||"").trim();if(this.saving||this.attachmentsUploading||!this.agentId||!e||!this.form.workDir.trim()||this.customDeliveryTarget&&!this.form.deliveryInstructions.trim())return;let t=this.form.scheduled?Xi(this.form.scheduleDraft):{};if(t.error||t.recurrence&&!this.recurringSchedulesSupported)return;this.createError="";let s=this.agentId,n=(Number(this.createGeneration)||0)+1;this.createGeneration=n,this.saving=!0;try{let r=this.store.workCenterCreateDraft,i=r?.sourceAgentId===s,o=await this.store.createWorkItem({requirement:e,title:e.replace(/\s+/g," ").slice(0,80),titleSource:"coordinator_pending",goal:e,acceptanceCriteria:[],workItemType:"auto",workDir:this.form.workDir.trim(),deliveryTarget:this.customDeliveryTarget?null:this.form.deliveryTarget||null,deliveryInstructions:this.form.deliveryInstructions.trim()||null,origin:i&&r.origin||null,linkedSessionIds:i?r.linkedSessionIds||[]:[],attachments:this.workItemAttachmentsSupported?(this.createAttachments||[]).map(a=>({fileId:a.fileId,name:a.name,mimeType:a.mimeType,size:a.size})):[],reuseMemory:!0,start:this.form.scheduled?!1:this.form.start,scheduledFor:t.scheduledFor||null,recurrence:t.recurrence||null},s);if(this.agentId!==s||this.createGeneration!==n)return;this.openWorkItem(o.id),this.form={requirement:"",workDir:"",deliveryTarget:"",deliveryInstructions:"",start:this.settings?.startImmediately!==!1,scheduled:!1,scheduleDraft:Qi()},this.customDeliveryTarget=!1,this.store.workCenterCreateDraft=null,this.createAttachments=[],this.workDirTouched=!1,this.startTouched=!1,this.scheduleDraftStarted=!1,this.createOpen=!1}catch(r){this.agentId===s&&this.createGeneration===n&&(this.createError=r?.message||String(r))}finally{this.agentId===s&&this.createGeneration===n&&(this.saving=!1)}},async startSelected(){this.selected&&await this.store.startWorkItem(this.selected.id,this.agentId)},async sendSelectedWorkItemMessage(){if(!this.selected||!this.composerCanSend)return;let e=this.workItemComposerScope,t=this.composerTargetValue,s=this.composerTargetAction;if(!this.composerTargetIsCoordinator&&!s)return;let n=this.selected.id,r=this.selected.revision,i=this.workItemMessage.trim(),o=Mt(this.workItemMessageQuote),a=this.workItemMessageAttachments.map(c=>({fileId:c.fileId,name:c.name,mimeType:c.mimeType,size:c.size})),l=(Number(this.actionInputRequestGeneration)||0)+1;this.actionInputRequestGeneration=l,this.workItemMessageSending=!0,this.workItemMessageError="",this.saveComposerDraft();try{let c={planRevision:this.selected.planRevision,ledgerRevision:this.selected.ledgerRevision,coordinatorRevision:this.selected.coordinatorRevision};this.canonicalMessageWireSupported?await this.store.postWorkItemMessage(n,i,s?{kind:"action",actionId:s.id,generation:s.generation}:{kind:"coordinator"},r,a,this.agentId,c,o):s?await this.store.sendWorkItemActionInput(n,i,s.id,r,s.generation,a,this.agentId,o):await this.store.sendWorkItemMessage(n,i,r,a,this.agentId,c,o),this.workItemComposerScope===e&&this.actionInputRequestGeneration===l&&this.composerTargetValue===t&&this.workItemMessage.trim()===i&&!this.store.loadWorkCenterMessageEnvelope(this.agentId,n)&&(this.workItemMessage="",this.workItemMessageQuote=null,this.workItemMessageAttachments=[],this.store.removeWorkCenterComposerDraft(this.agentId,n))}catch(c){if(this.workItemComposerScope===e&&this.actionInputRequestGeneration===l)if(c?.code==="WORK_CENTER_INPUT_STALE"){if(this.clearPendingMessageEnvelope({preserveAttachments:!0}),await this.$nextTick(),this.workItemComposerScope!==e)return;this.workItemMessageError=this.$t("workCenter.inputStale"),this.saveComposerDraft(),this.store.getWorkItem(n,this.agentId).catch(()=>{})}else this.workItemMessageError=c?.message||String(c),this.saveComposerDraft()}finally{this.workItemComposerScope===e&&this.actionInputRequestGeneration===l&&(this.workItemMessageSending=!1)}},workItemCanDelete(e){return["done","cancelled","draft","needs_attention"].includes(e?.status)},workItemDeleting(e){return!!this.deletingWorkItemIds[e?.id]},async deleteWorkItem(e){if(!e||this.workItemDeleting(e))return;let t=this.tr("workCenter.deleteConfirm","Permanently delete this Work Item, its execution history, and attachments?");if(await We(t,{destructive:!0})){this.deleteWorkItemError="",this.deletingWorkItemIds={...this.deletingWorkItemIds,[e.id]:!0};try{let s=await this.store.deleteWorkItem(e.id,e.revision,this.agentId);s?.cleanupWarning&&(this.deleteWorkItemError=s.cleanupWarning),this.selectedId===e.id&&this.showItemsPane()}catch(s){this.deleteWorkItemError=s?.message||String(s)}finally{let s={...this.deletingWorkItemIds};delete s[e.id],this.deletingWorkItemIds=s}}},async cancelSelected(){if(!this.selected||["done","cancelled"].includes(this.selected.status))return;let e=this.tr("workCenter.cancelConfirm","Stop this work item and its unfinished Actions?");await We(e,{destructive:!0})&&await this.store.cancelWorkItem(this.selected.id,this.agentId)},async resumeSelected(){!this.selected||this.selected.status!=="cancelled"||await this.store.resumeWorkItem(this.selected.id,this.selected.revision,this.agentId,this.selected.executionControl?.revision)}},template:`
6882
+ `),textSegments:a.map((l,c)=>({key:`${e.id}:${c}`,content:l,kind:e.status==="thinking"?"progress":"result",isStreaming:e.status==="thinking"})),isStreaming:e.status==="thinking",speakerVpId:r,speakerTimestamp:t,showSpeakerHeader:!0,timestamp:t,createdAt:t,todoMsg:null,toolMsgs:[],toolSummaryCount:0,imageMsgs:[],askMsg:null,attachments:Array.isArray(e.attachments)?e.attachments:[]}}}return{key:e.id,kind:"system",message:e}})},conversationScrollState(){return{agentId:this.agentId,workItemId:this.detail?.id===this.selectedId?this.selectedId:null,blocks:this.conversationBlocks}},coordinatorThinking(){return(this.selected?.messages||[]).some(e=>e?.role==="assistant"&&e.status==="thinking")},coordinatorReadOnly(){return!!this.selected?.schedule?.recurrence||["done","cancelled"].includes(this.selected?.status)},actionMessages(){let e=Array.isArray(this.selectedAction?.messages)?this.selectedAction.messages:[],t=(Array.isArray(this.selectedAction?.thread)?this.selectedAction.thread:[]).flatMap(o=>Array.isArray(o?.messages)?o.messages:[]),s=this.store.workCenterActionMessages[this.actionMessageKey]?.messages||[],n=gi(t,s,e),r=this.selectedAction?.liveMessage,i=r&&n.some(o=>o.role==="assistant"&&o.runId!=null&&o.runId===r.runId&&(r.status==="running"?o.text===r.text:o.status!=="running"));return gi(n,i?null:r)},actionMessagesNextCursor(){let e=this.store.workCenterActionMessages[this.actionMessageKey];return e?e.nextCursor:this.selectedAction?.messageCursor},actionMessagesLoading(){return!!this.store.workCenterActionMessagesLoading[this.actionMessageKey]},actionMessagesError(){return this.store.workCenterActionMessagesError[this.actionMessageKey]||""},orderedActions(){let e=Array.isArray(this.selected?.actions)?this.selected.actions:[];return Ql(e)},boardLanes(){return[{id:"active",title:this.tr("workCenter.board.active","Active")},{id:"needs_attention",title:this.tr("workCenter.board.needsAttention","Needs attention")},{id:"closed",title:this.tr("workCenter.board.closed","Closed")}].map(e=>({...e,items:this.items.filter(t=>t.boardLane===e.id)}))},boardExecutorOptions(){let e=new Map;for(let t of this.items)for(let s of Array.isArray(t.executors)?t.executors:[])s?.id&&e.set(s.id,s.name||s.id);return[...e.entries()].map(([t,s])=>({id:t,name:s}))},boardTypeOptions(){return[...new Set(this.items.map(e=>e.workItemType).filter(Boolean))].sort()},emptyState(){return{title:this.search.trim()?this.tr("workCenter.noMatchesTitle","No matching work items"):this.tr("workCenter.emptyTitle","No work items yet"),body:this.search.trim()?this.tr("workCenter.noMatchesBody","Try a different search or filter."):this.tr("workCenter.emptyBody","Create a persistent task when work must continue beyond one conversation turn."),canCreate:!this.search.trim()}}},watch:{selectedId(){this.infoTab="requirement",this.scheduleError=""},"workbenchContext.workspaceGeneration"(){this.workbenchExpanded=!1},agents:{immediate:!0,deep:!0,handler(){this.loadUnavailableAgentStates()}},agentId:{immediate:!0,handler(e,t){if(Ga(this),this.createGeneration=(Number(this.createGeneration)||0)+1,this.createAttachmentUploadCount=0,this.attachmentsUploading=!1,this.deliveryInstructionOptions=[],this.deliveryInstructionsGeneration+=1,this.saving=!1,this.selectedId=null,this.selectedActionId=null,this.contentPanelOpen=!1,this.resetWorkItemComposer?.(),this.resetContentStack?.(),this.composerTargetValue="coordinator",this.narrowPane="items",this.filtersOpen=!1,this.previewingAttachmentId=null,this.attachmentPreviewError="",this.attachmentPreviewGeneration=(Number(this.attachmentPreviewGeneration)||0)+1,t&&e!==t&&(this.closeFolderPicker(),this.resetCreateExecutionContext(e,{keepOpen:!!e&&this.createAgentSelection===e})),this.createAgentSelection=null,this.store.workCenterAgentId!==e){this.store.enterWorkCenter(e);return}e&&((typeof this.boardFilters=="function"?this.store.listWorkItems(e,this.boardFilters()):this.store.listWorkItems(e)).catch(()=>{}),this.store.loadWorkCenterSettings(e).catch(()=>{}),this.createOpen&&this.loadDeliveryInstructionOptions())}},actionsPaneWidth(e){try{localStorage.setItem("work-center-actions-width",String(e))}catch{}},createDefaultWorkDir(){this.applyCreateDefaults()},createDefaultStart(){this.applyCreateDefaults()},search(){this.scheduleBoardQuery()},boardVpId(){this.scheduleBoardQuery()},boardWorkItemType(){this.scheduleBoardQuery()},boardUpdatedRange(){this.scheduleBoardQuery()},conversationScrollState(e,t){let s=this.$refs.detailScroll;if(!s||!e.workItemId||e.workItemId!==t?.workItemId||e.agentId!==t.agentId||s.dataset.workItemId!==e.workItemId)return;let n=s.scrollTop;s.scrollHeight-s.clientHeight-n>64||this.$nextTick(()=>{this.$refs.detailScroll===s&&s.scrollTop===n&&this.agentId===e.agentId&&this.selectedId===e.workItemId&&(s.scrollTop=s.scrollHeight)})},pendingMessageEnvelope(e,t){if(!(!t||e||t.workItemId!==this.selectedId)){if(this.preserveComposerOnEnvelopeClear){this.preserveComposerOnEnvelopeClear=!1,this.workItemMessageError="",this.workItemMessageSending=!1;return}this.workItemMessage="",this.workItemMessageQuote=null,this.workItemMessageAttachments=[],this.workItemMessageError="",this.workItemMessageSending=!1}},detail:{deep:!0,handler(e){if(!e||e.id!==this.selectedId)return;let t=Array.isArray(e.actions)?e.actions:[];this.selectedActionId&&!t.some(s=>s.id===this.selectedActionId)&&(this.selectedActionId=null,this.contentPanelOpen=!1,this.resetContentStack(),this.syncWorkCenterUrl(!0),this.previewingAttachmentId=null,this.attachmentPreviewError="",this.attachmentPreviewGeneration=(Number(this.attachmentPreviewGeneration)||0)+1),this.composerTargetAction==null&&this.composerTargetValue!=="coordinator"?this.staleComposerTarget=this.composerTargetValue:this.staleComposerTarget=null}}},beforeUnmount(){Ga(this),this.createGeneration=(Number(this.createGeneration)||0)+1,this.workItemComposerGeneration+=1,this.unavailableAgentStateGeneration+=1,this.deliveryInstructionsGeneration+=1,this.boardQueryTimer&&clearTimeout(this.boardQueryTimer),clearInterval(this.actionClockTimer),window.removeEventListener("popstate",this.restoreWorkCenterUrl),document.removeEventListener("click",this.closeHeaderPopovers),this.navigationMedia?.removeEventListener("change",this.onNavigationResize)},mounted(){this.actionClockTimer=setInterval(()=>{this.actionNowMs=Date.now()},1e3),this.returnFocusElement=document.activeElement,this.navigationMedia=window.matchMedia("(max-width: 1100px)"),this.navigationMedia.addEventListener("change",this.onNavigationResize),this.$nextTick(()=>this.focusNavigationReturn()),window.addEventListener("popstate",this.restoreWorkCenterUrl),document.addEventListener("click",this.closeHeaderPopovers),this.restoreWorkCenterUrl();let e=this.store.workCenterCreateDraft;e&&(this.form={requirement:e.requirement||e.goal||e.title||"",workDir:e.workDir||"",deliveryTarget:e.deliveryTarget||"",deliveryInstructions:e.deliveryInstructions||"",start:this.settings?.startImmediately!==!1},this.customDeliveryTarget=!!this.form.deliveryInstructions.trim(),this.createOpen=!0,this.workDirTouched=!!String(e.workDir||"").trim(),this.startTouched=!1,this.applyCreateDefaults())},methods:{selectInfoTab(e){this.infoTab=e},onInfoTabKeydown(e,t){let s=this.infoTabs.map(r=>r.id),n=s.indexOf(t);if(e.key==="ArrowRight")n=(n+1)%s.length;else if(e.key==="ArrowLeft")n=(n+s.length-1)%s.length;else if(e.key==="Home")n=0;else if(e.key==="End")n=s.length-1;else return;e.preventDefault(),this.selectInfoTab(s[n]),this.$nextTick(()=>this.$refs.shell?.querySelector(`#work-item-info-tab-${s[n]}`)?.focus())},onNavigationResize(e){this.mobileNavigation=e.matches,this.sidebarExpanded=!e.matches},toggleNavigation(){this.sidebarExpanded=!this.sidebarExpanded,this.$nextTick(()=>this.sidebarExpanded&&this.mobileNavigation?this.$refs.navigation?.focusReturn():this.focusNavigationReturn())},focusNavigationReturn(){this.mobileNavigation?[...this.$refs.header?.querySelectorAll(".work-center-navigation-toggle")||[]].find(e=>e.getClientRects().length)?.focus({preventScroll:!0}):this.$refs.navigation?.focusReturn()},async selectActivity({item:e,actionId:t}){let s=this.agentId;if(await this.selectItem(e),!(this.agentId!==s||this.selectedId!==e.id||this.detailError)&&t){let n=this.selected?.actions?.find(r=>r.id===t);n&&this.selectAction(n)}},toggleWorkbench(){this.$refs.workbench?.toggle()},canOpenOutput(e){return this.workbenchContext.available&&this.store.hasAgentCapability(this.agentId,"file_editor")&&Wd(e,this.workbenchContext.ownerWorkDir)?.type==="file"},openOutput(e){this.canOpenOutput(e)&&this.workbenchContext.openOutput(e)},closeHeaderPopovers(e){e?.target?.closest?.(".work-center-filter-menu, .work-center-search")||(this.filtersOpen=!1)},backToChat(){this.store.leaveWorkCenter(),this.$nextTick(()=>{let e=this.returnFocusElement,t=n=>n?.isConnected&&n.getClientRects().length&&getComputedStyle(n).visibility!=="hidden"&&n.getBoundingClientRect().right>0;(t(e)&&e!==document.body?e:[...document.querySelectorAll(".sidebar-work-center-trigger, .header-sidebar-toggle, .yeaft-topbar-sidebar-toggle")].find(t))?.focus({preventScroll:!0})})},tr(e,t){let s=this.$t?this.$t(e):e;return s&&s!==e?s:t},async loadUnavailableAgentStates(){let e=++this.unavailableAgentStateGeneration,t=this.agents.filter(r=>r?.online&&r.capabilities?.includes("work_center_feature_settings")&&!r.capabilities.includes("work_center")&&(this.store.workCenterFeatureSettingsByAgent?.[r.id]?.loaded!==!0||this.store.workCenterFeatureSettingsByAgent?.[r.id]?.error));if(this.unavailableAgentStateLoading=t.length>0,this.unavailableAgentStateError="",t.length===0)return;let s=await Promise.allSettled(t.map(r=>this.store.loadWorkCenterFeatureSettings(r.id)));if(e!==this.unavailableAgentStateGeneration)return;let n=s.filter(r=>r.status==="rejected");this.unavailableAgentStateError=n.length?n[0].reason?.message||this.tr("workCenter.agentStatusLoadFailed","Could not check Work Center status."):"",this.unavailableAgentStateLoading=!1},openWorkCenterAgentSettings(){let e=this.configurableDisabledAgents[0]||this.configurableUnavailableAgents[0]||this.agents.find(t=>t?.online)||null;this.agentSettingsTargetId=e?.id||null,this.agentSettingsOpen=!0},closeWorkCenterAgentSettings({focusBack:e=!1}={}){this.agentSettingsOpen=!1,e&&this.$nextTick(()=>this.focusNavigationReturn())},selectWorkCenterAgent(e){if(this.mobileNavigation&&(this.sidebarExpanded=!1),!e||e===this.agentId){this.showItemsPane();return}this.saveComposerDraft(),this.showItemsPane(),this.store.enterWorkCenter(e)},statusLabel(e){return this.tr(`workCenter.status.${e}`,String(e||"").replace("_"," "))},goalStatusLabel(e){return this.tr(`workCenter.goalStatus.${e}`,this.statusLabel(e))},deliveryTargetLabel(e){let t={response:"Response",workspace_files:"Files",pull_request:"Pr",merge:"Merge"};return t[e]?this.tr(`workCenter.deliveryTarget${t[e]}`,e):e||this.tr("workCenter.deliveryTargetAsk","Ask me before delivery")},actionLabel(e){return this.tr(`workCenter.action.${e}`,e||"\u2014")},messageSpeakerRole(e,t){return e?this.$t("workCenter.messageSpeakerRole",{name:e,role:t}):t},workItemMessageSpeaker(e){if(e?.role==="user")return this.tr("workCenter.you","You");if(e?.role==="legacy_instruction")return this.tr("workCenter.originalRequest","Original request");let t=e?.speaker?.name||e?.speaker?.id||"";return this.messageSpeakerRole(t,this.tr("workCenter.coordinator","Coordinator"))},quoteWorkItemMessage(e){if(this.coordinatorReadOnly)return;let t=Mt(e);t&&(this.workItemMessageQuote=t,this.saveComposerDraft(),this.$nextTick(()=>this.$refs.workItemComposer?.getTextarea?.()?.focus?.()))},removeWorkItemMessageQuote(){this.workItemMessageQuote=null,this.saveComposerDraft()},editWorkItemMessageAsNew(e){this.coordinatorReadOnly||(this.workItemMessageQuote=null,this.workItemMessage=String(e||""),this.saveComposerDraft(),this.$nextTick(()=>{let t=this.$refs.workItemComposer?.getTextarea?.();t?.focus?.();let s=t?.value?.length||0;t?.setSelectionRange?.(s,s)}))},openConversationAttachment(e){return this.previewAttachment(e?.attachment||e,e?.trigger||null)},actionSequence(e){let t=Number(e?.sequence);if(Number.isFinite(t)&&t>0)return t;let n=(Array.isArray(this.selected?.actions)?this.selected.actions:[]).findIndex(r=>r?.id===e?.id);return n>=0?n+1:1},actionBreadcrumbDescription(e){return String(e?.brief?.objective||e?.objective||this.actionContentSummary(e)||"").trim().replace(/\s+/g," ")||this.tr("workCenter.untitledAction","Untitled Action")},itemActionProgress(e){let t=Math.max(0,Number(e?.actionCount)||0),s=Math.min(t,Math.max(0,Number(e?.completedActionCount)||0));return this.$t("workCenter.actionProgress",{completed:s,total:t})},actionDuration(e){let t=e?.executionDurationMs;if(!Number.isFinite(t)||t<0)return"\u2014";let s=e.executionStartedAt,n=e.status==="running"&&Number.isFinite(s)&&s>0?Math.max(0,this.actionNowMs-s):0;return Ei(t+n)||"\u2014"},time(e){if(!e)return"";try{return new Date(Number(e)).toLocaleString()}catch{return""}},onWorkItemMessageInput(){this.saveComposerDraft()},onWorkItemMessageKeydown(e){e.key!=="Enter"||e.shiftKey||e.isComposing||(e.preventDefault(),this.sendSelectedWorkItemMessage())},boardFilters(){let e=Date.now(),t=this.boardUpdatedRange==="day"?e-1440*60*1e3:this.boardUpdatedRange==="week"?e-10080*60*1e3:this.boardUpdatedRange==="month"?e-720*60*60*1e3:null;return{keyword:this.search.trim(),vpId:this.boardVpId,workItemType:this.boardWorkItemType,updatedFrom:t,limit:200}},scheduleBoardQuery(){this.boardQueryTimer&&clearTimeout(this.boardQueryTimer),this.boardQueryTimer=setTimeout(()=>{this.boardQueryTimer=null,this.agentId&&this.refresh()},180)},refresh(){return this.agentId?this.store.listWorkItems(this.agentId,this.boardFilters()).catch(()=>{}):Promise.resolve([])},refreshWorkCenterRuntime(e){if(!(!e||e!==this.agentId))return this.store.refreshWorkCenterRuntime(e).catch(()=>{})},loadMoreBoardItems(){return this.store.loadMoreWorkItems(this.agentId).catch(()=>{})},boardAction(e){return e.attentionAction||e.activeAction||e.currentAction||null},boardActionCountLabel(e){let t=e.actionCounts||{},s=[];for(let n of["running","failed","waiting","ready"])Number(t[n])>0&&s.push(`${t[n]} ${this.statusLabel(n)}`);return s.join(" \xB7 ")||this.itemActionProgress(e)},boardExecutorLabel(e){let t=Array.isArray(e.executors)?e.executors:[];if(t.length>0)return t.map(n=>n.name||n.id).join(", ");let s=this.boardAction(e);return s?.assignedVp?.name||s?.assignedVp?.id||this.tr("workCenter.assignment.planned","Planned assignment")},sameContentRef(e,t){return e?.type===t?.type&&e?.actionId===t?.actionId&&e?.runId===t?.runId&&e?.resourceId===t?.resourceId},resetContentStack(e=[{type:"action-list"}]){let t=Array.isArray(e)?e:[e],s=t[0]?.type==="action-list"?t:[{type:"action-list"},...t];this.contentStack=s.length>0?s:[{type:"action-list"}];let n=[...this.contentStack].reverse().find(r=>r.type==="action");this.selectedActionId=this.contentRef.actionId||n?.actionId||null},openContentPanel({syncUrl:e=!0}={}){this.contentPanelOpen=!0,e&&this.syncWorkCenterUrl(),this.$nextTick(()=>{this.$refs.actionsButton?.getClientRects().length||this.$refs.contentClose?.focus({preventScroll:!0})})},closeContentPanel({syncUrl:e=!0}={}){this.contentPanelOpen=!1,this.resetContentStack(),e&&this.syncWorkCenterUrl(),this.$nextTick(()=>this.$refs.actionsButton?.focus?.())},pushContentRef(e,{replace:t=!1,syncUrl:s=!0}={}){let n=this.contentRef;if(this.contentPanelOpen=!0,this.sameContentRef(n,e)){s&&this.syncWorkCenterUrl(t);return}this.contentStack=e.type==="action-list"?[{type:"action-list"}]:[...this.contentStack,e],this.selectedActionId=e.actionId||this.selectedActionId,s&&this.syncWorkCenterUrl(t)},popContentRef(){if(this.contentStack.length<=1)return;this.contentStack=this.contentStack.slice(0,-1);let e=[...this.contentStack].reverse().find(t=>t.type==="action");this.selectedActionId=e?.actionId||null,this.syncWorkCenterUrl()},contentRefParam(e){return e.type==="action"&&e.actionId?`action:${e.actionId}`:e.type==="run"&&e.actionId&&e.runId?`run:${e.actionId}:${e.runId}`:e.type==="attachment"&&e.resourceId?`attachment:${e.actionId||"-"}:${e.resourceId}`:"action-list"},contentStackParam(){return this.contentStack.map(e=>this.contentRefParam(e)).join("/")},parseContentRef(e){let t=String(e||"");if(t==="action-list")return{type:"action-list"};if(t.startsWith("action:"))return{type:"action",actionId:t.slice(7)};if(t.startsWith("run:")){let[,s,n]=t.split(":");return{type:"run",actionId:s,runId:n}}if(t.startsWith("attachment:")){let[,s,n]=t.split(":");return{type:"attachment",actionId:s==="-"?null:s,resourceId:n}}return{type:"action-list"}},parseContentStack(e){let s=[...String(e||"").split("/").filter(Boolean).map(n=>this.parseContentRef(n))].reverse().find(n=>n.actionId&&["action","run","attachment"].includes(n.type));return s?[{type:"action-list"},{type:"action",actionId:s.actionId}]:[{type:"action-list"}]},workCenterUrlRoute(){let e=new URLSearchParams(window.location.search);return{agentId:e.get("workAgentId"),itemId:e.get("workItemId"),content:e.has("workContent")?e.get("workContent"):null}},sameWorkCenterUrlRoute(e,t){return e?.agentId===t?.agentId&&e?.itemId===t?.itemId&&e?.content===t?.content},syncWorkCenterUrl(e=!1){Ga(this);let t=new URL(window.location.href);this.selectedId?(t.searchParams.set("workAgentId",this.agentId||""),t.searchParams.set("workItemId",this.selectedId),t.searchParams.set("workContent",this.contentPanelOpen?this.contentStackParam():"none")):(t.searchParams.delete("workAgentId"),t.searchParams.delete("workItemId"),t.searchParams.delete("workContent"));let s=`${t.pathname}${t.search}${t.hash}`;if(`${window.location.pathname}${window.location.search}${window.location.hash}`===s)return;let n={...window.history.state,workCenter:!!this.selectedId,workCenterContent:!!this.selectedId&&this.contentPanelOpen};window.history[e?"replaceState":"pushState"](n,"",s)},async restoreWorkCenterUrl(){let e=Ga(this),t=this.workCenterUrlRoute(),s=()=>e===this.workCenterUrlRestoreGeneration&&this.sameWorkCenterUrlRoute(t,this.workCenterUrlRoute()),n=t.agentId,r=t.itemId;if(!r||n&&n!==this.agentId){this.selectedId&&this.showItemsPane({syncUrl:!1});return}let i=t.content==null?(this.$refs.shell?.clientWidth||window.innerWidth)>900:t.content!=="none",o=this.parseContentStack(t.content),a=o.at(-1);if(this.selectedId!==r||this.detail?.id!==r){this.openWorkItem(r,{syncUrl:!1,contentRefs:o,contentOpen:i}),this.detailLoading=!0;try{await this.store.getWorkItem(r,this.agentId)}catch(c){s()&&(this.detailError=c?.message||String(c))}finally{s()&&(this.detailLoading=!1)}}if(!s())return;let l=a.actionId||[...o].reverse().find(c=>c.type==="action")?.actionId;if(l&&!this.selected?.actions?.some(c=>c.id===l)){this.resetContentStack(),this.syncWorkCenterUrl(!0);return}this.resetContentStack(o),this.contentPanelOpen=i,this.narrowPane="work-item",i&&l&&this.loadLatestActionMessages(this.selectedAction),i&&t.content!==this.contentStackParam()&&this.syncWorkCenterUrl(!0)},resetWorkItemComposer(){this.workItemComposerGeneration+=1,this.workItemMessage="",this.workItemMessageQuote=null,this.workItemMessageAttachments=[],this.workItemMessageAttachmentUploadCount=0,this.workItemMessageAttachmentsUploading=!1,this.workItemMessageError="",this.workItemMessageSending=!1},draftTarget(){let e=this.composerTargetAction;return e?{kind:"action",actionId:e.id,generation:Number(e.generation)}:this.composerTargetValue==="coordinator"?{kind:"coordinator"}:(()=>{let[,t="",s="0"]=this.composerTargetValue.split(":");return{kind:"action",actionId:t,generation:Number(s)||0}})()},targetValue(e){return typeof e=="string"&&e.startsWith("action:")?e:e?.kind==="action"?`action:${e.actionId}:${e.generation}`:"coordinator"},saveComposerDraft(){!this.selectedId||!this.agentId||this.store.saveWorkCenterComposerDraft(this.agentId,this.selectedId,{text:this.workItemMessage,quote:this.workItemMessageQuote,attachments:[...this.workItemMessageAttachments],target:this.draftTarget(),error:this.workItemMessageError})},restoreComposerDraft(e){let s=this.store.loadWorkCenterMessageEnvelope(this.agentId,e)||this.store.loadWorkCenterComposerDraft(this.agentId,e);this.workItemMessage=s?.text||"",this.workItemMessageQuote=Mt(s?.quote),this.workItemMessageAttachments=[...s?.attachments||[]],this.composerTargetValue=this.targetValue(s?.target),this.workItemMessageError=s?.error||"",this.staleComposerTarget=null,this.workItemMessageSending=!1,this.workItemMessageAttachmentUploadCount=0,this.workItemMessageAttachmentsUploading=!1,this.workItemComposerGeneration+=1},openWorkItem(e,{syncUrl:t=!0,contentRefs:s=[{type:"action-list"}],contentOpen:n=(this.$refs.shell?.clientWidth||window.innerWidth)>900}={}){this.saveComposerDraft(),this.selectedId=e,this.narrowPane="work-item",this.contentPanelOpen=n,this.resetContentStack(s),this.restoreComposerDraft(e),this.detailError="",this.detailLoading=!1,this.previewingAttachmentId=null,this.attachmentPreviewError="",this.attachmentPreviewGeneration=(Number(this.attachmentPreviewGeneration)||0)+1,t&&this.syncWorkCenterUrl()},async selectItem(e){this.mobileNavigation&&(this.sidebarExpanded=!1),this.openWorkItem(e.id),this.detailLoading=!0;try{await this.store.getWorkItem(e.id,this.agentId)}catch(t){this.selectedId===e.id&&(this.detailError=t?.message||String(t))}finally{this.selectedId===e.id&&(this.detailLoading=!1)}},selectAction(e){this.selectedActionId!==e.id&&(this.previewingAttachmentId=null,this.attachmentPreviewError="",this.attachmentPreviewGeneration=(Number(this.attachmentPreviewGeneration)||0)+1),this.pushContentRef({type:"action",actionId:e.id}),this.loadLatestActionMessages(e),this.$nextTick(()=>this.$refs.actionBack?.focus({preventScroll:!0}))},loadLatestActionMessages(e=this.selectedAction){if(!this.selected?.id||!e?.id||Array.isArray(e.messages))return null;let t=dr(this.agentId,this.selected.id,e.id,e.generation);return this.store.workCenterActionMessages[t]?null:this.store.loadWorkItemActionMessages(this.selected.id,e.id,e.generation,null,this.agentId).catch(()=>null)},showItemsPane({syncUrl:e=!0}={}){this.saveComposerDraft(),this.narrowPane="items",this.selectedId=null,this.contentPanelOpen=!1,this.resetContentStack(),this.composerTargetValue="coordinator",this.resetWorkItemComposer(),e&&this.syncWorkCenterUrl()},showActionsPane(){this.contentPanelOpen=!0,this.contentIsActionList?this.syncWorkCenterUrl():this.popContentRef(),this.$nextTick(()=>this.$refs.contentClose?.focus({preventScroll:!0}))},canMessageAction(e){return!e||["done","cancelled"].includes(this.selected?.status)?!1:["idle","ready","running","paused","waiting","failed","completed","stopped"].includes(e.status)&&e.admissionStatus!=="blocked"},clearPendingMessageEnvelope({preserveAttachments:e=!1}={}){return!this.selectedId||!this.pendingMessageEnvelope?!1:(this.actionInputRequestGeneration=(Number(this.actionInputRequestGeneration)||0)+1,this.preserveComposerOnEnvelopeClear=!0,this.store.discardWorkCenterMessageEnvelope(this.agentId,this.selectedId)?(e||(this.workItemMessageAttachments=[]),this.workItemMessageError="",this.workItemMessageSending=!1,!0):(this.preserveComposerOnEnvelopeClear=!1,!1))},replyToWaitingPrompt(e=null){this.replyEntryDisabled||e&&!this.canMessageAction(e)||!e&&this.coordinatorThinking||(this.composerTargetValue=e?`action:${e.id}:${e.generation}`:"coordinator",this.staleComposerTarget=null,this.workItemMessageError="",this.saveComposerDraft(),(this.$refs.shell?.clientWidth||window.innerWidth)<=900&&this.closeContentPanel(),this.$nextTick(()=>{let t=this.$refs.workItemComposer?.getTextarea?.();t?.scrollIntoView?.({block:"nearest"}),t?.focus?.()}))},chooseCoordinatorTarget(){this.pendingMessageEnvelope&&!this.clearPendingMessageEnvelope({preserveAttachments:!0})||(this.composerTargetValue="coordinator",this.staleComposerTarget=null,this.saveComposerDraft())},onComposerTargetChange(){this.pendingMessageEnvelope&&!this.clearPendingMessageEnvelope({preserveAttachments:!0})||(this.staleComposerTarget=this.composerTargetAction==null&&this.composerTargetValue!=="coordinator"?this.composerTargetValue:null,this.saveComposerDraft())},loadEarlierActionMessages(){return!this.selected?.id||!this.selectedAction?.id||this.actionMessagesNextCursor==null?null:this.store.loadWorkItemActionMessages(this.selected.id,this.selectedAction.id,this.selectedAction.generation,this.actionMessagesNextCursor,this.agentId).catch(()=>null)},actionExecutor(e){return e?.assignedVp?.name||e?.assignedVp?.id||e?.requiredRole||e?.assignmentPolicy?.fixedVpId||e?.assignmentPolicy?.capability||this.tr("workCenter.assignment.auto","Auto")},actionContentSummary(e){return String(e?.contentSummary||e?.response||e?.brief?.objective||"").trim()},executionStats(e){return e?.executionStats||{}},formatCount(e){return new Intl.NumberFormat().format(Math.max(0,Number(e)||0))},formatTokens(e){let t=Math.max(0,Number(e)||0);return t>=1e6?`${(t/1e6).toFixed(1)}m`:t>=1e3?`${(t/1e3).toFixed(1)}k`:String(t)},resetCreateExecutionContext(e,{keepOpen:t=!1}={}){let s=this.workDirTouched||this.startTouched,n=this.store.workCenterCreateDraft;n&&(this.store.workCenterCreateDraft={sourceAgentId:e||null,requirement:n.requirement||n.goal||n.title||"",workDir:"",deliveryTarget:n.deliveryTarget||"",deliveryInstructions:n.deliveryInstructions||"",origin:null,linkedSessionIds:[]}),this.createAttachments=[],this.createAttachmentError="",this.form.workDir="",this.form.start=!0,this.form.scheduled=!1,this.form.scheduleDraft=Qi(),this.scheduleDraftStarted=!1,this.createError="",this.workDirTouched=!1,this.startTouched=!1,s&&!t&&(this.createOpen=!1),this.applyCreateDefaults()},applyCreateDefaults(){this.createOpen&&(!this.workDirTouched&&!this.form.workDir.trim()&&(this.form.workDir=this.createDefaultWorkDir),this.startTouched||(this.form.start=this.createDefaultStart))},folderPickerInitialDir(){return this.form.workDir.trim()||this.createDefaultWorkDir},folderPickerSetWorkDir(e){this.form.workDir=e,this.workDirTouched=!0},onCreateWorkDirInput(){this.workDirTouched=!0},setExecutionMode(e){e==="scheduled"&&!this.scheduleDraftStarted&&(this.form.scheduleDraft=Qi(),this.scheduleDraftStarted=!0),this.form.scheduled=e==="scheduled",this.form.start=e==="now",this.startTouched=!0},scheduleStatusLabel(e){return this.$t("workCenter.scheduling.status."+(e?.status||"scheduled"))},scheduleSummary(e){if(!e)return"";let t=[this.scheduleStatusLabel(e)];if(e.lastError&&e.status==="scheduled"&&t.push(this.$t("workCenter.scheduling.retrying")),e.recurrence&&t.push(this.$t("workCenter.scheduling."+e.recurrence.frequency)),e.scheduledFor&&!["completed","cancelled"].includes(e.status)){let s=e.recurrence?.timeZone;t.push(new Intl.DateTimeFormat(this.$locale?.value||this.$locale||"en",{timeZone:s,dateStyle:"medium",timeStyle:"short",hour12:!1}).format(e.scheduledFor)),s&&t.push(s.replaceAll("_"," "))}return t.join(" \xB7 ")},async setSelectedScheduleEnabled(e){let t=this.selected?.schedule;if(!this.selected||!t||this.selected.status!=="draft"||this.scheduleSaving)return;let s=this.agentId,n=this.selected.id;this.scheduleSaving=!0,this.scheduleError="";try{await this.store.updateWorkItemSchedule(n,{enabled:e,revision:this.selected.revision},s)}catch(r){this.agentId===s&&this.selectedId===n&&(this.scheduleError=r?.message||String(r))}finally{this.scheduleSaving=!1}},clipboardFiles(e){return Array.from(e?.clipboardData?.items||[]).filter(t=>t?.kind==="file").map(t=>t.getAsFile?.()).filter(Boolean)},clipboardIncludesText(e){return Array.from(e?.clipboardData?.types||[]).some(t=>String(t).toLowerCase().startsWith("text/"))},attachmentUploadName(e,t){let s=String(e?.name||"").trim();if(s)return s;let n={"image/png":".png","image/jpeg":".jpg","image/gif":".gif","image/webp":".webp","application/pdf":".pdf","application/json":".json","text/plain":".txt"};return`${String(e?.type||"").startsWith("image/")?"pasted-image":"pasted-file"}-${Date.now()}-${t+1}${n[e?.type]||""}`},async uploadPendingAttachments(e){let t=new FormData;e.forEach((a,l)=>{t.append("files",a,this.attachmentUploadName(a,l))});let s=Pinia.useAuthStore(),n=s.getActiveToken?.()||s.token||null,r=n?{Authorization:`Bearer ${n}`}:{},i=await fetch("/api/upload",{method:"POST",headers:r,body:t});if(!i.ok)throw new Error(this.tr("workCenter.attachmentsUploadFailed","Attachment upload failed"));let o=await i.json();return Array.isArray(o.files)?o.files:[]},async addCreateAttachments(e){if(!this.workItemAttachmentsSupported){this.createAttachmentError=this.tr("workCenter.attachmentsUnsupported","The selected Agent does not support Work Item attachments.");return}let t=Math.max(0,10-this.createAttachments.length),s=Array.from(e||[]).slice(0,t);if(s.length===0)return;let n=this.createGeneration;this.createAttachmentUploadCount+=1,this.attachmentsUploading=!0,this.createAttachmentError="";try{let r=await this.uploadPendingAttachments(s);if(!this.createOpen||this.createGeneration!==n)return;this.createAttachments=[...this.createAttachments,...r].slice(0,10)}catch(r){this.createOpen&&this.createGeneration===n&&(this.createAttachmentError=r?.message||String(r))}finally{this.createGeneration===n&&(this.createAttachmentUploadCount=Math.max(0,this.createAttachmentUploadCount-1),this.attachmentsUploading=this.createAttachmentUploadCount>0)}},async onCreateAttachmentInput(e){let t=Array.from(e.target.files||[]);e.target.value="",await this.addCreateAttachments(t)},async onCreateRequirementPaste(e){let t=this.clipboardFiles(e);t.length!==0&&(this.clipboardIncludesText(e)||e.preventDefault(),await this.addCreateAttachments(t))},removeCreateAttachment(e){this.createAttachments=this.createAttachments.filter((t,s)=>s!==e)},discardPendingMessageEnvelope(){this.clearPendingMessageEnvelope()&&this.saveComposerDraft()},async addWorkItemMessageAttachments(e){if(!this.workItemAttachmentsSupported){this.workItemMessageError=this.tr("workCenter.attachmentsUnsupported","The selected Agent does not support Work Item attachments.");return}if(!e.length)return;let t=this.workItemComposerScope;if(!t)return;let s=this.pendingEnvelopeAttachmentRecovery,n=Array.isArray(this.selected?.attachments)?this.selected.attachments.length:0,r=Math.max(0,10-n-(s?0:this.workItemMessageAttachments.length)),i=Array.from(e).slice(0,r);if(i.length===0)return;let o=this.workItemComposerGeneration;this.workItemMessageAttachmentUploadCount+=1,this.workItemMessageAttachmentsUploading=!0,this.workItemMessageError="";try{let a=(await this.uploadPendingAttachments(i)).slice(0,Math.max(0,10-n));if(this.workItemComposerScope!==t||this.workItemComposerGeneration!==o)return;if(s){let l=this.store.replaceWorkCenterMessageEnvelopeAttachments(this.agentId,this.selectedId,a);if(!l)throw new Error(this.tr("workCenter.pendingEnvelopeChanged","The pending request changed; reopen this Work Item and try again."));this.workItemMessageAttachments=[...l.attachments],this.workItemMessageError=""}else this.workItemMessageAttachments=[...this.workItemMessageAttachments,...a].slice(0,Math.max(0,10-n)),this.saveComposerDraft()}catch(a){this.workItemComposerScope===t&&this.workItemComposerGeneration===o&&(this.workItemMessageError=a?.message||String(a))}finally{this.workItemComposerScope===t&&this.workItemComposerGeneration===o&&(this.workItemMessageAttachmentUploadCount=Math.max(0,this.workItemMessageAttachmentUploadCount-1),this.workItemMessageAttachmentsUploading=this.workItemMessageAttachmentUploadCount>0)}},async onWorkItemMessageAttachmentInput(e){let t=Array.from(e.target.files||[]);e.target.value="",await this.addWorkItemMessageAttachments(t)},async onWorkItemMessagePaste(e){let t=this.clipboardFiles(e);t.length!==0&&(this.clipboardIncludesText(e)||e.preventDefault(),await this.addWorkItemMessageAttachments(t))},removeWorkItemMessageAttachment(e){this.workItemMessageAttachments=this.workItemMessageAttachments.filter((t,s)=>s!==e),this.saveComposerDraft()},async previewAttachment(e,t=null){if(!this.selected?.id||!e?.id||this.previewingAttachmentId)return;let s=this.agentId,n=this.selected.id,r=this.selectedActionId||"",i=`${s}:${n}:${r}`,o=(Number(this.attachmentPreviewGeneration)||0)+1;this.attachmentPreviewGeneration=o;let a=()=>this.attachmentPreviewGeneration===o&&`${this.agentId}:${this.selected?.id||""}:${this.selectedActionId||""}`===i,l=e.isImage?null:window.open("","_blank");if(!e.isImage&&!l){this.attachmentPreviewError=this.tr("workCenter.attachmentOpenBlocked","The browser blocked the attachment window. Allow pop-ups and try again.");return}l&&(l.opener=null),this.previewingAttachmentId=e.id,this.attachmentPreviewError="";try{let c=await this.store.previewWorkItemAttachment(n,e.id,s);if(!a()){l?.close();return}c?.preview&&c.attachment?.isImage?Fs(c.preview,{alt:e.name||this.tr("workCenter.previewAttachment","Open attachment"),closeLabel:this.tr("common.close","Close"),trigger:t}):c?.preview&&l?l.location.replace(c.preview):l?.close()}catch(c){l?.close(),a()&&(this.attachmentPreviewError=c?.message||this.tr("workCenter.attachmentPreviewFailed","Could not open the attachment. Try again."))}finally{a()&&(this.previewingAttachmentId=null)}},isExternalOutput(e){return["link","pr"].includes(e?.kind)&&/^https?:\/\//i.test(String(e?.ref||""))},formatAttachmentSize(e){let t=Math.max(0,Number(e)||0);return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/1024/1024).toFixed(1)} MB`},async focusCustomDeliveryInput(){await this.$nextTick(),await this.$nextTick(),this.createOpen&&this.customDeliveryTarget&&this.$refs.customDeliveryInput?.focus()},async loadDeliveryInstructionOptions(){let e=this.agentId,t=++this.deliveryInstructionsGeneration;if(e)try{let s=await this.store.loadWorkCenterDeliveryInstructions(e);this.agentId===e&&this.deliveryInstructionsGeneration===t&&(this.deliveryInstructionOptions=s)}catch{this.agentId===e&&this.deliveryInstructionsGeneration===t&&(this.deliveryInstructionOptions=[])}},selectCreateAgent(e){this.saving||e===this.agentId||!this.onlineAgents.some(t=>t.id===e)||(this.createAgentSelection=e,this.selectWorkCenterAgent(e))},openCreate(){this.agentId&&(this.mobileNavigation&&(this.sidebarExpanded=!1),this.createGeneration=(Number(this.createGeneration)||0)+1,this.createAttachmentUploadCount=0,this.attachmentsUploading=!1,this.createOpen=!0,this.workDirTouched=!1,this.startTouched=!1,this.createAttachmentError="",this.applyCreateDefaults(),this.loadDeliveryInstructionOptions(),this.$nextTick(()=>this.$refs.createRequirement?.focus()))},closeCreate(){this.saving||(this.createGeneration=(Number(this.createGeneration)||0)+1,this.createAttachmentUploadCount=0,this.attachmentsUploading=!1,this.closeFolderPicker(),this.createOpen=!1,this.createAttachments=[],this.createAttachmentError="",this.createError="",this.store.workCenterCreateDraft=null)},async submitCreate(){let e=String(this.form.requirement||this.form.goal||this.form.title||"").trim();if(this.saving||this.attachmentsUploading||!this.agentId||!e||!this.form.workDir.trim()||this.customDeliveryTarget&&!this.form.deliveryInstructions.trim())return;let t=this.form.scheduled?Xi(this.form.scheduleDraft):{};if(t.error||t.recurrence&&!this.recurringSchedulesSupported)return;this.createError="";let s=this.agentId,n=(Number(this.createGeneration)||0)+1;this.createGeneration=n,this.saving=!0;try{let r=this.store.workCenterCreateDraft,i=r?.sourceAgentId===s,o=await this.store.createWorkItem({requirement:e,title:e.replace(/\s+/g," ").slice(0,80),titleSource:"coordinator_pending",goal:e,acceptanceCriteria:[],workItemType:"auto",workDir:this.form.workDir.trim(),deliveryTarget:this.customDeliveryTarget?null:this.form.deliveryTarget||null,deliveryInstructions:this.form.deliveryInstructions.trim()||null,origin:i&&r.origin||null,linkedSessionIds:i?r.linkedSessionIds||[]:[],attachments:this.workItemAttachmentsSupported?(this.createAttachments||[]).map(a=>({fileId:a.fileId,name:a.name,mimeType:a.mimeType,size:a.size})):[],reuseMemory:!0,start:this.form.scheduled?!1:this.form.start,scheduledFor:t.scheduledFor||null,recurrence:t.recurrence||null},s);if(this.agentId!==s||this.createGeneration!==n)return;this.openWorkItem(o.id),this.form={requirement:"",workDir:"",deliveryTarget:"",deliveryInstructions:"",start:this.settings?.startImmediately!==!1,scheduled:!1,scheduleDraft:Qi()},this.customDeliveryTarget=!1,this.store.workCenterCreateDraft=null,this.createAttachments=[],this.workDirTouched=!1,this.startTouched=!1,this.scheduleDraftStarted=!1,this.createOpen=!1}catch(r){this.agentId===s&&this.createGeneration===n&&(this.createError=r?.message||String(r))}finally{this.agentId===s&&this.createGeneration===n&&(this.saving=!1)}},async startSelected(){this.selected&&await this.store.startWorkItem(this.selected.id,this.agentId)},async sendSelectedWorkItemMessage(){if(!this.selected||!this.composerCanSend)return;let e=this.workItemComposerScope,t=this.composerTargetValue,s=this.composerTargetAction;if(!this.composerTargetIsCoordinator&&!s)return;let n=this.selected.id,r=this.selected.revision,i=this.workItemMessage.trim(),o=Mt(this.workItemMessageQuote),a=this.workItemMessageAttachments.map(c=>({fileId:c.fileId,name:c.name,mimeType:c.mimeType,size:c.size})),l=(Number(this.actionInputRequestGeneration)||0)+1;this.actionInputRequestGeneration=l,this.workItemMessageSending=!0,this.workItemMessageError="",this.saveComposerDraft();try{let c={planRevision:this.selected.planRevision,ledgerRevision:this.selected.ledgerRevision,coordinatorRevision:this.selected.coordinatorRevision};this.canonicalMessageWireSupported?await this.store.postWorkItemMessage(n,i,s?{kind:"action",actionId:s.id,generation:s.generation}:{kind:"coordinator"},r,a,this.agentId,c,o):s?await this.store.sendWorkItemActionInput(n,i,s.id,r,s.generation,a,this.agentId,o):await this.store.sendWorkItemMessage(n,i,r,a,this.agentId,c,o),this.workItemComposerScope===e&&this.actionInputRequestGeneration===l&&this.composerTargetValue===t&&this.workItemMessage.trim()===i&&!this.store.loadWorkCenterMessageEnvelope(this.agentId,n)&&(this.workItemMessage="",this.workItemMessageQuote=null,this.workItemMessageAttachments=[],this.store.removeWorkCenterComposerDraft(this.agentId,n))}catch(c){if(this.workItemComposerScope===e&&this.actionInputRequestGeneration===l)if(c?.code==="WORK_CENTER_INPUT_STALE"){if(this.clearPendingMessageEnvelope({preserveAttachments:!0}),await this.$nextTick(),this.workItemComposerScope!==e)return;this.workItemMessageError=this.$t("workCenter.inputStale"),this.saveComposerDraft(),this.store.getWorkItem(n,this.agentId).catch(()=>{})}else this.workItemMessageError=c?.message||String(c),this.saveComposerDraft()}finally{this.workItemComposerScope===e&&this.actionInputRequestGeneration===l&&(this.workItemMessageSending=!1)}},workItemCanDelete(e){return["done","cancelled","draft","needs_attention"].includes(e?.status)},workItemDeleting(e){return!!this.deletingWorkItemIds[e?.id]},async deleteWorkItem(e){if(!e||this.workItemDeleting(e))return;let t=this.tr("workCenter.deleteConfirm","Permanently delete this Work Item, its execution history, and attachments?");if(await We(t,{destructive:!0})){this.deleteWorkItemError="",this.deletingWorkItemIds={...this.deletingWorkItemIds,[e.id]:!0};try{let s=await this.store.deleteWorkItem(e.id,e.revision,this.agentId);s?.cleanupWarning&&(this.deleteWorkItemError=s.cleanupWarning),this.selectedId===e.id&&this.showItemsPane()}catch(s){this.deleteWorkItemError=s?.message||String(s)}finally{let s={...this.deletingWorkItemIds};delete s[e.id],this.deletingWorkItemIds=s}}},async cancelSelected(){if(!this.selected||["done","cancelled"].includes(this.selected.status))return;let e=this.tr("workCenter.cancelConfirm","Stop this work item and its unfinished Actions?");await We(e,{destructive:!0})&&await this.store.cancelWorkItem(this.selected.id,this.agentId)},async resumeSelected(){!this.selected||this.selected.status!=="cancelled"||await this.store.resumeWorkItem(this.selected.id,this.selected.revision,this.agentId,this.selected.executionControl?.revision)}},template:`
6883
6883
  <main class="work-center-main" :class="{ 'navigation-open': sidebarExpanded && mobileNavigation }" :aria-label="tr('workCenter.title', 'Work Center')">
6884
6884
  <WorkCenterSidebar ref="navigation" :agents="sidebarAgents" :agent-id="agentId" :item-id="selectedId"
6885
6885
  :action-id="selectedActionId" :expanded="sidebarExpanded"
@@ -7109,7 +7109,8 @@ ${String(e||"").trim()}
7109
7109
  <template v-if="selected">
7110
7110
  <div class="work-center-detail-layout" :class="{ 'content-open': contentPanelOpen }">
7111
7111
  <div class="work-center-detail-main work-center-conversation-pane">
7112
-
7112
+ <div class="work-center-conversation">
7113
+ <div ref="detailScroll" :key="agentId + ':' + selectedId" :data-work-item-id="detail?.id === selectedId ? selectedId : null" class="work-center-conversation-scroll">
7113
7114
  <section class="work-center-work-item-overview" :aria-label="$t('workCenter.itemInfo')">
7114
7115
  <div class="work-center-info-column">
7115
7116
  <div class="work-center-work-item-kicker">
@@ -7278,9 +7279,8 @@ ${String(e||"").trim()}
7278
7279
  </div>
7279
7280
  </section>
7280
7281
 
7281
- <section class="work-center-section work-center-item-messages work-center-conversation" :aria-label="tr('workCenter.conversation', 'Conversation')">
7282
+ <section class="work-center-section work-center-item-messages" :aria-label="tr('workCenter.conversation', 'Conversation')">
7282
7283
  <h3 class="work-center-conversation-heading">{{ tr('workCenter.conversation', 'Conversation') }}</h3>
7283
- <div class="work-center-conversation-scroll">
7284
7284
  <div class="work-center-conversation-column">
7285
7285
  <div v-if="detailLoading" class="work-center-detail-notice" aria-live="polite">{{ tr('workCenter.detailLoading', 'Loading full details\u2026') }}</div>
7286
7286
  <div v-else-if="detailError" class="work-center-detail-notice work-center-detail-error" role="alert">
@@ -7332,7 +7332,7 @@ ${String(e||"").trim()}
7332
7332
  <p v-if="!conversationBlocks.length && !coordinatorThinking" class="work-center-muted work-center-conversation-empty">{{ $t('workCenter.infoConversationEmpty') }}</p>
7333
7333
  <p v-if="workItemMessageError" class="work-center-error" role="alert">{{ workItemMessageError }}</p>
7334
7334
  </div>
7335
- </div>
7335
+ </section>
7336
7336
 
7337
7337
  <div class="work-center-conversation-composer">
7338
7338
  <div class="work-center-composer-column">
@@ -7407,7 +7407,8 @@ ${String(e||"").trim()}
7407
7407
  </template>
7408
7408
  </div>
7409
7409
  </div>
7410
- </section>
7410
+ </div>
7411
+ </div>
7411
7412
  </div>
7412
7413
 
7413
7414
  <PaneResizeHandle v-if="contentPanelOpen" v-model="actionsPaneWidth"
Binary file
@@ -6,7 +6,7 @@
6
6
  <title>Yeaft</title>
7
7
  <link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'><rect width='32' height='32' rx='8' fill='%232c2c2c'/><path d='M16 22V13M16 13L10 8M16 13L22 8' stroke='white' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round' fill='none'/><circle cx='10' cy='8' r='2.4' fill='white'/><circle cx='22' cy='8' r='2.4' fill='white'/><circle cx='16' cy='22' r='2.4' fill='white'/></svg>">
8
8
  <link rel="stylesheet" href="vendor/katex/katex.min.css?v=b0d91614">
9
- <link rel="stylesheet" href="style.bundle.css?v=95fab418">
9
+ <link rel="stylesheet" href="style.bundle.css?v=f3b9127a">
10
10
  <script src="vendor.bundle.js?v=b4d2c175"></script>
11
11
  <script defer src="jszip.min.js"></script>
12
12
  <script defer src="docx-preview.min.js"></script>
@@ -17,6 +17,6 @@
17
17
  </head>
18
18
  <body>
19
19
  <div id="app"></div>
20
- <script type="module" src="app.bundle.js?v=79eac4c8"></script>
20
+ <script type="module" src="app.bundle.js?v=454f3a0c"></script>
21
21
  </body>
22
22
  </html>