@gitlab/duo-cli 8.16.0 → 8.16.1

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/dist/index.js CHANGED
@@ -1169,7 +1169,7 @@ ${mOA(E)}`:""};if(typeof D==="string"){let F=Q?`
1169
1169
  ${B(Q)}`:"";this.#I(`${D}${F}${I(Q)}`,A)}else{let F=uH1(D);if(!F)return;this.#I(`${B(F)}${I(D)}`,A)}}#I(A,D){let Q=`${mH1.default().format("YYYY-MM-DDTHH:mm:ss:SSS")} [${D}]: `,B=(I)=>I.replace(/\n/g,`
1170
1170
  ${" ".repeat(uOA)}`);this.#A.write(`${Q}${B(A)}`)}setContext(A){this.#Q=A}debug(A,D){this.#B(dD.DEBUG,A,D)}info(A,D){this.#B(dD.INFO,A,D)}warn(A,D){this.#B(dD.WARNING,A,D)}error(A,D){this.#B(dD.ERROR,A,D)}withContext(A){let D=new bW(this.#A,this.#D);return D.setContext(A),D}}bW=_0([pH1.Injectable(e0,[Ej,Fj])],bW);function lH1(A){return(A.split(`
1171
1171
  `).find((D)=>D.trim())??A.replace(`
1172
- `,"")).trim()}function pOA(A){return lH1(A).match(/^(query|mutation|subscription)\s+/)?.[1]}function dOA(A){return lH1(A).match(/(?:query|mutation|subscription)\s+(\w+)/)?.[1]}function hy(A){let D=pOA(A),Q=dOA(A);if(D)return`${D}: ${Q??"anonymous"}`;return}var lOA=(A)=>{if(A.method==="GET"||A.method==="HEAD")return;if(!A.body)return;return ED("Body",JSON.stringify(A.body))},cOA=(A)=>{if(A.method==="POST"||A.method==="PATCH"||A.method==="PUT")return;if(!A.searchParams)return;return ED("Search Params",JSON.stringify(A.searchParams))},iOA=(A)=>{if(!A.headers)return;return ED("Headers",JSON.stringify(A.headers))},Jj=(A)=>{switch(A.type){case"graphql":return LF("GraphQL Request",ED("Query",A.query.replace(/[\s\n]+/g," ").trim()),ED("Variables",JSON.stringify(A.variables)));case"rest":return LF("REST Request",ED("Method",A.method),ED("Path",A.path),iOA(A),cOA(A),lOA(A));default:return ED("Unknown request type",A.type)}};var nH1=(A)=>{try{return JSON.parse(A)?.error}catch{return}},nOA=(A)=>{if(!A)return"";try{return JSON.parse(A)?.error_description??""}catch{return""}},br=(A,D)=>Boolean(A.status===401&&D&&nH1(D)==="invalid_token"),yr=(A,D)=>Boolean(A.status===400&&D&&nH1(D)==="invalid_grant");class uy extends Error{request;cause;constructor(A,D,Q){super(A);this.request=D,this.cause=Q?.cause}get sanitizedMessage(){return"API request failed"}}class gr extends uy{status;constructor(A,D,Q,B){super(A,D,B);this.status=Q}}class oH1 extends gr{type="rest";response;#A;constructor(A,D,Q,B){let I=`Fetching ${Q} from ${D.url} failed. ${nOA(B)}`;if(br(D,B))I=`Request for ${Q} failed because the token is expired or revoked.`;if(yr(D,B))I="Request to refresh token failed, because it's revoked or already refreshed.";super(I,A,D.status);this.response=D,this.#A=B}isInvalidTokenOrInvalidRefresh(){return br(this.response,this.#A)||yr(this.response,this.#A)}get ctx(){return LF("Error details",Jj(this.request),this.#D())}get sanitizedMessage(){if(br(this.response,this.#A))return"Request failed because the token is expired or revoked.";if(yr(this.response,this.#A))return"Request to refresh token failed, because it's revoked or already refreshed.";return`Request failed with error code: ${this.response.status}`}#D(){let A=Object.fromEntries(this.response.headers.entries());return LF("Response",ED("Status",String(this.status)),!iH1.default.isEmpty(A)?ED("Headers",JSON.stringify(A)):void 0,this.#A?ED("Response body",this.#A):void 0)}get body(){return this.#A}}var cH1=(A)=>A.errors?.map((D)=>D.message).join(",")||"";class fr extends gr{type="graphql";graphQlResponse;#A;constructor(A,D){let Q=hy(A.query),B=`GraphQL request "${Q}" failed with ${cH1(D)}`;super(B,A,D.status);this.graphQlResponse=D,this.#A=Q}get sanitizedMessage(){return`GraphQL request "${this.#A}" failed with status ${this.graphQlResponse.status}`}get ctx(){return LF("Error details",Jj(this.request),this.#D())}#D(){return LF("Response",ED("Status",String(this.graphQlResponse.status)),ED("Errors",cH1(this.graphQlResponse)))}}class my extends uy{type="network";cause;constructor(A,D){let Q=D instanceof Error?D.message:`Network error occurred: ${D}`;super(Q,A);this.cause=D}get ctx(){return LF("Error details",Jj(this.request),this.#A())}get sanitizedMessage(){let A=this.cause,D=A?.code||A?.errno,Q=this.#D(D);return`Network error occurred${Q?`: ${Q}`:""}`}#A(){if(!this.cause||!(this.cause instanceof Error))return;let A=this.cause;if(A.code||A.errno){let D=A.code||A.errno,Q=this.#D(D),B=Q?`${Q} (${D})`:`Error code: ${D}`;return ED("Network issue",B)}return}#D(A){return{ENOTFOUND:"DNS lookup failed - hostname could not be resolved",ECONNREFUSED:"Connection refused - server is not accepting connections",ECONNRESET:"Connection reset by peer - server closed the connection unexpectedly",ETIMEDOUT:"Connection timed out - server did not respond in time",EHOSTUNREACH:"Host unreachable - network route to server not available",ENETUNREACH:"Network unreachable - no network connectivity",ECONNABORTED:"Connection aborted - request was cancelled",EBADF:"Bad file descriptor - network connection issue",EPIPE:"Broken pipe - connection closed while writing data",EAI_AGAIN:"DNS lookup failed temporarily - try again later"}[A]}}class oOA extends uy{type="timeout";#A;constructor(A,D){let Q=`Request timed out${D?` after ${D}ms`:""}`;super(Q,A);this.#A=Q}get ctx(){return LF("Error details",Jj(this.request))}get sanitizedMessage(){return this.#A}}var aH1=oH1;var hr={type:"rest",method:"GET",path:"/api/v4/version"};var py=JSON;var rH1=(A)=>A.toUpperCase(),sH1=(A)=>{let D={};return A.forEach((Q,B)=>{D[B]=Q}),D};var tH1=(A,D,Q)=>{return A.document?A:{document:A,variables:D,requestHeaders:Q,signal:void 0}},eH1=(A,D,Q)=>{return A.query?A:{query:A,variables:D,requestHeaders:Q,signal:void 0}},AZ1=(A,D)=>{return A.documents?A:{documents:A,requestHeaders:D,signal:void 0}};var ug=HA(nM1(),1),oM1=(A)=>{let D=void 0,Q=A.definitions.filter((B)=>B.kind==="OperationDefinition");if(Q.length===1)D=Q[0]?.name?.value;return D},eW=(A)=>{if(typeof A==="string"){let Q=void 0;try{let B=ug.parse(A);Q=oM1(B)}catch(B){}return{query:A,operationName:Q}}let D=oM1(A);return{query:ug.print(A),operationName:D}};class jI extends Error{constructor(A,D){let Q=`${jI.extractMessage(A)}: ${JSON.stringify({response:A,request:D})}`;super(Q);if(Object.setPrototypeOf(this,jI.prototype),this.response=A,this.request=D,typeof Error.captureStackTrace==="function")Error.captureStackTrace(this,jI)}static extractMessage(A){return A.errors?.[0]?.message??`GraphQL Error (Code: ${A.status})`}}var CU=HA(gO1(),1);var PhA="connection_init",RhA="connection_ack",hO1="ping",uO1="pong",jhA="subscribe",ThA="next",ShA="error",mO1="complete";class GU{get type(){return this._type}get id(){return this._id}get payload(){return this._payload}constructor(A,D,Q){this._type=A,this._payload=D,this._id=Q}get text(){let A={type:this.type};if(this.id!=null&&this.id!=null)A.id=this.id;if(this.payload!=null&&this.payload!=null)A.payload=this.payload;return JSON.stringify(A)}static parse(A,D){let{type:Q,payload:B,id:I}=JSON.parse(A);return new GU(Q,D(B),I)}}class Ne{constructor(A,{onInit:D,onAcknowledged:Q,onPing:B,onPong:I}){this.socketState={acknowledged:!1,lastRequestId:0,subscriptions:{}},this.socket=A,A.addEventListener("open",async(F)=>{this.socketState.acknowledged=!1,this.socketState.subscriptions={},A.send(khA(D?await D():null).text)}),A.addEventListener("close",(F)=>{this.socketState.acknowledged=!1,this.socketState.subscriptions={}}),A.addEventListener("error",(F)=>{console.error(F)}),A.addEventListener("message",(F)=>{try{let E=vhA(F.data);switch(E.type){case RhA:{if(this.socketState.acknowledged)console.warn("Duplicate CONNECTION_ACK message ignored");else if(this.socketState.acknowledged=!0,Q)Q(E.payload);return}case hO1:{if(B)B(E.payload).then((G)=>A.send(fO1(G).text));else A.send(fO1(null).text);return}case uO1:{if(I)I(E.payload);return}}if(!this.socketState.acknowledged)return;if(E.id===void 0||E.id===null||!this.socketState.subscriptions[E.id])return;let{query:J,variables:$,subscriber:Y}=this.socketState.subscriptions[E.id];switch(E.type){case ThA:{if(!E.payload.errors&&E.payload.data)Y.next&&Y.next(E.payload.data);if(E.payload.errors)Y.error&&Y.error(new jI({...E.payload,status:200},{query:J,variables:$}));return}case ShA:{Y.error&&Y.error(new jI({errors:E.payload,status:200},{query:J,variables:$}));return}case mO1:{Y.complete&&Y.complete(),delete this.socketState.subscriptions[E.id];return}}}catch(E){console.error(E),A.close(1006)}A.close(4400,"Unknown graphql-ws message.")})}makeSubscribe(A,D,Q,B){let I=(this.socketState.lastRequestId++).toString();return this.socketState.subscriptions[I]={query:A,variables:B,subscriber:Q},this.socket.send(_hA(I,{query:A,operationName:D,variables:B}).text),()=>{this.socket.send(bhA(I).text),delete this.socketState.subscriptions[I]}}rawRequest(A,D){return new Promise((Q,B)=>{let I;this.rawSubscribe(A,{next:(F,E)=>I={data:F,extensions:E},error:B,complete:()=>Q(I)},D)})}request(A,D){return new Promise((Q,B)=>{let I;this.subscribe(A,{next:(F)=>I=F,error:B,complete:()=>Q(I)},D)})}subscribe(A,D,Q){let{query:B,operationName:I}=eW(A);return this.makeSubscribe(B,I,D,Q)}rawSubscribe(A,D,Q){return this.makeSubscribe(A,void 0,D,Q)}ping(A){this.socket.send(xhA(A).text)}close(){this.socket.close(1000)}}Ne.PROTOCOL="graphql-transport-ws";function vhA(A,D=(Q)=>Q){return GU.parse(A,D)}function khA(A){return new GU(PhA,A)}function xhA(A){return new GU(hO1,A,void 0)}function fO1(A){return new GU(uO1,A,void 0)}function _hA(A,D){return new GU(jhA,D,A)}function bhA(A){return new GU(mO1,void 0,A)}var LM=(A)=>{let D={};if(A)if(typeof Headers<"u"&&A instanceof Headers||CU&&CU.Headers&&A instanceof CU.Headers)D=sH1(A);else if(Array.isArray(A))A.forEach(([Q,B])=>{if(Q&&B!==void 0)D[Q]=B});else D=A;return D},pO1=(A)=>A.replace(/([\s,]|#[^\n\r]+)+/g," ").trim(),yhA=(A)=>{if(!Array.isArray(A.query)){let B=A,I=[`query=${encodeURIComponent(pO1(B.query))}`];if(A.variables)I.push(`variables=${encodeURIComponent(B.jsonSerializer.stringify(B.variables))}`);if(B.operationName)I.push(`operationName=${encodeURIComponent(B.operationName)}`);return I.join("&")}if(typeof A.variables<"u"&&!Array.isArray(A.variables))throw Error("Cannot create query with given variable type, array expected");let D=A,Q=A.query.reduce((B,I,F)=>{return B.push({query:pO1(I),variables:D.variables?D.jsonSerializer.stringify(D.variables[F]):void 0}),B},[]);return`query=${encodeURIComponent(D.jsonSerializer.stringify(Q))}`},ghA=(A)=>async(D)=>{let{url:Q,query:B,variables:I,operationName:F,fetch:E,fetchOptions:J,middleware:$}=D,Y={...D.headers},G="",U=void 0;if(A==="POST"){if(U=fhA(B,I,F,J.jsonSerializer),typeof U==="string")Y["Content-Type"]="application/json"}else G=yhA({query:B,variables:I,operationName:F,jsonSerializer:J.jsonSerializer??py});let H={method:A,headers:Y,body:U,...J},C=Q,Z=H;if($){let W=await Promise.resolve($({...H,url:Q,operationName:F,variables:I})),{url:q,...M}=W;C=q,Z=M}if(G)C=`${C}?${G}`;return await E(C,Z)};class Re{constructor(A,D={}){this.url=A,this.requestConfig=D,this.rawRequest=async(...Q)=>{let[B,I,F]=Q,E=eH1(B,I,F),{headers:J,fetch:$=CU.default,method:Y="POST",requestMiddleware:G,responseMiddleware:U,...H}=this.requestConfig,{url:C}=this;if(E.signal!==void 0)H.signal=E.signal;let{operationName:Z}=eW(E.query);return Le({url:C,query:E.query,variables:E.variables,headers:{...LM(Pe(J)),...LM(E.requestHeaders)},operationName:Z,fetch:$,method:Y,fetchOptions:H,middleware:G}).then((W)=>{if(U)U(W);return W}).catch((W)=>{if(U)U(W);throw W})}}async request(A,...D){let[Q,B]=D,I=tH1(A,Q,B),{headers:F,fetch:E=CU.default,method:J="POST",requestMiddleware:$,responseMiddleware:Y,...G}=this.requestConfig,{url:U}=this;if(I.signal!==void 0)G.signal=I.signal;let{query:H,operationName:C}=eW(I.document);return Le({url:U,query:H,variables:I.variables,headers:{...LM(Pe(F)),...LM(I.requestHeaders)},operationName:C,fetch:E,method:J,fetchOptions:G,middleware:$}).then((Z)=>{if(Y)Y(Z);return Z.data}).catch((Z)=>{if(Y)Y(Z);throw Z})}batchRequests(A,D){let Q=AZ1(A,D),{headers:B,...I}=this.requestConfig;if(Q.signal!==void 0)I.signal=Q.signal;let F=Q.documents.map(({document:J})=>eW(J).query),E=Q.documents.map(({variables:J})=>J);return Le({url:this.url,query:F,variables:E,headers:{...LM(Pe(B)),...LM(Q.requestHeaders)},operationName:void 0,fetch:this.requestConfig.fetch??CU.default,method:this.requestConfig.method||"POST",fetchOptions:I,middleware:this.requestConfig.requestMiddleware}).then((J)=>{if(this.requestConfig.responseMiddleware)this.requestConfig.responseMiddleware(J);return J.data}).catch((J)=>{if(this.requestConfig.responseMiddleware)this.requestConfig.responseMiddleware(J);throw J})}setHeaders(A){return this.requestConfig.headers=A,this}setHeader(A,D){let{headers:Q}=this.requestConfig;if(Q)Q[A]=D;else this.requestConfig.headers={[A]:D};return this}setEndpoint(A){return this.url=A,this}}var Le=async(A)=>{let{query:D,variables:Q,fetchOptions:B}=A,I=ghA(rH1(A.method??"post")),F=Array.isArray(A.query),E=await I(A),J=await hhA(E,B.jsonSerializer??py),$=Array.isArray(J)?!J.some(({data:G})=>!G):Boolean(J.data),Y=Array.isArray(J)||!J.errors||Array.isArray(J.errors)&&!J.errors.length||B.errorPolicy==="all"||B.errorPolicy==="ignore";if(E.ok&&Y&&$){let{errors:G,...U}=Array.isArray(J)?J:J,H=B.errorPolicy==="ignore"?U:J;return{...F?{data:H}:H,headers:E.headers,status:E.status}}else throw new jI({...typeof J==="string"?{error:J}:J,status:E.status,headers:E.headers},{query:D,variables:Q})};var fhA=(A,D,Q,B)=>{let I=B??py;if(!Array.isArray(A))return I.stringify({query:A,variables:D,operationName:Q});if(typeof D<"u"&&!Array.isArray(D))throw Error("Cannot create request body with given variable type, array expected");let F=A.reduce((E,J,$)=>{return E.push({query:J,variables:D?D[$]:void 0}),E},[]);return I.stringify(F)},hhA=async(A,D)=>{let Q;if(A.headers.forEach((B,I)=>{if(I.toLowerCase()==="content-type")Q=B}),Q&&(Q.toLowerCase().startsWith("application/json")||Q.toLowerCase().startsWith("application/graphql+json")||Q.toLowerCase().startsWith("application/graphql-response+json")))return D.parse(await A.text());else return A.text()},Pe=(A)=>{return typeof A==="function"?A():A},Bz=(A,...D)=>{return A.reduce((Q,B,I)=>`${Q}${B}${I in D?String(D[I]):""}`,"")};var dO1=async(A,D,Q)=>{if(!D.ok){let B=await D.text().catch(()=>{return});throw new aH1(A,D,Q,B)}};function qY(){return"8.16.0"}var lO1=(A)=>{let D=A?`${A?.name}:${A?.version}`:"missing client info";return`gitlab-language-server:${qY()} (${D})`};function cO1(A){return A!==null&&A!==void 0}var je=(A,D)=>{return Object.entries(D).forEach(([Q,B])=>{if(cO1(B))A.searchParams.append(Q,String(B))}),A},ng=(A)=>A.toString().replace(/\/?$/,"/"),PM=(A)=>A.replace(/^\.?\/?/,"./"),iO1=(A)=>{if(A.startsWith("git@")){let D=A.match(/git@([^:]+):(.+)/);if(D){let[,Q,B]=D;return`https://${Q}/${B}`}}if(A.startsWith("git://"))return A.replace("git://","https://");if(A.startsWith("ssh://"))return A.replace("ssh://","https://").replace(/git@([^/]+)/,"$1");return A};var uhA=(A)=>A.split("/").pop()||"unknown resource";class Te{#A;#D;#Q;#B;#F;constructor(A,D,Q,B,I){this.#A=A,this.#D=D,this.#Q=new URL(ng(B)),this.#B=I,this.#F=Q}getDefaultHeaders(){return{Authorization:`Bearer ${this.#B}`,"User-Agent":lO1(this.#F),"X-Gitlab-Language-Server-Version":qY()}}async fetchFromApiRaw(A){try{let D=`Unknown request method "${A.method}", request type "${A.type}"`;switch(A.method){case"GET":return await this.#E(A);case"POST":return await this.#J(A);case"PATCH":return await this.#$(A);case"PUT":return await this.#Y(A);case"HEAD":return await this.#X(A);default:throw Error(D)}}catch(D){throw new my(A,D)}}async fetchFromApi(A){if(A.type==="graphql")return this.#I(A);let D=await this.fetchFromApiRaw(A);return await dO1(A,D,uhA(A.path)),D.json()}fetchOperation=(A)=>(D)=>this.fetchFromApi({...A,signal:D});async#I(A){let D=new URL("./api/graphql",this.#Q),Q=hy(A.query);if(Q)this.#A.debug(`[SimpleApiClient] Making GraphQL request: ${Q}`);let B=async(F,E)=>{let J=F instanceof URL?F.toString():F;return this.#D.post(J,{...E,headers:{...E?.headers},signal:A.signal})},I=new Re(D.href,{fetch:B,headers:{...this.getDefaultHeaders()}});try{return await I.request(A.query,A.variables)}catch(F){if(F instanceof jI)throw new fr(A,F.response);throw new my(A,F)}}async#E(A){let D=PM(A.path),Q=new URL(D,this.#Q);return je(Q,A.searchParams??{}),this.#D.get(Q,{headers:{...this.getDefaultHeaders(),...A.headers},signal:A.signal})}async#J(A){let D=PM(A.path),Q=new URL(D,this.#Q);return this.#D.post(Q,{headers:{"Content-Type":"application/json",...this.getDefaultHeaders(),...A.headers},body:JSON.stringify(A.body),signal:A.signal})}async#$(A){let D=PM(A.path),Q=new URL(D,this.#Q);return this.#D.patch(Q,{headers:{"Content-Type":"application/json",...this.getDefaultHeaders(),...A.headers},body:JSON.stringify(A.body),signal:A.signal})}async#Y(A){let D=PM(A.path),Q=new URL(D,this.#Q);return this.#D.put(Q,{headers:{"Content-Type":"application/json",...this.getDefaultHeaders(),...A.headers},body:JSON.stringify(A.body),signal:A.signal})}async#X(A){let D=PM(A.path),Q=new URL(D,this.#Q);return je(Q,A.searchParams??{}),this.#D.head(Q,{headers:{...this.getDefaultHeaders(),...A.headers},signal:A.signal})}}var nO1=HA(m0(),1),oO1=nO1.createInterfaceId("UserService");var aO1=1e4,rO1=4;import phA from"events";class DT{#A="Closed";#D;#Q;#B=0;#F=new phA;#I=null;constructor(A=rO1,D=aO1){this.#D=A,this.#Q=D}error(){if(this.#B+=1,this.#B>=this.#D)this.#E()}#E(){this.#A="Open",this.#I=setTimeout(()=>this.#J(),this.#Q),this.#F.emit("open")}isOpen(){return this.#A==="Open"}#J(){if(this.#A==="Closed")return;if(this.#I)clearTimeout(this.#I);this.#A="Closed",this.#F.emit("close")}success(){this.#B=0,this.#J()}onOpen(A){return this.#F.on("open",A),{dispose:()=>this.#F.removeListener("open",A)}}onClose(A){return this.#F.on("close",A),{dispose:()=>this.#F.removeListener("close",A)}}}import dhA from"events";var lhA=1000,chA=60000,ihA=2;class nhA{#A="Closed";#D;#Q;#B;#F=0;#I=new dhA;#E=null;constructor({initialBackoffMs:A=lhA,maxBackoffMs:D=chA,backoffMultiplier:Q=ihA}={}){this.#D=A,this.#Q=D,this.#B=Q}error(){this.#F+=1,this.#J()}megaError(){this.#F+=3,this.#J()}#J(){if(this.#A==="Open")return;this.#A="Open",this.#E=setTimeout(()=>this.#$(),this.#Y()),this.#I.emit("open")}#$(){if(this.#A==="Closed")return;if(this.#E)clearTimeout(this.#E);this.#A="Closed",this.#I.emit("close")}isOpen(){return this.#A==="Open"}success(){this.#F=0,this.#$()}onOpen(A){return this.#I.on("open",A),{dispose:()=>this.#I.removeListener("open",A)}}onClose(A){return this.#I.on("close",A),{dispose:()=>this.#I.removeListener("close",A)}}#Y(){return Math.min(this.#D*this.#B**(this.#F-1),this.#Q)}}import ohA from"events";var Se="EVENT";class KU{#A;eventEmitter=new ohA;event=(A,D={})=>{let Q=(B,I)=>A.bind(D)(B,I);return this.eventEmitter.on(Se,Q),{dispose:()=>this.eventEmitter.removeListener(Se,Q)}};fire(A){if(this.#A)this.#A.abort();this.#A=new AbortController,this.eventEmitter.emit(Se,A,this.#A.signal)}dispose(){this.#A?.abort(),this.eventEmitter.removeAllListeners()}}class QT{#A;#D=0;#Q;#B=new KU;constructor(A,D){this.#A=D,this.#Q=A}error(){if(this.#D+=1,this.#F){this.#B.fire();return}this.#Q.error()}success(){this.#D=0,this.#Q.success()}onOpen(A){return this.#Q.onOpen(A)}onClose(A){return this.#Q.onClose(A)}get#F(){return this.#D>=this.#A}onReachedMaxAttempts=this.#B.event;isOpen(){return this.#F||this.#Q.isOpen()}reset(){this.#D=0,this.#Q.success()}}var Gf=HA(m0(),1);var cL1=HA(NF(),1);var TM=HA(ce(),1);function MY(A,D,Q,B){if(!TM.valid(D))throw Error(`minimumRequiredVersion argument ${D} isn't valid`);let I=TM.coerce(A);if(!I)return console.warn(`Could not parse version from "${A}", running logic for the latest GitLab version`),Q();if(TM.gte(I,D))return Q();return B()}import{Buffer as mL1}from"buffer";function uL1(A){return mL1.from(A).byteLength}function GT(A,D,Q={}){let{separator:B=/\s+/g,suffix:I}=Q;if(uL1(A)<=D)return A;let F=I?uL1(` ${I}`):0,E=Math.max(0,D-F);if(E===0&&I)return` ${I}`.slice(0,D);let J=mL1.from(A).subarray(0,E).toString(),$=[...J.matchAll(B)].pop();if($)J=J.slice(0,$.index);return I?`${J} ${I}`:J}var pL1=(A)=>{};function ie(A){let D=parseInt(A.replace(/gid:\/\/gitlab\/.*\//g,""),10);if(!D||Number.isNaN(D))return;return D}var ne=HA(NF(),1),Jf=(A,D)=>{let Q,B=D||ne.default.isEqual;return{event:A.event.bind(A),fire:(I)=>{if(!B(Q,I))Q=ne.default.cloneDeep(I),A.fire(I)},dispose:A.dispose.bind(A)}};var oe=HA(NF(),1);function $f(A){if(oe.default.isPlainObject(A)){let D={},Q=A;return Object.keys(Q).forEach((B)=>{D[oe.default.camelCase(B)]=$f(Q[B])}),D}if(Array.isArray(A))return A.map((D)=>$f(D));return A}var Yf;((F)=>{F.EditorAdvancedContext="advanced_context_resolver";F.CodeSuggestionsContext="code_suggestions_context";F.UseDuoContextExclusion="use_duo_context_exclusion";F.DuoAgenticChat="duo_agentic_chat";F.DuoWorkflow="duo_workflow"})(Yf||={});var dL1={["duo_agentic_chat"]:"18.0.0",["duo_workflow"]:"17.2.0",["advanced_context_resolver"]:"17.1.0",["code_suggestions_context"]:"17.1.0",["use_duo_context_exclusion"]:"18.2.0"},lL1={["duo_agentic_chat"]:"18.5.0",["duo_workflow"]:"18.2.0",["advanced_context_resolver"]:"17.4.0",["code_suggestions_context"]:"17.4.0"};var mpA=Bz`
1172
+ `,"")).trim()}function pOA(A){return lH1(A).match(/^(query|mutation|subscription)\s+/)?.[1]}function dOA(A){return lH1(A).match(/(?:query|mutation|subscription)\s+(\w+)/)?.[1]}function hy(A){let D=pOA(A),Q=dOA(A);if(D)return`${D}: ${Q??"anonymous"}`;return}var lOA=(A)=>{if(A.method==="GET"||A.method==="HEAD")return;if(!A.body)return;return ED("Body",JSON.stringify(A.body))},cOA=(A)=>{if(A.method==="POST"||A.method==="PATCH"||A.method==="PUT")return;if(!A.searchParams)return;return ED("Search Params",JSON.stringify(A.searchParams))},iOA=(A)=>{if(!A.headers)return;return ED("Headers",JSON.stringify(A.headers))},Jj=(A)=>{switch(A.type){case"graphql":return LF("GraphQL Request",ED("Query",A.query.replace(/[\s\n]+/g," ").trim()),ED("Variables",JSON.stringify(A.variables)));case"rest":return LF("REST Request",ED("Method",A.method),ED("Path",A.path),iOA(A),cOA(A),lOA(A));default:return ED("Unknown request type",A.type)}};var nH1=(A)=>{try{return JSON.parse(A)?.error}catch{return}},nOA=(A)=>{if(!A)return"";try{return JSON.parse(A)?.error_description??""}catch{return""}},br=(A,D)=>Boolean(A.status===401&&D&&nH1(D)==="invalid_token"),yr=(A,D)=>Boolean(A.status===400&&D&&nH1(D)==="invalid_grant");class uy extends Error{request;cause;constructor(A,D,Q){super(A);this.request=D,this.cause=Q?.cause}get sanitizedMessage(){return"API request failed"}}class gr extends uy{status;constructor(A,D,Q,B){super(A,D,B);this.status=Q}}class oH1 extends gr{type="rest";response;#A;constructor(A,D,Q,B){let I=`Fetching ${Q} from ${D.url} failed. ${nOA(B)}`;if(br(D,B))I=`Request for ${Q} failed because the token is expired or revoked.`;if(yr(D,B))I="Request to refresh token failed, because it's revoked or already refreshed.";super(I,A,D.status);this.response=D,this.#A=B}isInvalidTokenOrInvalidRefresh(){return br(this.response,this.#A)||yr(this.response,this.#A)}get ctx(){return LF("Error details",Jj(this.request),this.#D())}get sanitizedMessage(){if(br(this.response,this.#A))return"Request failed because the token is expired or revoked.";if(yr(this.response,this.#A))return"Request to refresh token failed, because it's revoked or already refreshed.";return`Request failed with error code: ${this.response.status}`}#D(){let A=Object.fromEntries(this.response.headers.entries());return LF("Response",ED("Status",String(this.status)),!iH1.default.isEmpty(A)?ED("Headers",JSON.stringify(A)):void 0,this.#A?ED("Response body",this.#A):void 0)}get body(){return this.#A}}var cH1=(A)=>A.errors?.map((D)=>D.message).join(",")||"";class fr extends gr{type="graphql";graphQlResponse;#A;constructor(A,D){let Q=hy(A.query),B=`GraphQL request "${Q}" failed with ${cH1(D)}`;super(B,A,D.status);this.graphQlResponse=D,this.#A=Q}get sanitizedMessage(){return`GraphQL request "${this.#A}" failed with status ${this.graphQlResponse.status}`}get ctx(){return LF("Error details",Jj(this.request),this.#D())}#D(){return LF("Response",ED("Status",String(this.graphQlResponse.status)),ED("Errors",cH1(this.graphQlResponse)))}}class my extends uy{type="network";cause;constructor(A,D){let Q=D instanceof Error?D.message:`Network error occurred: ${D}`;super(Q,A);this.cause=D}get ctx(){return LF("Error details",Jj(this.request),this.#A())}get sanitizedMessage(){let A=this.cause,D=A?.code||A?.errno,Q=this.#D(D);return`Network error occurred${Q?`: ${Q}`:""}`}#A(){if(!this.cause||!(this.cause instanceof Error))return;let A=this.cause;if(A.code||A.errno){let D=A.code||A.errno,Q=this.#D(D),B=Q?`${Q} (${D})`:`Error code: ${D}`;return ED("Network issue",B)}return}#D(A){return{ENOTFOUND:"DNS lookup failed - hostname could not be resolved",ECONNREFUSED:"Connection refused - server is not accepting connections",ECONNRESET:"Connection reset by peer - server closed the connection unexpectedly",ETIMEDOUT:"Connection timed out - server did not respond in time",EHOSTUNREACH:"Host unreachable - network route to server not available",ENETUNREACH:"Network unreachable - no network connectivity",ECONNABORTED:"Connection aborted - request was cancelled",EBADF:"Bad file descriptor - network connection issue",EPIPE:"Broken pipe - connection closed while writing data",EAI_AGAIN:"DNS lookup failed temporarily - try again later"}[A]}}class oOA extends uy{type="timeout";#A;constructor(A,D){let Q=`Request timed out${D?` after ${D}ms`:""}`;super(Q,A);this.#A=Q}get ctx(){return LF("Error details",Jj(this.request))}get sanitizedMessage(){return this.#A}}var aH1=oH1;var hr={type:"rest",method:"GET",path:"/api/v4/version"};var py=JSON;var rH1=(A)=>A.toUpperCase(),sH1=(A)=>{let D={};return A.forEach((Q,B)=>{D[B]=Q}),D};var tH1=(A,D,Q)=>{return A.document?A:{document:A,variables:D,requestHeaders:Q,signal:void 0}},eH1=(A,D,Q)=>{return A.query?A:{query:A,variables:D,requestHeaders:Q,signal:void 0}},AZ1=(A,D)=>{return A.documents?A:{documents:A,requestHeaders:D,signal:void 0}};var ug=HA(nM1(),1),oM1=(A)=>{let D=void 0,Q=A.definitions.filter((B)=>B.kind==="OperationDefinition");if(Q.length===1)D=Q[0]?.name?.value;return D},eW=(A)=>{if(typeof A==="string"){let Q=void 0;try{let B=ug.parse(A);Q=oM1(B)}catch(B){}return{query:A,operationName:Q}}let D=oM1(A);return{query:ug.print(A),operationName:D}};class jI extends Error{constructor(A,D){let Q=`${jI.extractMessage(A)}: ${JSON.stringify({response:A,request:D})}`;super(Q);if(Object.setPrototypeOf(this,jI.prototype),this.response=A,this.request=D,typeof Error.captureStackTrace==="function")Error.captureStackTrace(this,jI)}static extractMessage(A){return A.errors?.[0]?.message??`GraphQL Error (Code: ${A.status})`}}var CU=HA(gO1(),1);var PhA="connection_init",RhA="connection_ack",hO1="ping",uO1="pong",jhA="subscribe",ThA="next",ShA="error",mO1="complete";class GU{get type(){return this._type}get id(){return this._id}get payload(){return this._payload}constructor(A,D,Q){this._type=A,this._payload=D,this._id=Q}get text(){let A={type:this.type};if(this.id!=null&&this.id!=null)A.id=this.id;if(this.payload!=null&&this.payload!=null)A.payload=this.payload;return JSON.stringify(A)}static parse(A,D){let{type:Q,payload:B,id:I}=JSON.parse(A);return new GU(Q,D(B),I)}}class Ne{constructor(A,{onInit:D,onAcknowledged:Q,onPing:B,onPong:I}){this.socketState={acknowledged:!1,lastRequestId:0,subscriptions:{}},this.socket=A,A.addEventListener("open",async(F)=>{this.socketState.acknowledged=!1,this.socketState.subscriptions={},A.send(khA(D?await D():null).text)}),A.addEventListener("close",(F)=>{this.socketState.acknowledged=!1,this.socketState.subscriptions={}}),A.addEventListener("error",(F)=>{console.error(F)}),A.addEventListener("message",(F)=>{try{let E=vhA(F.data);switch(E.type){case RhA:{if(this.socketState.acknowledged)console.warn("Duplicate CONNECTION_ACK message ignored");else if(this.socketState.acknowledged=!0,Q)Q(E.payload);return}case hO1:{if(B)B(E.payload).then((G)=>A.send(fO1(G).text));else A.send(fO1(null).text);return}case uO1:{if(I)I(E.payload);return}}if(!this.socketState.acknowledged)return;if(E.id===void 0||E.id===null||!this.socketState.subscriptions[E.id])return;let{query:J,variables:$,subscriber:Y}=this.socketState.subscriptions[E.id];switch(E.type){case ThA:{if(!E.payload.errors&&E.payload.data)Y.next&&Y.next(E.payload.data);if(E.payload.errors)Y.error&&Y.error(new jI({...E.payload,status:200},{query:J,variables:$}));return}case ShA:{Y.error&&Y.error(new jI({errors:E.payload,status:200},{query:J,variables:$}));return}case mO1:{Y.complete&&Y.complete(),delete this.socketState.subscriptions[E.id];return}}}catch(E){console.error(E),A.close(1006)}A.close(4400,"Unknown graphql-ws message.")})}makeSubscribe(A,D,Q,B){let I=(this.socketState.lastRequestId++).toString();return this.socketState.subscriptions[I]={query:A,variables:B,subscriber:Q},this.socket.send(_hA(I,{query:A,operationName:D,variables:B}).text),()=>{this.socket.send(bhA(I).text),delete this.socketState.subscriptions[I]}}rawRequest(A,D){return new Promise((Q,B)=>{let I;this.rawSubscribe(A,{next:(F,E)=>I={data:F,extensions:E},error:B,complete:()=>Q(I)},D)})}request(A,D){return new Promise((Q,B)=>{let I;this.subscribe(A,{next:(F)=>I=F,error:B,complete:()=>Q(I)},D)})}subscribe(A,D,Q){let{query:B,operationName:I}=eW(A);return this.makeSubscribe(B,I,D,Q)}rawSubscribe(A,D,Q){return this.makeSubscribe(A,void 0,D,Q)}ping(A){this.socket.send(xhA(A).text)}close(){this.socket.close(1000)}}Ne.PROTOCOL="graphql-transport-ws";function vhA(A,D=(Q)=>Q){return GU.parse(A,D)}function khA(A){return new GU(PhA,A)}function xhA(A){return new GU(hO1,A,void 0)}function fO1(A){return new GU(uO1,A,void 0)}function _hA(A,D){return new GU(jhA,D,A)}function bhA(A){return new GU(mO1,void 0,A)}var LM=(A)=>{let D={};if(A)if(typeof Headers<"u"&&A instanceof Headers||CU&&CU.Headers&&A instanceof CU.Headers)D=sH1(A);else if(Array.isArray(A))A.forEach(([Q,B])=>{if(Q&&B!==void 0)D[Q]=B});else D=A;return D},pO1=(A)=>A.replace(/([\s,]|#[^\n\r]+)+/g," ").trim(),yhA=(A)=>{if(!Array.isArray(A.query)){let B=A,I=[`query=${encodeURIComponent(pO1(B.query))}`];if(A.variables)I.push(`variables=${encodeURIComponent(B.jsonSerializer.stringify(B.variables))}`);if(B.operationName)I.push(`operationName=${encodeURIComponent(B.operationName)}`);return I.join("&")}if(typeof A.variables<"u"&&!Array.isArray(A.variables))throw Error("Cannot create query with given variable type, array expected");let D=A,Q=A.query.reduce((B,I,F)=>{return B.push({query:pO1(I),variables:D.variables?D.jsonSerializer.stringify(D.variables[F]):void 0}),B},[]);return`query=${encodeURIComponent(D.jsonSerializer.stringify(Q))}`},ghA=(A)=>async(D)=>{let{url:Q,query:B,variables:I,operationName:F,fetch:E,fetchOptions:J,middleware:$}=D,Y={...D.headers},G="",U=void 0;if(A==="POST"){if(U=fhA(B,I,F,J.jsonSerializer),typeof U==="string")Y["Content-Type"]="application/json"}else G=yhA({query:B,variables:I,operationName:F,jsonSerializer:J.jsonSerializer??py});let H={method:A,headers:Y,body:U,...J},C=Q,Z=H;if($){let W=await Promise.resolve($({...H,url:Q,operationName:F,variables:I})),{url:q,...M}=W;C=q,Z=M}if(G)C=`${C}?${G}`;return await E(C,Z)};class Re{constructor(A,D={}){this.url=A,this.requestConfig=D,this.rawRequest=async(...Q)=>{let[B,I,F]=Q,E=eH1(B,I,F),{headers:J,fetch:$=CU.default,method:Y="POST",requestMiddleware:G,responseMiddleware:U,...H}=this.requestConfig,{url:C}=this;if(E.signal!==void 0)H.signal=E.signal;let{operationName:Z}=eW(E.query);return Le({url:C,query:E.query,variables:E.variables,headers:{...LM(Pe(J)),...LM(E.requestHeaders)},operationName:Z,fetch:$,method:Y,fetchOptions:H,middleware:G}).then((W)=>{if(U)U(W);return W}).catch((W)=>{if(U)U(W);throw W})}}async request(A,...D){let[Q,B]=D,I=tH1(A,Q,B),{headers:F,fetch:E=CU.default,method:J="POST",requestMiddleware:$,responseMiddleware:Y,...G}=this.requestConfig,{url:U}=this;if(I.signal!==void 0)G.signal=I.signal;let{query:H,operationName:C}=eW(I.document);return Le({url:U,query:H,variables:I.variables,headers:{...LM(Pe(F)),...LM(I.requestHeaders)},operationName:C,fetch:E,method:J,fetchOptions:G,middleware:$}).then((Z)=>{if(Y)Y(Z);return Z.data}).catch((Z)=>{if(Y)Y(Z);throw Z})}batchRequests(A,D){let Q=AZ1(A,D),{headers:B,...I}=this.requestConfig;if(Q.signal!==void 0)I.signal=Q.signal;let F=Q.documents.map(({document:J})=>eW(J).query),E=Q.documents.map(({variables:J})=>J);return Le({url:this.url,query:F,variables:E,headers:{...LM(Pe(B)),...LM(Q.requestHeaders)},operationName:void 0,fetch:this.requestConfig.fetch??CU.default,method:this.requestConfig.method||"POST",fetchOptions:I,middleware:this.requestConfig.requestMiddleware}).then((J)=>{if(this.requestConfig.responseMiddleware)this.requestConfig.responseMiddleware(J);return J.data}).catch((J)=>{if(this.requestConfig.responseMiddleware)this.requestConfig.responseMiddleware(J);throw J})}setHeaders(A){return this.requestConfig.headers=A,this}setHeader(A,D){let{headers:Q}=this.requestConfig;if(Q)Q[A]=D;else this.requestConfig.headers={[A]:D};return this}setEndpoint(A){return this.url=A,this}}var Le=async(A)=>{let{query:D,variables:Q,fetchOptions:B}=A,I=ghA(rH1(A.method??"post")),F=Array.isArray(A.query),E=await I(A),J=await hhA(E,B.jsonSerializer??py),$=Array.isArray(J)?!J.some(({data:G})=>!G):Boolean(J.data),Y=Array.isArray(J)||!J.errors||Array.isArray(J.errors)&&!J.errors.length||B.errorPolicy==="all"||B.errorPolicy==="ignore";if(E.ok&&Y&&$){let{errors:G,...U}=Array.isArray(J)?J:J,H=B.errorPolicy==="ignore"?U:J;return{...F?{data:H}:H,headers:E.headers,status:E.status}}else throw new jI({...typeof J==="string"?{error:J}:J,status:E.status,headers:E.headers},{query:D,variables:Q})};var fhA=(A,D,Q,B)=>{let I=B??py;if(!Array.isArray(A))return I.stringify({query:A,variables:D,operationName:Q});if(typeof D<"u"&&!Array.isArray(D))throw Error("Cannot create request body with given variable type, array expected");let F=A.reduce((E,J,$)=>{return E.push({query:J,variables:D?D[$]:void 0}),E},[]);return I.stringify(F)},hhA=async(A,D)=>{let Q;if(A.headers.forEach((B,I)=>{if(I.toLowerCase()==="content-type")Q=B}),Q&&(Q.toLowerCase().startsWith("application/json")||Q.toLowerCase().startsWith("application/graphql+json")||Q.toLowerCase().startsWith("application/graphql-response+json")))return D.parse(await A.text());else return A.text()},Pe=(A)=>{return typeof A==="function"?A():A},Bz=(A,...D)=>{return A.reduce((Q,B,I)=>`${Q}${B}${I in D?String(D[I]):""}`,"")};var dO1=async(A,D,Q)=>{if(!D.ok){let B=await D.text().catch(()=>{return});throw new aH1(A,D,Q,B)}};function qY(){return"8.16.1"}var lO1=(A)=>{let D=A?`${A?.name}:${A?.version}`:"missing client info";return`gitlab-language-server:${qY()} (${D})`};function cO1(A){return A!==null&&A!==void 0}var je=(A,D)=>{return Object.entries(D).forEach(([Q,B])=>{if(cO1(B))A.searchParams.append(Q,String(B))}),A},ng=(A)=>A.toString().replace(/\/?$/,"/"),PM=(A)=>A.replace(/^\.?\/?/,"./"),iO1=(A)=>{if(A.startsWith("git@")){let D=A.match(/git@([^:]+):(.+)/);if(D){let[,Q,B]=D;return`https://${Q}/${B}`}}if(A.startsWith("git://"))return A.replace("git://","https://");if(A.startsWith("ssh://"))return A.replace("ssh://","https://").replace(/git@([^/]+)/,"$1");return A};var uhA=(A)=>A.split("/").pop()||"unknown resource";class Te{#A;#D;#Q;#B;#F;constructor(A,D,Q,B,I){this.#A=A,this.#D=D,this.#Q=new URL(ng(B)),this.#B=I,this.#F=Q}getDefaultHeaders(){return{Authorization:`Bearer ${this.#B}`,"User-Agent":lO1(this.#F),"X-Gitlab-Language-Server-Version":qY()}}async fetchFromApiRaw(A){try{let D=`Unknown request method "${A.method}", request type "${A.type}"`;switch(A.method){case"GET":return await this.#E(A);case"POST":return await this.#J(A);case"PATCH":return await this.#$(A);case"PUT":return await this.#Y(A);case"HEAD":return await this.#X(A);default:throw Error(D)}}catch(D){throw new my(A,D)}}async fetchFromApi(A){if(A.type==="graphql")return this.#I(A);let D=await this.fetchFromApiRaw(A);return await dO1(A,D,uhA(A.path)),D.json()}fetchOperation=(A)=>(D)=>this.fetchFromApi({...A,signal:D});async#I(A){let D=new URL("./api/graphql",this.#Q),Q=hy(A.query);if(Q)this.#A.debug(`[SimpleApiClient] Making GraphQL request: ${Q}`);let B=async(F,E)=>{let J=F instanceof URL?F.toString():F;return this.#D.post(J,{...E,headers:{...E?.headers},signal:A.signal})},I=new Re(D.href,{fetch:B,headers:{...this.getDefaultHeaders()}});try{return await I.request(A.query,A.variables)}catch(F){if(F instanceof jI)throw new fr(A,F.response);throw new my(A,F)}}async#E(A){let D=PM(A.path),Q=new URL(D,this.#Q);return je(Q,A.searchParams??{}),this.#D.get(Q,{headers:{...this.getDefaultHeaders(),...A.headers},signal:A.signal})}async#J(A){let D=PM(A.path),Q=new URL(D,this.#Q);return this.#D.post(Q,{headers:{"Content-Type":"application/json",...this.getDefaultHeaders(),...A.headers},body:JSON.stringify(A.body),signal:A.signal})}async#$(A){let D=PM(A.path),Q=new URL(D,this.#Q);return this.#D.patch(Q,{headers:{"Content-Type":"application/json",...this.getDefaultHeaders(),...A.headers},body:JSON.stringify(A.body),signal:A.signal})}async#Y(A){let D=PM(A.path),Q=new URL(D,this.#Q);return this.#D.put(Q,{headers:{"Content-Type":"application/json",...this.getDefaultHeaders(),...A.headers},body:JSON.stringify(A.body),signal:A.signal})}async#X(A){let D=PM(A.path),Q=new URL(D,this.#Q);return je(Q,A.searchParams??{}),this.#D.head(Q,{headers:{...this.getDefaultHeaders(),...A.headers},signal:A.signal})}}var nO1=HA(m0(),1),oO1=nO1.createInterfaceId("UserService");var aO1=1e4,rO1=4;import phA from"events";class DT{#A="Closed";#D;#Q;#B=0;#F=new phA;#I=null;constructor(A=rO1,D=aO1){this.#D=A,this.#Q=D}error(){if(this.#B+=1,this.#B>=this.#D)this.#E()}#E(){this.#A="Open",this.#I=setTimeout(()=>this.#J(),this.#Q),this.#F.emit("open")}isOpen(){return this.#A==="Open"}#J(){if(this.#A==="Closed")return;if(this.#I)clearTimeout(this.#I);this.#A="Closed",this.#F.emit("close")}success(){this.#B=0,this.#J()}onOpen(A){return this.#F.on("open",A),{dispose:()=>this.#F.removeListener("open",A)}}onClose(A){return this.#F.on("close",A),{dispose:()=>this.#F.removeListener("close",A)}}}import dhA from"events";var lhA=1000,chA=60000,ihA=2;class nhA{#A="Closed";#D;#Q;#B;#F=0;#I=new dhA;#E=null;constructor({initialBackoffMs:A=lhA,maxBackoffMs:D=chA,backoffMultiplier:Q=ihA}={}){this.#D=A,this.#Q=D,this.#B=Q}error(){this.#F+=1,this.#J()}megaError(){this.#F+=3,this.#J()}#J(){if(this.#A==="Open")return;this.#A="Open",this.#E=setTimeout(()=>this.#$(),this.#Y()),this.#I.emit("open")}#$(){if(this.#A==="Closed")return;if(this.#E)clearTimeout(this.#E);this.#A="Closed",this.#I.emit("close")}isOpen(){return this.#A==="Open"}success(){this.#F=0,this.#$()}onOpen(A){return this.#I.on("open",A),{dispose:()=>this.#I.removeListener("open",A)}}onClose(A){return this.#I.on("close",A),{dispose:()=>this.#I.removeListener("close",A)}}#Y(){return Math.min(this.#D*this.#B**(this.#F-1),this.#Q)}}import ohA from"events";var Se="EVENT";class KU{#A;eventEmitter=new ohA;event=(A,D={})=>{let Q=(B,I)=>A.bind(D)(B,I);return this.eventEmitter.on(Se,Q),{dispose:()=>this.eventEmitter.removeListener(Se,Q)}};fire(A){if(this.#A)this.#A.abort();this.#A=new AbortController,this.eventEmitter.emit(Se,A,this.#A.signal)}dispose(){this.#A?.abort(),this.eventEmitter.removeAllListeners()}}class QT{#A;#D=0;#Q;#B=new KU;constructor(A,D){this.#A=D,this.#Q=A}error(){if(this.#D+=1,this.#F){this.#B.fire();return}this.#Q.error()}success(){this.#D=0,this.#Q.success()}onOpen(A){return this.#Q.onOpen(A)}onClose(A){return this.#Q.onClose(A)}get#F(){return this.#D>=this.#A}onReachedMaxAttempts=this.#B.event;isOpen(){return this.#F||this.#Q.isOpen()}reset(){this.#D=0,this.#Q.success()}}var Gf=HA(m0(),1);var cL1=HA(NF(),1);var TM=HA(ce(),1);function MY(A,D,Q,B){if(!TM.valid(D))throw Error(`minimumRequiredVersion argument ${D} isn't valid`);let I=TM.coerce(A);if(!I)return console.warn(`Could not parse version from "${A}", running logic for the latest GitLab version`),Q();if(TM.gte(I,D))return Q();return B()}import{Buffer as mL1}from"buffer";function uL1(A){return mL1.from(A).byteLength}function GT(A,D,Q={}){let{separator:B=/\s+/g,suffix:I}=Q;if(uL1(A)<=D)return A;let F=I?uL1(` ${I}`):0,E=Math.max(0,D-F);if(E===0&&I)return` ${I}`.slice(0,D);let J=mL1.from(A).subarray(0,E).toString(),$=[...J.matchAll(B)].pop();if($)J=J.slice(0,$.index);return I?`${J} ${I}`:J}var pL1=(A)=>{};function ie(A){let D=parseInt(A.replace(/gid:\/\/gitlab\/.*\//g,""),10);if(!D||Number.isNaN(D))return;return D}var ne=HA(NF(),1),Jf=(A,D)=>{let Q,B=D||ne.default.isEqual;return{event:A.event.bind(A),fire:(I)=>{if(!B(Q,I))Q=ne.default.cloneDeep(I),A.fire(I)},dispose:A.dispose.bind(A)}};var oe=HA(NF(),1);function $f(A){if(oe.default.isPlainObject(A)){let D={},Q=A;return Object.keys(Q).forEach((B)=>{D[oe.default.camelCase(B)]=$f(Q[B])}),D}if(Array.isArray(A))return A.map((D)=>$f(D));return A}var Yf;((F)=>{F.EditorAdvancedContext="advanced_context_resolver";F.CodeSuggestionsContext="code_suggestions_context";F.UseDuoContextExclusion="use_duo_context_exclusion";F.DuoAgenticChat="duo_agentic_chat";F.DuoWorkflow="duo_workflow"})(Yf||={});var dL1={["duo_agentic_chat"]:"18.0.0",["duo_workflow"]:"17.2.0",["advanced_context_resolver"]:"17.1.0",["code_suggestions_context"]:"17.1.0",["use_duo_context_exclusion"]:"18.2.0"},lL1={["duo_agentic_chat"]:"18.5.0",["duo_workflow"]:"18.2.0",["advanced_context_resolver"]:"17.4.0",["code_suggestions_context"]:"17.4.0"};var mpA=Bz`
1173
1173
  query featureFlagsEnabled($names: [String!]!) {
1174
1174
  metadata {
1175
1175
  featureFlags(names: $names) {
@@ -1401,5 +1401,5 @@ echo $GIT_PASSWORD`,{mode:448}),A}async#I(A){try{await E06(A,{force:!0})}catch(D
1401
1401
  `,variables:{}},B=`@${(await this.#A.fetchFromApi(D)).currentUser.username}`;try{this.#I=await this.#Q.preCreateWorkflow("","chat"),await this.#Q.subscribeToUpdates((E)=>{this.#D.info(`[CLI/WORKFLOW_UPDATES] ${JSON.stringify(E)}`),this.#X(E)},()=>{},this.#I)}catch(E){this.#D.error("Failed to initialize workflow",E)}let F={messages:[{id:"welcome",role:"assistant",content:`Hi ${B}. Let's Go!`,timestamp:new Date}],input:{value:"",cursorPosition:0,isLoading:!1}};this.#G(F)}async#$(A){if(!A.trim()||this.#J.input.isLoading||!this.#I)return;this.#G({...this.#J,input:{...this.#J.input,value:"",cursorPosition:0,isLoading:!0}});try{await this.#Q.runWorkflow({goal:A,metadata:{projectId:""},type:"chat",existingWorkflowId:this.#I,additionalContext:[]})}catch(D){this.#D.error("Error when processing prompt",D);let Q={id:Date.now().toString(),role:"assistant",content:"Sorry, there was an error processing your message. Please try again.",timestamp:new Date};this.#G({...this.#J,messages:[...this.#J.messages,Q],input:{...this.#J.input,isLoading:!1}})}}#Y(A,D){if(D.return&&!this.#J.input.isLoading){this.#$(this.#J.input.value).catch((E)=>{this.#D.error("Error handling send message",E)});return}if(D.ctrl&&A==="c"){this.#C();return}let Q=this.#J.input.value,B=this.#J.input.cursorPosition,I=Q,F=B;if(D.backspace||D.delete){if(B>0)I=Q.slice(0,B-1)+Q.slice(B),F=B-1}else if(A&&A.length===1&&!D.ctrl&&!D.meta)I=Q.slice(0,B)+A+Q.slice(B),F=B+1;if(I!==Q||F!==B)this.#G({...this.#J,input:{...this.#J.input,value:I,cursorPosition:F}})}#X(A){let D=UWA(A);if(D.isErr()){this.#D.error("Failed to parse workflow checkpoint",D.error),this.#G({...this.#J,input:{...this.#J.input,isLoading:!1}});return}let Q=D.value,B=aX1.default.groupBy(Q,"id"),I=this.#J.messages.map((E)=>B[E.id]?.[0]??E),F=aX1.default.differenceBy(Q,this.#J.messages,"id");this.#G({...this.#J,messages:[...I,...F],input:{...this.#J.input,isLoading:A.workflowStatus==="INPUT_REQUIRED"?!1:this.#J.input.isLoading}})}#C(){process.exit(0)}#G(A){if(this.#J=A,!this.#E)throw Error("GitLab backend is not initialized");this.#E(this.#J)}}l_=_0([ZWA.Injectable(Vo,[pD,e0,_O,Sz,qo])],l_);var WWA=HA(m0(),1);class c_{get logLevel(){return Object.values(dD).find((D)=>D===process.env.LOG_LEVEL)??dD.DEBUG}}c_=_0([WWA.Injectable(Fj,[])],c_);var zWA=HA(m0(),1);import*as QZ from"fs";import*as wo from"path";class i_{#A;constructor(){this.#A=this.#Q(),this.#B()}write(A){if(!this.#A){console.error(A);return}try{QZ.appendFileSync(this.#A,`${A}
1402
1402
  `)}catch(D){console.error(`Failed to write to log file: ${this.#A}`,D),console.error(A)}}#D(){let D=process.cwd().split(wo.sep).slice(-3).join("-"),Q=new Date().toISOString().replace(/[:.]/g,"-").slice(0,19);return`duo-cli-log-${D}-${Q}.log`}#Q(){try{let A=PR();if(!QZ.existsSync(A))QZ.mkdirSync(A,{recursive:!0});let D=wo.join(A,this.#D());return QZ.writeFileSync(D,""),D}catch(A){console.error("Failed to create log file. Logs will be printed to stderr.",A);return}}#B(){process.on("exit",()=>{if(!this.#A)return;console.error(`CLI log file: ${this.#A}`)})}}i_=_0([zWA.Injectable(Ej,[])],i_);async function VWA(A){let D=new F$.ServiceCollection;D.add(F$.createInstanceDescriptor({instance:A,aliases:[qo]})),D.addClass(c_,i_,bW,DS,d_),D.add(F$.createFactoryDescriptor({aliases:[hx],factory:(I)=>new vi(I,I.getRequiredService(e0)),lifetime:F$.ServiceLifetime.Singleton})),D.addClass(YS,GL,CL,KL,gP),D.add(F$.createInstanceDescriptor({instance:{isEnabled:()=>!1,trackEvent:()=>{}},aliases:[bO]})),D.add(F$.createFactoryDescriptor({aliases:[GH],factory:()=>({reload:async()=>[]}),lifetime:F$.ServiceLifetime.Singleton})),D.addClass(p_,DP,QP,HL,FL,yP),D.addClass(l_);let Q=D.build();return await Q.getRequiredService(NU).initialize(),Q}class rX1{#A;#D;#Q;constructor(A,D){this.#A=A,this.#Q=D}async initialize(){let A=await VWA(this.#Q);this.#D=A.getRequiredService(Vo),await this.#D.initialize((D)=>this.#A(D))}getCallbacks(){if(!this.#D)throw Error("Backend not initialized. Call initialize() first.");return this.#D.callbacks}}var Mo=HA(IJ(),1),U86=({runConfig:A})=>{let[D,Q]=n_.useState(void 0),[B]=n_.useState(()=>new rX1(Q,A));if(n_.useEffect(()=>{pL1(B.initialize())},[B]),!D)return Mo.jsxDEV(G9,{children:"Initializing..."},void 0,!1,void 0,this);return Mo.jsxDEV(Or,{state:D,callbacks:B.getCallbacks()},void 0,!1,void 0,this)},qWA=(A={cwd:process.cwd()})=>{Vr(Mo.jsxDEV(U86,{runConfig:A},void 0,!1,void 0,this))};var Oo=new _G1;Oo.name("duo").description("GitLab Duo for your command line");Oo.option("-C, --cwd <path>","change working directory",process.cwd()).action((A)=>{let D={cwd:A.cwd};qWA(D)});var wWA=Oo.command("log").description("log management commands");wWA.command("last").description("open the last log file").action(()=>{gG1()});wWA.command("list").description("list all log files").action(()=>{fG1()});Oo.parse();
1403
1403
 
1404
- //# debugId=D91A59089ECEDE0F64756E2164756E21
1404
+ //# debugId=5C54E4CF50D128BF64756E2164756E21
1405
1405
  //# sourceMappingURL=index.js.map