import{u as e}from"./terminalPersistedTabs-DSLsAslX.js";import"./deriveSessionChrome-4J3GRvX8.js";function t(e,t,n){return{isFreshLaunch:!!(e.spawnPi&&!e.sessionFilePath),sessionId:t?.id??e.piSessionId??null,sessionFilePath:t?.filePath??e.sessionFilePath??null,ptySessionId:null,pendingInputAt:e.pendingInputAt??null,pendingInputText:e.pendingInputText??null,pendingLaunchStatus:e.pendingLaunchStatus??null,hasSubmittedPrompt:!!(e.pendingInputAt||e.pendingInputText?.trim()||e.pendingLaunchStatus===`spawned`||e.pendingLaunchStatus===`bound`),hasMessages:(t?.messageCount??0)>0,isWorking:n?.isWorking??(t?.status===`active`&&!t?.awaiting_approval),deliveryStatus:n?.deliveryStatus,deliveryIntentStatus:n?.deliveryIntentStatus,deliveryPendingCount:n?.deliveryPendingCount,hasRecentPtyActivity:n?.hasRecentPtyActivity}}function n(e,t){let n=!!(t?.id||e.sessionFilePath);return{tabTitle:e.title,sessionTitle:t?.title??null,cwd:t?.cwd??e.cwd??null,pendingInputPreview:n?null:e.pendingInputPreview??null}}function r(e,t){return t.status===`stopping`||t.status===`stop_failed`||t.status===`aborted`||t.status===`sending`||t.status===`queued`||t.status===`awaiting_agent`||t.status===`retrying`||t.intentStatus===`delivering`||t.intentStatus===`written`||t.intentStatus===`needs_human_review`||t.intentStatus===`rebound_takeover`?t:e.readiness===`failed`?{...t,status:`retrying`,intentStatus:`failed_retryable`,lastError:e.statusDetail}:e.readiness===`working`?{...t,status:`connected`,intentStatus:`processing`,lastError:void 0}:e.readiness===`launching`||e.readiness===`binding`?{...t,status:`queued`,intentStatus:`queued`,lastError:e.statusDetail}:{...t,status:`connected`,intentStatus:e.readiness===`draft`||e.readiness===`live`?`accepted`:t.intentStatus,lastError:void 0}}function i(e){return(e.kind??`terminal`)===`terminal`&&!e.sessionFilePath&&!!(e.spawnPi||e.pendingInputAt||e.pendingLaunchId)}function a(e){return`tab-new-pi-${e}`}function o(e,t){return t?.trim()||a(e)}function s(e){return e.sessionFilePath||e.piSessionId,!1}function c(t,n,r={}){let a=i(t),o=n.pendingLaunchStatus===`bound`||!!n.sessionId,s=n.clearPendingInput??o,c=r.preserveFreshLaunchTitle??a,l=n.title?.trim(),u=c?t.title:l&&!e(l)?l:t.title;return{...t,piSessionId:n.sessionId??t.piSessionId,sessionFilePath:n.sessionFilePath,spawnPi:void 0,pendingInputAt:s?void 0:t.pendingInputAt,pendingInputPreview:s?void 0:t.pendingInputPreview,pendingInputText:s?void 0:t.pendingInputText,pendingInputDelivery:s?void 0:t.pendingInputDelivery,pendingLaunchId:o?void 0:t.pendingLaunchId,pendingLaunchAt:o?void 0:t.pendingLaunchAt,pendingLaunchStatus:o?`bound`:n.pendingLaunchStatus??(n.sessionId?`bound`:t.pendingLaunchStatus),title:u}}export{r as a,s as i,a as n,n as o,o as r,t as s,c as t};