MCPcopy Create free account
hub / github.com/ChinaSiro/claude-code-sourcemap / We1

Function We1

package/cli.js:3121–3121  ·  view source on GitHub ↗
(q,K,_,z=0)

Source from the content-addressed store, hash-verified

3119
3120`:_}};this.options=O8Y({},K,q),this.rules=new o2K(this.options)}$m8.prototype={turndown:function(q){if(!S8Y(q))throw TypeError(q+" is not a string, or an element/document/fragment node.");if(q==="")return"";var K=s2K.call(this,new G8Y(q,this.options));return R8Y.call(this,K)},use:function(q){if(Array.isArray(q))for(var K=0;K<q.length;K++)this.use(q[K]);else if(typeof q==="function")q(this);else throw TypeError("plugin must be a Function or an Array of Functions");return this},addRule:function(q,K){return this.rules.add(q,K),this},keep:function(q){return this.rules.keep(q),this},remove:function(q){return this.rules.remove(q),this},escape:function(q){return L8Y.reduce(function(K,_){return K.replace(_[0],_[1])},q)}};function s2K(q){var K=this;return E8Y.call(q.childNodes,function(_,z){z=new k8Y(z,K.options);var Y="";if(z.nodeType===3)Y=z.isCode?z.nodeValue:K.escape(z.nodeValue);else if(z.nodeType===1)Y=h8Y.call(K,z);return t2K(_,Y)},"")}function R8Y(q){var K=this;return this.rules.forEach(function(_){if(typeof _.append==="function")q=t2K(q,_.append(K.options))}),q.replace(/^[\t\r\n]+/,"").replace(/[\t\r\n\s]+$/,"")}function h8Y(q){var K=this.rules.forNode(q),_=s2K.call(this,q),z=q.flankingWhitespace;if(z.leading||z.trailing)_=_.trim();return z.leading+K.replacement(_,q,this.options)+z.trailing}function t2K(q,K){var _=j8Y(q),z=w8Y(K),Y=Math.max(q.length-_.length,K.length-z.length),$=`
3121
3122`.substring(0,Y);return _+$+z}function S8Y(q){return q!=null&&(typeof q==="string"||q.nodeType&&(q.nodeType===1||q.nodeType===9||q.nodeType===11))}e2K.exports=$m8});var AjK={};T8(AjK,{validateURL:()=>zjK,isPreapprovedUrl:()=>Pe1,isPermittedRedirect:()=>$jK,getWithPermittedRedirects:()=>We1,getURLMarkdownContent:()=>De1,clearWebFetchCache:()=>x8Y,checkDomainBlocklist:()=>YjK,applyPromptToMarkdown:()=>fe1,MAX_MARKDOWN_LENGTH:()=>y88});function x8Y(){Me1.clear(),Xe1.clear()}function u8Y(){return I8Y??=Promise.resolve().then(() => O6(qjK(),1)).then((q)=>{return new q.default})}function Pe1(q){try{let K=new URL(q);return Vu8(K.hostname,K.pathname)}catch{return!1}}function zjK(q){if(q.length>m8Y)return!1;let K;try{K=new URL(q)}catch{return!1}if(K.username||K.password)return!1;if(K.hostname.split(".").length<2)return!1;return!0}async function YjK(q){if(Xe1.has(q))return{status:"allowed"};try{let K=await $1.get(`https://api.anthropic.com/api/web/domain_info?domain=${encodeURIComponent(q)}`,{timeout:g8Y});if(K.status===200){if(K.data.can_fetch===!0)return Xe1.set(q,!0),{status:"allowed"};return{status:"blocked"}}return{status:"check_failed",error:Error(`Domain check returned status ${K.status}`)}}catch(K){return H6(K),{status:"check_failed",error:K}}}function $jK(q,K){try{let _=new URL(q),z=new URL(K);if(z.protocol!==_.protocol)return!1;if(z.port!==_.port)return!1;if(z.username||z.password)return!1;let Y=(O)=>O.replace(/^www\./,""),$=Y(_.hostname),A=Y(z.hostname);return $===A}catch(_){return!1}}async function We1(q,K,_,z=0){if(z>KjK)throw Error(`Too many redirects (exceeded ${KjK})`);try{return await $1.get(q,{signal:K,timeout:B8Y,maxRedirects:0,responseType:"arraybuffer",maxContentLength:p8Y,headers:{Accept:"text/markdown, text/html, */*","User-Agent":tCq()}})}catch(Y){if($1.isAxiosError(Y)&&Y.response&&[301,302,307,308].includes(Y.response.status)){let $=Y.response.headers.location;if(!$)throw Error("Redirect missing Location header");let A=new URL($,q).toString();if(_(q,A))return We1(A,K,_,z+1);else return{type:"redirect",originalUrl:q,redirectUrl:A,statusCode:Y.response.status}}if($1.isAxiosError(Y)&&Y.response?.status===403&&Y.response.headers["x-proxy-error"]==="blocked-by-allowlist"){let $=new URL(q).hostname;throw new _jK($)}throw Y}}function F8Y(q){return"type"in q&&q.type==="redirect"}async function De1(q,K){if(!zjK(q))throw Error("Invalid URL");let _=Me1.get(q);if(_)return{bytes:_.bytes,code:_.code,codeText:_.codeText,content:_.content,contentType:_.contentType,persistedPath:_.persistedPath,persistedSize:_.persistedSize};let z,Y=q;try{if(z=new URL(q),z.protocol==="http:")z.protocol="https:",Y=z.toString();let W=z.hostname;if(!Z7().skipWebFetchPreflight)switch((await YjK(W)).status){case"allowed":break;case"blocked":throw new He1(W);case"check_failed":throw new Je1(W)}}catch(W){if(W instanceof He1||W instanceof Je1)throw W;H6(W)}let $=await We1(Y,K.signal,$jK);if(F8Y($))return $;let A=Buffer.from($.data);$.data=null;let O=$.headers["content-type"]??"",w,j;if(_h4(O)){let W=`webfetch-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,D=await ZN6(A,O,W);if(!("error"in D))w=D.filepath,j=D.size}let H=A.length,J=A.toString("utf-8"),M,X;if(O.includes("text/html"))M=(await u8Y()).turndown(J),X=Buffer.byteLength(M);else M=J,X=H;let P={bytes:H,code:$.status,codeText:$.statusText,content:M,contentType:O,persistedPath:w,persistedSize:j};return Me1.set(q,P,{size:Math.max(1,X)}),P}async function fe1(q,K,_,z,Y){let $=K.length>y88?K.slice(0,y88)+`
3123
3124[Content truncated due to length...]`:K,A=B54($,q,Y),O=await RG({systemPrompt:iK([]),userPrompt:A,signal:_,options:{querySource:"web_fetch_apply",agents:[],isNonInteractiveSession:z,hasAppendSystemPrompt:!1,mcpTools:[]}});if(_.aborted)throw new Uz;let{content:w}=O.message;if(w.length>0){let j=w[0];if("text"in j)return j.text}return"No response from model"}var He1,Je1,_jK,C8Y=900000,b8Y=52428800,Me1,Xe1,I8Y,m8Y=2000,p8Y=10485760,B8Y=60000,g8Y=1e4,KjK=10,y88=1e5;var Ze1=y(()=>{CK();gW6();k8();ew();y8();jG();E8();fE8();U1();Us1();He1=class He1 extends Error{constructor(q){super(`Claude Code is unable to fetch from ${q}`);this.name="DomainBlockedError"}};Je1=class Je1 extends Error{constructor(q){super(`Unable to verify if domain ${q} is safe to fetch. This may be due to network restrictions or enterprise security policies blocking claude.ai.`);this.name="DomainCheckFailedError"}};_jK=class _jK extends Error{domain;constructor(q){super(JSON.stringify({error_type:"EGRESS_BLOCKED",domain:q,message:`Access to ${q} is blocked by the network egress proxy.`}));this.domain=q;this.name="EgressBlockedError"}};Me1=new nk({maxSize:b8Y,ttl:C8Y}),Xe1=new nk({max:128,ttl:300000})});function d8Y(q){try{let K=mD.inputSchema.safeParse(q);if(!K.success)return`input:${q.toString()}`;let{url:_}=K.data;return`domain:${new URL(_).hostname}`}catch{return`input:${q.toString()}`}}function OjK(q){return[{type:"addRules",destination:"localSettings",rules:[{toolName:Sj,ruleContent:q}],behavior:"allow"}]}var U8Y,Q8Y,mD;var WR6=y(()=>{x7();Bq();U7();Fj();Us1();IAK();Ze1();U8Y=B6(()=>L.strictObject({url:L.string().url().describe("The URL to fetch content from"),prompt:L.string().describe("The prompt to run on the fetched content")})),Q8Y=B6(()=>L.object({bytes:L.number().describe("Size of the fetched content in bytes"),code:L.number().describe("HTTP response code"),codeText:L.string().describe("HTTP response code text"),result:L.string().describe("Processed result from applying the prompt to the content"),durationMs:L.number().describe("Time taken to fetch and process the content"),url:L.string().describe("The URL that was fetched")}));mD=sq({name:Sj,searchHint:"fetch and extract content from a URL",maxResultSizeChars:1e5,shouldDefer:!0,async description(q){let{url:K}=q;try{return`Claude wants to fetch content from ${new URL(K).hostname}`}catch{return"Claude wants to fetch content from this URL"}},userFacingName(){return"Fetch"},getToolUseSummary:Qs1,getActivityDescription(q){let K=Qs1(q);return K?`Fetching ${K}`:"Fetching web page"},get inputSchema(){return U8Y()},get outputSchema(){return Q8Y()},isConcurrencySafe(){return!0},isReadOnly(){return!0},toAutoClassifierInput(q){return q.prompt?`${q.url}: ${q.prompt}`:q.url},async checkPermissions(q,K){let z=K.getAppState().toolPermissionContext;try{let{url:w}=q,j=new URL(w);if(Vu8(j.hostname,j.pathname))return{behavior:"allow",updatedInput:q,decisionReason:{type:"other",reason:"Preapproved host"}}}catch{}let Y=d8Y(q),$=sm(z,mD,"deny").get(Y);if($)return{behavior:"deny",message:`${mD.name} denied access to ${Y}.`,decisionReason:{type:"rule",rule:$}};let A=sm(z,mD,"ask").get(Y);if(A)return{behavior:"ask",message:`Claude requested permissions to use ${mD.name}, but you haven't granted it yet.`,decisionReason:{type:"rule",rule:A},suggestions:OjK(Y)};let O=sm(z,mD,"allow").get(Y);if(O)return{behavior:"allow",updatedInput:q,decisionReason:{type:"rule",rule:O}};return{behavior:"ask",message:`Claude requested permissions to use ${mD.name}, but you haven't granted it yet.`,suggestions:OjK(Y)}},async prompt(q){return`IMPORTANT: WebFetch WILL FAIL for authenticated or private URLs. Before using this tool, check if the URL points to an authenticated service (e.g. Google Docs, Confluence, Jira, GitHub). If so, look for a specialized MCP tool that provides authenticated access.

Callers 1

De1Function · 0.85

Calls 5

tCqFunction · 0.85
includesMethod · 0.80
_Class · 0.70
toStringMethod · 0.65
getMethod · 0.45

Tested by

no test coverage detected