import{n as e}from"./rolldown-runtime-Czos8NxU.js";import{Bt as t,Ft as n,Pt as r,bt as i,fi as a,gt as o,xo as s}from"./app-initial~app-main~worktree-init-v2-page~appgen-settings-page~page~appgen-publication-ter~fzo5ij6p-BKVLyD1q.js";import{Jb as c,Ub as l,fo as u,mo as d}from"./app-initial~app-main~onboarding-page-CNHnOMz8.js";import{C_ as f,fv as p,pv as m,x_ as h}from"./app-initial~app-main~new-thread-panel-page-BZHGOlMi.js";import{R as g,z as _}from"./app-initial~app-main~onboarding-page~debug-window-page~debug-modal-C5dk1tqp.js";async function v({entry:e,threadGoalObjective:t,workspaceRoot:n}){let r=C(e);if(e.launchMode===`fork-conversation`){let t;return t=e.targetTurnId==null?await m(`fork-conversation-from-latest`,{hostId:e.hostId,conversationId:e.sourceConversationId,cwd:n,workspaceRoots:[n],collaborationMode:e.sourceCollaborationMode,threadSource:e.threadSource}):await m(`fork-conversation-from-turn`,{conversationId:e.sourceConversationId,targetTurnId:e.targetTurnId,cwd:n,workspaceRoots:[n],collaborationMode:e.sourceCollaborationMode,threadSource:e.threadSource}),r!=null&&await m(`add-worktree-init-synthetic-turn`,{conversationId:t,worktreeInit:r}),t}if(e.launchMode!==`start-conversation`)throw Error(`Unsupported launch mode: ${e.launchMode}`);let i=t==null?e.startConversationParamsInput:{...e.startConversationParamsInput,fileAttachments:y(e),input:x(e.startConversationParamsInput.input,h(t))},a=i.projectAssignment;return m(`start-conversation`,{hostId:e.threadStartHostId??e.hostId,...g({...i,workspaceRoots:[n],cwd:n,projectAssignment:a==null?a:{...a,cwd:n}}),skipAutoTitleGeneration:e.initialThreadTitle!=null,worktreeInit:r??void 0})}function y(e){let t=new Set(e.threadGoalDraft?.pastedTextAttachments.map(e=>e.file.path));return e.startConversationParamsInput.fileAttachments.filter(e=>!t.has(e.path))}async function b({entry:e,conversationId:t,hostConfig:r,threadGoalObjective:i}){let s=e.initialThreadTitle==null&&e.labelEdited,c=(e.initialThreadTitle??(s?e.label:``)).trim();if(c.length>0&&await m(`set-thread-title`,{conversationId:t,title:c,...s?{onlyIfUntitled:!0}:{}}),e.worktreeGitRoot!=null)try{await o(`worktree-set-owner-thread`,{params:{hostId:r.id,worktree:a(e.worktreeGitRoot),conversationId:t}})}catch(e){n.warning(`Worktree created and conversation started, but failed to set worktree owner metadata: {}`,{safe:{},sensitive:{error:e}})}if(e.isPinned)try{await d(t,!0,e.pinnedBeforeThreadId)}catch(e){n.warning(`Worktree conversation started, but failed to set pinned metadata: {}`,{safe:{},sensitive:{error:e}})}e.launchMode===`start-conversation`&&i!=null&&await m(`set-thread-goal`,{appendTranscriptItem:!1,conversationId:t,hostId:e.threadStartHostId??r.id,objective:i})}function x(e,t){let n=!1;return e.map(e=>!n&&e.type===`text`?(n=!0,{...e,text:t}):e)}function S(e,t){let n=e.browserTransferSourceConversationId;if(n==null)return;let r=e.browserTransferSourceBrowserTabIds,i=r!=null&&r.length>0,a=s(`${n}:legacy`),o=r!=null&&r.length>0?r:[e.browserTransferSourceBrowserTabId??a],l=e.browserTransferSourceBrowserTabId!=null&&o.includes(e.browserTransferSourceBrowserTabId)?e.browserTransferSourceBrowserTabId:o.at(-1);for(let r of o)c(t,{active:r===l,browserTabId:i||e.browserTransferSourceBrowserTabId!=null?r:s(`${t}:legacy`),transferSourceBrowserTabId:r,transferSourceConversationId:n})}function C(e){return e.phase===`worktree-ready`?{id:`${e.id}:${e.attempt}`,worktreeOutputText:e.worktreeOutputText,setup:e.localEnvironmentConfigPath==null?null:{outcome:e.errorMessage==null?`completed`:`skipped`,outputText:e.setupOutputText}}:null}var w=e((()=>{t(),p(),l(),_(),f(),u(),r(),i()}));export{S as i,w as n,v as r,b as t};
//# sourceMappingURL=app-initial~app-main~worktree-init-v2-page~hotkey-window-worktree-init-page~local-conversation-page-Be55pNiO.js.map