MCPcopy Index your code
hub / github.com/ChinaSiro/claude-code-sourcemap / Lj6

Function Lj6

package/cli.js:2445–2447  ·  view source on GitHub ↗
(q)

Source from the content-addressed store, hash-verified

2443`))}}async function jdz(q,K){let _=await Ur1();if(_.size>0)d("tengu_teleport_errors_detected",{error_types:Array.from(_).join(","),errors_ignored:Array.from(K||[]).join(",")}),await new Promise((z)=>{q.render(bx8.default.createElement(LJ,null,bx8.default.createElement(WM,null,bx8.default.createElement(Yx8,{errorsToIgnore:K,onComplete:()=>{d("tengu_teleport_errors_resolved",{error_types:Array.from(_).join(",")}),z()}}))))})}async function Go1(q,K,_,z){return await jdz(q,new Set(["needsGitStash"])),Lj6({initialMessage:K,signal:_,branchName:z,onBundleFail:($)=>process.stderr.write(`
2444${$}
2445`)})}async function $3K(q,K,_,z,Y){let $=Date.now();try{N(`[teleport] Starting fetch for session: ${q}`),z?.("fetching_logs");let A=Date.now(),O=await Z5K(q,_,K);if(O===null)N("[teleport] v2 endpoint returned null, trying session-ingress"),O=await f5K(q,_,K);if(N(`[teleport] Session logs fetched in ${Date.now()-A}ms`),O===null)throw Error("Failed to fetch session logs");let w=Date.now(),j=O.filter((J)=>Oa(J)&&!J.isSidechain);N(`[teleport] Filtered ${O.length} entries to ${j.length} messages in ${Date.now()-w}ms`),z?.("fetching_branch");let H=Y?Wb8(Y):void 0;if(H)N(`[teleport] Found branch: ${H}`);return N(`[teleport] Total teleportFromSessionsAPI time: ${Date.now()-$}ms`),{log:j,branch:H}}catch(A){let O=x1(A);if($1.isAxiosError(A)&&A.response?.status===404)throw d("tengu_teleport_error_session_not_found_404",{sessionId:q}),new AP(`${q} not found.`,`${q} not found.
2446${$8.dim("Run /status in Claude Code to check your account.")}`);throw H6(O),Error(`Failed to fetch session from Sessions API: ${O.message}`)}}async function T68(q,K=null,_){let z=Kq()?.accessToken;if(!z)throw Error("No access token for polling");let Y=await mW();if(!Y)throw Error("No org UUID for polling");let $={...UY(z),"anthropic-beta":"ccr-byoc-2025-07-29","x-organization-uuid":Y},A=`${u7().BASE_API_URL}/v1/sessions/${q}/events`,O=50,w=[],j=K;for(let M=0;M<O;M++){let X=await $1.get(A,{headers:$,params:j?{after_id:j}:void 0,timeout:30000});if(X.status!==200)throw Error(`Failed to fetch session events: ${X.statusText}`);let P=X.data;if(!P?.data||!Array.isArray(P.data))throw Error("Invalid events response");for(let W of P.data)if(W&&typeof W==="object"&&"type"in W){if(W.type==="env_manager_log"||W.type==="control_response")continue;if("session_id"in W)w.push(W)}if(!P.last_id)break;if(j=P.last_id,!P.has_more)break}if(_?.skipMetadata)return{newEvents:w,lastEventId:j};let H,J;try{let M=await s46(q);H=Wb8(M),J=M.session_status}catch(M){N(`teleport: failed to fetch session ${q} metadata: ${M}`,{level:"debug"})}return{newEvents:w,lastEventId:j,branch:H,sessionStatus:J}}async function Lj6(q){let{initialMessage:K,signal:_}=q;try{await k$();let z=Kq()?.accessToken;if(!z)return H6(Error("No access token found for remote session creation")),null;let Y=await mW();if(!Y)return H6(Error("Unable to get organization UUID for remote session creation")),null;if(q.environmentId){let C=`${u7().BASE_API_URL}/v1/sessions`,g={...UY(z),"anthropic-beta":"ccr-byoc-2025-07-29","x-organization-uuid":Y},F={CLAUDE_CODE_OAUTH_TOKEN:z,...q.environmentVariables??{}},U=null,c=null;if(q.useBundle){let e=await fo1({oauthToken:z,sessionId:N8(),baseUrl:u7().BASE_API_URL},{signal:_});if(!e.success)return H6(Error(`Bundle upload failed: ${e.error}`)),null;c=e.fileId,d("tengu_teleport_bundle_mode",{size_bytes:e.bundleSizeBytes,scope:e.scope,has_wip:e.hasWip,reason:"explicit_env_bundle"})}else{let e=await Dh();if(e)U={type:"git_repository",url:`https://${e.host}/${e.owner}/${e.name}`,revision:q.branchName}}let K6={title:q.title||q.description||"Remote task",events:[],session_context:{sources:U?[U]:[],...c&&{seed_bundle_file_id:c},outcomes:[],environment_variables:F},environment_id:q.environmentId};N(`[teleportToRemote] explicit env ${q.environmentId}, ${Object.keys(F).length} env vars, ${c?`bundle=${c}`:`source=${U?.url??"none"}@${q.branchName??"default"}`}`);let t=await $1.post(C,K6,{headers:g,signal:_});if(t.status!==200&&t.status!==201)return H6(Error(`CreateSession ${t.status}: ${g6(t.data)}`)),null;let q6=t.data;if(!q6||typeof q6.id!=="string")return H6(Error(`No session id in response: ${g6(t.data)}`)),null;return{id:q6.id,title:q6.title||K6.title}}let $=null,A=null,O=null,w=await Dh(),j,H;if(q.title&&q.reuseOutcomeBranch)j=q.title,H=q.reuseOutcomeBranch;else{let C=await $dz(q.description||K||"Background task",_);j=q.title||C.title,H=q.reuseOutcomeBranch||C.branchName}let J=!1,M="no_git_at_all",X=hY(Z8()),P=!q.skipBundle&&i6(process.env.CCR_FORCE_BUNDLE),W=!q.skipBundle&&X!==null&&(i6(process.env.CCR_ENABLE_BUNDLE)||await FV("tengu_ccr_bundle_seed_enabled"));if(w&&!P)if(w.host==="github.com")J=await K68(w.owner,w.name,_),M=J?"github_preflight_ok":"github_preflight_failed";else J=!0,M="ghes_optimistic";else if(P)M="forced_bundle";else if(X)M="no_github_remote";if(!J&&!W&&w)J=!0;if(J&&w){let{host:C,owner:g,name:F}=w,U=q.branchName??await dT()??void 0;N(`[teleportToRemote] Git source: ${C}/${g}/${F}, revision: ${U??"none"}`),$={type:"git_repository",url:`https://${C}/${g}/${F}`,revision:U,...q.reuseOutcomeBranch&&{allow_unrestricted_git_push:!0}},A={type:"git_repository",git_info:{type:"github",repo:`${g}/${F}`,branches:[H]}}}if(!$&&W){N(`[teleportToRemote] Bundling (reason: ${M})`);let C=await fo1({oauthToken:z,sessionId:N8(),baseUrl:u7().BASE_API_URL},{signal:_});if(!C.success){H6(Error(`Bundle upload failed: ${C.error}`));let g=w?". Please setup GitHub on https://claude.ai/code":"",F;switch(C.failReason){case"empty_repo":F='Repository has no commits — run `git add . && git commit -m "initial"` then retry';break;case"too_large":F=`Repo is too large to teleport${g}`;break;case"git_error":F=`Failed to create git bundle (${C.error})${g}`;break;case void 0:F=`Bundle upload failed: ${C.error}${g}`;break;default:{let U=C.failReason;F=`Bundle upload failed: ${C.error}`}}return q.onBundleFail?.(F),null}O=C.fileId,d("tengu_teleport_bundle_mode",{size_bytes:C.bundleSizeBytes,scope:C.scope,has_wip:C.hasWip,reason:M})}if(d("tengu_teleport_source_decision",{reason:M,path:$?"github":O?"bundle":"empty"}),!$&&!O)N("[teleportToRemote] No repository detected — session will have an empty sandbox");let D=await rm();if(!D||D.length===0)return H6(Error("No environments available for session creation")),null;N(`Available environments: ${D.map((C)=>`${C.environment_id} (${C.name}, ${C.kind})`).join(", ")}`);let f=Z7(),G=q.useDefaultEnvironment?void 0:f?.remote?.defaultEnvironmentId,Z=D.find((C)=>C.kind==="anthropic_cloud");if(q.useDefaultEnvironment&&!Z){N(`No anthropic_cloud in env list (${D.length} envs); retrying fetchEnvironments`);let C=await rm();if(Z=C?.find((g)=>g.kind==="anthropic_cloud"),!Z)return H6(Error(`No anthropic_cloud environment available after retry (got: ${(C??D).map((g)=>`${g.name} (${g.kind})`).join(", ")}). Silent byoc fallthrough would launch into a dead env — fail fast instead.`)),null;if(C)D=C}let T=G&&D.find((C)=>C.environment_id===G)||Z||D.find((C)=>C.kind!=="bridge")||D[0];if(!T)return H6(Error("No environments available for session creation")),null;if(G){let C=T.environment_id===G;N(C?`Using configured default environment: ${G}`:`Configured default environment ${G} not found, using first available`)}let v=T.environment_id;N(`Selected environment: ${v} (${T.name}, ${T.kind})`);let V=`${u7().BASE_API_URL}/v1/sessions`,E={...UY(z),"anthropic-beta":"ccr-byoc-2025-07-29","x-organization-uuid":Y},S={sources:$?[$]:[],...O&&{seed_bundle_file_id:O},outcomes:A?[A]:[],model:q.model??D5(),...q.reuseOutcomeBranch&&{reuse_outcome_branches:!0},...q.githubPr&&{github_pr:q.githubPr}},R=[];if(q.permissionMode)R.push({type:"event",data:{type:"control_request",request_id:`set-mode-${Y3K()}`,request:{subtype:"set_permission_mode",mode:q.permissionMode,ultraplan:q.ultraplan}}});if(K)R.push({type:"event",data:{uuid:Y3K(),session_id:"",type:"user",parent_tool_use_id:null,message:{role:"user",content:K}}});let x={title:q.ultraplan?`ultraplan: ${j}`:j,events:R,session_context:S,environment_id:v};N(`Creating session with payload: ${g6(x,null,2)}`);let I=await $1.post(V,x,{headers:E,signal:_});if(!(I.status===200||I.status===201))return H6(Error(`API request failed with status ${I.status}: ${I.statusText}
2447
2448Response data: ${g6(I.data,null,2)}`)),null;let p=I.data;if(!p||typeof p.id!=="string")return H6(Error(`Cannot determine session ID from API response: ${g6(I.data)}`)),null;return N(`Successfully created remote session: ${p.id}`),{id:p.id,title:p.title||x.title}}catch(z){let Y=x1(z);return H6(Y),null}}async function $L6(q){let K=Kq()?.accessToken;if(!K)return;let _=await mW();if(!_)return;let z={...UY(K),"anthropic-beta":"ccr-byoc-2025-07-29","x-organization-uuid":_},Y=`${u7().BASE_API_URL}/v1/sessions/${q}/archive`;try{let $=await $1.post(Y,{},{headers:z,timeout:1e4,validateStatus:(A)=>A<500});if($.status===200||$.status===409)N(`[archiveRemoteSession] archived ${q}`);else N(`[archiveRemoteSession] ${q} failed ${$.status}: ${g6($.data)}`)}catch($){H6($)}}var bx8,Ydz=`You are coming up with a succinct title and git branch name for a coding session based on the provided description. The title should be clear, concise, and accurately reflect the content of the coding task.
2449You should keep it short and simple, ideally no more than 6 words. Avoid using jargon or overly technical terms unless absolutely necessary. The title should be easy to understand for anyone reading it.
2450Use sentence case for the title (capitalize only the first word and proper nouns), not Title Case.

Callers 3

Go1Function · 0.85
VSKFunction · 0.85
sGYFunction · 0.85

Calls 15

k$Function · 0.85
H6Function · 0.85
mWFunction · 0.85
u7Function · 0.85
UYFunction · 0.85
fo1Function · 0.85
N8Function · 0.85
dFunction · 0.85
DhFunction · 0.85
NFunction · 0.85
g6Function · 0.85
$dzFunction · 0.85

Tested by

no test coverage detected