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

Function P96

package/cli.js:58–58  ·  view source on GitHub ↗
(q,K,_,z,Y,$)

Source from the content-addressed store, hash-verified

56`)+`\r
57\r
58`+_)}function P96(q,K,_,z,Y,$){if(q.listenerCount("wsClientError")){let A=Error(Y);Error.captureStackTrace(A,P96),q.emit("wsClientError",A,_,K)}else JI6(_,z,Y,$)}});var MI6={};T8(MI6,{default:()=>jf,createWebSocketStream:()=>MX7.default,WebSocketServer:()=>WX7.default,WebSocket:()=>no8.default,Sender:()=>PX7.default,Receiver:()=>XX7.default});var MX7,XX7,PX7,no8,WX7,jf;var W96=y(()=>{MX7=O6(YX7(),1),XX7=O6(po8(),1),PX7=O6(go8(),1),no8=O6(h98(),1),WX7=O6(JX7(),1),jf=no8.default});import{promises as DX7}from"fs";import{createConnection as tA5}from"net";import{platform as eA5}from"os";import{dirname as qO5}from"path";function KO5(q){return"result"in q||"error"in q}function _O5(q){return"method"in q&&typeof q.method==="string"}class fX7{socket=null;connected=!1;connecting=!1;responseCallback=null;notificationHandler=null;responseBuffer=Buffer.alloc(0);reconnectAttempts=0;maxReconnectAttempts=10;reconnectDelay=1000;reconnectTimer=null;context;disableAutoReconnect=!1;constructor(q){this.context=q}async connect(){let{serverName:q,logger:K}=this.context;if(this.connecting){K.info(`[${q}] Already connecting, skipping duplicate attempt`);return}this.closeSocket(),this.connecting=!0;let _=this.context.getSocketPath?.()??this.context.socketPath;K.info(`[${q}] Attempting to connect to: ${_}`);try{await this.validateSocketSecurity(_)}catch(Y){this.connecting=!1,K.info(`[${q}] Security validation failed:`,Y);return}this.socket=tA5(_);let z=setTimeout(()=>{if(!this.connected)K.info(`[${q}] Connection attempt timed out after 5000ms`),this.closeSocket(),this.scheduleReconnect()},5000);this.socket.on("connect",()=>{clearTimeout(z),this.connected=!0,this.connecting=!1,this.reconnectAttempts=0,K.info(`[${q}] Successfully connected to bridge server`)}),this.socket.on("data",(Y)=>{this.responseBuffer=Buffer.concat([this.responseBuffer,Y]);while(this.responseBuffer.length>=4){let $=this.responseBuffer.readUInt32LE(0);if(this.responseBuffer.length<4+$)break;let A=this.responseBuffer.slice(4,4+$);this.responseBuffer=this.responseBuffer.slice(4+$);try{let O=JSON.parse(A.toString("utf-8"));if(_O5(O)){if(K.info(`[${q}] Received notification: ${O.method}`),this.notificationHandler)this.notificationHandler(O)}else if(KO5(O))K.info(`[${q}] Received tool response: ${O}`),this.handleResponse(O);else K.info(`[${q}] Received unknown message: ${O}`)}catch(O){K.info(`[${q}] Failed to parse message:`,O)}}}),this.socket.on("error",(Y)=>{if(clearTimeout(z),K.info(`[${q}] Socket error (code: ${Y.code}):`,Y),this.connected=!1,this.connecting=!1,Y.code&&["ECONNREFUSED","ECONNRESET","EPIPE","ENOENT","EOPNOTSUPP","ECONNABORTED"].includes(Y.code))this.scheduleReconnect()}),this.socket.on("close",()=>{clearTimeout(z),this.connected=!1,this.connecting=!1,this.scheduleReconnect()})}scheduleReconnect(){let{serverName:q,logger:K}=this.context;if(this.disableAutoReconnect)return;if(this.reconnectTimer){K.info(`[${q}] Reconnect already scheduled, skipping`);return}this.reconnectAttempts++;let _=100;if(this.reconnectAttempts>_){K.info(`[${q}] Giving up after ${_} attempts. Will retry on next tool call.`),this.reconnectAttempts=0;return}let z=Math.min(this.reconnectDelay*Math.pow(1.5,this.reconnectAttempts-1),30000);if(this.reconnectAttempts<=this.maxReconnectAttempts)K.info(`[${q}] Reconnecting in ${Math.round(z)}ms (attempt ${this.reconnectAttempts})`);else if(this.reconnectAttempts%10===0)K.info(`[${q}] Still polling for native host (attempt ${this.reconnectAttempts})`);this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.connect()},z)}handleResponse(q){if(this.responseCallback){let K=this.responseCallback;this.responseCallback=null,K(q)}}setNotificationHandler(q){this.notificationHandler=q}async ensureConnected(){let{serverName:q}=this.context;if(this.connected&&this.socket)return!0;if(!this.socket&&!this.connecting)await this.connect();return new Promise((K,_)=>{let z=null,Y=setTimeout(()=>{if(z)clearTimeout(z);_(new bT(`[${q}] Connection attempt timed out after 5000ms`))},5000),$=()=>{if(this.connected)clearTimeout(Y),K(!0);else z=setTimeout($,500)};$()})}async sendRequest(q,K=30000){let{serverName:_}=this.context;if(!this.socket)throw new bT(`[${_}] Cannot send request: not connected`);let z=this.socket;return new Promise((Y,$)=>{let A=setTimeout(()=>{this.responseCallback=null,$(new bT(`[${_}] Tool request timed out after ${K}ms`))},K);this.responseCallback=(J)=>{clearTimeout(A),Y(J)};let O=JSON.stringify(q),w=Buffer.from(O,"utf-8"),j=Buffer.allocUnsafe(4);j.writeUInt32LE(w.length,0);let H=Buffer.concat([j,w]);z.write(H)})}async callTool(q,K,_){let z={method:"execute_tool",params:{client_id:this.context.clientTypeId,tool:q,args:K}};return this.sendRequestWithRetry(z)}async sendRequestWithRetry(q){let{serverName:K,logger:_}=this.context;try{return await this.sendRequest(q)}catch(z){if(!(z instanceof bT))throw z;return _.info(`[${K}] Connection error, forcing reconnect and retrying: ${z.message}`),this.closeSocket(),await this.ensureConnected(),await this.sendRequest(q)}}async setPermissionMode(q,K){}isConnected(){return this.connected}closeSocket(){if(this.socket)this.socket.removeAllListeners(),this.socket.end(),this.socket.destroy(),this.socket=null;this.connected=!1,this.connecting=!1}cleanup(){if(this.reconnectTimer)clearTimeout(this.reconnectTimer),this.reconnectTimer=null;this.closeSocket(),this.reconnectAttempts=0,this.responseBuffer=Buffer.alloc(0),this.responseCallback=null}disconnect(){this.cleanup()}async validateSocketSecurity(q){let{serverName:K,logger:_}=this.context;if(eA5()==="win32")return;try{let z=qO5(q);if((z.split("/").pop()||"").startsWith("claude-mcp-browser-bridge-"))try{let j=await DX7.stat(z);if(j.isDirectory()){let H=j.mode&511;if(H!==448)throw Error(`[${K}] Insecure socket directory permissions: ${H.toString(8)} (expected 0700). Directory may have been tampered with.`);let J=process.getuid?.();if(J!==void 0&&j.uid!==J)throw Error(`Socket directory not owned by current user (uid: ${J}, dir uid: ${j.uid}). Potential security risk.`)}}catch(j){if(j.code!=="ENOENT")throw j}let A=await DX7.stat(q);if(!A.isSocket())throw Error(`[${K}] Path exists but it's not a socket: ${q}`);let O=A.mode&511;if(O!==384)throw Error(`[${K}] Insecure socket permissions: ${O.toString(8)} (expected 0600). Socket may have been tampered with.`);let w=process.getuid?.();if(w!==void 0&&A.uid!==w)throw Error(`Socket not owned by current user (uid: ${w}, socket uid: ${A.uid}). Potential security risk.`);_.info(`[${K}] Socket security validation passed`)}catch(z){if(z.code==="ENOENT"){_.info(`[${K}] Socket not found, will be created by server`);return}throw z}}}function C98(q){return new fX7(q)}var bT;var XI6=y(()=>{bT=class bT extends Error{constructor(q){super(q);this.name="SocketConnectionError"}}});function b98(){return process.platform==="darwin"?"macOS":process.platform==="win32"?"Windows":"Linux"}class x98{ws=null;connected=!1;authenticated=!1;connecting=!1;reconnectTimer=null;reconnectAttempts=0;pendingCalls=new Map;notificationHandler=null;context;permissionMode="ask";allowedDomains;tabsContextCollectionTimeoutMs=2000;toolCallTimeoutMs=120000;connectionStartTime=null;connectionEstablishedTime=null;selectedDeviceId;discoveryComplete=!1;discoveryPromise=null;pendingDiscovery=null;previousSelectedDeviceId;peerConnectedWaiters=[];pendingPairingRequestId;pairingInProgress=!1;persistedDeviceId;pendingSwitchResolve=null;constructor(q){if(this.context=q,q.initialPermissionMode)this.permissionMode=q.initialPermissionMode}async ensureConnected(){let{logger:q,serverName:K}=this.context;if(q.info(`[${K}] ensureConnected called, connected=${this.connected}, authenticated=${this.authenticated}, wsState=${this.ws?.readyState}`),this.connected&&this.authenticated&&this.ws?.readyState===jf.OPEN)return q.info(`[${K}] Already connected and authenticated`),!0;if(!this.connecting)q.info(`[${K}] Not connecting, starting connection...`),await this.connect();else q.info(`[${K}] Already connecting, waiting...`);return new Promise((_)=>{let z=setTimeout(()=>{q.info(`[${K}] Connection timeout, connected=${this.connected}, authenticated=${this.authenticated}`),_(!1)},1e4),Y=()=>{if(this.connected&&this.authenticated)q.info(`[${K}] Connection successful`),clearTimeout(z),_(!0);else if(!this.connecting)q.info(`[${K}] No longer connecting, giving up`),clearTimeout(z),_(!1);else setTimeout(Y,200)};Y()})}async callTool(q,K,_){let{logger:z,serverName:Y,trackEvent:$}=this.context;if(!this.ws||this.ws.readyState!==jf.OPEN)throw new bT(`[${Y}] Bridge not connected`);if(!this.selectedDeviceId&&!this.discoveryComplete)this.discoveryPromise??=this.discoverAndSelectExtension().finally(()=>{this.discoveryPromise=null}),await this.discoveryPromise;let A=crypto.randomUUID(),O=q==="tabs_context_mcp",w=Date.now(),j=O?this.tabsContextCollectionTimeoutMs:this.toolCallTimeoutMs;$?.("chrome_bridge_tool_call_started",{tool_name:q,tool_use_id:A});let H=_?.permissionMode??this.permissionMode,J=_?.allowedDomains??this.allowedDomains;return new Promise((M,X)=>{let P=setTimeout(()=>{let D=this.pendingCalls.get(A);if(D){this.pendingCalls.delete(A);let f=Date.now()-D.startTime;if(O&&D.results.length>0)$?.("chrome_bridge_tool_call_completed",{tool_name:q,tool_use_id:A,duration_ms:f}),M(this.mergeTabsResults(D.results));else z.warn(`[${Y}] Tool call timeout: ${q} (${A.slice(0,8)}) after ${f}ms, pending calls: ${this.pendingCalls.size}`),$?.("chrome_bridge_tool_call_timeout",{tool_name:q,tool_use_id:A,duration_ms:f,timeout_ms:j}),X(new bT(`[${Y}] Tool call timed out: ${q}`))}},j);this.pendingCalls.set(A,{resolve:M,reject:X,timer:P,results:[],isTabsContext:O,onPermissionRequest:_?.onPermissionRequest,startTime:w,toolName:q});let W={type:"tool_call",tool_use_id:A,client_type:this.context.clientTypeId,tool:q,args:K};if(this.selectedDeviceId)W.target_device_id=this.selectedDeviceId;if(H)W.permission_mode=H;if(J?.length)W.allowed_domains=J;if(_?.onPermissionRequest)W.handle_permission_prompts=!0;z.debug(`[${Y}] Sending tool_call: ${q} (${A.slice(0,8)})`),this.ws.send(JSON.stringify(W))})}isConnected(){return this.connected&&this.authenticated&&this.ws?.readyState===jf.OPEN}disconnect(){this.cleanup()}setNotificationHandler(q){this.notificationHandler=q}async setPermissionMode(q,K){this.permissionMode=q,this.allowedDomains=K}async discoverAndSelectExtension(){let{logger:q,serverName:K}=this.context;this.persistedDeviceId??=this.context.getPersistedDeviceId?.();let _=await this.queryBridgeExtensions();if(_.length===0){if(q.info(`[${K}] No extensions connected, waiting up to ${ZX7}ms for peer_connected`),await this.waitForPeerConnected(ZX7))_=await this.queryBridgeExtensions()}if(this.discoveryComplete=!0,_.length===0){q.info(`[${K}] No extensions found after waiting`);return}if(_.length===1){let z=_[0];if(!this.isLocalExtension(z))this.context.onRemoteExtensionWarning?.(z);this.selectExtension(z.deviceId);return}if(this.persistedDeviceId){let z=_.find((Y)=>Y.deviceId===this.persistedDeviceId);if(z){q.info(`[${K}] Auto-connecting to persisted extension: ${z.name||z.deviceId.slice(0,8)}`),this.selectExtension(z.deviceId);return}}this.broadcastPairingRequest(),this.pairingInProgress=!0}async queryBridgeExtensions(){let q=await new Promise((_)=>{let z=setTimeout(()=>{this.pendingDiscovery=null,_([])},zO5);this.pendingDiscovery={resolve:_,timeout:z},this.ws?.send(JSON.stringify({type:"list_extensions"}))}),K=new Map;for(let _ of q){let z=K.get(_.deviceId);if(!z||_.connectedAt>z.connectedAt)K.set(_.deviceId,_)}return[...K.values()]}selectExtension(q){let{logger:K,serverName:_}=this.context;this.selectedDeviceId=q,this.previousSelectedDeviceId=void 0,K.info(`[${_}] Selected Chrome extension: ${q.slice(0,8)}...`)}isLocalExtension(q){if(!q.osPlatform)return!1;return q.osPlatform===b98()}waitForPeerConnected(q){return new Promise((K)=>{let _=setTimeout(()=>{this.peerConnectedWaiters=this.peerConnectedWaiters.filter((Y)=>Y!==z),K(!1)},q),z=(Y)=>{clearTimeout(_),K(Y)};this.peerConnectedWaiters.push(z)})}broadcastPairingRequest(){let q=crypto.randomUUID();this.pendingPairingRequestId=q,this.ws?.send(JSON.stringify({type:"pairing_request",request_id:q,client_type:this.context.clientTypeId}))}async switchBrowser(){let q=await this.queryBridgeExtensions(),K=this.selectedDeviceId??this.previousSelectedDeviceId;if(q.length===0||q.length===1&&(!K||q[0].deviceId===K))return"no_other_browsers";this.previousSelectedDeviceId=this.selectedDeviceId,this.selectedDeviceId=void 0,this.discoveryComplete=!1,this.pairingInProgress=!1;let _=crypto.randomUUID();if(this.pendingPairingRequestId=_,this.ws?.readyState!==jf.OPEN)return null;if(this.ws.send(JSON.stringify({type:"pairing_request",request_id:_,client_type:this.context.clientTypeId})),this.pendingSwitchResolve)this.pendingSwitchResolve(null);return new Promise((z)=>{let Y=setTimeout(()=>{if(this.pendingPairingRequestId===_)this.pendingPairingRequestId=void 0;this.pendingSwitchResolve=null,z(null)},120000);this.pendingSwitchResolve=($)=>{clearTimeout(Y),this.pendingSwitchResolve=null,z($)}})}async connect(){let{logger:q,serverName:K,bridgeConfig:_,trackEvent:z}=this.context;if(!_){q.error(`[${K}] No bridge config provided`);return}if(this.connecting)return;this.connecting=!0,this.authenticated=!1,this.connectionStartTime=Date.now(),this.closeSocket();let Y,$;if(_.devUserId)Y=_.devUserId,q.debug(`[${K}] Using dev user ID for bridge connection`);else{q.debug(`[${K}] Fetching user ID for bridge connection`);let O=await _.getUserId();if(!O){let w=Date.now()-this.connectionStartTime;q.error(`[${K}] No user ID available after ${w}ms`),z?.("chrome_bridge_connection_failed",{duration_ms:w,error_type:"no_user_id",reconnect_attempt:this.reconnectAttempts}),this.connecting=!1,this.context.onAuthenticationError?.();return}if(Y=O,q.debug(`[${K}] Fetching OAuth token for bridge connection`),$=await _.getOAuthToken(),!$){let w=Date.now()-this.connectionStartTime;q.error(`[${K}] No OAuth token available after ${w}ms`),z?.("chrome_bridge_connection_failed",{duration_ms:w,error_type:"no_oauth_token",reconnect_attempt:this.reconnectAttempts}),this.connecting=!1,this.context.onAuthenticationError?.();return}}let A=`${_.url}/chrome/${Y}`;q.info(`[${K}] Connecting to bridge: ${A}`),z?.("chrome_bridge_connection_started",{bridge_url:A});try{this.ws=new jf(A)}catch(O){let w=Date.now()-this.connectionStartTime;q.error(`[${K}] Failed to create WebSocket after ${w}ms:`,O),z?.("chrome_bridge_connection_failed",{duration_ms:w,error_type:"websocket_error",reconnect_attempt:this.reconnectAttempts}),this.connecting=!1,this.scheduleReconnect();return}this.ws.on("open",()=>{q.info(`[${K}] WebSocket connected, sending connect message`);let O={type:"connect",client_type:this.context.clientTypeId};if(_.devUserId)O.dev_user_id=_.devUserId;else O.oauth_token=$;this.ws?.send(JSON.stringify(O))}),this.ws.on("message",(O)=>{try{let w=JSON.parse(O.toString());q.debug(`[${K}] Bridge received: ${JSON.stringify(w)}`),this.handleMessage(w)}catch(w){q.error(`[${K}] Failed to parse bridge message:`,w)}}),this.ws.on("close",(O)=>{let w=this.connectionEstablishedTime?Date.now()-this.connectionEstablishedTime:0;q.info(`[${K}] Bridge connection closed (code: ${O}, duration: ${w}ms)`),z?.("chrome_bridge_disconnected",{close_code:O,duration_since_connect_ms:w,reconnect_attempt:this.reconnectAttempts+1}),this.connected=!1,this.authenticated=!1,this.connecting=!1,this.connectionEstablishedTime=null,this.scheduleReconnect()}),this.ws.on("error",(O)=>{let w=this.connectionStartTime?Date.now()-this.connectionStartTime:0;q.error(`[${K}] Bridge WebSocket error after ${w}ms: ${O.message}`),z?.("chrome_bridge_connection_failed",{duration_ms:w,error_type:"websocket_error",reconnect_attempt:this.reconnectAttempts}),this.connected=!1,this.authenticated=!1,this.connecting=!1})}handleMessage(q){let{logger:K,serverName:_,trackEvent:z}=this.context;switch(q.type){case"paired":{let Y=this.connectionStartTime?Date.now()-this.connectionStartTime:0;K.info(`[${_}] Paired with Chrome extension (duration: ${Y}ms)`),this.connected=!0,this.authenticated=!0,this.connecting=!1,this.reconnectAttempts=0,this.connectionEstablishedTime=Date.now(),z?.("chrome_bridge_connection_succeeded",{duration_ms:Y,status:"paired"});break}case"waiting":{let Y=this.connectionStartTime?Date.now()-this.connectionStartTime:0;K.info(`[${_}] Waiting for Chrome extension to connect (duration: ${Y}ms)`),this.connected=!0,this.authenticated=!0,this.connecting=!1,this.reconnectAttempts=0,this.connectionEstablishedTime=Date.now(),z?.("chrome_bridge_connection_succeeded",{duration_ms:Y,status:"waiting"});break}case"peer_connected":if(K.info(`[${_}] Chrome extension connected to bridge`),z?.("chrome_bridge_peer_connected",null),!this.selectedDeviceId)this.discoveryComplete=!1;if(this.previousSelectedDeviceId&&q.deviceId===this.previousSelectedDeviceId&&!this.pendingSwitchResolve)K.info(`[${_}] Previously selected extension reconnected, auto-reselecting`),this.selectExtension(this.previousSelectedDeviceId),this.previousSelectedDeviceId=void 0;if(this.peerConnectedWaiters.length>0){let Y=this.peerConnectedWaiters;this.peerConnectedWaiters=[];for(let $ of Y)$(!0)}break;case"peer_disconnected":if(K.info(`[${_}] Chrome extension disconnected from bridge`),z?.("chrome_bridge_peer_disconnected",null),q.deviceId&&q.deviceId===this.selectedDeviceId)K.info(`[${_}] Selected extension disconnected, clearing selection`),this.previousSelectedDeviceId=this.selectedDeviceId,this.selectedDeviceId=void 0,this.discoveryComplete=!1;break;case"extensions_list":if(this.pendingDiscovery)clearTimeout(this.pendingDiscovery.timeout),this.pendingDiscovery.resolve(q.extensions??[]),this.pendingDiscovery=null;break;case"pairing_response":{let{request_id:Y,device_id:$,name:A}=q;if(this.pendingPairingRequestId===Y&&$&&A){if(this.pendingPairingRequestId=void 0,this.pairingInProgress=!1,this.selectExtension($),this.context.onExtensionPaired?.($,A),K.info(`[${_}] Paired with "${A}" (${$.slice(0,8)})`),this.pendingSwitchResolve)this.pendingSwitchResolve({deviceId:$,name:A}),this.pendingSwitchResolve=null}break}case"ping":this.ws?.send(JSON.stringify({type:"pong"}));break;case"pong":break;case"tool_result":this.handleToolResult(q);break;case"permission_request":this.handlePermissionRequest(q);break;case"notification":if(this.notificationHandler)this.notificationHandler({method:q.method,params:q.params});break;case"error":if(K.warn(`[${_}] Bridge error: ${q.error}`),this.selectedDeviceId)this.selectedDeviceId=void 0,this.discoveryComplete=!1;break;default:K.warn(`[${_}] Unrecognized bridge message type: ${q.type}`)}}async handlePermissionRequest(q){let{logger:K,serverName:_}=this.context,z=q.tool_use_id,Y=q.request_id;if(!z||!Y){K.warn(`[${_}] permission_request missing tool_use_id or request_id`);return}let $=this.pendingCalls.get(z);if(!$?.onPermissionRequest){K.debug(`[${_}] Ignoring permission_request for unknown tool_use_id ${z.slice(0,8)} (not our call)`);return}let A={toolUseId:z,requestId:Y,toolType:q.tool_type??"unknown",url:q.url??"",actionData:q.action_data};try{let O=await $.onPermissionRequest(A);this.sendPermissionResponse(Y,O)}catch(O){K.error(`[${_}] Error handling permission request:`,O),this.sendPermissionResponse(Y,!1)}}sendPermissionResponse(q,K){if(this.ws?.readyState===jf.OPEN){let _={type:"permission_response",request_id:q,allowed:K};if(this.selectedDeviceId)_.target_device_id=this.selectedDeviceId;this.ws.send(JSON.stringify(_))}}handleToolResult(q){let{logger:K,serverName:_,trackEvent:z}=this.context,Y=q.tool_use_id;if(!Y){K.warn(`[${_}] Received tool_result without tool_use_id`);return}let $=this.pendingCalls.get(Y);if(!$){K.debug(`[${_}] Received tool_result for unknown call: ${Y.slice(0,8)}`);return}let A=Date.now()-$.startTime,O=this.normalizeBridgeResponse(q),w=Boolean(q.is_error)||"error"in O;if($.isTabsContext&&!this.selectedDeviceId)$.results.push(O);else{if(clearTimeout($.timer),this.pendingCalls.delete(Y),w){let j=O.error?.content,H="Unknown error";if(Array.isArray(j)){let J=j.find((M)=>typeof M==="object"&&M!==null&&("text"in M));if(J?.text)H=J.text.slice(0,200)}K.warn(`[${_}] Tool call error: ${$.toolName} (${Y.slice(0,8)}) after ${A}ms`),z?.("chrome_bridge_tool_call_error",{tool_name:$.toolName,tool_use_id:Y,duration_ms:A,error_message:H})}else K.debug(`[${_}] Tool call completed: ${$.toolName} (${Y.slice(0,8)}) in ${A}ms`),z?.("chrome_bridge_tool_call_completed",{tool_name:$.toolName,tool_use_id:Y,duration_ms:A});$.resolve(O)}}normalizeBridgeResponse(q){if(q.result||q.error)return q;if(q.content){if(q.is_error)return{error:{content:q.content}};return{result:{content:q.content}}}return q}mergeTabsResults(q){let K=[];for(let _ of q){let $=_.result?.content;if(!$||!Array.isArray($))continue;for(let A of $)if(A.type==="text"&&A.text)try{let O=JSON.parse(A.text);if(Array.isArray(O))K.push(...O);else if(O?.availableTabs&&Array.isArray(O.availableTabs))K.push(...O.availableTabs)}catch{}}if(K.length>0){let _=K.map((z)=>{let Y=z;return` • tabId ${Y.tabId}: "${Y.title}" (${Y.url})`}).join(`
59`);return{result:{content:[{type:"text",text:JSON.stringify({availableTabs:K})},{type:"text",text:`
60
61Tab Context:

Callers 1

handleUpgradeMethod · 0.85

Calls 2

JI6Function · 0.85
emitMethod · 0.45

Tested by

no test coverage detected