@github/copilot 0.0.335 → 0.0.336-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +1 -1
- package/package.json +2 -2
- package/sdk/index.js +214 -214
- package/sdk/index.js.map +2 -2
package/index.js
CHANGED
|
@@ -1593,7 +1593,7 @@ Answer:
|
|
|
1593
1593
|
`}var XBl=kWe.platform==="win32"?["APPDATA","HOMEDRIVE","HOMEPATH","LOCALAPPDATA","PATH","PROCESSOR_ARCHITECTURE","SYSTEMDRIVE","SYSTEMROOT","TEMP","USERNAME","USERPROFILE","PROGRAMFILES"]:["HOME","LOGNAME","PATH","SHELL","TERM","USER"];function fBl(){let t={};for(let e of XBl){let l=kWe.env[e];l!==void 0&&(l.startsWith("()")||(t[e]=l))}return t}var JWe=class{constructor(e){this._abortController=new AbortController,this._readBuffer=new fWe,this._stderrStream=null,this._serverParams=e,(e.stderr==="pipe"||e.stderr==="overlapped")&&(this._stderrStream=new HBl)}async start(){if(this._process)throw new Error("StdioClientTransport already started! If using Client class, note that connect() calls start() automatically.");return new Promise((e,l)=>{var I,n,r,a,o;this._process=(0,rYt.default)(this._serverParams.command,(I=this._serverParams.args)!==null&&I!==void 0?I:[],{env:{...fBl(),...this._serverParams.env},stdio:["pipe","pipe",(n=this._serverParams.stderr)!==null&&n!==void 0?n:"inherit"],shell:!1,signal:this._abortController.signal,windowsHide:kWe.platform==="win32"&&JBl(),cwd:this._serverParams.cwd}),this._process.on("error",s=>{var d,G;if(s.name==="AbortError"){(d=this.onclose)===null||d===void 0||d.call(this);return}l(s),(G=this.onerror)===null||G===void 0||G.call(this,s)}),this._process.on("spawn",()=>{e()}),this._process.on("close",s=>{var d;this._process=void 0,(d=this.onclose)===null||d===void 0||d.call(this)}),(r=this._process.stdin)===null||r===void 0||r.on("error",s=>{var d;(d=this.onerror)===null||d===void 0||d.call(this,s)}),(a=this._process.stdout)===null||a===void 0||a.on("data",s=>{this._readBuffer.append(s),this.processReadBuffer()}),(o=this._process.stdout)===null||o===void 0||o.on("error",s=>{var d;(d=this.onerror)===null||d===void 0||d.call(this,s)}),this._stderrStream&&this._process.stderr&&this._process.stderr.pipe(this._stderrStream)})}get stderr(){var e,l;return this._stderrStream?this._stderrStream:(l=(e=this._process)===null||e===void 0?void 0:e.stderr)!==null&&l!==void 0?l:null}get pid(){var e,l;return(l=(e=this._process)===null||e===void 0?void 0:e.pid)!==null&&l!==void 0?l:null}processReadBuffer(){for(var e,l;;)try{let I=this._readBuffer.readMessage();if(I===null)break;(e=this.onmessage)===null||e===void 0||e.call(this,I)}catch(I){(l=this.onerror)===null||l===void 0||l.call(this,I)}}async close(){this._abortController.abort(),this._process=void 0,this._readBuffer.clear()}send(e){return new Promise(l=>{var I;if(!(!((I=this._process)===null||I===void 0)&&I.stdin))throw new Error("Not connected");let n=nYt(e);this._process.stdin.write(n)?l():this._process.stdin.once("drain",l)})}};function JBl(){return"type"in kWe}c();c();var LWe=class extends TransformStream{constructor({onError:e,onRetry:l,onComment:I}={}){let n;super({start(r){n=FWe({onEvent:a=>{r.enqueue(a)},onError(a){e==="terminate"?r.error(a):typeof e=="function"&&e(a)},onRetry:l,onComment:I})},transform(r){n.feed(r)}})}};var kBl={initialReconnectionDelay:1e3,maxReconnectionDelay:3e4,reconnectionDelayGrowFactor:1.5,maxRetries:2},dre=class extends Error{constructor(e,l){super(`Streamable HTTP error: ${l}`),this.code=e}},xWe=class{constructor(e,l){var I;this._url=e,this._resourceMetadataUrl=void 0,this._requestInit=l?.requestInit,this._authProvider=l?.authProvider,this._fetch=l?.fetch,this._sessionId=l?.sessionId,this._reconnectionOptions=(I=l?.reconnectionOptions)!==null&&I!==void 0?I:kBl}async _authThenStart(){var e;if(!this._authProvider)throw new kN("No auth provider");let l;try{l=await t5(this._authProvider,{serverUrl:this._url,resourceMetadataUrl:this._resourceMetadataUrl,fetchFn:this._fetch})}catch(I){throw(e=this.onerror)===null||e===void 0||e.call(this,I),I}if(l!=="AUTHORIZED")throw new kN;return await this._startOrAuthSse({resumptionToken:void 0})}async _commonHeaders(){var e;let l={};if(this._authProvider){let n=await this._authProvider.tokens();n&&(l.Authorization=`Bearer ${n.access_token}`)}this._sessionId&&(l["mcp-session-id"]=this._sessionId),this._protocolVersion&&(l["mcp-protocol-version"]=this._protocolVersion);let I=this._normalizeHeaders((e=this._requestInit)===null||e===void 0?void 0:e.headers);return new Headers({...l,...I})}async _startOrAuthSse(e){var l,I,n;let{resumptionToken:r}=e;try{let a=await this._commonHeaders();a.set("Accept","text/event-stream"),r&&a.set("last-event-id",r);let o=await((l=this._fetch)!==null&&l!==void 0?l:fetch)(this._url,{method:"GET",headers:a,signal:(I=this._abortController)===null||I===void 0?void 0:I.signal});if(!o.ok){if(o.status===401&&this._authProvider)return await this._authThenStart();if(o.status===405)return;throw new dre(o.status,`Failed to open SSE stream: ${o.statusText}`)}this._handleSseStream(o.body,e,!0)}catch(a){throw(n=this.onerror)===null||n===void 0||n.call(this,a),a}}_getNextReconnectionDelay(e){let l=this._reconnectionOptions.initialReconnectionDelay,I=this._reconnectionOptions.reconnectionDelayGrowFactor,n=this._reconnectionOptions.maxReconnectionDelay;return Math.min(l*Math.pow(I,e),n)}_normalizeHeaders(e){return e?e instanceof Headers?Object.fromEntries(e.entries()):Array.isArray(e)?Object.fromEntries(e):{...e}:{}}_scheduleReconnection(e,l=0){var I;let n=this._reconnectionOptions.maxRetries;if(n>0&&l>=n){(I=this.onerror)===null||I===void 0||I.call(this,new Error(`Maximum reconnection attempts (${n}) exceeded.`));return}let r=this._getNextReconnectionDelay(l);setTimeout(()=>{this._startOrAuthSse(e).catch(a=>{var o;(o=this.onerror)===null||o===void 0||o.call(this,new Error(`Failed to reconnect SSE stream: ${a instanceof Error?a.message:String(a)}`)),this._scheduleReconnection(e,l+1)})},r)}_handleSseStream(e,l,I){if(!e)return;let{onresumptiontoken:n,replayMessageId:r}=l,a;(async()=>{var s,d,G,u;try{let h=e.pipeThrough(new TextDecoderStream).pipeThrough(new LWe).getReader();for(;;){let{value:W,done:y}=await h.read();if(y)break;if(W.id&&(a=W.id,n?.(W.id)),!W.event||W.event==="message")try{let R=zf.parse(JSON.parse(W.data));r!==void 0&&Zne(R)&&(R.id=r),(s=this.onmessage)===null||s===void 0||s.call(this,R)}catch(R){(d=this.onerror)===null||d===void 0||d.call(this,R)}}}catch(h){if((G=this.onerror)===null||G===void 0||G.call(this,new Error(`SSE stream disconnected: ${h}`)),I&&this._abortController&&!this._abortController.signal.aborted)try{this._scheduleReconnection({resumptionToken:a,onresumptiontoken:n,replayMessageId:r},0)}catch(W){(u=this.onerror)===null||u===void 0||u.call(this,new Error(`Failed to reconnect: ${W instanceof Error?W.message:String(W)}`))}}})()}async start(){if(this._abortController)throw new Error("StreamableHTTPClientTransport already started! If using Client class, note that connect() calls start() automatically.");this._abortController=new AbortController}async finishAuth(e){if(!this._authProvider)throw new kN("No auth provider");if(await t5(this._authProvider,{serverUrl:this._url,authorizationCode:e,resourceMetadataUrl:this._resourceMetadataUrl,fetchFn:this._fetch})!=="AUTHORIZED")throw new kN("Failed to authorize")}async close(){var e,l;(e=this._abortController)===null||e===void 0||e.abort(),(l=this.onclose)===null||l===void 0||l.call(this)}async send(e,l){var I,n,r,a;try{let{resumptionToken:o,onresumptiontoken:s}=l||{};if(o){this._startOrAuthSse({resumptionToken:o,replayMessageId:kNe(e)?e.id:void 0}).catch(V=>{var Q;return(Q=this.onerror)===null||Q===void 0?void 0:Q.call(this,V)});return}let d=await this._commonHeaders();d.set("content-type","application/json"),d.set("accept","application/json, text/event-stream");let G={...this._requestInit,method:"POST",headers:d,body:JSON.stringify(e),signal:(I=this._abortController)===null||I===void 0?void 0:I.signal},u=await((n=this._fetch)!==null&&n!==void 0?n:fetch)(this._url,G),h=u.headers.get("mcp-session-id");if(h&&(this._sessionId=h),!u.ok){if(u.status===401&&this._authProvider){if(this._resourceMetadataUrl=ire(u),await t5(this._authProvider,{serverUrl:this._url,resourceMetadataUrl:this._resourceMetadataUrl,fetchFn:this._fetch})!=="AUTHORIZED")throw new kN;return this.send(e)}let V=await u.text().catch(()=>null);throw new Error(`Error POSTing to endpoint (HTTP ${u.status}): ${V}`)}if(u.status===202){u0t(e)&&this._startOrAuthSse({resumptionToken:void 0}).catch(V=>{var Q;return(Q=this.onerror)===null||Q===void 0?void 0:Q.call(this,V)});return}let y=(Array.isArray(e)?e:[e]).filter(V=>"method"in V&&"id"in V&&V.id!==void 0).length>0,R=u.headers.get("content-type");if(y)if(R?.includes("text/event-stream"))this._handleSseStream(u.body,{onresumptiontoken:s},!1);else if(R?.includes("application/json")){let V=await u.json(),Q=Array.isArray(V)?V.map(f=>zf.parse(f)):[zf.parse(V)];for(let f of Q)(r=this.onmessage)===null||r===void 0||r.call(this,f)}else throw new dre(-1,`Unexpected content type: ${R}`)}catch(o){throw(a=this.onerror)===null||a===void 0||a.call(this,o),o}}get sessionId(){return this._sessionId}async terminateSession(){var e,l,I;if(this._sessionId)try{let n=await this._commonHeaders(),r={...this._requestInit,method:"DELETE",headers:n,signal:(e=this._abortController)===null||e===void 0?void 0:e.signal},a=await((l=this._fetch)!==null&&l!==void 0?l:fetch)(this._url,r);if(!a.ok&&a.status!==405)throw new dre(a.status,`Failed to terminate session: ${a.statusText}`);this._sessionId=void 0}catch(n){throw(I=this.onerror)===null||I===void 0||I.call(this,n),n}}setProtocolVersion(e){this._protocolVersion=e}get protocolVersion(){return this._protocolVersion}};c();var SWe=class{constructor(e){this.server=e}onmessage;onerror;onclose;serverTransport;closed=!1;async start(){if(this.closed)throw new Error("Transport is closed");this.serverTransport=new a9e(this),await this.server.connect(this.serverTransport)}async send(e){if(this.closed)throw new Error("Transport is closed");setImmediate(()=>{try{this.serverTransport?.onmessage?.(e)}catch(l){this.onerror?.(l instanceof Error?l:new Error(String(l)))}})}receive(e){this.closed||this.onmessage?.(e)}async close(){this.closed||(this.closed=!0,await this.serverTransport?.close(),this.onclose?.())}},a9e=class{constructor(e){this.clientTransport=e}onmessage;onerror;onclose;closed=!1;async start(){}async send(e){if(this.closed)throw new Error("Transport is closed");setImmediate(()=>{try{this.clientTransport.receive(e)}catch(l){this.onerror?.(l instanceof Error?l:new Error(String(l)))}})}async close(){this.closed||(this.closed=!0,this.onclose?.())}};var BWe=class{createTransport(e){switch(e.type){case"stdio":{let l=new JWe({command:e.command,args:e.args,env:e.env,stderr:e.stderr?"pipe":void 0});return l.stderr?.pipe(e.stderr),l}case"http":return new xWe(new URL(e.url),{requestInit:{headers:e.headers||{}}});case"sse":return new HWe(new URL(e.url),{requestInit:{headers:e.headers||{}}});case"memory":return new SWe(e.server);default:throw new Error(`Unsupported transport type: ${e.type}`)}}};c();var kx="blackbird-mcp-server",HD="github-mcp-server",o9e="playwright";function XD(t){return t.type===void 0||t.type.toLowerCase()==="local"||t.type.toLowerCase()==="stdio"}function fD(t){return mre(t)||Gre(t)}function mre(t){return t.type?.toLowerCase()==="http"}function Gre(t){return t.type?.toLowerCase()==="sse"}function bre(t){return t.type?.toLowerCase()==="memory"}var s9e=class extends LBl{constructor(l,I){super({decodeStrings:!1});this.serverName=l;this.logger=I}_write(l,I,n){try{let r=l.toString();this.logger.log(`[mcp server ${this.serverName} stderr] ${r}`),n()}catch(r){n(r instanceof Error?r:new Error(String(r)))}}},OWe=class{constructor(e,l=new VWe,I=new BWe){this.logger=e;this.clientFactory=l;this.transportFactory=I}clients={};transports={};async startLocalMcpClient(e,l,I,n){this.logger.log(`Starting MCP client for ${e} with command: ${I} and args: ${n}`);let r=new s9e(e,this.logger),a={type:"stdio",command:I,args:n,env:{...l,PATH:process.env.PATH},stderr:r},o=this.transportFactory.createTransport(a);await this.setupAndConnectClient(e,o)}async startHttpMcpClient(e,l){this.logger.log(`Starting remote MCP client for ${e} with url: ${l.url}`);let I={type:"http",url:l.url,headers:l.headers},n=this.transportFactory.createTransport(I);await this.setupAndConnectClient(e,n)}async startSseMcpClient(e,l){this.logger.log(`Starting remote MCP client for ${e} with url: ${l.url}`);let I={type:"sse",url:l.url,headers:l.headers},n=this.transportFactory.createTransport(I);await this.setupAndConnectClient(e,n)}async startInMemoryMcpClient(e,l){this.logger.log(`Starting in-memory MCP client for ${e}`);let I={type:"memory",server:l},n=this.transportFactory.createTransport(I);await this.setupAndConnectClient(e,n)}async setupAndConnectClient(e,l){this.transports[e]=l,l.onclose=()=>{this.logger.log(`MCP transport for ${e} closed`),delete this.transports[e]},this.logger.log(`Creating MCP client for ${e}...`);let I=this.clientFactory.createClient({name:"github-copilot-developer",version:"1.0.0"},{capabilities:{experimental:void 0,roots:void 0,sampling:void 0}}),n=Date.now();this.logger.log(`Connecting MCP client for ${e}...`),await I.connect(l),I.onclose=()=>{this.logger.log(`MCP client for ${e} closed`),delete this.clients[e]},I.onerror=r=>{this.logger.error(`MCP client for ${e} errored ${r}`)},this.logger.log(`MCP client for ${e} connected, took ${Date.now()-n}ms`),this.clients[e]=I}async getTools(e,l){let I={};for(let[n,r]of Object.entries(this.clients)){let a=[];try{this.logger.log(`Fetching tools from client: ${n}`);let o=await r.listTools(),s=e?.mcpServers[n].tools,d=e?.mcpServers[n].filterMapping;for(let u of o.tools){if(u.name==="get_copilot_space")continue;if(!(s?.includes("*")||s?.includes(u.name))){this.logger.log(`Tool ${u.name} is not in the allowed list for client: ${n}`);continue}let W=Lbe(n,u.name),y=`${n}-${u.name}`,R;typeof d=="string"?R=PCe(d):R=PCe(d?.[u.name]??"hidden_characters"),I[`${n}/${u.name}`]={name:y,title:u.title??u.annotations?.title??u.name,description:u.description??y,input_schema:u.inputSchema,readOnly:u.annotations?.readOnlyHint,safeForTelemetry:{name:!!(e?.mcpServers[n].isDefaultServer||W),inputsNames:!!e?.mcpServers[n].isDefaultServer},filterMode:R},a.push(u.name),this.logger.log(`Tool ${u.name} added to tools list for client: ${n}`)}this.logger.log(`Successfully retrieved ${a.length} tools from client: ${n}`);let G=r.getServerVersion();await this.logServerSuccessWithTools(n,a,G,l)}catch(o){this.logger.error(`Failed to get tools from client: ${n} ${o}`)}}return this.logger.log(`All tools retrieved: ${JSON.stringify(I,null,2)}`),I}async logServerSuccessWithTools(e,l,I,n){if(e!=kx&&n)try{let r=l.map(s=>`- ${s}`).join(`
|
|
1594
1594
|
`),o=`MCP server started successfully${I?` (version ${I.version})`:""} with ${l.length} ${l.length===1?"tool":"tools"} - for the full output, see the verbose logs
|
|
1595
1595
|
|
|
1596
|
-
${r}`;await n.logMCPSetup(e,o),this.logger.log(`Updated session log for ${e} with ${l.length} tools`)}catch(r){this.logger.error(`Failed to update session log for ${e}: ${r}`)}}};c();var c9e={mcpServers:{}},TWe=class{constructor(e,l,I){this.logger=e;this.registry=l;this.remoteEnabled=I?.remoteEnabled??!1,this.mcp3pEnabled=I?.mcp3pEnabled??!1,this.blackbirdMetisIndexEnabled=I?.blackbirdMetisIndexEnabled??!1,this.sessionClient=I?.sessionClient,this.mcpEnvConfig=void 0}remoteEnabled;mcp3pEnabled;blackbirdMetisIndexEnabled;mcpEnvConfig;sessionClient;ReadMcpConfigFromEnv(e){this.mcpEnvConfig=process.env.GITHUB_COPILOT_MCP_JSON,this.mcp3pEnabled=process.env.GITHUB_COPILOT_3P_MCP_ENABLED==="true",this.remoteEnabled=process.env.GITHUB_COPILOT_REMOTE_MCP_ENABLED==="true",this.blackbirdMetisIndexEnabled=process.env.BLACKBIRD_METIS_INDEX_ENABLED==="true";let l=this.validateEnvConfig();return process.env.GITHUB_COPILOT_CLI_MODE==="true"?this.logger.log("CLI mode detected - skipping default MCP servers"):(this.logger.log("Adding default MCP servers to configuration"),this.configureBlackbirdMcp(l,e),this.configureGitHubMcp(l,e),this.configurePlaywrightMcp(l)),l}validateEnvConfig(){if(!this.mcp3pEnabled)return this.logger.log("User-provided MCPs are disabled"),c9e;if(this.logger.log("User-provided MCPs are enabled, checking for environment variable"),!this.mcpEnvConfig)return this.logger.log("No user-provided MCP servers found"),c9e;try{let e=JSON.parse(this.mcpEnvConfig);if(!e.mcpServers)throw new Error("User-provided config had incorrect format. Missing 'mcpServers' property.");for(let l in e.mcpServers)e.mcpServers[l].isDefaultServer=!1;return e}catch(e){return this.logger.error(`Warning: User-provided MCP servers were defined but invalid: ${e}`),c9e}}configureGitHubMcp(e,l){this.remoteEnabled?this.configureRemoteGitHubMcp(e,l):this.configureLocalGitHubMcp(e)}configureRemoteGitHubMcp(e,l){this.logger.log("Using default remote GitHub MCP server configuration");let I="repos,issues,users,pull_requests,code_security,secret_protection,actions";process.env.COPILOT_MCP_COPILOT_SPACES_ENABLED==="true"&&(this.logger.log("Enabling Copilot Spaces in GitHub MCP server configuration"),I=I+",copilot_spaces");let n={Authorization:"Bearer "+process.env.GITHUB_PERSONAL_ACCESS_TOKEN,"X-MCP-Toolsets":I,"X-MCP-Host":"github-coding-agent","X-Initiator":"agent"};l&&l.api?.copilot?.integrationId&&(n["Copilot-Integration-Id"]=l.api.copilot.integrationId),process.env.GITHUB_COPILOT_INTERACTION_ID&&(n["X-Interaction-Id"]=process.env.GITHUB_COPILOT_INTERACTION_ID);let r={type:"http",url:this.getCapiMcpUrl(),headers:n,tools:["*"],isDefaultServer:!0,filterMapping:{get_issue:"markdown",get_issue_comments:"markdown",get_pull_request:"markdown",get_pull_request_comments:"markdown",get_pull_request_reviews:"markdown"}};e.mcpServers[HD]=r}configureLocalGitHubMcp(e){if(e.mcpServers[HD]){this.logger.log("Using user-provided GitHub MCP server configuration");let l=e.mcpServers[HD]??{};XD(l)&&!l.command&&(e.mcpServers[HD]={...l,command:"./copilot-developer-action-main/github-mcp-server/github-mcp-server",isDefaultServer:!0},this.logger.log("Added default command to user-provided GitHub MCP server configuration"))}else{this.logger.log("Using default local GitHub MCP server configuration");let l={command:"./copilot-developer-action-main/github-mcp-server/github-mcp-server",args:["stdio","--read-only"],env:{GITHUB_PERSONAL_ACCESS_TOKEN:"GITHUB_PERSONAL_ACCESS_TOKEN",GITHUB_HOST:"GITHUB_SERVER_URL"},tools:["*"],isDefaultServer:!0};e.mcpServers[HD]=l}}configurePlaywrightMcp(e){if(!e.mcpServers[o9e]){if((process.env.COPILOT_FEATURE_FLAGS??"").split(",").map(I=>I.trim()).includes("copilot_swe_agent_playwright_use_firewall")){this.logger.log("Playwright MCP server is configured to use the firewall, skipping launch.");return}this.logger.log("Enabling Playwright MCP server");let l={command:"npx",args:[...CHe,"--allowed-origins","localhost;localhost:*;127.0.0.1;127.0.0.1:*"],tools:["*"],isDefaultServer:!0};e.mcpServers[o9e]=l}}configureBlackbirdMcp(e,l){this.remoteEnabled?this.configureRemoteBlackbirdMcp(e):this.blackbirdMetisIndexEnabled?this.configureLocalMetisBlackbirdMCP(e,l):this.configureLocalBlackbirdMcp(e)}configureLocalMetisBlackbirdMCP(e,l){this.logger.log("Using local Metis Blackbird MCP server configuration"),this.logger.log(`Using blackbird mode: ${l.blackbird?.mode}`);let I=process.env.AGENT_DIR||"/agent";this.logger.log(`Using agent directory: ${I}`);let n=[];l.blackbird?.mode==="tool"&&(n=["*"]),this.logger.log(`Using blackbird Metis server: ${l.blackbird?.mode}`);let r={command:`${I}/blackbird/mcp`,args:["serve","--index",`${I}/blackbird/metis`],env:{GITHUB_PERSONAL_ACCESS_TOKEN:"GITHUB_PERSONAL_ACCESS_TOKEN",COPILOT_API_HMAC_KEY:"CAPI_HMAC_KEY",MODEL_BASED_RETRIEVAL_TOKEN:"BLACKBIRD_AUTH_MODEL_BASED_RETRIEVAL_TOKEN",METIS_API_KEY:"BLACKBIRD_AUTH_METIS_API_KEY"},tools:n,isDefaultServer:!0};e.mcpServers[kx]=r}configureLocalBlackbirdMcp(e){this.logger.log("Using local Blackbird MCP server configuration"),this.logger.log(`Using blackbird mode: ${process.env.BLACKBIRD_MODE}`);let l=[];process.env.BLACKBIRD_MODE==="tool"&&(l=["*"]);let I={command:"./copilot-developer-action-main/blackbird-mcp-server/blackbird-mcp-server",args:["stdio"],env:{GITHUB_PERSONAL_ACCESS_TOKEN:"GITHUB_PERSONAL_ACCESS_TOKEN",CAPI_HOST:"COPILOT_API_URL"},tools:l,isDefaultServer:!0};e.mcpServers[kx]=I}configureRemoteBlackbirdMcp(e){this.logger.log("Using remote Blackbird MCP server configuration"),this.logger.log(`Using blackbird mode: ${process.env.BLACKBIRD_MODE}`);let l=[];process.env.BLACKBIRD_MODE==="tool"&&(l=["*"]);let I={Authorization:"Bearer "+process.env.GITHUB_PERSONAL_ACCESS_TOKEN,"X-MCP-Toolsets":"search_agent","X-MCP-Host":"github-coding-agent"};process.env.GITHUB_COPILOT_INTERACTION_ID&&(I["X-Interaction-Id"]=process.env.GITHUB_COPILOT_INTERACTION_ID);let n={type:"http",url:this.getCapiMcpUrl(),headers:I,tools:l,isDefaultServer:!0};e.mcpServers[kx]=n}getCapiMcpUrl(){return process.env.COPILOT_API_URL?new URL("/mcp/readonly",process.env.COPILOT_API_URL).toString():"https://api.githubcopilot.com/mcp/readonly"}isValidServerType(e){return XD(e)||mre(e)||Gre(e)||bre(e)}isValidLocalServerConfig(e){return e.command!==void 0&&e.command.trim()!==""&&Array.isArray(e.args)}isValidRemoteServerConfig(e){return e.url!==void 0&&e.url.trim()!==""}isValidInMemoryServerConfig(e){return e.serverInstance!==void 0&&typeof e.serverInstance=="object"}validateServerConfig(e,l){return this.remoteEnabled&&!this.isValidServerType(l)?(this.logger.error(`Unsupported server type "${l.type}" for server "${e}". Only "Local", "STDIO", "HTTP", "SSE", or "Memory" are supported.`),!1):!this.remoteEnabled&&!XD(l)&&!bre(l)?(this.logger.error(`Unsupported server type "${l.type}" for server "${e}". Only "Local", "STDIO", or "Memory" are supported.`),!1):l.tools?XD(l)&&!this.isValidLocalServerConfig(l)?(this.logger.error(`Invalid local server configuration for "${e}". Please ensure 'command' and 'args' are provided.`),!1):(mre(l)||Gre(l))&&!this.isValidRemoteServerConfig(l)?(this.logger.error(`Invalid remote server configuration for "${e}". Please ensure 'url' is provided.`),!1):bre(l)&&!this.isValidInMemoryServerConfig(l)?(this.logger.error(`Invalid in-memory server configuration for "${e}". Please ensure 'serverInstance' is provided and is an instance of MCPServer.`),!1):!0:(this.logger.error(`No tools specified for server "${e}". Please provide a list of tools or "*" to include all tools.`),!1)}async processHttpServer(e,l){try{let I=this.resolveHeaders(l.headers,process.env),n={...l,headers:I};await this.registry.startHttpMcpClient(e,n),this.logger.log(`Started MCP client for remote server ${e}`)}catch(I){throw this.logger.error(`Failed to start MCP client for remote server ${e}: ${I}`),I}}async processSseServer(e,l){try{let I=this.resolveHeaders(l.headers,process.env),n={...l,headers:I};await this.registry.startSseMcpClient(e,n),this.logger.log(`Started MCP client for remote server ${e}`)}catch(I){throw this.logger.error(`Failed to start MCP client for remote server ${e}: ${I}`),I}}async processInMemoryServer(e,l){try{await this.registry.startInMemoryMcpClient(e,l.serverInstance),this.logger.log(`Started in-memory MCP client for ${e}`)}catch(I){throw this.logger.error(`Failed to start in-memory MCP client for ${e}: ${I}`),I}}async processLocalServer(e,l){let I={...l};if(l.command==="python")try{I=await this.convertPythonToPipx(I)}catch(a){this.logger.error(`Failed to handle Python module for ${e}: ${a}`)}let n=this.buildEnvironment(I),r=this.resolveArray(I.args,n);this.logger.log(`Starting MCP client for ${e} with command: ${I.command} and args: ${r}`);try{await this.registry.startLocalMcpClient(e,n,I.command,r),this.logger.log(`Started MCP client for ${e}`)}catch(a){throw this.logger.error(`Failed to start MCP client for ${e}: ${a}`),a}}convertPythonToPipx(e){if(!e||!e.args||e.args.length===0)return e;let l=e.args,I=l.indexOf("-m");if(I===-1||I===l.length-1)throw new Error("Python command with -m flag must specify a module");let n=l[I+1];this.logger.log(`Converting Python module: ${n} to pipx command`);let r=["run",n];for(let a=I+2;a<l.length;a++)r.push(l[a]);for(let a=0;a<I;a++)r.push(l[a]);return{...e,command:"pipx",args:r}}buildEnvironment(e){let l={};if(e.env)for(let[I,n]of Object.entries(e.env)){let r=n.trim();process.env[r]!==void 0&&(l[I]=process.env[r])}return l}resolveArray(e,l){return e?l?e.map(I=>I.replace(/\$([A-Z0-9_]+)/g,(n,r)=>l[r]||n)):e:[]}resolveHeaders(e,l){if(!e)return{};if(!l)return e;let I={};for(let[n,r]of Object.entries(e)){let a=this.resolveArray([r],l);I[n]=a[0]}return I}async processServers(e){if(!e)throw new Error("No servers to process");let l=Object.entries(e.mcpServers).map(([I,n])=>this.processServer(I,n));await Promise.all(l)}async processServer(e,l){if(!this.validateServerConfig(e,l)){this.logger.error(`Skipping server "${e}" due to invalid configuration.`);return}try{XD(l)?await this.processLocalServer(e,l):mre(l)&&this.remoteEnabled?await this.processHttpServer(e,l):Gre(l)&&this.remoteEnabled?await this.processSseServer(e,l):bre(l)&&await this.processInMemoryServer(e,l)}catch(I){e!==kx&&await this.logServerFailure(e,I)}}async logServerFailure(e,l){if(this.sessionClient)try{await this.sessionClient.logMCPSetup(e,`<error>MCP server failed to start: ${l.message} - for the full output, see the verbose logs</error>`)}catch(I){this.logger.error(`Failed to log failure for MCP Server '${e}': '${I}'`)}}};var UWe=class{constructor(e,l,I){this.logger=e;let n;if(typeof l=="string"){if(n=JSON.parse(l),typeof n!="object")throw new Error("Invalid MCP configuration: must be an object");if(n===null||!("mcpServers"in n)||typeof n.mcpServers!="object")throw new Error("Invalid MCP configuration: missing or invalid mcpServers property");this.config=n}else this.config=l;this.disabledServers=new Set(I||[]),this.registry=new OWe(this.logger),this.processor=new TWe(this.logger,this.registry,{mcp3pEnabled:!0,remoteEnabled:!0})}registry;processor;config;startServersPromise=null;allTools=null;disabledServers;async startServers(){return this.startServersPromise||(this.startServersPromise=this.processServersWithExtensions()),this.startServersPromise}async injectDefaultServers(e){}async processServersWithExtensions(){await this.injectDefaultServers(this.config);let e;if(this.disabledServers.size>0){let l={};for(let[I,n]of Object.entries(this.config.mcpServers))this.disabledServers.has(I)?this.logger.log(`Skipping disabled MCP server: ${I}`):l[I]=n;e={...this.config,mcpServers:l}}else e=this.config;return this.processor.processServers(e)}async stopServers(){for(let[e,l]of Object.entries(this.registry.transports))try{await l.close()}catch(I){this.logger.error(`Error closing transport for ${e}: ${I}`)}this.startServersPromise=null,this.allTools=null}async getTools(e,l,I){if(!this.allTools){await this.startServers();let n=new Aee(e,l,I),r=[];for(let a of Object.keys(this.registry.clients)){let o=await n.loadTools({mcpClient:this.registry.clients[a],clientName:a,tools:this.config.mcpServers[a]?.tools||["*"],filterMapping:this.config.mcpServers[a]?.filterMapping||"hidden_characters"});r.push(...o)}this.allTools=r}return this.allTools}getConfig(){return this.config}async startServer(e,l){await this.startServers(),this.config.mcpServers[e]=l,await this.processor.processServer(e,l),this.allTools=null}async stopServer(e){let l=this.registry.transports[e];if(l)try{await l.close(),delete this.registry.transports[e]}catch(I){this.logger.error(`Error closing transport for ${e}: ${I}`)}this.registry.clients[e]&&delete this.registry.clients[e],this.allTools=null}async restartServer(e,l){this.isServerRunning(e)&&await this.stopServer(e),delete this.config.mcpServers[e],await this.startServer(e,l)}isServerRunning(e){return e in this.registry.transports&&e in this.registry.clients}isServerDisabled(e){return this.disabledServers.has(e)}async disableServer(e){if(this.disabledServers.has(e)){this.logger.log(`Server ${e} is already disabled`);return}this.disabledServers.add(e),this.logger.log(`Disabled server ${e} for this session`),this.isServerRunning(e)&&await this.stopServer(e),this.allTools=null}async enableServer(e){if(!this.disabledServers.has(e)){this.logger.log(`Server ${e} is not disabled`);return}this.disabledServers.delete(e),this.logger.log(`Enabled server ${e} for this session`);let l=this.getServerConfig(e);l?await this.startServer(e,l):await this.startBuiltInServer(e),this.allTools=null}async startBuiltInServer(e){}getServerConfig(e){return this.config.mcpServers[e]}};c();var xBl="/login/device/code",SBl="/login/oauth/access_token",aYt="Ov23ctDVkRmgkPke0Mmm",U2="https://github.com",l5=class extends Error{constructor(l,I){super(I);this.status=l;this.message=I;this.name="GitHubApiError"}};function oYt(t){let e=new URL(t);return e.hostname.startsWith("api.")||(e.hostname="api."+e.hostname),e.href}async function sYt(t){let e=new URL(xBl,t),l=await fetch(e.href,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json"},body:new URLSearchParams({client_id:aYt,scope:"user:email,read:user,repo,workflow"})});if(!l.ok)throw new l5(l.status,`Failed to request device code: ${l.statusText}`);return await l.json()}async function cYt(t,e){let l=new URL(SBl,t),I=await fetch(l.href,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json"},body:new URLSearchParams({client_id:aYt,device_code:e,grant_type:"urn:ietf:params:oauth:grant-type:device_code"})});if(!I.ok)throw new l5(I.status,`Failed to authorize: ${I.statusText}`);let n=await I.json();if(typeof n.access_token=="string")return n.access_token;if(n.error!=="authorization_pending"&&n.error!=="slow_down")throw new Error(n.error_description||`Unexpected error: ${n.error}`)}async function JD(t,e){let l=new URL("/user",oYt(t)),I=await fetch(l.href,{headers:{Authorization:`Bearer ${e}`,Accept:"application/json"}});if(!I.ok)throw new l5(I.status,`Failed to fetch user info: ${I.statusText}`);return(await I.json()).login}async function kD(t,e){let l=`
|
|
1596
|
+
${r}`;await n.logMCPSetup(e,o),this.logger.log(`Updated session log for ${e} with ${l.length} tools`)}catch(r){this.logger.error(`Failed to update session log for ${e}: ${r}`)}}};c();var c9e={mcpServers:{}},TWe=class{constructor(e,l,I){this.logger=e;this.registry=l;this.remoteEnabled=I?.remoteEnabled??!1,this.mcp3pEnabled=I?.mcp3pEnabled??!1,this.blackbirdMetisIndexEnabled=I?.blackbirdMetisIndexEnabled??!1,this.sessionClient=I?.sessionClient,this.mcpEnvConfig=void 0}remoteEnabled;mcp3pEnabled;blackbirdMetisIndexEnabled;mcpEnvConfig;sessionClient;ReadMcpConfigFromEnv(e){this.mcpEnvConfig=process.env.GITHUB_COPILOT_MCP_JSON,this.mcp3pEnabled=process.env.GITHUB_COPILOT_3P_MCP_ENABLED==="true",this.remoteEnabled=process.env.GITHUB_COPILOT_REMOTE_MCP_ENABLED==="true",this.blackbirdMetisIndexEnabled=process.env.BLACKBIRD_METIS_INDEX_ENABLED==="true";let l=this.validateEnvConfig();return process.env.GITHUB_COPILOT_CLI_MODE==="true"?this.logger.log("CLI mode detected - skipping default MCP servers"):(this.logger.log("Adding default MCP servers to configuration"),this.configureBlackbirdMcp(l,e),this.configureGitHubMcp(l,e),this.configurePlaywrightMcp(l)),l}validateEnvConfig(){if(!this.mcp3pEnabled)return this.logger.log("User-provided MCPs are disabled"),c9e;if(this.logger.log("User-provided MCPs are enabled, checking for environment variable"),!this.mcpEnvConfig)return this.logger.log("No user-provided MCP servers found"),c9e;try{let e=JSON.parse(this.mcpEnvConfig);if(!e.mcpServers)throw new Error("User-provided config had incorrect format. Missing 'mcpServers' property.");for(let l in e.mcpServers)e.mcpServers[l].isDefaultServer=!1;return e}catch(e){return this.logger.error(`Warning: User-provided MCP servers were defined but invalid: ${e}`),c9e}}configureGitHubMcp(e,l){this.remoteEnabled?this.configureRemoteGitHubMcp(e,l):this.configureLocalGitHubMcp(e)}configureRemoteGitHubMcp(e,l){this.logger.log("Using default remote GitHub MCP server configuration");let I="repos,issues,users,pull_requests,code_security,secret_protection,actions";process.env.COPILOT_MCP_COPILOT_SPACES_ENABLED==="true"&&(this.logger.log("Enabling Copilot Spaces in GitHub MCP server configuration"),I=I+",copilot_spaces");let n={Authorization:"Bearer "+process.env.GITHUB_PERSONAL_ACCESS_TOKEN,"X-MCP-Toolsets":I,"X-MCP-Host":"github-coding-agent","X-Initiator":"agent"};l&&l.api?.copilot?.integrationId&&(n["Copilot-Integration-Id"]=l.api.copilot.integrationId),process.env.GITHUB_COPILOT_INTERACTION_ID&&(n["X-Interaction-Id"]=process.env.GITHUB_COPILOT_INTERACTION_ID);let r={type:"http",url:this.getCapiMcpUrl(),headers:n,tools:["*"],isDefaultServer:!0,filterMapping:{get_issue:"markdown",get_issue_comments:"markdown",get_pull_request:"markdown",get_pull_request_comments:"markdown",get_pull_request_reviews:"markdown"}};e.mcpServers[HD]=r}configureLocalGitHubMcp(e){if(e.mcpServers[HD]){this.logger.log("Using user-provided GitHub MCP server configuration");let l=e.mcpServers[HD]??{};XD(l)&&!l.command&&(e.mcpServers[HD]={...l,command:"./copilot-developer-action-main/github-mcp-server/github-mcp-server",isDefaultServer:!0},this.logger.log("Added default command to user-provided GitHub MCP server configuration"))}else{this.logger.log("Using default local GitHub MCP server configuration");let l={command:"./copilot-developer-action-main/github-mcp-server/github-mcp-server",args:["stdio","--read-only"],env:{GITHUB_PERSONAL_ACCESS_TOKEN:"GITHUB_PERSONAL_ACCESS_TOKEN",GITHUB_HOST:"GITHUB_SERVER_URL"},tools:["*"],isDefaultServer:!0};e.mcpServers[HD]=l}}configurePlaywrightMcp(e){if(!e.mcpServers[o9e]){if((process.env.COPILOT_FEATURE_FLAGS??"").split(",").map(I=>I.trim()).includes("copilot_swe_agent_playwright_use_firewall")){this.logger.log("Playwright MCP server is configured to use the firewall, skipping launch.");return}this.logger.log("Enabling Playwright MCP server");let l={command:"npx",args:[...CHe,"--allowed-origins","localhost;localhost:*;127.0.0.1;127.0.0.1:*"],tools:["*"],isDefaultServer:!0};e.mcpServers[o9e]=l}}configureBlackbirdMcp(e,l){this.remoteEnabled?this.configureRemoteBlackbirdMcp(e):this.blackbirdMetisIndexEnabled?this.configureLocalMetisBlackbirdMCP(e,l):this.configureLocalBlackbirdMcp(e)}configureLocalMetisBlackbirdMCP(e,l){this.logger.log("Using local Metis Blackbird MCP server configuration"),this.logger.log(`Using blackbird mode: ${l.blackbird?.mode}`);let I=process.env.AGENT_DIR||"/agent";this.logger.log(`Using agent directory: ${I}`);let n=[];l.blackbird?.mode==="tool"&&(n=["*"]),this.logger.log(`Using blackbird Metis server: ${l.blackbird?.mode}`);let r={command:`${I}/blackbird/mcp`,args:["serve","--index",`${I}/blackbird/metis`],env:{GITHUB_PERSONAL_ACCESS_TOKEN:"GITHUB_PERSONAL_ACCESS_TOKEN",COPILOT_API_HMAC_KEY:"CAPI_HMAC_KEY",MODEL_BASED_RETRIEVAL_TOKEN:"BLACKBIRD_AUTH_MODEL_BASED_RETRIEVAL_TOKEN",METIS_API_KEY:"BLACKBIRD_AUTH_METIS_API_KEY"},tools:n,isDefaultServer:!0};e.mcpServers[kx]=r}configureLocalBlackbirdMcp(e){this.logger.log("Using local Blackbird MCP server configuration"),this.logger.log(`Using blackbird mode: ${process.env.BLACKBIRD_MODE}`);let l=[];process.env.BLACKBIRD_MODE==="tool"&&(l=["*"]);let I={command:"./copilot-developer-action-main/blackbird-mcp-server/blackbird-mcp-server",args:["stdio"],env:{GITHUB_PERSONAL_ACCESS_TOKEN:"GITHUB_PERSONAL_ACCESS_TOKEN",CAPI_HOST:"COPILOT_API_URL"},tools:l,isDefaultServer:!0};e.mcpServers[kx]=I}configureRemoteBlackbirdMcp(e){this.logger.log("Using remote Blackbird MCP server configuration"),this.logger.log(`Using blackbird mode: ${process.env.BLACKBIRD_MODE}`);let l=[];process.env.BLACKBIRD_MODE==="tool"&&(l=["*"]);let I={Authorization:"Bearer "+process.env.GITHUB_PERSONAL_ACCESS_TOKEN,"X-MCP-Toolsets":"search_agent","X-MCP-Host":"github-coding-agent"};process.env.GITHUB_COPILOT_INTERACTION_ID&&(I["X-Interaction-Id"]=process.env.GITHUB_COPILOT_INTERACTION_ID);let n={type:"http",url:this.getCapiMcpUrl(),headers:I,tools:l,isDefaultServer:!0};e.mcpServers[kx]=n}getCapiMcpUrl(){return process.env.COPILOT_API_URL?new URL("/mcp/readonly",process.env.COPILOT_API_URL).toString():"https://api.githubcopilot.com/mcp/readonly"}isValidServerType(e){return XD(e)||mre(e)||Gre(e)||bre(e)}isValidLocalServerConfig(e){return e.command!==void 0&&e.command.trim()!==""&&Array.isArray(e.args)}isValidRemoteServerConfig(e){return e.url!==void 0&&e.url.trim()!==""}isValidInMemoryServerConfig(e){return e.serverInstance!==void 0&&typeof e.serverInstance=="object"}validateServerConfig(e,l){return this.remoteEnabled&&!this.isValidServerType(l)?(this.logger.error(`Unsupported server type "${l.type}" for server "${e}". Only "Local", "STDIO", "HTTP", "SSE", or "Memory" are supported.`),!1):!this.remoteEnabled&&!XD(l)&&!bre(l)?(this.logger.error(`Unsupported server type "${l.type}" for server "${e}". Only "Local", "STDIO", or "Memory" are supported.`),!1):l.tools?XD(l)&&!this.isValidLocalServerConfig(l)?(this.logger.error(`Invalid local server configuration for "${e}". Please ensure 'command' and 'args' are provided.`),!1):(mre(l)||Gre(l))&&!this.isValidRemoteServerConfig(l)?(this.logger.error(`Invalid remote server configuration for "${e}". Please ensure 'url' is provided.`),!1):bre(l)&&!this.isValidInMemoryServerConfig(l)?(this.logger.error(`Invalid in-memory server configuration for "${e}". Please ensure 'serverInstance' is provided and is an instance of MCPServer.`),!1):!0:(this.logger.error(`No tools specified for server "${e}". Please provide a list of tools or "*" to include all tools.`),!1)}async processHttpServer(e,l){try{let I=this.resolveHeaders(l.headers,process.env),n={...l,headers:I};await this.registry.startHttpMcpClient(e,n),this.logger.log(`Started MCP client for remote server ${e}`)}catch(I){throw this.logger.error(`Failed to start MCP client for remote server ${e}: ${I}`),I}}async processSseServer(e,l){try{let I=this.resolveRemoteServerConfig(l);await this.registry.startSseMcpClient(e,I),this.logger.log(`Started MCP client for remote server ${e}`)}catch(I){throw this.logger.error(`Failed to start MCP client for remote server ${e}: ${I}`),I}}resolveRemoteServerConfig(e){return e.url=this.resolveString(e.url,process.env),e.headers=this.resolveHeaders(e.headers,process.env),{...e,url:e.url,headers:e.headers}}async processInMemoryServer(e,l){try{await this.registry.startInMemoryMcpClient(e,l.serverInstance),this.logger.log(`Started in-memory MCP client for ${e}`)}catch(I){throw this.logger.error(`Failed to start in-memory MCP client for ${e}: ${I}`),I}}async processLocalServer(e,l){let I={...l};if(l.command==="python")try{I=await this.convertPythonToPipx(I)}catch(a){this.logger.error(`Failed to handle Python module for ${e}: ${a}`)}let n=this.buildEnvironment(I),r=this.resolveLocalServerConfig(I,n);this.logger.log(`Starting MCP client for ${e} with command: ${r.command} and args: ${r.args}`);try{await this.registry.startLocalMcpClient(e,n,r.command,r.args),this.logger.log(`Started MCP client for ${e}`)}catch(a){throw this.logger.error(`Failed to start MCP client for ${e}: ${a}`),a}}convertPythonToPipx(e){if(!e||!e.args||e.args.length===0)return e;let l=e.args,I=l.indexOf("-m");if(I===-1||I===l.length-1)throw new Error("Python command with -m flag must specify a module");let n=l[I+1];this.logger.log(`Converting Python module: ${n} to pipx command`);let r=["run",n];for(let a=I+2;a<l.length;a++)r.push(l[a]);for(let a=0;a<I;a++)r.push(l[a]);return{...e,command:"pipx",args:r}}buildEnvironment(e){let l={};if(e.env)for(let[I,n]of Object.entries(e.env)){let r=n.trim();process.env[r]!==void 0&&(l[I]=process.env[r])}return l}resolveLocalServerConfig(e,l){let I=this.resolveString(e.command,l),n=this.resolveArray(e.args,l);return{...e,command:I,args:n}}resolveString(e,l){return l?e.replace(/\$(?:\{([A-Z0-9_]+)(?::-(.*?))?\}|([A-Z0-9_]+))/g,(I,n,r,a)=>{let s=l[n||a];return s!==void 0?s:r!==void 0?r:I}):e}resolveArray(e,l){return e?l?e.map(I=>this.resolveString(I,l)):e:[]}resolveHeaders(e,l){if(!e)return{};if(!l)return e;let I={};for(let[n,r]of Object.entries(e)){let a=this.resolveArray([r],l);I[n]=a[0]}return I}async processServers(e){if(!e)throw new Error("No servers to process");let l=Object.entries(e.mcpServers).map(([I,n])=>this.processServer(I,n));await Promise.all(l)}async processServer(e,l){if(!this.validateServerConfig(e,l)){this.logger.error(`Skipping server "${e}" due to invalid configuration.`);return}try{XD(l)?await this.processLocalServer(e,l):mre(l)&&this.remoteEnabled?await this.processHttpServer(e,l):Gre(l)&&this.remoteEnabled?await this.processSseServer(e,l):bre(l)&&await this.processInMemoryServer(e,l)}catch(I){e!==kx&&await this.logServerFailure(e,I)}}async logServerFailure(e,l){if(this.sessionClient)try{await this.sessionClient.logMCPSetup(e,`<error>MCP server failed to start: ${l.message} - for the full output, see the verbose logs</error>`)}catch(I){this.logger.error(`Failed to log failure for MCP Server '${e}': '${I}'`)}}};var UWe=class{constructor(e,l,I){this.logger=e;let n;if(typeof l=="string"){if(n=JSON.parse(l),typeof n!="object")throw new Error("Invalid MCP configuration: must be an object");if(n===null||!("mcpServers"in n)||typeof n.mcpServers!="object")throw new Error("Invalid MCP configuration: missing or invalid mcpServers property");this.config=n}else this.config=l;this.disabledServers=new Set(I||[]),this.registry=new OWe(this.logger),this.processor=new TWe(this.logger,this.registry,{mcp3pEnabled:!0,remoteEnabled:!0})}registry;processor;config;startServersPromise=null;allTools=null;disabledServers;async startServers(){return this.startServersPromise||(this.startServersPromise=this.processServersWithExtensions()),this.startServersPromise}async injectDefaultServers(e){}async processServersWithExtensions(){await this.injectDefaultServers(this.config);let e;if(this.disabledServers.size>0){let l={};for(let[I,n]of Object.entries(this.config.mcpServers))this.disabledServers.has(I)?this.logger.log(`Skipping disabled MCP server: ${I}`):l[I]=n;e={...this.config,mcpServers:l}}else e=this.config;return this.processor.processServers(e)}async stopServers(){for(let[e,l]of Object.entries(this.registry.transports))try{await l.close()}catch(I){this.logger.error(`Error closing transport for ${e}: ${I}`)}this.startServersPromise=null,this.allTools=null}async getTools(e,l,I){if(!this.allTools){await this.startServers();let n=new Aee(e,l,I),r=[];for(let a of Object.keys(this.registry.clients)){let o=await n.loadTools({mcpClient:this.registry.clients[a],clientName:a,tools:this.config.mcpServers[a]?.tools||["*"],filterMapping:this.config.mcpServers[a]?.filterMapping||"hidden_characters"});r.push(...o)}this.allTools=r}return this.allTools}getConfig(){return this.config}async startServer(e,l){await this.startServers(),this.config.mcpServers[e]=l,await this.processor.processServer(e,l),this.allTools=null}async stopServer(e){let l=this.registry.transports[e];if(l)try{await l.close(),delete this.registry.transports[e]}catch(I){this.logger.error(`Error closing transport for ${e}: ${I}`)}this.registry.clients[e]&&delete this.registry.clients[e],this.allTools=null}async restartServer(e,l){this.isServerRunning(e)&&await this.stopServer(e),delete this.config.mcpServers[e],await this.startServer(e,l)}isServerRunning(e){return e in this.registry.transports&&e in this.registry.clients}isServerDisabled(e){return this.disabledServers.has(e)}async disableServer(e){if(this.disabledServers.has(e)){this.logger.log(`Server ${e} is already disabled`);return}this.disabledServers.add(e),this.logger.log(`Disabled server ${e} for this session`),this.isServerRunning(e)&&await this.stopServer(e),this.allTools=null}async enableServer(e){if(!this.disabledServers.has(e)){this.logger.log(`Server ${e} is not disabled`);return}this.disabledServers.delete(e),this.logger.log(`Enabled server ${e} for this session`);let l=this.getServerConfig(e);l?await this.startServer(e,l):await this.startBuiltInServer(e),this.allTools=null}async startBuiltInServer(e){}getServerConfig(e){return this.config.mcpServers[e]}};c();var xBl="/login/device/code",SBl="/login/oauth/access_token",aYt="Ov23ctDVkRmgkPke0Mmm",U2="https://github.com",l5=class extends Error{constructor(l,I){super(I);this.status=l;this.message=I;this.name="GitHubApiError"}};function oYt(t){let e=new URL(t);return e.hostname.startsWith("api.")||(e.hostname="api."+e.hostname),e.href}async function sYt(t){let e=new URL(xBl,t),l=await fetch(e.href,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json"},body:new URLSearchParams({client_id:aYt,scope:"user:email,read:user,repo,workflow"})});if(!l.ok)throw new l5(l.status,`Failed to request device code: ${l.statusText}`);return await l.json()}async function cYt(t,e){let l=new URL(SBl,t),I=await fetch(l.href,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json"},body:new URLSearchParams({client_id:aYt,device_code:e,grant_type:"urn:ietf:params:oauth:grant-type:device_code"})});if(!I.ok)throw new l5(I.status,`Failed to authorize: ${I.statusText}`);let n=await I.json();if(typeof n.access_token=="string")return n.access_token;if(n.error!=="authorization_pending"&&n.error!=="slow_down")throw new Error(n.error_description||`Unexpected error: ${n.error}`)}async function JD(t,e){let l=new URL("/user",oYt(t)),I=await fetch(l.href,{headers:{Authorization:`Bearer ${e}`,Accept:"application/json"}});if(!I.ok)throw new l5(I.status,`Failed to fetch user info: ${I.statusText}`);return(await I.json()).login}async function kD(t,e){let l=`
|
|
1597
1597
|
{
|
|
1598
1598
|
viewer {
|
|
1599
1599
|
copilotEndpoints {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@github/copilot",
|
|
3
3
|
"description": "GitHub Copilot CLI brings the power of Copilot coding agent directly to your terminal.",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.336-0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"sdk/**/*"
|
|
34
34
|
],
|
|
35
35
|
"buildMetadata": {
|
|
36
|
-
"gitCommit": "
|
|
36
|
+
"gitCommit": "b97079f"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"node-pty": "npm:@devm33/node-pty@^1.0.8",
|