import{n as e}from"./chunk-DR8-3Aex.js";import{n as t,r as n}from"./analytics-DqMQntaB.js";import{Fr as r,Fv as i,Hv as a,Sr as o,zv as s}from"./loadAgentsDir-C_wFhytF.js";import{n as c,o as l}from"./api-CDmgYrwN.js";function u(e){return e}function d(e){return[`## Available sessions (most recent first)`,``,...e.slice(0,p).map((e,t)=>`  ${String(t+1).padStart(2)}. ${e.title.slice(0,50).padEnd(50)}  ${e.status.padEnd(14)}  ${e.created_at.slice(0,10)}  id=${e.id}`),``,"Run `/teleport <session-id>` to resume a session."].join(`
`)}var f,p,m;e((()=>{t(),r(),i(),l(),f=8,p=20,m=async(e,t,r)=>{let i=r.trim(),l=i===`--print`||i.startsWith(`--print `),m=l?i.replace(/^--print\s*/,``).trim():i;if(n(`tengu_teleport_started`,{has_session_id:u(m?`true`:`false`)}),!m){n(`tengu_teleport_source_decision`,{source:u(`sessions_api`)});let t;try{t=(await c()).map(e=>({id:e.id,title:e.title??`Untitled`,status:e.status??`unknown`,created_at:e.created_at??``}))}catch(t){let r=t instanceof Error?t.message:String(t);return/forbidden|401|403/i.test(r)?(n(`tengu_teleport_events_fetch_forbidden`,{error:u(r.slice(0,200))}),e("Teleport: permission denied fetching sessions. Check your OAuth token (`claude auth status`).",{display:`system`}),null):/not found|404/i.test(r)?(n(`tengu_teleport_events_fetch_not_found`,{error:u(r.slice(0,200))}),e(`Teleport: sessions endpoint returned 404. The Sessions API may not be available for your account.`,{display:`system`}),null):/token|unauthorized/i.test(r)?(n(`tengu_teleport_error_bad_token`,{error:u(r.slice(0,200))}),e(`Teleport: authentication error — ${r}. Try \`claude auth login\`.`,{display:`system`}),null):(n(`tengu_teleport_events_fetch_fail`,{error:u(r.slice(0,200))}),e(`Teleport: failed to fetch sessions — ${r}.\nUsage: /teleport SESSION_ID`,{display:`system`}),null)}return t.length===0?(n(`tengu_teleport_null`,{}),e(`No active sessions found on claude.ai/code.
Start a new session at https://claude.ai/code`,{display:`system`}),null):(t.length>=p&&n(`tengu_teleport_page_cap`,{count:u(String(t.length))}),e(d(t),{display:`system`}),null)}if(m.length<f||!/^[0-9a-f-]{8,}$/i.test(m))return n(`tengu_teleport_error_bad_status`,{error:u(`invalid_session_id: ${m.slice(0,40)}`)}),e(`Invalid session id "${m}". Expected a UUID-like string (e.g. 12345678-abcd-...).`,{display:`system`}),null;n(`tengu_teleport_source_decision`,{source:u(`explicit_id`)});let h=[],g=e=>{h.push(e)};g(`validate`);try{await a()}catch(t){let r=t instanceof Error?t.message:String(t);return n(`tengu_teleport_errors_detected`,{error:u(r.slice(0,200))}),e(`Cannot teleport: ${r}`,{display:`system`}),null}g(`resume`);try{let r=``;if(await s(m,e=>{r=String(e)}),n(`tengu_teleport_resume_session`,{stage:u(r)}),g(`ready`),!t.resume)return n(`tengu_teleport_null`,{}),l?(e(`Session ${m} fetched successfully.`,{display:`system`}),null):(e(`Teleport resume succeeded for ${m}, but the REPL did not provide a resume callback.`,{display:`system`}),null);g(`fetch`);let i=await o(m);return i?(n(`tengu_teleport_errors_resolved`,{}),await t.resume(m,i,`slash_command_session_id`),n(`tengu_teleport_first_message_success`,{}),null):(n(`tengu_teleport_errors_detected`,{error:u(`log_not_found_after_resume`)}),e(`Teleport fetched session ${m} but the local log was not found. Try /resume ${m} manually.`,{display:`system`}),null)}catch(t){let r=t instanceof Error?t.message:String(t),i=`tengu_teleport_failed`;return/not found/i.test(r)?i=`tengu_teleport_error_session_not_found_`:/repo.*mismatch/i.test(r)?i=`tengu_teleport_error_repo_mismatch_sessions_api`:/not in.*git|git.*dir/i.test(r)?i=`tengu_teleport_error_repo_not_in_git_dir_sessions_api`:/cancelled|aborted/i.test(r)?i=`tengu_teleport_cancelled`:/token|unauthorized|401/i.test(r)?i=`tengu_teleport_error_bad_token`:/status|4\d\d|5\d\d/i.test(r)&&(i=`tengu_teleport_error_bad_status`),n(i,{error:u(r.slice(0,200))}),n(`tengu_teleport_first_message_error`,{error:u(r.slice(0,200))}),e(`Teleport failed: ${r}`,{display:`system`}),null}}}))();export{m as callTeleport};