import{n as e}from"./chunk-DR8-3Aex.js";import{s as t,u as n}from"./envUtils-BWeoiL4Y.js";import{r,t as i}from"./src-BJz1KAd_.js";import{Cc as a,Jt as o,M as s,S as c,_ as l,dc as u,oc as d,on as f,yc as p,z as m}from"./paths-Ci1iwL5Y.js";import{l as h,p as g}from"./debug-otxXY3j-.js";import{n as _,r as v}from"./analytics-DqMQntaB.js";import{R_ as y,z_ as b}from"./loadAgentsDir-C_wFhytF.js";import{r as x,t as S}from"./datadog-YsyhnDmr.js";import{c as C,i as w,o as T}from"./common-Da57Qwms.js";import{n as E,t as D}from"./stdio-Cg20AQ5W.js";import{r as O,t as k}from"./sink-Do5fWbUC.js";import{format as A}from"util";function j(e){return z.some(t=>t===e)}function M(){if(process.env.USER_TYPE===`ant`||l(`tengu_copper_bridge`,!1))return n(process.env.USE_LOCAL_OAUTH)||n(process.env.LOCAL_BRIDGE)?`ws://localhost:8765`:n(process.env.USE_STAGING_OAUTH)?`wss://bridge-staging.claudeusercontent.com`:`wss://bridge.claudeusercontent.com`}function N(){return n(process.env.USE_LOCAL_OAUTH)||n(process.env.LOCAL_BRIDGE)}function P(e){let t=new B,n=M();t.info(`Bridge URL: ${n??`none (using native socket)`}`);let r=e?.CLAUDE_CHROME_PERMISSION_MODE??process.env.CLAUDE_CHROME_PERMISSION_MODE,i;return r&&(j(r)?i=r:t.warn(`Invalid CLAUDE_CHROME_PERMISSION_MODE "${r}". Valid values: ${z.join(`, `)}`)),{serverName:`Claude in Chrome`,logger:t,socketPath:T(),getSocketPaths:w,clientTypeId:`claude-code`,onAuthenticationError:()=>{t.warn(`Authentication error occurred. Please ensure you are logged into the Claude browser extension with the same claude.ai account as Claude Code.`)},onToolCallDisconnected:()=>`Browser extension is not connected. Please ensure the Claude browser extension is installed and running (${I}), and that you are logged into claude.ai with the same account as Claude Code. If this is your first time connecting to Chrome, you may need to restart Chrome for the installation to take effect. If you continue to experience issues, please report a bug: ${L}`,onExtensionPaired:(e,n)=>{a(t=>t.chromeExtension?.pairedDeviceId===e&&t.chromeExtension?.pairedDeviceName===n?t:{...t,chromeExtension:{pairedDeviceId:e,pairedDeviceName:n}}),t.info(`Paired with "${n}" (${e.slice(0,8)})`)},getPersistedDeviceId:()=>u().chromeExtension?.pairedDeviceId,...n&&{bridgeConfig:{url:n,getUserId:async()=>u().oauthAccount?.accountUuid,getOAuthToken:async()=>o()?.accessToken??``,...N()&&{devUserId:`dev_user_local`}}},...i&&{initialPermissionMode:i},...process.env.USER_TYPE===`ant`&&{callAnthropicMessages:async e=>{let t=await b({model:e.model,system:e.system,messages:e.messages,max_tokens:e.max_tokens,stop_sequences:e.stop_sequences,signal:e.signal,skipSystemPromptPrefix:!0,tools:[],querySource:`chrome_mcp`}),n=[];for(let e of t.content)e.type===`text`&&n.push({type:`text`,text:e.text});return{content:n,stop_reason:t.stop_reason,usage:{input_tokens:t.usage.input_tokens,output_tokens:t.usage.output_tokens}}}},trackEvent:(e,t)=>{let n={};if(t)for(let[e,r]of Object.entries(t)){let t=e===`status`?`bridge_status`:e;(typeof r==`boolean`||typeof r==`number`||typeof r==`string`&&R.has(t))&&(n[t]=r)}v(e,n)}}}async function F(){d(),O();let e=r(P()),t=new D,n=!1,i=async()=>{n||(n=!0,await m(),await x(),process.exit(0))};process.stdin.on(`end`,()=>void i()),process.stdin.on(`error`,()=>void i()),g(`[Claude in Chrome] Starting MCP server`),await e.connect(t),g(`[Claude in Chrome] MCP server started`)}var I,L,R,z,B;e((()=>{i(),k(),E(),S(),s(),c(),_(),f(),p(),h(),t(),y(),C(),I=`https://claude.ai/chrome`,L=`https://github.com/anthropics/claude-code/issues/new?labels=bug,claude-in-chrome`,R=new Set([`bridge_status`,`error_type`,`tool_name`]),z=[`ask`,`skip_all_permission_checks`,`follow_a_plan`],B=class{silly(e,t){g(A(e,t??``),{level:`debug`})}debug(e,t){g(A(e,t??``),{level:`debug`})}info(e,t){g(A(e,t??``),{level:`info`})}warn(e,t){g(A(e,t??``),{level:`warn`})}error(e,t){g(A(e,t??``),{level:`error`})}}}))();export{P as createChromeContext,F as runClaudeInChromeMcpServer};