@microsoft/agents-copilotstudio-client 0.6.11 → 0.6.16-gc874f0c9d8

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.
@@ -3,8 +3,8 @@ var Ja=Object.create;var In=Object.defineProperty;var Ka=Object.getOwnPropertyDe
3
3
  `)}getSetCookie(){return this.get("set-cookie")||[]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(e){return e instanceof this?e:new this(e)}static concat(e,...r){let n=new this(e);return r.forEach(o=>n.set(o)),n}static accessor(e){let n=(this[Oi]=this[Oi]={accessors:{}}).accessors,o=this.prototype;function i(s){let a=Wt(s);n[a]||(tu(o,s),n[a]=!0)}return p.isArray(e)?e.forEach(i):i(e),this}};ct.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]);p.reduceDescriptors(ct.prototype,({value:t},e)=>{let r=e[0].toUpperCase()+e.slice(1);return{get:()=>t,set(n){this[r]=n}}});p.freezeMethods(ct);var F=ct;function Jt(t,e){let r=this||at,n=e||r,o=F.from(n.headers),i=n.data;return p.forEach(t,function(a){i=a.call(r,i,o.normalize(),e?e.status:void 0)}),o.normalize(),i}function Kt(t){return!!(t&&t.__CANCEL__)}function Ei(t,e,r){A.call(this,t==null?"canceled":t,A.ERR_CANCELED,e,r),this.name="CanceledError"}p.inherits(Ei,A,{__CANCEL__:!0});var de=Ei;function Gt(t,e,r){let n=r.config.validateStatus;!r.status||!n||n(r.status)?t(r):e(new A("Request failed with status code "+r.status,[A.ERR_BAD_REQUEST,A.ERR_BAD_RESPONSE][Math.floor(r.status/100)-4],r.config,r.request,r))}function Ln(t){let e=/^([-+\w]{1,25})(:?\/\/|:)/.exec(t);return e&&e[1]||""}function ru(t,e){t=t||10;let r=new Array(t),n=new Array(t),o=0,i=0,s;return e=e!==void 0?e:1e3,function(c){let u=Date.now(),d=n[i];s||(s=u),r[o]=c,n[o]=u;let m=i,b=0;for(;m!==o;)b+=r[m++],m=m%t;if(o=(o+1)%t,o===i&&(i=(i+1)%t),u-s<e)return;let C=d&&u-d;return C?Math.round(b*1e3/C):void 0}}var Ri=ru;function nu(t,e){let r=0,n=1e3/e,o,i,s=(u,d=Date.now())=>{r=d,o=null,i&&(clearTimeout(i),i=null),t.apply(null,u)};return[(...u)=>{let d=Date.now(),m=d-r;m>=n?s(u,d):(o=u,i||(i=setTimeout(()=>{i=null,s(o)},n-m)))},()=>o&&s(o)]}var Pi=nu;var ut=(t,e,r=3)=>{let n=0,o=Ri(50,250);return Pi(i=>{let s=i.loaded,a=i.lengthComputable?i.total:void 0,c=s-n,u=o(c),d=s<=a;n=s;let m={loaded:s,total:a,progress:a?s/a:void 0,bytes:c,rate:u||void 0,estimated:u&&a&&d?(a-s)/u:void 0,event:i,lengthComputable:a!=null,[e?"download":"upload"]:!0};t(m)},r)},Mn=(t,e)=>{let r=t!=null;return[n=>e[0]({lengthComputable:r,total:t,loaded:n}),e[1]]},Fn=t=>(...e)=>p.asap(()=>t(...e));var ki=L.hasStandardBrowserEnv?((t,e)=>r=>(r=new URL(r,L.origin),t.protocol===r.protocol&&t.host===r.host&&(e||t.port===r.port)))(new URL(L.origin),L.navigator&&/(msie|trident)/i.test(L.navigator.userAgent)):()=>!0;var ji=L.hasStandardBrowserEnv?{write(t,e,r,n,o,i){let s=[t+"="+encodeURIComponent(e)];p.isNumber(r)&&s.push("expires="+new Date(r).toGMTString()),p.isString(n)&&s.push("path="+n),p.isString(o)&&s.push("domain="+o),i===!0&&s.push("secure"),document.cookie=s.join("; ")},read(t){let e=document.cookie.match(new RegExp("(^|;\\s*)("+t+")=([^;]*)"));return e?decodeURIComponent(e[3]):null},remove(t){this.write(t,"",Date.now()-864e5)}}:{write(){},read(){return null},remove(){}};function zn(t){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(t)}function qn(t,e){return e?t.replace(/\/?\/$/,"")+"/"+e.replace(/^\/+/,""):t}function Yt(t,e,r){let n=!zn(e);return t&&(n||r==!1)?qn(t,e):e}var Zi=t=>t instanceof F?{...t}:t;function ae(t,e){e=e||{};let r={};function n(u,d,m,b){return p.isPlainObject(u)&&p.isPlainObject(d)?p.merge.call({caseless:b},u,d):p.isPlainObject(d)?p.merge({},d):p.isArray(d)?d.slice():d}function o(u,d,m,b){if(p.isUndefined(d)){if(!p.isUndefined(u))return n(void 0,u,m,b)}else return n(u,d,m,b)}function i(u,d){if(!p.isUndefined(d))return n(void 0,d)}function s(u,d){if(p.isUndefined(d)){if(!p.isUndefined(u))return n(void 0,u)}else return n(void 0,d)}function a(u,d,m){if(m in e)return n(u,d);if(m in t)return n(void 0,u)}let c={url:i,method:i,data:i,baseURL:s,transformRequest:s,transformResponse:s,paramsSerializer:s,timeout:s,timeoutMessage:s,withCredentials:s,withXSRFToken:s,adapter:s,responseType:s,xsrfCookieName:s,xsrfHeaderName:s,onUploadProgress:s,onDownloadProgress:s,decompress:s,maxContentLength:s,maxBodyLength:s,beforeRedirect:s,transport:s,httpAgent:s,httpsAgent:s,cancelToken:s,socketPath:s,responseEncoding:s,validateStatus:a,headers:(u,d,m)=>o(Zi(u),Zi(d),m,!0)};return p.forEach(Object.keys(Object.assign({},t,e)),function(d){let m=c[d]||o,b=m(t[d],e[d],d);p.isUndefined(b)&&m!==a||(r[d]=b)}),r}var Er=t=>{let e=ae({},t),{data:r,withXSRFToken:n,xsrfHeaderName:o,xsrfCookieName:i,headers:s,auth:a}=e;e.headers=s=F.from(s),e.url=Ht(Yt(e.baseURL,e.url,e.allowAbsoluteUrls),t.params,t.paramsSerializer),a&&s.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):"")));let c;if(p.isFormData(r)){if(L.hasStandardBrowserEnv||L.hasStandardBrowserWebWorkerEnv)s.setContentType(void 0);else if((c=s.getContentType())!==!1){let[u,...d]=c?c.split(";").map(m=>m.trim()).filter(Boolean):[];s.setContentType([u||"multipart/form-data",...d].join("; "))}}if(L.hasStandardBrowserEnv&&(n&&p.isFunction(n)&&(n=n(e)),n||n!==!1&&ki(e.url))){let u=o&&i&&ji.read(i);u&&s.set(o,u)}return e};var ou=typeof XMLHttpRequest!="undefined",Ui=ou&&function(t){return new Promise(function(r,n){let o=Er(t),i=o.data,s=F.from(o.headers).normalize(),{responseType:a,onUploadProgress:c,onDownloadProgress:u}=o,d,m,b,C,h;function v(){C&&C(),h&&h(),o.cancelToken&&o.cancelToken.unsubscribe(d),o.signal&&o.signal.removeEventListener("abort",d)}let _=new XMLHttpRequest;_.open(o.method.toUpperCase(),o.url,!0),_.timeout=o.timeout;function x(){if(!_)return;let N=F.from("getAllResponseHeaders"in _&&_.getAllResponseHeaders()),D={data:!a||a==="text"||a==="json"?_.responseText:_.response,status:_.status,statusText:_.statusText,headers:N,config:t,request:_};Gt(function(ye){r(ye),v()},function(ye){n(ye),v()},D),_=null}"onloadend"in _?_.onloadend=x:_.onreadystatechange=function(){!_||_.readyState!==4||_.status===0&&!(_.responseURL&&_.responseURL.indexOf("file:")===0)||setTimeout(x)},_.onabort=function(){_&&(n(new A("Request aborted",A.ECONNABORTED,t,_)),_=null)},_.onerror=function(){n(new A("Network Error",A.ERR_NETWORK,t,_)),_=null},_.ontimeout=function(){let z=o.timeout?"timeout of "+o.timeout+"ms exceeded":"timeout exceeded",D=o.transitional||Ir;o.timeoutErrorMessage&&(z=o.timeoutErrorMessage),n(new A(z,D.clarifyTimeoutError?A.ETIMEDOUT:A.ECONNABORTED,t,_)),_=null},i===void 0&&s.setContentType(null),"setRequestHeader"in _&&p.forEach(s.toJSON(),function(z,D){_.setRequestHeader(D,z)}),p.isUndefined(o.withCredentials)||(_.withCredentials=!!o.withCredentials),a&&a!=="json"&&(_.responseType=o.responseType),u&&([b,h]=ut(u,!0),_.addEventListener("progress",b)),c&&_.upload&&([m,C]=ut(c),_.upload.addEventListener("progress",m),_.upload.addEventListener("loadend",C)),(o.cancelToken||o.signal)&&(d=N=>{_&&(n(!N||N.type?new de(null,t,_):N),_.abort(),_=null)},o.cancelToken&&o.cancelToken.subscribe(d),o.signal&&(o.signal.aborted?d():o.signal.addEventListener("abort",d)));let P=Ln(o.url);if(P&&L.protocols.indexOf(P)===-1){n(new A("Unsupported protocol "+P+":",A.ERR_BAD_REQUEST,t));return}_.send(i||null)})};var iu=(t,e)=>{let{length:r}=t=t?t.filter(Boolean):[];if(e||r){let n=new AbortController,o,i=function(u){if(!o){o=!0,a();let d=u instanceof Error?u:this.reason;n.abort(d instanceof A?d:new de(d instanceof Error?d.message:d))}},s=e&&setTimeout(()=>{s=null,i(new A(`timeout ${e} of ms exceeded`,A.ETIMEDOUT))},e),a=()=>{t&&(s&&clearTimeout(s),s=null,t.forEach(u=>{u.unsubscribe?u.unsubscribe(i):u.removeEventListener("abort",i)}),t=null)};t.forEach(u=>u.addEventListener("abort",i));let{signal:c}=n;return c.unsubscribe=()=>p.asap(a),c}},Ni=iu;var su=function*(t,e){let r=t.byteLength;if(!e||r<e){yield t;return}let n=0,o;for(;n<r;)o=n+e,yield t.slice(n,o),n=o},au=async function*(t,e){for await(let r of cu(t))yield*su(r,e)},cu=async function*(t){if(t[Symbol.asyncIterator]){yield*t;return}let e=t.getReader();try{for(;;){let{done:r,value:n}=await e.read();if(r)break;yield n}}finally{await e.cancel()}},Vn=(t,e,r,n)=>{let o=au(t,e),i=0,s,a=c=>{s||(s=!0,n&&n(c))};return new ReadableStream({async pull(c){try{let{done:u,value:d}=await o.next();if(u){a(),c.close();return}let m=d.byteLength;if(r){let b=i+=m;r(b)}c.enqueue(new Uint8Array(d))}catch(u){throw a(u),u}},cancel(c){return a(c),o.return()}},{highWaterMark:2})};var Pr=typeof fetch=="function"&&typeof Request=="function"&&typeof Response=="function",Li=Pr&&typeof ReadableStream=="function",uu=Pr&&(typeof TextEncoder=="function"?(t=>e=>t.encode(e))(new TextEncoder):async t=>new Uint8Array(await new Response(t).arrayBuffer())),Mi=(t,...e)=>{try{return!!t(...e)}catch{return!1}},du=Li&&Mi(()=>{let t=!1,e=new Request(L.origin,{body:new ReadableStream,method:"POST",get duplex(){return t=!0,"half"}}).headers.has("Content-Type");return t&&!e}),Di=64*1024,$n=Li&&Mi(()=>p.isReadableStream(new Response("").body)),Rr={stream:$n&&(t=>t.body)};Pr&&(t=>{["text","arrayBuffer","blob","formData","stream"].forEach(e=>{!Rr[e]&&(Rr[e]=p.isFunction(t[e])?r=>r[e]():(r,n)=>{throw new A(`Response type '${e}' is not supported`,A.ERR_NOT_SUPPORT,n)})})})(new Response);var lu=async t=>{if(t==null)return 0;if(p.isBlob(t))return t.size;if(p.isSpecCompliantForm(t))return(await new Request(L.origin,{method:"POST",body:t}).arrayBuffer()).byteLength;if(p.isArrayBufferView(t)||p.isArrayBuffer(t))return t.byteLength;if(p.isURLSearchParams(t)&&(t=t+""),p.isString(t))return(await uu(t)).byteLength},fu=async(t,e)=>{let r=p.toFiniteNumber(t.getContentLength());return r==null?lu(e):r},Fi=Pr&&(async t=>{let{url:e,method:r,data:n,signal:o,cancelToken:i,timeout:s,onDownloadProgress:a,onUploadProgress:c,responseType:u,headers:d,withCredentials:m="same-origin",fetchOptions:b}=Er(t);u=u?(u+"").toLowerCase():"text";let C=Ni([o,i&&i.toAbortSignal()],s),h,v=C&&C.unsubscribe&&(()=>{C.unsubscribe()}),_;try{if(c&&du&&r!=="get"&&r!=="head"&&(_=await fu(d,n))!==0){let D=new Request(e,{method:"POST",body:n,duplex:"half"}),te;if(p.isFormData(n)&&(te=D.headers.get("content-type"))&&d.setContentType(te),D.body){let[ye,ke]=Mn(_,ut(Fn(c)));n=Vn(D.body,Di,ye,ke)}}p.isString(m)||(m=m?"include":"omit");let x="credentials"in Request.prototype;h=new Request(e,{...b,signal:C,method:r.toUpperCase(),headers:d.normalize().toJSON(),body:n,duplex:"half",credentials:x?m:void 0});let P=await fetch(h,b),N=$n&&(u==="stream"||u==="response");if($n&&(a||N&&v)){let D={};["status","statusText","headers"].forEach(gr=>{D[gr]=P[gr]});let te=p.toFiniteNumber(P.headers.get("content-length")),[ye,ke]=a&&Mn(te,ut(Fn(a),!0))||[];P=new Response(Vn(P.body,Di,ye,()=>{ke&&ke(),v&&v()}),D)}u=u||"text";let z=await Rr[p.findKey(Rr,u)||"text"](P,t);return!N&&v&&v(),await new Promise((D,te)=>{Gt(D,te,{data:z,headers:F.from(P.headers),status:P.status,statusText:P.statusText,config:t,request:h})})}catch(x){throw v&&v(),x&&x.name==="TypeError"&&/Load failed|fetch/i.test(x.message)?Object.assign(new A("Network Error",A.ERR_NETWORK,t,h),{cause:x.cause||x}):A.from(x,x&&x.code,t,h)}});var Bn={http:Tr,xhr:Ui,fetch:Fi};p.forEach(Bn,(t,e)=>{if(t){try{Object.defineProperty(t,"name",{value:e})}catch{}Object.defineProperty(t,"adapterName",{value:e})}});var zi=t=>`- ${t}`,pu=t=>p.isFunction(t)||t===null||t===!1,kr={getAdapter:t=>{t=p.isArray(t)?t:[t];let{length:e}=t,r,n,o={};for(let i=0;i<e;i++){r=t[i];let s;if(n=r,!pu(r)&&(n=Bn[(s=String(r)).toLowerCase()],n===void 0))throw new A(`Unknown adapter '${s}'`);if(n)break;o[s||"#"+i]=n}if(!n){let i=Object.entries(o).map(([a,c])=>`adapter ${a} `+(c===!1?"is not supported by the environment":"is not available in the build")),s=e?i.length>1?`since :
4
4
  `+i.map(zi).join(`
5
5
  `):" "+zi(i[0]):"as no adapter specified";throw new A("There is no suitable adapter to dispatch the request "+s,"ERR_NOT_SUPPORT")}return n},adapters:Bn};function Hn(t){if(t.cancelToken&&t.cancelToken.throwIfRequested(),t.signal&&t.signal.aborted)throw new de(null,t)}function jr(t){return Hn(t),t.headers=F.from(t.headers),t.data=Jt.call(t,t.transformRequest),["post","put","patch"].indexOf(t.method)!==-1&&t.headers.setContentType("application/x-www-form-urlencoded",!1),kr.getAdapter(t.adapter||at.adapter)(t).then(function(n){return Hn(t),n.data=Jt.call(t,t.transformResponse,n),n.headers=F.from(n.headers),n},function(n){return Kt(n)||(Hn(t),n&&n.response&&(n.response.data=Jt.call(t,t.transformResponse,n.response),n.response.headers=F.from(n.response.headers))),Promise.reject(n)})}var Zr="1.10.0";var Ur={};["object","boolean","number","function","string","symbol"].forEach((t,e)=>{Ur[t]=function(n){return typeof n===t||"a"+(e<1?"n ":" ")+t}});var qi={};Ur.transitional=function(e,r,n){function o(i,s){return"[Axios v"+Zr+"] Transitional option '"+i+"'"+s+(n?". "+n:"")}return(i,s,a)=>{if(e===!1)throw new A(o(s," has been removed"+(r?" in "+r:"")),A.ERR_DEPRECATED);return r&&!qi[s]&&(qi[s]=!0,console.warn(o(s," has been deprecated since v"+r+" and will be removed in the near future"))),e?e(i,s,a):!0}};Ur.spelling=function(e){return(r,n)=>(console.warn(`${n} is likely a misspelling of ${e}`),!0)};function mu(t,e,r){if(typeof t!="object")throw new A("options must be an object",A.ERR_BAD_OPTION_VALUE);let n=Object.keys(t),o=n.length;for(;o-- >0;){let i=n[o],s=e[i];if(s){let a=t[i],c=a===void 0||s(a,i,t);if(c!==!0)throw new A("option "+i+" must be "+c,A.ERR_BAD_OPTION_VALUE);continue}if(r!==!0)throw new A("Unknown option "+i,A.ERR_BAD_OPTION)}}var Xt={assertOptions:mu,validators:Ur};var le=Xt.validators,dt=class{constructor(e){this.defaults=e||{},this.interceptors={request:new Pn,response:new Pn}}async request(e,r){try{return await this._request(e,r)}catch(n){if(n instanceof Error){let o={};Error.captureStackTrace?Error.captureStackTrace(o):o=new Error;let i=o.stack?o.stack.replace(/^.+\n/,""):"";try{n.stack?i&&!String(n.stack).endsWith(i.replace(/^.+\n.+\n/,""))&&(n.stack+=`
6
- `+i):n.stack=i}catch{}}throw n}}_request(e,r){typeof e=="string"?(r=r||{},r.url=e):r=e||{},r=ae(this.defaults,r);let{transitional:n,paramsSerializer:o,headers:i}=r;n!==void 0&&Xt.assertOptions(n,{silentJSONParsing:le.transitional(le.boolean),forcedJSONParsing:le.transitional(le.boolean),clarifyTimeoutError:le.transitional(le.boolean)},!1),o!=null&&(p.isFunction(o)?r.paramsSerializer={serialize:o}:Xt.assertOptions(o,{encode:le.function,serialize:le.function},!0)),r.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?r.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:r.allowAbsoluteUrls=!0),Xt.assertOptions(r,{baseUrl:le.spelling("baseURL"),withXsrfToken:le.spelling("withXSRFToken")},!0),r.method=(r.method||this.defaults.method||"get").toLowerCase();let s=i&&p.merge(i.common,i[r.method]);i&&p.forEach(["delete","get","head","post","put","patch","common"],h=>{delete i[h]}),r.headers=F.concat(s,i);let a=[],c=!0;this.interceptors.request.forEach(function(v){typeof v.runWhen=="function"&&v.runWhen(r)===!1||(c=c&&v.synchronous,a.unshift(v.fulfilled,v.rejected))});let u=[];this.interceptors.response.forEach(function(v){u.push(v.fulfilled,v.rejected)});let d,m=0,b;if(!c){let h=[jr.bind(this),void 0];for(h.unshift.apply(h,a),h.push.apply(h,u),b=h.length,d=Promise.resolve(r);m<b;)d=d.then(h[m++],h[m++]);return d}b=a.length;let C=r;for(m=0;m<b;){let h=a[m++],v=a[m++];try{C=h(C)}catch(_){v.call(this,_);break}}try{d=jr.call(this,C)}catch(h){return Promise.reject(h)}for(m=0,b=u.length;m<b;)d=d.then(u[m++],u[m++]);return d}getUri(e){e=ae(this.defaults,e);let r=Yt(e.baseURL,e.url,e.allowAbsoluteUrls);return Ht(r,e.params,e.paramsSerializer)}};p.forEach(["delete","get","head","options"],function(e){dt.prototype[e]=function(r,n){return this.request(ae(n||{},{method:e,url:r,data:(n||{}).data}))}});p.forEach(["post","put","patch"],function(e){function r(n){return function(i,s,a){return this.request(ae(a||{},{method:e,headers:n?{"Content-Type":"multipart/form-data"}:{},url:i,data:s}))}}dt.prototype[e]=r(),dt.prototype[e+"Form"]=r(!0)});var Qt=dt;var Wn=class t{constructor(e){if(typeof e!="function")throw new TypeError("executor must be a function.");let r;this.promise=new Promise(function(i){r=i});let n=this;this.promise.then(o=>{if(!n._listeners)return;let i=n._listeners.length;for(;i-- >0;)n._listeners[i](o);n._listeners=null}),this.promise.then=o=>{let i,s=new Promise(a=>{n.subscribe(a),i=a}).then(o);return s.cancel=function(){n.unsubscribe(i)},s},e(function(i,s,a){n.reason||(n.reason=new de(i,s,a),r(n.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(e){if(this.reason){e(this.reason);return}this._listeners?this._listeners.push(e):this._listeners=[e]}unsubscribe(e){if(!this._listeners)return;let r=this._listeners.indexOf(e);r!==-1&&this._listeners.splice(r,1)}toAbortSignal(){let e=new AbortController,r=n=>{e.abort(n)};return this.subscribe(r),e.signal.unsubscribe=()=>this.unsubscribe(r),e.signal}static source(){let e;return{token:new t(function(o){e=o}),cancel:e}}},Vi=Wn;function Jn(t){return function(r){return t.apply(null,r)}}function Kn(t){return p.isObject(t)&&t.isAxiosError===!0}var Gn={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(Gn).forEach(([t,e])=>{Gn[e]=t});var $i=Gn;function Bi(t){let e=new Qt(t),r=Vt(Qt.prototype.request,e);return p.extend(r,Qt.prototype,e,{allOwnKeys:!0}),p.extend(r,e,null,{allOwnKeys:!0}),r.create=function(o){return Bi(ae(t,o))},r}var M=Bi(at);M.Axios=Qt;M.CanceledError=de;M.CancelToken=Vi;M.isCancel=Kt;M.VERSION=Zr;M.toFormData=Ce;M.AxiosError=A;M.Cancel=M.CanceledError;M.all=function(e){return Promise.all(e)};M.spread=Jn;M.isAxiosError=Kn;M.mergeConfig=ae;M.AxiosHeaders=F;M.formToJSON=t=>Ar(p.isHTMLForm(t)?new FormData(t):t);M.getAdapter=kr.getAdapter;M.HttpStatusCode=$i;M.default=M;var Nr=M;var{Axios:by,AxiosError:_y,CanceledError:xy,isCancel:wy,CancelToken:Cy,VERSION:Ty,all:Sy,Cancel:Iy,isAxiosError:Ay,spread:Oy,toFormData:Ey,AxiosHeaders:Ry,HttpStatusCode:Py,formToJSON:ky,getAdapter:jy,mergeConfig:Zy}=Nr;var Xi=vr(Fr());var zr=class{constructor(e){this.API_VERSION="2022-03-01-preview";let{identifier:r,host:n}=e;this.baseURL=new URL(`/copilotstudio/prebuilt/authenticated/bots/${r}`,n),this.baseURL.searchParams.append("api-version",this.API_VERSION)}getConversationUrl(e){let r=new URL(this.baseURL.href);return r.pathname=`${r.pathname}/conversations`,e&&(r.pathname=`${r.pathname}/${e}`),r.href}};var qr=class{constructor(e){this.API_VERSION="2022-03-01-preview";let{schema:r,host:n}=e;this.baseURL=new URL(`/copilotstudio/dataverse-backed/authenticated/bots/${r}`,n),this.baseURL.searchParams.append("api-version",this.API_VERSION)}getConversationUrl(e){let r=new URL(this.baseURL.href);return r.pathname=`${r.pathname}/conversations`,e&&(r.pathname=`${r.pathname}/${e}`),r.href}};var Ne=(0,Xi.debug)("copilot-studio:power-platform");function $r(t,e){var d,m;let r=5;if((d=t.directConnectUrl)!=null&&d.trim()){if(Ne.debug(`Using direct connection: ${t.directConnectUrl}`),!er(t.directConnectUrl))throw new Error("directConnectUrl must be a valid URL");return t.directConnectUrl.toLowerCase().includes("tenants/00000000-0000-0000-0000-000000000000")?(Ne.debug(`Direct connection cannot be used, forcing default settings flow. Tenant ID is missing in the URL: ${t.directConnectUrl}`),$r({...t,directConnectUrl:""},e)):Pu(t.directConnectUrl,e).href}let n=t.cloud&&t.cloud.toString().trim()!=="",o=t.customPowerPlatformCloud!==void 0&&t.customPowerPlatformCloud.trim()!=="";if(n&&!Object.values(qt).includes(t.cloud))throw new Error("Invalid PowerPlatformCloud enum key");let i=n?t.cloud:-1;if(i===100&&o)throw new Error("customPowerPlatformCloud must be provided when PowerPlatformCloud is Other");if(!((m=t.environmentId)!=null&&m.trim()))throw new Error("EnvironmentId must be provided");if(t.agentIdentifier===void 0||t.agentIdentifier.trim()==="")throw new Error("AgentIdentifier must be provided");if(i!==-1&&(Ne.debug(`Using specified cloud setting: ${i}`),r=i),i===100)if(o&&er(t.customPowerPlatformCloud))Ne.debug(`Using custom Power Platform cloud: ${t.customPowerPlatformCloud}`),r=100;else throw new Error("customPowerPlatformCloud must be a valid URL");let s;if(t.copilotAgentType&&t.copilotAgentType.toString().trim()!=="")if(Object.values(zt).includes(t.copilotAgentType))Ne.debug(`Using specified agent type: ${t.copilotAgentType}`),s=t.copilotAgentType;else throw new Error("Invalid AgentType enum key");else Ne.debug("Using default agent type: Published"),s=0;t.customPowerPlatformCloud=o?t.customPowerPlatformCloud:"api.unknown.powerplatform.com";let a=ku(r,t.environmentId,t.customPowerPlatformCloud),u={0:()=>new qr({host:a,schema:t.agentIdentifier}),1:()=>new zr({host:a,identifier:t.agentIdentifier})}[s]().getConversationUrl(e);return Ne.debug(`Generated Copilot Studio connection URL: ${u}`),u}function Qi(t,e=-1,r="",n=""){var o,i;if(!n&&!(t!=null&&t.directConnectUrl)){if(e===100&&!r)throw new Error("cloudBaseAddress must be provided when PowerPlatformCloudCategory is Other");if(!t&&e===-1)throw new Error("Either settings or cloud must be provided");if(t&&t.cloud&&t.cloud!==-1&&(e=t.cloud),e===100)if(r&&er(r))e=100;else if(t!=null&&t.customPowerPlatformCloud&&er(t.customPowerPlatformCloud))e=100,r=t.customPowerPlatformCloud;else throw new Error("Either CustomPowerPlatformCloud or cloudBaseAddress must be provided when PowerPlatformCloudCategory is Other");return r!=null||(r="api.unknown.powerplatform.com"),`https://${Vr(e,r)}/.default`}else if(n||(n=(o=t==null?void 0:t.directConnectUrl)!=null?o:""),n&&er(n)){if(Yi(new URL(n))===-1){let s=(i=t==null?void 0:t.cloud)!=null?i:e;if(s===100||s===-1)throw new Error("Unable to resolve the PowerPlatform Cloud from DirectConnectUrl. The Token Audience resolver requires a specific PowerPlatformCloudCategory.");if(s!==-1)return`https://${Vr(s,"")}/.default`;throw new Error("Unable to resolve the PowerPlatform Cloud from DirectConnectUrl. The Token Audience resolver requires a specific PowerPlatformCloudCategory.")}return`https://${Vr(Yi(new URL(n)),"")}/.default`}else throw new Error("DirectConnectUrl must be provided when DirectConnectUrl is set")}function er(t){try{let e=t.startsWith("http")?t:`https://${t}`;return!!new URL(e)}catch{return!1}}function Pu(t,e){let r=new URL(t);return r.searchParams.has("api-version")||r.searchParams.append("api-version","2022-03-01-preview"),r.pathname.endsWith("/")&&(r.pathname=r.pathname.slice(0,-1)),r.pathname.includes("/conversations")&&(r.pathname=r.pathname.substring(0,r.pathname.indexOf("/conversations"))),r.pathname=`${r.pathname}/conversations`,e&&(r.pathname=`${r.pathname}/${e}`),r}function ku(t,e,r){if(t===100&&(!r||!r.trim()))throw new Error("cloudBaseAddress must be provided when PowerPlatformCloud is Other");r=r!=null?r:"api.unknown.powerplatform.com";let n=e.toLowerCase().replaceAll("-",""),o=ju(t),i=n.substring(0,n.length-o),s=n.substring(n.length-o);return new URL(`https://${i}.${s}.environment.${Vr(t,r)}`)}function Vr(t,e){switch(t){case 13:return"api.powerplatform.localhost";case 0:return"api.exp.powerplatform.com";case 1:return"api.dev.powerplatform.com";case 12:return"api.prv.powerplatform.com";case 2:return"api.test.powerplatform.com";case 3:return"api.preprod.powerplatform.com";case 4:case 5:return"api.powerplatform.com";case 14:return"api.gov.powerplatform.microsoft.us";case 6:return"api.gov.powerplatform.microsoft.us";case 7:return"api.high.powerplatform.microsoft.us";case 8:return"api.appsplatform.us";case 9:return"api.powerplatform.partner.microsoftonline.cn";case 10:return"api.powerplatform.eaglex.ic.gov";case 11:return"api.powerplatform.microsoft.scloud";case 100:return e;default:throw new Error(`Invalid cluster category value: ${t}`)}}function ju(t){switch(t){case 4:case 5:return 2;default:return 1}}function Yi(t){switch(t.host.toLowerCase()){case"api.powerplatform.localhost":return 13;case"api.exp.powerplatform.com":return 0;case"api.dev.powerplatform.com":return 1;case"api.prv.powerplatform.com":return 12;case"api.test.powerplatform.com":return 2;case"api.preprod.powerplatform.com":return 3;case"api.powerplatform.com":return 5;case"api.gov.powerplatform.microsoft.us":return 14;case"api.high.powerplatform.microsoft.us":return 7;case"api.appsplatform.us":return 8;case"api.powerplatform.partner.microsoftonline.cn":return 9;default:return-1}}var mr=vr(Oa());var bn=class{constructor(e){this.activity=e}};var Pa=vr(Fr());var Ea={name:"@microsoft/agents-copilotstudio-client",version:"0.6.11",homepage:"https://github.com/microsoft/Agents-for-js",repository:{type:"git",url:"git+https://github.com/microsoft/Agents-for-js.git"},author:{name:"Microsoft",email:"agentssdk@microsoft.com",url:"https://aka.ms/Agents"},description:"Microsoft Copilot Studio Client for JavaScript. Copilot Studio Client.",keywords:["Agents","copilotstudio","powerplatform"],main:"dist/src/index.js",types:"dist/src/index.d.ts",browser:{os:"./src/browser/os.ts",crypto:"./src/browser/crypto.ts"},scripts:{"build:browser":"esbuild --platform=browser --target=es2019 --format=esm --bundle --sourcemap --minify --outfile=dist/src/browser.mjs src/index.ts"},dependencies:{"@microsoft/agents-activity":"0.6.11",axios:"^1.9.0",rxjs:"7.8.2",uuid:"^11.1.0"},license:"MIT",files:["README.md","dist/src","src"],exports:{".":{import:{browser:"./dist/src/browser.mjs",default:"./dist/src/index.js"},require:{default:"./dist/src/index.js"}},"./package.json":"./package.json"},engines:{node:">=20.0.0"}};var _n={};var Q=(0,Pa.debug)("copilot-studio:client"),we=class we{constructor(e,r){this.conversationId="";this.settings=e,this.client=Nr.create(),this.client.defaults.headers.common.Authorization=`Bearer ${r}`,this.client.defaults.headers.common["User-Agent"]=we.getProductInfo()}async postRequestAsync(e){var m,b,C,h;let r=[];Q.debug(`>>> SEND TO ${e.url}`);let n=await this.client(e);if(this.settings.useExperimentalEndpoint&&!((m=this.settings.directConnectUrl)!=null&&m.trim())){let v=(b=n.headers)==null?void 0:b[we.islandExperimentalUrlHeaderKey];v&&(this.settings.directConnectUrl=v,Q.debug(`Island Experimental URL: ${v}`))}this.conversationId=(h=(C=n.headers)==null?void 0:C[we.conversationIdHeaderKey])!=null?h:"",this.conversationId&&Q.debug(`Conversation ID: ${this.conversationId}`);let o={...n.headers};delete o.Authorization,delete o[we.conversationIdHeaderKey],Q.debug("Headers received:",o);let s=n.data.pipeThrough(new TextDecoderStream).getReader(),a="",c=[],u=async({done:v,value:_})=>v?(Q.debug("Stream complete"),a+=_,c.push(a),c):(Q.info("Agent is typing ..."),a+=_,await u(await s.read()));return(await s.read().then(u)).forEach(v=>{v.toString().split(`
7
- `).filter(P=>P.substring(0,4)==="data"&&P!=="data: end\r").forEach(P=>{var N,z;try{let D=mr.Activity.fromJson(P.substring(5,P.length));D.type===mr.ActivityTypes.Message?(r.push(D),this.conversationId.trim()||(this.conversationId=(z=(N=D.conversation)==null?void 0:N.id)!=null?z:"",Q.debug(`Conversation ID: ${this.conversationId}`))):Q.debug(`Activity type: ${D.type}`)}catch(D){throw Q.error("Error: ",D),D}})}),r}static getProductInfo(){let e=`CopilotStudioClient.agents-sdk-js/${Ea.version}`,r;return typeof window!="undefined"&&window.navigator?r=`${e} ${navigator.userAgent}`:r=`${e} nodejs/${process.version} ${_n.platform()}-${_n.arch()}/${_n.release()}`,Q.debug(`User-Agent: ${r}`),r}async startConversationAsync(e=!0){var a;let o={method:"post",url:$r(this.settings),headers:{Accept:"text/event-stream","Content-Type":"application/json"},data:{emitStartConversationEvent:e},responseType:"stream",adapter:"fetch"};Q.info("Starting conversation ...");let i=await this.postRequestAsync(o),s=i[0];return Q.info(`Conversation '${(a=s.conversation)==null?void 0:a.id}' started. Received ${i.length} activities.`,i),s}async askQuestionAsync(e,r=this.conversationId){var m,b;let o={type:"message",text:e,conversation:{id:r}},i=mr.Activity.fromObject(o),s=(b=(m=i.conversation)==null?void 0:m.id)!=null?b:r,a=$r(this.settings,s),c=new bn(i),u={method:"post",url:a,headers:{Accept:"text/event-stream","Content-Type":"application/json"},data:c,responseType:"stream",adapter:"fetch"};Q.info(`Asking question: ${e} ...`);let d=await this.postRequestAsync(u);return Q.info(`Received ${d.length} activities.`,d),d}};we.conversationIdHeaderKey="x-ms-conversationid",we.islandExperimentalUrlHeaderKey="x-ms-d2e-experimental",we.scopeFromSettings=Qi;var Ra=we;var V=[];for(let t=0;t<256;++t)V.push((t+256).toString(16).slice(1));function ka(t,e=0){return(V[t[e+0]]+V[t[e+1]]+V[t[e+2]]+V[t[e+3]]+"-"+V[t[e+4]]+V[t[e+5]]+"-"+V[t[e+6]]+V[t[e+7]]+"-"+V[t[e+8]]+V[t[e+9]]+"-"+V[t[e+10]]+V[t[e+11]]+V[t[e+12]]+V[t[e+13]]+V[t[e+14]]+V[t[e+15]]).toLowerCase()}var Jo,rp=new Uint8Array(16);function Ko(){if(!Jo){if(typeof crypto=="undefined"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Jo=crypto.getRandomValues.bind(crypto)}return Jo(rp)}var np=typeof crypto!="undefined"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Go={randomUUID:np};function op(t,e,r){var o,i,s;if(Go.randomUUID&&!e&&!t)return Go.randomUUID();t=t||{};let n=(s=(i=t.random)!=null?i:(o=t.rng)==null?void 0:o.call(t))!=null?s:Ko();if(n.length<16)throw new Error("Random bytes length must be >= 16");if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,e){if(r=r||0,r<0||r+16>e.length)throw new RangeError(`UUID byte range ${r}:${r+15} is out of buffer bounds`);for(let a=0;a<16;++a)e[r+a]=n[a];return e}return ka(n)}var Yo=op;var Xo=function(t,e){return Xo=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,n){r.__proto__=n}||function(r,n){for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(r[o]=n[o])},Xo(t,e)};function Re(t,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");Xo(t,e);function r(){this.constructor=t}t.prototype=e===null?Object.create(e):(r.prototype=e.prototype,new r)}function hr(t){var e=typeof Symbol=="function"&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function Ut(t,e){var r=typeof Symbol=="function"&&t[Symbol.iterator];if(!r)return t;var n=r.call(t),o,i=[],s;try{for(;(e===void 0||e-- >0)&&!(o=n.next()).done;)i.push(o.value)}catch(a){s={error:a}}finally{try{o&&!o.done&&(r=n.return)&&r.call(n)}finally{if(s)throw s.error}}return i}function Nt(t,e,r){if(r||arguments.length===2)for(var n=0,o=e.length,i;n<o;n++)(i||!(n in e))&&(i||(i=Array.prototype.slice.call(e,0,n)),i[n]=e[n]);return t.concat(i||Array.prototype.slice.call(e))}function ie(t){return typeof t=="function"}function xn(t){var e=function(n){Error.call(n),n.stack=new Error().stack},r=t(e);return r.prototype=Object.create(Error.prototype),r.prototype.constructor=r,r}var wn=xn(function(t){return function(r){t(this),this.message=r?r.length+` errors occurred during unsubscription:
6
+ `+i):n.stack=i}catch{}}throw n}}_request(e,r){typeof e=="string"?(r=r||{},r.url=e):r=e||{},r=ae(this.defaults,r);let{transitional:n,paramsSerializer:o,headers:i}=r;n!==void 0&&Xt.assertOptions(n,{silentJSONParsing:le.transitional(le.boolean),forcedJSONParsing:le.transitional(le.boolean),clarifyTimeoutError:le.transitional(le.boolean)},!1),o!=null&&(p.isFunction(o)?r.paramsSerializer={serialize:o}:Xt.assertOptions(o,{encode:le.function,serialize:le.function},!0)),r.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?r.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:r.allowAbsoluteUrls=!0),Xt.assertOptions(r,{baseUrl:le.spelling("baseURL"),withXsrfToken:le.spelling("withXSRFToken")},!0),r.method=(r.method||this.defaults.method||"get").toLowerCase();let s=i&&p.merge(i.common,i[r.method]);i&&p.forEach(["delete","get","head","post","put","patch","common"],h=>{delete i[h]}),r.headers=F.concat(s,i);let a=[],c=!0;this.interceptors.request.forEach(function(v){typeof v.runWhen=="function"&&v.runWhen(r)===!1||(c=c&&v.synchronous,a.unshift(v.fulfilled,v.rejected))});let u=[];this.interceptors.response.forEach(function(v){u.push(v.fulfilled,v.rejected)});let d,m=0,b;if(!c){let h=[jr.bind(this),void 0];for(h.unshift.apply(h,a),h.push.apply(h,u),b=h.length,d=Promise.resolve(r);m<b;)d=d.then(h[m++],h[m++]);return d}b=a.length;let C=r;for(m=0;m<b;){let h=a[m++],v=a[m++];try{C=h(C)}catch(_){v.call(this,_);break}}try{d=jr.call(this,C)}catch(h){return Promise.reject(h)}for(m=0,b=u.length;m<b;)d=d.then(u[m++],u[m++]);return d}getUri(e){e=ae(this.defaults,e);let r=Yt(e.baseURL,e.url,e.allowAbsoluteUrls);return Ht(r,e.params,e.paramsSerializer)}};p.forEach(["delete","get","head","options"],function(e){dt.prototype[e]=function(r,n){return this.request(ae(n||{},{method:e,url:r,data:(n||{}).data}))}});p.forEach(["post","put","patch"],function(e){function r(n){return function(i,s,a){return this.request(ae(a||{},{method:e,headers:n?{"Content-Type":"multipart/form-data"}:{},url:i,data:s}))}}dt.prototype[e]=r(),dt.prototype[e+"Form"]=r(!0)});var Qt=dt;var Wn=class t{constructor(e){if(typeof e!="function")throw new TypeError("executor must be a function.");let r;this.promise=new Promise(function(i){r=i});let n=this;this.promise.then(o=>{if(!n._listeners)return;let i=n._listeners.length;for(;i-- >0;)n._listeners[i](o);n._listeners=null}),this.promise.then=o=>{let i,s=new Promise(a=>{n.subscribe(a),i=a}).then(o);return s.cancel=function(){n.unsubscribe(i)},s},e(function(i,s,a){n.reason||(n.reason=new de(i,s,a),r(n.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(e){if(this.reason){e(this.reason);return}this._listeners?this._listeners.push(e):this._listeners=[e]}unsubscribe(e){if(!this._listeners)return;let r=this._listeners.indexOf(e);r!==-1&&this._listeners.splice(r,1)}toAbortSignal(){let e=new AbortController,r=n=>{e.abort(n)};return this.subscribe(r),e.signal.unsubscribe=()=>this.unsubscribe(r),e.signal}static source(){let e;return{token:new t(function(o){e=o}),cancel:e}}},Vi=Wn;function Jn(t){return function(r){return t.apply(null,r)}}function Kn(t){return p.isObject(t)&&t.isAxiosError===!0}var Gn={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(Gn).forEach(([t,e])=>{Gn[e]=t});var $i=Gn;function Bi(t){let e=new Qt(t),r=Vt(Qt.prototype.request,e);return p.extend(r,Qt.prototype,e,{allOwnKeys:!0}),p.extend(r,e,null,{allOwnKeys:!0}),r.create=function(o){return Bi(ae(t,o))},r}var M=Bi(at);M.Axios=Qt;M.CanceledError=de;M.CancelToken=Vi;M.isCancel=Kt;M.VERSION=Zr;M.toFormData=Ce;M.AxiosError=A;M.Cancel=M.CanceledError;M.all=function(e){return Promise.all(e)};M.spread=Jn;M.isAxiosError=Kn;M.mergeConfig=ae;M.AxiosHeaders=F;M.formToJSON=t=>Ar(p.isHTMLForm(t)?new FormData(t):t);M.getAdapter=kr.getAdapter;M.HttpStatusCode=$i;M.default=M;var Nr=M;var{Axios:by,AxiosError:_y,CanceledError:xy,isCancel:wy,CancelToken:Cy,VERSION:Ty,all:Sy,Cancel:Iy,isAxiosError:Ay,spread:Oy,toFormData:Ey,AxiosHeaders:Ry,HttpStatusCode:Py,formToJSON:ky,getAdapter:jy,mergeConfig:Zy}=Nr;var Xi=vr(Fr());var zr=class{constructor(e){this.API_VERSION="2022-03-01-preview";let{identifier:r,host:n}=e;this.baseURL=new URL(`/copilotstudio/prebuilt/authenticated/bots/${r}`,n),this.baseURL.searchParams.append("api-version",this.API_VERSION)}getConversationUrl(e){let r=new URL(this.baseURL.href);return r.pathname=`${r.pathname}/conversations`,e&&(r.pathname=`${r.pathname}/${e}`),r.href}};var qr=class{constructor(e){this.API_VERSION="2022-03-01-preview";let{schema:r,host:n}=e;this.baseURL=new URL(`/copilotstudio/dataverse-backed/authenticated/bots/${r}`,n),this.baseURL.searchParams.append("api-version",this.API_VERSION)}getConversationUrl(e){let r=new URL(this.baseURL.href);return r.pathname=`${r.pathname}/conversations`,e&&(r.pathname=`${r.pathname}/${e}`),r.href}};var Ne=(0,Xi.debug)("copilot-studio:power-platform");function $r(t,e){var d,m;let r=5;if((d=t.directConnectUrl)!=null&&d.trim()){if(Ne.debug(`Using direct connection: ${t.directConnectUrl}`),!er(t.directConnectUrl))throw new Error("directConnectUrl must be a valid URL");return t.directConnectUrl.toLowerCase().includes("tenants/00000000-0000-0000-0000-000000000000")?(Ne.debug(`Direct connection cannot be used, forcing default settings flow. Tenant ID is missing in the URL: ${t.directConnectUrl}`),$r({...t,directConnectUrl:""},e)):Pu(t.directConnectUrl,e).href}let n=t.cloud&&t.cloud.toString().trim()!=="",o=t.customPowerPlatformCloud!==void 0&&t.customPowerPlatformCloud.trim()!=="";if(n&&!Object.values(qt).includes(t.cloud))throw new Error("Invalid PowerPlatformCloud enum key");let i=n?t.cloud:-1;if(i===100&&o)throw new Error("customPowerPlatformCloud must be provided when PowerPlatformCloud is Other");if(!((m=t.environmentId)!=null&&m.trim()))throw new Error("EnvironmentId must be provided");if(t.agentIdentifier===void 0||t.agentIdentifier.trim()==="")throw new Error("AgentIdentifier must be provided");if(i!==-1&&(Ne.debug(`Using specified cloud setting: ${i}`),r=i),i===100)if(o&&er(t.customPowerPlatformCloud))Ne.debug(`Using custom Power Platform cloud: ${t.customPowerPlatformCloud}`),r=100;else throw new Error("customPowerPlatformCloud must be a valid URL");let s;if(t.copilotAgentType&&t.copilotAgentType.toString().trim()!=="")if(Object.values(zt).includes(t.copilotAgentType))Ne.debug(`Using specified agent type: ${t.copilotAgentType}`),s=t.copilotAgentType;else throw new Error("Invalid AgentType enum key");else Ne.debug("Using default agent type: Published"),s=0;t.customPowerPlatformCloud=o?t.customPowerPlatformCloud:"api.unknown.powerplatform.com";let a=ku(r,t.environmentId,t.customPowerPlatformCloud),u={0:()=>new qr({host:a,schema:t.agentIdentifier}),1:()=>new zr({host:a,identifier:t.agentIdentifier})}[s]().getConversationUrl(e);return Ne.debug(`Generated Copilot Studio connection URL: ${u}`),u}function Qi(t,e=-1,r="",n=""){var o,i;if(!n&&!(t!=null&&t.directConnectUrl)){if(e===100&&!r)throw new Error("cloudBaseAddress must be provided when PowerPlatformCloudCategory is Other");if(!t&&e===-1)throw new Error("Either settings or cloud must be provided");if(t&&t.cloud&&t.cloud!==-1&&(e=t.cloud),e===100)if(r&&er(r))e=100;else if(t!=null&&t.customPowerPlatformCloud&&er(t.customPowerPlatformCloud))e=100,r=t.customPowerPlatformCloud;else throw new Error("Either CustomPowerPlatformCloud or cloudBaseAddress must be provided when PowerPlatformCloudCategory is Other");return r!=null||(r="api.unknown.powerplatform.com"),`https://${Vr(e,r)}/.default`}else if(n||(n=(o=t==null?void 0:t.directConnectUrl)!=null?o:""),n&&er(n)){if(Yi(new URL(n))===-1){let s=(i=t==null?void 0:t.cloud)!=null?i:e;if(s===100||s===-1)throw new Error("Unable to resolve the PowerPlatform Cloud from DirectConnectUrl. The Token Audience resolver requires a specific PowerPlatformCloudCategory.");if(s!==-1)return`https://${Vr(s,"")}/.default`;throw new Error("Unable to resolve the PowerPlatform Cloud from DirectConnectUrl. The Token Audience resolver requires a specific PowerPlatformCloudCategory.")}return`https://${Vr(Yi(new URL(n)),"")}/.default`}else throw new Error("DirectConnectUrl must be provided when DirectConnectUrl is set")}function er(t){try{let e=t.startsWith("http")?t:`https://${t}`;return!!new URL(e)}catch{return!1}}function Pu(t,e){let r=new URL(t);return r.searchParams.has("api-version")||r.searchParams.append("api-version","2022-03-01-preview"),r.pathname.endsWith("/")&&(r.pathname=r.pathname.slice(0,-1)),r.pathname.includes("/conversations")&&(r.pathname=r.pathname.substring(0,r.pathname.indexOf("/conversations"))),r.pathname=`${r.pathname}/conversations`,e&&(r.pathname=`${r.pathname}/${e}`),r}function ku(t,e,r){if(t===100&&(!r||!r.trim()))throw new Error("cloudBaseAddress must be provided when PowerPlatformCloud is Other");r=r!=null?r:"api.unknown.powerplatform.com";let n=e.toLowerCase().replaceAll("-",""),o=ju(t),i=n.substring(0,n.length-o),s=n.substring(n.length-o);return new URL(`https://${i}.${s}.environment.${Vr(t,r)}`)}function Vr(t,e){switch(t){case 13:return"api.powerplatform.localhost";case 0:return"api.exp.powerplatform.com";case 1:return"api.dev.powerplatform.com";case 12:return"api.prv.powerplatform.com";case 2:return"api.test.powerplatform.com";case 3:return"api.preprod.powerplatform.com";case 4:case 5:return"api.powerplatform.com";case 14:return"api.gov.powerplatform.microsoft.us";case 6:return"api.gov.powerplatform.microsoft.us";case 7:return"api.high.powerplatform.microsoft.us";case 8:return"api.appsplatform.us";case 9:return"api.powerplatform.partner.microsoftonline.cn";case 10:return"api.powerplatform.eaglex.ic.gov";case 11:return"api.powerplatform.microsoft.scloud";case 100:return e;default:throw new Error(`Invalid cluster category value: ${t}`)}}function ju(t){switch(t){case 4:case 5:return 2;default:return 1}}function Yi(t){switch(t.host.toLowerCase()){case"api.powerplatform.localhost":return 13;case"api.exp.powerplatform.com":return 0;case"api.dev.powerplatform.com":return 1;case"api.prv.powerplatform.com":return 12;case"api.test.powerplatform.com":return 2;case"api.preprod.powerplatform.com":return 3;case"api.powerplatform.com":return 5;case"api.gov.powerplatform.microsoft.us":return 14;case"api.high.powerplatform.microsoft.us":return 7;case"api.appsplatform.us":return 8;case"api.powerplatform.partner.microsoftonline.cn":return 9;default:return-1}}var mr=vr(Oa());var bn=class{constructor(e){this.activity=e}};var Pa=vr(Fr());var Ea="0.6.16-gc874f0c9d8";var _n={};var Q=(0,Pa.debug)("copilot-studio:client"),we=class we{constructor(e,r){this.conversationId="";this.settings=e,this.client=Nr.create(),this.client.defaults.headers.common.Authorization=`Bearer ${r}`,this.client.defaults.headers.common["User-Agent"]=we.getProductInfo()}async postRequestAsync(e){var m,b,C,h;let r=[];Q.debug(`>>> SEND TO ${e.url}`);let n=await this.client(e);if(this.settings.useExperimentalEndpoint&&!((m=this.settings.directConnectUrl)!=null&&m.trim())){let v=(b=n.headers)==null?void 0:b[we.islandExperimentalUrlHeaderKey];v&&(this.settings.directConnectUrl=v,Q.debug(`Island Experimental URL: ${v}`))}this.conversationId=(h=(C=n.headers)==null?void 0:C[we.conversationIdHeaderKey])!=null?h:"",this.conversationId&&Q.debug(`Conversation ID: ${this.conversationId}`);let o={...n.headers};delete o.Authorization,delete o[we.conversationIdHeaderKey],Q.debug("Headers received:",o);let s=n.data.pipeThrough(new TextDecoderStream).getReader(),a="",c=[],u=async({done:v,value:_})=>v?(Q.debug("Stream complete"),a+=_,c.push(a),c):(Q.info("Agent is typing ..."),a+=_,await u(await s.read()));return(await s.read().then(u)).forEach(v=>{v.toString().split(`
7
+ `).filter(P=>P.substring(0,4)==="data"&&P!=="data: end\r").forEach(P=>{var N,z;try{let D=mr.Activity.fromJson(P.substring(5,P.length));D.type===mr.ActivityTypes.Message?(r.push(D),this.conversationId.trim()||(this.conversationId=(z=(N=D.conversation)==null?void 0:N.id)!=null?z:"",Q.debug(`Conversation ID: ${this.conversationId}`))):Q.debug(`Activity type: ${D.type}`)}catch(D){throw Q.error("Error: ",D),D}})}),r}static getProductInfo(){let e=`CopilotStudioClient.agents-sdk-js/${Ea}`,r;return typeof window!="undefined"&&window.navigator?r=`${e} ${navigator.userAgent}`:r=`${e} nodejs/${process.version} ${_n.platform()}-${_n.arch()}/${_n.release()}`,Q.debug(`User-Agent: ${r}`),r}async startConversationAsync(e=!0){var a;let o={method:"post",url:$r(this.settings),headers:{Accept:"text/event-stream","Content-Type":"application/json"},data:{emitStartConversationEvent:e},responseType:"stream",adapter:"fetch"};Q.info("Starting conversation ...");let i=await this.postRequestAsync(o),s=i[0];return Q.info(`Conversation '${(a=s.conversation)==null?void 0:a.id}' started. Received ${i.length} activities.`,i),s}async askQuestionAsync(e,r=this.conversationId){var m,b;let o={type:"message",text:e,conversation:{id:r}},i=mr.Activity.fromObject(o),s=(b=(m=i.conversation)==null?void 0:m.id)!=null?b:r,a=$r(this.settings,s),c=new bn(i),u={method:"post",url:a,headers:{Accept:"text/event-stream","Content-Type":"application/json"},data:c,responseType:"stream",adapter:"fetch"};Q.info(`Asking question: ${e} ...`);let d=await this.postRequestAsync(u);return Q.info(`Received ${d.length} activities.`,d),d}};we.conversationIdHeaderKey="x-ms-conversationid",we.islandExperimentalUrlHeaderKey="x-ms-d2e-experimental",we.scopeFromSettings=Qi;var Ra=we;var V=[];for(let t=0;t<256;++t)V.push((t+256).toString(16).slice(1));function ka(t,e=0){return(V[t[e+0]]+V[t[e+1]]+V[t[e+2]]+V[t[e+3]]+"-"+V[t[e+4]]+V[t[e+5]]+"-"+V[t[e+6]]+V[t[e+7]]+"-"+V[t[e+8]]+V[t[e+9]]+"-"+V[t[e+10]]+V[t[e+11]]+V[t[e+12]]+V[t[e+13]]+V[t[e+14]]+V[t[e+15]]).toLowerCase()}var Jo,rp=new Uint8Array(16);function Ko(){if(!Jo){if(typeof crypto=="undefined"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Jo=crypto.getRandomValues.bind(crypto)}return Jo(rp)}var np=typeof crypto!="undefined"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Go={randomUUID:np};function op(t,e,r){var o,i,s;if(Go.randomUUID&&!e&&!t)return Go.randomUUID();t=t||{};let n=(s=(i=t.random)!=null?i:(o=t.rng)==null?void 0:o.call(t))!=null?s:Ko();if(n.length<16)throw new Error("Random bytes length must be >= 16");if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,e){if(r=r||0,r<0||r+16>e.length)throw new RangeError(`UUID byte range ${r}:${r+15} is out of buffer bounds`);for(let a=0;a<16;++a)e[r+a]=n[a];return e}return ka(n)}var Yo=op;var Xo=function(t,e){return Xo=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,n){r.__proto__=n}||function(r,n){for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(r[o]=n[o])},Xo(t,e)};function Re(t,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");Xo(t,e);function r(){this.constructor=t}t.prototype=e===null?Object.create(e):(r.prototype=e.prototype,new r)}function hr(t){var e=typeof Symbol=="function"&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function Ut(t,e){var r=typeof Symbol=="function"&&t[Symbol.iterator];if(!r)return t;var n=r.call(t),o,i=[],s;try{for(;(e===void 0||e-- >0)&&!(o=n.next()).done;)i.push(o.value)}catch(a){s={error:a}}finally{try{o&&!o.done&&(r=n.return)&&r.call(n)}finally{if(s)throw s.error}}return i}function Nt(t,e,r){if(r||arguments.length===2)for(var n=0,o=e.length,i;n<o;n++)(i||!(n in e))&&(i||(i=Array.prototype.slice.call(e,0,n)),i[n]=e[n]);return t.concat(i||Array.prototype.slice.call(e))}function ie(t){return typeof t=="function"}function xn(t){var e=function(n){Error.call(n),n.stack=new Error().stack},r=t(e);return r.prototype=Object.create(Error.prototype),r.prototype.constructor=r,r}var wn=xn(function(t){return function(r){t(this),this.message=r?r.length+` errors occurred during unsubscription:
8
8
  `+r.map(function(n,o){return o+1+") "+n.toString()}).join(`
9
9
  `):"",this.name="UnsubscriptionError",this.errors=r}});function yr(t,e){if(t){var r=t.indexOf(e);0<=r&&t.splice(r,1)}}var Dt=function(){function t(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}return t.prototype.unsubscribe=function(){var e,r,n,o,i;if(!this.closed){this.closed=!0;var s=this._parentage;if(s)if(this._parentage=null,Array.isArray(s))try{for(var a=hr(s),c=a.next();!c.done;c=a.next()){var u=c.value;u.remove(this)}}catch(v){e={error:v}}finally{try{c&&!c.done&&(r=a.return)&&r.call(a)}finally{if(e)throw e.error}}else s.remove(this);var d=this.initialTeardown;if(ie(d))try{d()}catch(v){i=v instanceof wn?v.errors:[v]}var m=this._finalizers;if(m){this._finalizers=null;try{for(var b=hr(m),C=b.next();!C.done;C=b.next()){var h=C.value;try{ja(h)}catch(v){i=i!=null?i:[],v instanceof wn?i=Nt(Nt([],Ut(i)),Ut(v.errors)):i.push(v)}}}catch(v){n={error:v}}finally{try{C&&!C.done&&(o=b.return)&&o.call(b)}finally{if(n)throw n.error}}}if(i)throw new wn(i)}},t.prototype.add=function(e){var r;if(e&&e!==this)if(this.closed)ja(e);else{if(e instanceof t){if(e.closed||e._hasParent(this))return;e._addParent(this)}(this._finalizers=(r=this._finalizers)!==null&&r!==void 0?r:[]).push(e)}},t.prototype._hasParent=function(e){var r=this._parentage;return r===e||Array.isArray(r)&&r.includes(e)},t.prototype._addParent=function(e){var r=this._parentage;this._parentage=Array.isArray(r)?(r.push(e),r):r?[r,e]:e},t.prototype._removeParent=function(e){var r=this._parentage;r===e?this._parentage=null:Array.isArray(r)&&yr(r,e)},t.prototype.remove=function(e){var r=this._finalizers;r&&yr(r,e),e instanceof t&&e._removeParent(this)},t.EMPTY=function(){var e=new t;return e.closed=!0,e}(),t}();var Qo=Dt.EMPTY;function Cn(t){return t instanceof Dt||t&&"closed"in t&&ie(t.remove)&&ie(t.add)&&ie(t.unsubscribe)}function ja(t){ie(t)?t():t.unsubscribe()}var ue={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1};var Lt={setTimeout:function(t,e){for(var r=[],n=2;n<arguments.length;n++)r[n-2]=arguments[n];var o=Lt.delegate;return o!=null&&o.setTimeout?o.setTimeout.apply(o,Nt([t,e],Ut(r))):setTimeout.apply(void 0,Nt([t,e],Ut(r)))},clearTimeout:function(t){var e=Lt.delegate;return((e==null?void 0:e.clearTimeout)||clearTimeout)(t)},delegate:void 0};function Za(t){Lt.setTimeout(function(){var e=ue.onUnhandledError;if(e)e(t);else throw t})}function ei(){}var Ua=function(){return ti("C",void 0,void 0)}();function Na(t){return ti("E",void 0,t)}function Da(t){return ti("N",t,void 0)}function ti(t,e,r){return{kind:t,value:e,error:r}}var ot=null;function Mt(t){if(ue.useDeprecatedSynchronousErrorHandling){var e=!ot;if(e&&(ot={errorThrown:!1,error:null}),t(),e){var r=ot,n=r.errorThrown,o=r.error;if(ot=null,n)throw o}}else t()}function La(t){ue.useDeprecatedSynchronousErrorHandling&&ot&&(ot.errorThrown=!0,ot.error=t)}var oi=function(t){Re(e,t);function e(r){var n=t.call(this)||this;return n.isStopped=!1,r?(n.destination=r,Cn(r)&&r.add(n)):n.destination=cp,n}return e.create=function(r,n,o){return new Sn(r,n,o)},e.prototype.next=function(r){this.isStopped?ni(Da(r),this):this._next(r)},e.prototype.error=function(r){this.isStopped?ni(Na(r),this):(this.isStopped=!0,this._error(r))},e.prototype.complete=function(){this.isStopped?ni(Ua,this):(this.isStopped=!0,this._complete())},e.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,t.prototype.unsubscribe.call(this),this.destination=null)},e.prototype._next=function(r){this.destination.next(r)},e.prototype._error=function(r){try{this.destination.error(r)}finally{this.unsubscribe()}},e.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},e}(Dt);var ip=Function.prototype.bind;function ri(t,e){return ip.call(t,e)}var sp=function(){function t(e){this.partialObserver=e}return t.prototype.next=function(e){var r=this.partialObserver;if(r.next)try{r.next(e)}catch(n){Tn(n)}},t.prototype.error=function(e){var r=this.partialObserver;if(r.error)try{r.error(e)}catch(n){Tn(n)}else Tn(e)},t.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(r){Tn(r)}},t}(),Sn=function(t){Re(e,t);function e(r,n,o){var i=t.call(this)||this,s;if(ie(r)||!r)s={next:r!=null?r:void 0,error:n!=null?n:void 0,complete:o!=null?o:void 0};else{var a;i&&ue.useDeprecatedNextContext?(a=Object.create(r),a.unsubscribe=function(){return i.unsubscribe()},s={next:r.next&&ri(r.next,a),error:r.error&&ri(r.error,a),complete:r.complete&&ri(r.complete,a)}):s=r}return i.destination=new sp(s),i}return e}(oi);function Tn(t){ue.useDeprecatedSynchronousErrorHandling?La(t):Za(t)}function ap(t){throw t}function ni(t,e){var r=ue.onStoppedNotification;r&&Lt.setTimeout(function(){return r(t,e)})}var cp={closed:!0,next:ei,error:ap,complete:ei};var Ma=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function Fa(t){return t}function za(t){return t.length===0?Fa:t.length===1?t[0]:function(r){return t.reduce(function(n,o){return o(n)},r)}}var Ft=function(){function t(e){e&&(this._subscribe=e)}return t.prototype.lift=function(e){var r=new t;return r.source=this,r.operator=e,r},t.prototype.subscribe=function(e,r,n){var o=this,i=dp(e)?e:new Sn(e,r,n);return Mt(function(){var s=o,a=s.operator,c=s.source;i.add(a?a.call(i,c):c?o._subscribe(i):o._trySubscribe(i))}),i},t.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(r){e.error(r)}},t.prototype.forEach=function(e,r){var n=this;return r=qa(r),new r(function(o,i){var s=new Sn({next:function(a){try{e(a)}catch(c){i(c),s.unsubscribe()}},error:i,complete:o});n.subscribe(s)})},t.prototype._subscribe=function(e){var r;return(r=this.source)===null||r===void 0?void 0:r.subscribe(e)},t.prototype[Ma]=function(){return this},t.prototype.pipe=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return za(e)(this)},t.prototype.toPromise=function(e){var r=this;return e=qa(e),new e(function(n,o){var i;r.subscribe(function(s){return i=s},function(s){return o(s)},function(){return n(i)})})},t.create=function(e){return new t(e)},t}();function qa(t){var e;return(e=t!=null?t:ue.Promise)!==null&&e!==void 0?e:Promise}function up(t){return t&&ie(t.next)&&ie(t.error)&&ie(t.complete)}function dp(t){return t&&t instanceof oi||up(t)&&Cn(t)}var Va=xn(function(t){return function(){t(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}});var ii=function(t){Re(e,t);function e(){var r=t.call(this)||this;return r.closed=!1,r.currentObservers=null,r.observers=[],r.isStopped=!1,r.hasError=!1,r.thrownError=null,r}return e.prototype.lift=function(r){var n=new $a(this,this);return n.operator=r,n},e.prototype._throwIfClosed=function(){if(this.closed)throw new Va},e.prototype.next=function(r){var n=this;Mt(function(){var o,i;if(n._throwIfClosed(),!n.isStopped){n.currentObservers||(n.currentObservers=Array.from(n.observers));try{for(var s=hr(n.currentObservers),a=s.next();!a.done;a=s.next()){var c=a.value;c.next(r)}}catch(u){o={error:u}}finally{try{a&&!a.done&&(i=s.return)&&i.call(s)}finally{if(o)throw o.error}}}})},e.prototype.error=function(r){var n=this;Mt(function(){if(n._throwIfClosed(),!n.isStopped){n.hasError=n.isStopped=!0,n.thrownError=r;for(var o=n.observers;o.length;)o.shift().error(r)}})},e.prototype.complete=function(){var r=this;Mt(function(){if(r._throwIfClosed(),!r.isStopped){r.isStopped=!0;for(var n=r.observers;n.length;)n.shift().complete()}})},e.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(e.prototype,"observed",{get:function(){var r;return((r=this.observers)===null||r===void 0?void 0:r.length)>0},enumerable:!1,configurable:!0}),e.prototype._trySubscribe=function(r){return this._throwIfClosed(),t.prototype._trySubscribe.call(this,r)},e.prototype._subscribe=function(r){return this._throwIfClosed(),this._checkFinalizedStatuses(r),this._innerSubscribe(r)},e.prototype._innerSubscribe=function(r){var n=this,o=this,i=o.hasError,s=o.isStopped,a=o.observers;return i||s?Qo:(this.currentObservers=null,a.push(r),new Dt(function(){n.currentObservers=null,yr(a,r)}))},e.prototype._checkFinalizedStatuses=function(r){var n=this,o=n.hasError,i=n.thrownError,s=n.isStopped;o?r.error(i):s&&r.complete()},e.prototype.asObservable=function(){var r=new Ft;return r.source=this,r},e.create=function(r,n){return new $a(r,n)},e}(Ft);var $a=function(t){Re(e,t);function e(r,n){var o=t.call(this)||this;return o.destination=r,o.source=n,o}return e.prototype.next=function(r){var n,o;(o=(n=this.destination)===null||n===void 0?void 0:n.next)===null||o===void 0||o.call(n,r)},e.prototype.error=function(r){var n,o;(o=(n=this.destination)===null||n===void 0?void 0:n.error)===null||o===void 0||o.call(n,r)},e.prototype.complete=function(){var r,n;(n=(r=this.destination)===null||r===void 0?void 0:r.complete)===null||n===void 0||n.call(r)},e.prototype._subscribe=function(r){var n,o;return(o=(n=this.source)===null||n===void 0?void 0:n.subscribe(r))!==null&&o!==void 0?o:Qo},e}(ii);var si=function(t){Re(e,t);function e(r){var n=t.call(this)||this;return n._value=r,n}return Object.defineProperty(e.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),e.prototype._subscribe=function(r){var n=t.prototype._subscribe.call(this,r);return!n.closed&&r.next(this._value),n},e.prototype.getValue=function(){var r=this,n=r.hasError,o=r.thrownError,i=r._value;if(n)throw o;return this._throwIfClosed(),i},e.prototype.next=function(r){t.prototype.next.call(this,this._value=r)},e}(ii);var Wa=vr(Fr()),Pe=(0,Wa.debug)("copilot-studio:webchat"),Ba=class{static createConnection(e,r){Pe.info("--> Creating connection between Copilot Studio and WebChat ...");let n=0,o,i,s=new si(0),a=Ha(async d=>{if(o=d,s.value<2){s.next(2);return}Pe.debug("--> Connection established."),u();let m=await e.startConversationAsync();i=m.conversation,n=0,c(m)}),c=d=>{let m={...d,timestamp:new Date().toISOString(),channelData:{...d.channelData,"webchat:sequence-id":n++}};Pe.debug(`Notify '${m.type}' activity to WebChat:`,m),o==null||o.next(m)},u=()=>{if(!(r!=null&&r.showTyping))return;let d=i?{id:i.id,name:i.name}:{id:"agent",name:"Agent"};c({type:"typing",from:d})};return{connectionStatus$:s,activity$:a,postActivity(d){var m;if(Pe.info("--> Preparing to send activity to Copilot Studio ..."),!((m=d.text)!=null&&m.trim()))throw new Error("Activity text cannot be empty.");if(!o)throw new Error("Activity subscriber is not initialized.");return Ha(async b=>{try{let C=Yo();Pe.info("--> Sending activity to Copilot Studio ..."),c({...d,id:C}),u();let h=await e.askQuestionAsync(d.text);for(let v of h)c(v);b.next(C),b.complete(),Pe.info("--> Activity received correctly from Copilot Studio.")}catch(C){Pe.error("Error sending Activity to Copilot Studio:",C),b.error(C)}})},end(){Pe.info("--> Ending connection between Copilot Studio and WebChat ..."),s.complete(),o&&(o.complete(),o=void 0)}}}};function Ha(t){return new Ft(e=>{Promise.resolve(t(e)).catch(r=>e.error(r))})}export{zt as AgentType,ai as ConnectionSettings,Ra as CopilotStudioClient,Ba as CopilotStudioWebChat,bn as ExecuteTurnRequest,qt as PowerPlatformCloud,$r as getCopilotStudioConnectionUrl,Qi as getTokenAudience,yp as loadCopilotStudioConnectionSettingsFromEnv};
10
10
  //# sourceMappingURL=browser.mjs.map