@asgard-js/core 0.3.11 → 0.3.12

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
@@ -1,5 +1,5 @@
1
- (function(p,C){typeof exports=="object"&&typeof module<"u"?C(exports):typeof define=="function"&&define.amd?define(["exports"],C):(p=typeof globalThis<"u"?globalThis:p||self,C(p["@asgard-js/core"]={}))})(this,(function(p){"use strict";class C extends Error{status;statusText;body;constructor(t,e,r){super(`HTTP ${t}: ${e}`),this.name="HttpError",this.status=t,this.statusText=e,this.body=r}}function et(n){return n instanceof C}var $=(n=>(n.RESET_CHANNEL="RESET_CHANNEL",n.NONE="NONE",n.RESPONSE_TOOL_CALL_CONSENT="RESPONSE_TOOL_CALL_CONSENT",n))($||{}),d=(n=>(n.INIT="asgard.run.init",n.PROCESS="asgard.process",n.PROCESS_START="asgard.process.start",n.PROCESS_COMPLETE="asgard.process.complete",n.MESSAGE="asgard.message",n.MESSAGE_START="asgard.message.start",n.MESSAGE_DELTA="asgard.message.delta",n.MESSAGE_COMPLETE="asgard.message.complete",n.MESSAGE_USER="asgard.message.user",n.MESSAGE_THINKING_START="asgard.message.thinking.start",n.MESSAGE_THINKING_DELTA="asgard.message.thinking.delta",n.MESSAGE_THINKING_COMPLETE="asgard.message.thinking.complete",n.TOOL_CALL="asgard.tool_call",n.TOOL_CALL_START="asgard.tool_call.start",n.TOOL_CALL_COMPLETE="asgard.tool_call.complete",n.TOOL_CALL_CONSENT="asgard.tool_call.consent",n.SUBAGENT_START="asgard.subagent.start",n.SUBAGENT_COMPLETE="asgard.subagent.complete",n.CHANNEL_TITLE_UPDATE="asgard.channel.title.update",n.DONE="asgard.run.done",n.ERROR="asgard.run.error",n))(d||{}),ae=(n=>(n.ALLOW_ONCE="ALLOW_ONCE",n.ALLOW_ALWAYS="ALLOW_ALWAYS",n.DENY_ONCE="DENY_ONCE",n))(ae||{}),ce=(n=>(n.TEXT="TEXT",n.HINT="HINT",n.BUTTON="BUTTON",n.IMAGE="IMAGE",n.VIDEO="VIDEO",n.AUDIO="AUDIO",n.LOCATION="LOCATION",n.CAROUSEL="CAROUSEL",n.CHART="CHART",n.TABLE="TABLE",n.ATTACHMENT="ATTACHMENT",n))(ce||{}),W=function(n,t){return W=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(e[s]=r[s])},W(n,t)};function I(n,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");W(n,t);function e(){this.constructor=n}n.prototype=t===null?Object.create(t):(e.prototype=t.prototype,new e)}function tt(n,t,e,r){function s(i){return i instanceof e?i:new e(function(o){o(i)})}return new(e||(e=Promise))(function(i,o){function a(h){try{c(r.next(h))}catch(m){o(m)}}function u(h){try{c(r.throw(h))}catch(m){o(m)}}function c(h){h.done?i(h.value):s(h.value).then(a,u)}c((r=r.apply(n,t||[])).next())})}function ue(n,t){var e={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},r,s,i,o=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return o.next=a(0),o.throw=a(1),o.return=a(2),typeof Symbol=="function"&&(o[Symbol.iterator]=function(){return this}),o;function a(c){return function(h){return u([c,h])}}function u(c){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(e=0)),e;)try{if(r=1,s&&(i=c[0]&2?s.return:c[0]?s.throw||((i=s.return)&&i.call(s),0):s.next)&&!(i=i.call(s,c[1])).done)return i;switch(s=0,i&&(c=[c[0]&2,i.value]),c[0]){case 0:case 1:i=c;break;case 4:return e.label++,{value:c[1],done:!1};case 5:e.label++,s=c[1],c=[0];continue;case 7:c=e.ops.pop(),e.trys.pop();continue;default:if(i=e.trys,!(i=i.length>0&&i[i.length-1])&&(c[0]===6||c[0]===2)){e=0;continue}if(c[0]===3&&(!i||c[1]>i[0]&&c[1]<i[3])){e.label=c[1];break}if(c[0]===6&&e.label<i[1]){e.label=i[1],i=c;break}if(i&&e.label<i[2]){e.label=i[2],e.ops.push(c);break}i[2]&&e.ops.pop(),e.trys.pop();continue}c=t.call(n,e)}catch(h){c=[6,h],s=0}finally{r=i=0}if(c[0]&5)throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}function U(n){var t=typeof Symbol=="function"&&Symbol.iterator,e=t&&n[t],r=0;if(e)return e.call(n);if(n&&typeof n.length=="number")return{next:function(){return n&&r>=n.length&&(n=void 0),{value:n&&n[r++],done:!n}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function j(n,t){var e=typeof Symbol=="function"&&n[Symbol.iterator];if(!e)return n;var r=e.call(n),s,i=[],o;try{for(;(t===void 0||t-- >0)&&!(s=r.next()).done;)i.push(s.value)}catch(a){o={error:a}}finally{try{s&&!s.done&&(e=r.return)&&e.call(r)}finally{if(o)throw o.error}}return i}function D(n,t,e){if(e||arguments.length===2)for(var r=0,s=t.length,i;r<s;r++)(i||!(r in t))&&(i||(i=Array.prototype.slice.call(t,0,r)),i[r]=t[r]);return n.concat(i||Array.prototype.slice.call(t))}function x(n){return this instanceof x?(this.v=n,this):new x(n)}function nt(n,t,e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r=e.apply(n,t||[]),s,i=[];return s=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),a("next"),a("throw"),a("return",o),s[Symbol.asyncIterator]=function(){return this},s;function o(l){return function(f){return Promise.resolve(f).then(l,m)}}function a(l,f){r[l]&&(s[l]=function(g){return new Promise(function(k,T){i.push([l,g,k,T])>1||u(l,g)})},f&&(s[l]=f(s[l])))}function u(l,f){try{c(r[l](f))}catch(g){b(i[0][3],g)}}function c(l){l.value instanceof x?Promise.resolve(l.value.v).then(h,m):b(i[0][2],l)}function h(l){u("next",l)}function m(l){u("throw",l)}function b(l,f){l(f),i.shift(),i.length&&u(i[0][0],i[0][1])}}function rt(n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=n[Symbol.asyncIterator],e;return t?t.call(n):(n=typeof U=="function"?U(n):n[Symbol.iterator](),e={},r("next"),r("throw"),r("return"),e[Symbol.asyncIterator]=function(){return this},e);function r(i){e[i]=n[i]&&function(o){return new Promise(function(a,u){o=n[i](o),s(a,u,o.done,o.value)})}}function s(i,o,a,u){Promise.resolve(u).then(function(c){i({value:c,done:a})},o)}}typeof SuppressedError=="function"&&SuppressedError;function v(n){return typeof n=="function"}function le(n){var t=function(r){Error.call(r),r.stack=new Error().stack},e=n(t);return e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,e}var X=le(function(n){return function(e){n(this),this.message=e?e.length+` errors occurred during unsubscription:
1
+ (function(p,C){typeof exports=="object"&&typeof module<"u"?C(exports):typeof define=="function"&&define.amd?define(["exports"],C):(p=typeof globalThis<"u"?globalThis:p||self,C(p["@asgard-js/core"]={}))})(this,(function(p){"use strict";class C extends Error{status;statusText;body;constructor(t,e,r){super(`HTTP ${t}: ${e}`),this.name="HttpError",this.status=t,this.statusText=e,this.body=r}}function et(n){return n instanceof C}var j=(n=>(n.RESET_CHANNEL="RESET_CHANNEL",n.NONE="NONE",n.RESPONSE_TOOL_CALL_CONSENT="RESPONSE_TOOL_CALL_CONSENT",n))(j||{}),d=(n=>(n.INIT="asgard.run.init",n.PROCESS="asgard.process",n.PROCESS_START="asgard.process.start",n.PROCESS_COMPLETE="asgard.process.complete",n.MESSAGE="asgard.message",n.MESSAGE_START="asgard.message.start",n.MESSAGE_DELTA="asgard.message.delta",n.MESSAGE_COMPLETE="asgard.message.complete",n.MESSAGE_USER="asgard.message.user",n.MESSAGE_THINKING_START="asgard.message.thinking.start",n.MESSAGE_THINKING_DELTA="asgard.message.thinking.delta",n.MESSAGE_THINKING_COMPLETE="asgard.message.thinking.complete",n.TOOL_CALL="asgard.tool_call",n.TOOL_CALL_START="asgard.tool_call.start",n.TOOL_CALL_COMPLETE="asgard.tool_call.complete",n.TOOL_CALL_CONSENT="asgard.tool_call.consent",n.SUBAGENT_START="asgard.subagent.start",n.SUBAGENT_COMPLETE="asgard.subagent.complete",n.CHANNEL_TITLE_UPDATE="asgard.channel.title.update",n.SANDBOX_LAUNCH="asgard.sandbox.launch",n.SANDBOX_READY="asgard.sandbox.ready",n.DONE="asgard.run.done",n.ERROR="asgard.run.error",n))(d||{}),ae=(n=>(n.ALLOW_ONCE="ALLOW_ONCE",n.ALLOW_ALWAYS="ALLOW_ALWAYS",n.DENY_ONCE="DENY_ONCE",n))(ae||{}),ce=(n=>(n.TEXT="TEXT",n.HINT="HINT",n.BUTTON="BUTTON",n.IMAGE="IMAGE",n.VIDEO="VIDEO",n.AUDIO="AUDIO",n.LOCATION="LOCATION",n.CAROUSEL="CAROUSEL",n.CHART="CHART",n.TABLE="TABLE",n.ATTACHMENT="ATTACHMENT",n))(ce||{}),W=function(n,t){return W=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(e[s]=r[s])},W(n,t)};function I(n,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");W(n,t);function e(){this.constructor=n}n.prototype=t===null?Object.create(t):(e.prototype=t.prototype,new e)}function tt(n,t,e,r){function s(i){return i instanceof e?i:new e(function(o){o(i)})}return new(e||(e=Promise))(function(i,o){function a(h){try{c(r.next(h))}catch(m){o(m)}}function u(h){try{c(r.throw(h))}catch(m){o(m)}}function c(h){h.done?i(h.value):s(h.value).then(a,u)}c((r=r.apply(n,t||[])).next())})}function ue(n,t){var e={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},r,s,i,o=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return o.next=a(0),o.throw=a(1),o.return=a(2),typeof Symbol=="function"&&(o[Symbol.iterator]=function(){return this}),o;function a(c){return function(h){return u([c,h])}}function u(c){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(e=0)),e;)try{if(r=1,s&&(i=c[0]&2?s.return:c[0]?s.throw||((i=s.return)&&i.call(s),0):s.next)&&!(i=i.call(s,c[1])).done)return i;switch(s=0,i&&(c=[c[0]&2,i.value]),c[0]){case 0:case 1:i=c;break;case 4:return e.label++,{value:c[1],done:!1};case 5:e.label++,s=c[1],c=[0];continue;case 7:c=e.ops.pop(),e.trys.pop();continue;default:if(i=e.trys,!(i=i.length>0&&i[i.length-1])&&(c[0]===6||c[0]===2)){e=0;continue}if(c[0]===3&&(!i||c[1]>i[0]&&c[1]<i[3])){e.label=c[1];break}if(c[0]===6&&e.label<i[1]){e.label=i[1],i=c;break}if(i&&e.label<i[2]){e.label=i[2],e.ops.push(c);break}i[2]&&e.ops.pop(),e.trys.pop();continue}c=t.call(n,e)}catch(h){c=[6,h],s=0}finally{r=i=0}if(c[0]&5)throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}function k(n){var t=typeof Symbol=="function"&&Symbol.iterator,e=t&&n[t],r=0;if(e)return e.call(n);if(n&&typeof n.length=="number")return{next:function(){return n&&r>=n.length&&(n=void 0),{value:n&&n[r++],done:!n}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function D(n,t){var e=typeof Symbol=="function"&&n[Symbol.iterator];if(!e)return n;var r=e.call(n),s,i=[],o;try{for(;(t===void 0||t-- >0)&&!(s=r.next()).done;)i.push(s.value)}catch(a){o={error:a}}finally{try{s&&!s.done&&(e=r.return)&&e.call(r)}finally{if(o)throw o.error}}return i}function H(n,t,e){if(e||arguments.length===2)for(var r=0,s=t.length,i;r<s;r++)(i||!(r in t))&&(i||(i=Array.prototype.slice.call(t,0,r)),i[r]=t[r]);return n.concat(i||Array.prototype.slice.call(t))}function U(n){return this instanceof U?(this.v=n,this):new U(n)}function nt(n,t,e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r=e.apply(n,t||[]),s,i=[];return s=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),a("next"),a("throw"),a("return",o),s[Symbol.asyncIterator]=function(){return this},s;function o(l){return function(f){return Promise.resolve(f).then(l,m)}}function a(l,f){r[l]&&(s[l]=function(g){return new Promise(function(P,T){i.push([l,g,P,T])>1||u(l,g)})},f&&(s[l]=f(s[l])))}function u(l,f){try{c(r[l](f))}catch(g){y(i[0][3],g)}}function c(l){l.value instanceof U?Promise.resolve(l.value.v).then(h,m):y(i[0][2],l)}function h(l){u("next",l)}function m(l){u("throw",l)}function y(l,f){l(f),i.shift(),i.length&&u(i[0][0],i[0][1])}}function rt(n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=n[Symbol.asyncIterator],e;return t?t.call(n):(n=typeof k=="function"?k(n):n[Symbol.iterator](),e={},r("next"),r("throw"),r("return"),e[Symbol.asyncIterator]=function(){return this},e);function r(i){e[i]=n[i]&&function(o){return new Promise(function(a,u){o=n[i](o),s(a,u,o.done,o.value)})}}function s(i,o,a,u){Promise.resolve(u).then(function(c){i({value:c,done:a})},o)}}typeof SuppressedError=="function"&&SuppressedError;function v(n){return typeof n=="function"}function le(n){var t=function(r){Error.call(r),r.stack=new Error().stack},e=n(t);return e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,e}var z=le(function(n){return function(e){n(this),this.message=e?e.length+` errors occurred during unsubscription:
2
2
  `+e.map(function(r,s){return s+1+") "+r.toString()}).join(`
3
- `):"",this.name="UnsubscriptionError",this.errors=e}});function F(n,t){if(n){var e=n.indexOf(t);0<=e&&n.splice(e,1)}}var N=(function(){function n(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return n.prototype.unsubscribe=function(){var t,e,r,s,i;if(!this.closed){this.closed=!0;var o=this._parentage;if(o)if(this._parentage=null,Array.isArray(o))try{for(var a=U(o),u=a.next();!u.done;u=a.next()){var c=u.value;c.remove(this)}}catch(g){t={error:g}}finally{try{u&&!u.done&&(e=a.return)&&e.call(a)}finally{if(t)throw t.error}}else o.remove(this);var h=this.initialTeardown;if(v(h))try{h()}catch(g){i=g instanceof X?g.errors:[g]}var m=this._finalizers;if(m){this._finalizers=null;try{for(var b=U(m),l=b.next();!l.done;l=b.next()){var f=l.value;try{fe(f)}catch(g){i=i??[],g instanceof X?i=D(D([],j(i)),j(g.errors)):i.push(g)}}}catch(g){r={error:g}}finally{try{l&&!l.done&&(s=b.return)&&s.call(b)}finally{if(r)throw r.error}}}if(i)throw new X(i)}},n.prototype.add=function(t){var e;if(t&&t!==this)if(this.closed)fe(t);else{if(t instanceof n){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(e=this._finalizers)!==null&&e!==void 0?e:[]).push(t)}},n.prototype._hasParent=function(t){var e=this._parentage;return e===t||Array.isArray(e)&&e.includes(t)},n.prototype._addParent=function(t){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(t),e):e?[e,t]:t},n.prototype._removeParent=function(t){var e=this._parentage;e===t?this._parentage=null:Array.isArray(e)&&F(e,t)},n.prototype.remove=function(t){var e=this._finalizers;e&&F(e,t),t instanceof n&&t._removeParent(this)},n.EMPTY=(function(){var t=new n;return t.closed=!0,t})(),n})(),de=N.EMPTY;function he(n){return n instanceof N||n&&"closed"in n&&v(n.remove)&&v(n.add)&&v(n.unsubscribe)}function fe(n){v(n)?n():n.unsubscribe()}var st={Promise:void 0},it={setTimeout:function(n,t){for(var e=[],r=2;r<arguments.length;r++)e[r-2]=arguments[r];return setTimeout.apply(void 0,D([n,t],j(e)))},clearTimeout:function(n){return clearTimeout(n)},delegate:void 0};function pe(n){it.setTimeout(function(){throw n})}function z(){}function K(n){n()}var J=(function(n){I(t,n);function t(e){var r=n.call(this)||this;return r.isStopped=!1,e?(r.destination=e,he(e)&&e.add(r)):r.destination=ct,r}return t.create=function(e,r,s){return new Q(e,r,s)},t.prototype.next=function(e){this.isStopped||this._next(e)},t.prototype.error=function(e){this.isStopped||(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,n.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(e){this.destination.next(e)},t.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t})(N),ot=(function(){function n(t){this.partialObserver=t}return n.prototype.next=function(t){var e=this.partialObserver;if(e.next)try{e.next(t)}catch(r){B(r)}},n.prototype.error=function(t){var e=this.partialObserver;if(e.error)try{e.error(t)}catch(r){B(r)}else B(t)},n.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(e){B(e)}},n})(),Q=(function(n){I(t,n);function t(e,r,s){var i=n.call(this)||this,o;return v(e)||!e?o={next:e??void 0,error:r??void 0,complete:s??void 0}:o=e,i.destination=new ot(o),i}return t})(J);function B(n){pe(n)}function at(n){throw n}var ct={closed:!0,next:z,error:at,complete:z},Z=(function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"})();function q(n){return n}function ut(n){return n.length===0?q:n.length===1?n[0]:function(e){return n.reduce(function(r,s){return s(r)},e)}}var E=(function(){function n(t){t&&(this._subscribe=t)}return n.prototype.lift=function(t){var e=new n;return e.source=this,e.operator=t,e},n.prototype.subscribe=function(t,e,r){var s=this,i=dt(t)?t:new Q(t,e,r);return K(function(){var o=s,a=o.operator,u=o.source;i.add(a?a.call(i,u):u?s._subscribe(i):s._trySubscribe(i))}),i},n.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(e){t.error(e)}},n.prototype.forEach=function(t,e){var r=this;return e=ge(e),new e(function(s,i){var o=new Q({next:function(a){try{t(a)}catch(u){i(u),o.unsubscribe()}},error:i,complete:s});r.subscribe(o)})},n.prototype._subscribe=function(t){var e;return(e=this.source)===null||e===void 0?void 0:e.subscribe(t)},n.prototype[Z]=function(){return this},n.prototype.pipe=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return ut(t)(this)},n.prototype.toPromise=function(t){var e=this;return t=ge(t),new t(function(r,s){var i;e.subscribe(function(o){return i=o},function(o){return s(o)},function(){return r(i)})})},n.create=function(t){return new n(t)},n})();function ge(n){var t;return(t=n??st.Promise)!==null&&t!==void 0?t:Promise}function lt(n){return n&&v(n.next)&&v(n.error)&&v(n.complete)}function dt(n){return n&&n instanceof J||lt(n)&&he(n)}function ht(n){return v(n?.lift)}function O(n){return function(t){if(ht(t))return t.lift(function(e){try{return n(e,this)}catch(r){this.error(r)}});throw new TypeError("Unable to lift unknown Observable type")}}function A(n,t,e,r,s){return new ft(n,t,e,r,s)}var ft=(function(n){I(t,n);function t(e,r,s,i,o,a){var u=n.call(this,e)||this;return u.onFinalize=o,u.shouldUnsubscribe=a,u._next=r?function(c){try{r(c)}catch(h){e.error(h)}}:n.prototype._next,u._error=i?function(c){try{i(c)}catch(h){e.error(h)}finally{this.unsubscribe()}}:n.prototype._error,u._complete=s?function(){try{s()}catch(c){e.error(c)}finally{this.unsubscribe()}}:n.prototype._complete,u}return t.prototype.unsubscribe=function(){var e;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var r=this.closed;n.prototype.unsubscribe.call(this),!r&&((e=this.onFinalize)===null||e===void 0||e.call(this))}},t})(J),pt=le(function(n){return function(){n(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),ee=(function(n){I(t,n);function t(){var e=n.call(this)||this;return e.closed=!1,e.currentObservers=null,e.observers=[],e.isStopped=!1,e.hasError=!1,e.thrownError=null,e}return t.prototype.lift=function(e){var r=new me(this,this);return r.operator=e,r},t.prototype._throwIfClosed=function(){if(this.closed)throw new pt},t.prototype.next=function(e){var r=this;K(function(){var s,i;if(r._throwIfClosed(),!r.isStopped){r.currentObservers||(r.currentObservers=Array.from(r.observers));try{for(var o=U(r.currentObservers),a=o.next();!a.done;a=o.next()){var u=a.value;u.next(e)}}catch(c){s={error:c}}finally{try{a&&!a.done&&(i=o.return)&&i.call(o)}finally{if(s)throw s.error}}}})},t.prototype.error=function(e){var r=this;K(function(){if(r._throwIfClosed(),!r.isStopped){r.hasError=r.isStopped=!0,r.thrownError=e;for(var s=r.observers;s.length;)s.shift().error(e)}})},t.prototype.complete=function(){var e=this;K(function(){if(e._throwIfClosed(),!e.isStopped){e.isStopped=!0;for(var r=e.observers;r.length;)r.shift().complete()}})},t.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(t.prototype,"observed",{get:function(){var e;return((e=this.observers)===null||e===void 0?void 0:e.length)>0},enumerable:!1,configurable:!0}),t.prototype._trySubscribe=function(e){return this._throwIfClosed(),n.prototype._trySubscribe.call(this,e)},t.prototype._subscribe=function(e){return this._throwIfClosed(),this._checkFinalizedStatuses(e),this._innerSubscribe(e)},t.prototype._innerSubscribe=function(e){var r=this,s=this,i=s.hasError,o=s.isStopped,a=s.observers;return i||o?de:(this.currentObservers=null,a.push(e),new N(function(){r.currentObservers=null,F(a,e)}))},t.prototype._checkFinalizedStatuses=function(e){var r=this,s=r.hasError,i=r.thrownError,o=r.isStopped;s?e.error(i):o&&e.complete()},t.prototype.asObservable=function(){var e=new E;return e.source=this,e},t.create=function(e,r){return new me(e,r)},t})(E),me=(function(n){I(t,n);function t(e,r){var s=n.call(this)||this;return s.destination=e,s.source=r,s}return t.prototype.next=function(e){var r,s;(s=(r=this.destination)===null||r===void 0?void 0:r.next)===null||s===void 0||s.call(r,e)},t.prototype.error=function(e){var r,s;(s=(r=this.destination)===null||r===void 0?void 0:r.error)===null||s===void 0||s.call(r,e)},t.prototype.complete=function(){var e,r;(r=(e=this.destination)===null||e===void 0?void 0:e.complete)===null||r===void 0||r.call(e)},t.prototype._subscribe=function(e){var r,s;return(s=(r=this.source)===null||r===void 0?void 0:r.subscribe(e))!==null&&s!==void 0?s:de},t})(ee),H=(function(n){I(t,n);function t(e){var r=n.call(this)||this;return r._value=e,r}return Object.defineProperty(t.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),t.prototype._subscribe=function(e){var r=n.prototype._subscribe.call(this,e);return!r.closed&&e.next(this._value),r},t.prototype.getValue=function(){var e=this,r=e.hasError,s=e.thrownError,i=e._value;if(r)throw s;return this._throwIfClosed(),i},t.prototype.next=function(e){n.prototype.next.call(this,this._value=e)},t})(ee),gt={now:function(){return Date.now()}},mt=(function(n){I(t,n);function t(e,r){return n.call(this)||this}return t.prototype.schedule=function(e,r){return this},t})(N),ve={setInterval:function(n,t){for(var e=[],r=2;r<arguments.length;r++)e[r-2]=arguments[r];return setInterval.apply(void 0,D([n,t],j(e)))},clearInterval:function(n){return clearInterval(n)},delegate:void 0},vt=(function(n){I(t,n);function t(e,r){var s=n.call(this,e,r)||this;return s.scheduler=e,s.work=r,s.pending=!1,s}return t.prototype.schedule=function(e,r){var s;if(r===void 0&&(r=0),this.closed)return this;this.state=e;var i=this.id,o=this.scheduler;return i!=null&&(this.id=this.recycleAsyncId(o,i,r)),this.pending=!0,this.delay=r,this.id=(s=this.id)!==null&&s!==void 0?s:this.requestAsyncId(o,this.id,r),this},t.prototype.requestAsyncId=function(e,r,s){return s===void 0&&(s=0),ve.setInterval(e.flush.bind(e,this),s)},t.prototype.recycleAsyncId=function(e,r,s){if(s===void 0&&(s=0),s!=null&&this.delay===s&&this.pending===!1)return r;r!=null&&ve.clearInterval(r)},t.prototype.execute=function(e,r){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var s=this._execute(e,r);if(s)return s;this.pending===!1&&this.id!=null&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},t.prototype._execute=function(e,r){var s=!1,i;try{this.work(e)}catch(o){s=!0,i=o||new Error("Scheduled action threw falsy error")}if(s)return this.unsubscribe(),i},t.prototype.unsubscribe=function(){if(!this.closed){var e=this,r=e.id,s=e.scheduler,i=s.actions;this.work=this.state=this.scheduler=null,this.pending=!1,F(i,this),r!=null&&(this.id=this.recycleAsyncId(s,r,null)),this.delay=null,n.prototype.unsubscribe.call(this)}},t})(mt),ye=(function(){function n(t,e){e===void 0&&(e=n.now),this.schedulerActionCtor=t,this.now=e}return n.prototype.schedule=function(t,e,r){return e===void 0&&(e=0),new this.schedulerActionCtor(this,t).schedule(r,e)},n.now=gt.now,n})(),yt=(function(n){I(t,n);function t(e,r){r===void 0&&(r=ye.now);var s=n.call(this,e,r)||this;return s.actions=[],s._active=!1,s}return t.prototype.flush=function(e){var r=this.actions;if(this._active){r.push(e);return}var s;this._active=!0;do if(s=e.execute(e.state,e.delay))break;while(e=r.shift());if(this._active=!1,s){for(;e=r.shift();)e.unsubscribe();throw s}},t})(ye),be=new yt(vt),bt=be,St=new E(function(n){return n.complete()});function Se(n){return n&&v(n.schedule)}function Ee(n){return n[n.length-1]}function Et(n){return v(Ee(n))?n.pop():void 0}function Ie(n){return Se(Ee(n))?n.pop():void 0}var we=(function(n){return n&&typeof n.length=="number"&&typeof n!="function"});function Te(n){return v(n?.then)}function Ce(n){return v(n[Z])}function Oe(n){return Symbol.asyncIterator&&v(n?.[Symbol.asyncIterator])}function Ae(n){return new TypeError("You provided "+(n!==null&&typeof n=="object"?"an invalid object":"'"+n+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function It(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var _e=It();function Me(n){return v(n?.[_e])}function Le(n){return nt(this,arguments,function(){var e,r,s,i;return ue(this,function(o){switch(o.label){case 0:e=n.getReader(),o.label=1;case 1:o.trys.push([1,,9,10]),o.label=2;case 2:return[4,x(e.read())];case 3:return r=o.sent(),s=r.value,i=r.done,i?[4,x(void 0)]:[3,5];case 4:return[2,o.sent()];case 5:return[4,x(s)];case 6:return[4,o.sent()];case 7:return o.sent(),[3,2];case 8:return[3,10];case 9:return e.releaseLock(),[7];case 10:return[2]}})})}function ke(n){return v(n?.getReader)}function L(n){if(n instanceof E)return n;if(n!=null){if(Ce(n))return wt(n);if(we(n))return Tt(n);if(Te(n))return Ct(n);if(Oe(n))return Pe(n);if(Me(n))return Ot(n);if(ke(n))return At(n)}throw Ae(n)}function wt(n){return new E(function(t){var e=n[Z]();if(v(e.subscribe))return e.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function Tt(n){return new E(function(t){for(var e=0;e<n.length&&!t.closed;e++)t.next(n[e]);t.complete()})}function Ct(n){return new E(function(t){n.then(function(e){t.closed||(t.next(e),t.complete())},function(e){return t.error(e)}).then(null,pe)})}function Ot(n){return new E(function(t){var e,r;try{for(var s=U(n),i=s.next();!i.done;i=s.next()){var o=i.value;if(t.next(o),t.closed)return}}catch(a){e={error:a}}finally{try{i&&!i.done&&(r=s.return)&&r.call(s)}finally{if(e)throw e.error}}t.complete()})}function Pe(n){return new E(function(t){_t(n,t).catch(function(e){return t.error(e)})})}function At(n){return Pe(Le(n))}function _t(n,t){var e,r,s,i;return tt(this,void 0,void 0,function(){var o,a;return ue(this,function(u){switch(u.label){case 0:u.trys.push([0,5,6,11]),e=rt(n),u.label=1;case 1:return[4,e.next()];case 2:if(r=u.sent(),!!r.done)return[3,4];if(o=r.value,t.next(o),t.closed)return[2];u.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return a=u.sent(),s={error:a},[3,11];case 6:return u.trys.push([6,,9,10]),r&&!r.done&&(i=e.return)?[4,i.call(e)]:[3,8];case 7:u.sent(),u.label=8;case 8:return[3,10];case 9:if(s)throw s.error;return[7];case 10:return[7];case 11:return t.complete(),[2]}})})}function _(n,t,e,r,s){r===void 0&&(r=0),s===void 0&&(s=!1);var i=t.schedule(function(){e(),s?n.add(this.schedule(null,r)):this.unsubscribe()},r);if(n.add(i),!s)return i}function Ue(n,t){return t===void 0&&(t=0),O(function(e,r){e.subscribe(A(r,function(s){return _(r,n,function(){return r.next(s)},t)},function(){return _(r,n,function(){return r.complete()},t)},function(s){return _(r,n,function(){return r.error(s)},t)}))})}function xe(n,t){return t===void 0&&(t=0),O(function(e,r){r.add(n.schedule(function(){return e.subscribe(r)},t))})}function Mt(n,t){return L(n).pipe(xe(t),Ue(t))}function Lt(n,t){return L(n).pipe(xe(t),Ue(t))}function kt(n,t){return new E(function(e){var r=0;return t.schedule(function(){r===n.length?e.complete():(e.next(n[r++]),e.closed||this.schedule())})})}function Pt(n,t){return new E(function(e){var r;return _(e,t,function(){r=n[_e](),_(e,t,function(){var s,i,o;try{s=r.next(),i=s.value,o=s.done}catch(a){e.error(a);return}o?e.complete():e.next(i)},0,!0)}),function(){return v(r?.return)&&r.return()}})}function Ne(n,t){if(!n)throw new Error("Iterable cannot be null");return new E(function(e){_(e,t,function(){var r=n[Symbol.asyncIterator]();_(e,t,function(){r.next().then(function(s){s.done?e.complete():e.next(s.value)})},0,!0)})})}function Ut(n,t){return Ne(Le(n),t)}function xt(n,t){if(n!=null){if(Ce(n))return Mt(n,t);if(we(n))return kt(n,t);if(Te(n))return Lt(n,t);if(Oe(n))return Ne(n,t);if(Me(n))return Pt(n,t);if(ke(n))return Ut(n,t)}throw Ae(n)}function te(n,t){return t?xt(n,t):L(n)}function Nt(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var e=Ie(n);return te(n,e)}function Rt(n){return n instanceof Date&&!isNaN(n)}function R(n,t){return O(function(e,r){var s=0;e.subscribe(A(r,function(i){r.next(n.call(t,i,s++))}))})}var $t=Array.isArray;function jt(n,t){return $t(t)?n.apply(void 0,D([],j(t))):n(t)}function Dt(n){return R(function(t){return jt(n,t)})}var Ht=Array.isArray,Gt=Object.getPrototypeOf,Ft=Object.prototype,Kt=Object.keys;function Bt(n){if(n.length===1){var t=n[0];if(Ht(t))return{args:t,keys:null};if(qt(t)){var e=Kt(t);return{args:e.map(function(r){return t[r]}),keys:e}}}return{args:n,keys:null}}function qt(n){return n&&typeof n=="object"&&Gt(n)===Ft}function Vt(n,t){return n.reduce(function(e,r,s){return e[r]=t[s],e},{})}function Yt(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var e=Ie(n),r=Et(n),s=Bt(n),i=s.args,o=s.keys;if(i.length===0)return te([],e);var a=new E(Wt(i,e,o?function(u){return Vt(o,u)}:q));return r?a.pipe(Dt(r)):a}function Wt(n,t,e){return e===void 0&&(e=q),function(r){Re(t,function(){for(var s=n.length,i=new Array(s),o=s,a=s,u=function(h){Re(t,function(){var m=te(n[h],t),b=!1;m.subscribe(A(r,function(l){i[h]=l,b||(b=!0,a--),a||r.next(e(i.slice()))},function(){--o||r.complete()}))},r)},c=0;c<s;c++)u(c)},r)}}function Re(n,t,e){n?_(e,n,t):t()}function Xt(n,t,e,r,s,i,o,a){var u=[],c=0,h=0,m=!1,b=function(){m&&!u.length&&!c&&t.complete()},l=function(g){return c<r?f(g):u.push(g)},f=function(g){c++;var k=!1;L(e(g,h++)).subscribe(A(t,function(T){t.next(T)},function(){k=!0},void 0,function(){if(k)try{c--;for(var T=function(){var P=u.shift();o||f(P)};u.length&&c<r;)T();b()}catch(P){t.error(P)}}))};return n.subscribe(A(t,l,function(){m=!0,b()})),function(){}}function V(n,t,e){return e===void 0&&(e=1/0),v(t)?V(function(r,s){return R(function(i,o){return t(r,i,s,o)})(L(n(r,s)))},e):(typeof t=="number"&&(e=t),O(function(r,s){return Xt(r,s,n,e)}))}function zt(n,t,e){n===void 0&&(n=0),e===void 0&&(e=bt);var r=-1;return t!=null&&(Se(t)?e=t:r=t),new E(function(s){var i=Rt(n)?+n-e.now():n;i<0&&(i=0);var o=0;return e.schedule(function(){s.closed||(s.next(o++),0<=r?this.schedule(void 0,r):s.complete())},i)})}function Jt(n,t){return v(t)?V(n,t,1):V(n,1)}function Qt(n){return n<=0?function(){return St}:O(function(t,e){var r=0;t.subscribe(A(e,function(s){++r<=n&&(e.next(s),n<=r&&e.complete())}))})}function Zt(n){return R(function(){return n})}function en(n,t){return V(function(e,r){return L(n(e,r)).pipe(Qt(1),Zt(e))})}function tn(n,t){t===void 0&&(t=be);var e=zt(n,t);return en(function(){return e})}function ne(n,t){return t===void 0&&(t=q),n=n??nn,O(function(e,r){var s,i=!0;e.subscribe(A(r,function(o){var a=t(o);(i||!n(s,a))&&(i=!1,s=a,r.next(o))}))})}function nn(n,t){return n===t}function rn(n){return O(function(t,e){try{t.subscribe(e)}finally{e.add(n)}})}function sn(n){return O(function(t,e){L(n).subscribe(A(e,function(){return e.complete()},z)),!e.closed&&t.subscribe(e)})}async function on(n,t){const e=n.getReader();let r;for(;!(r=await e.read()).done;)t(r.value)}function an(n){let t,e,r,s=!1;return function(o){t===void 0?(t=o,e=0,r=-1):t=un(t,o);const a=t.length;let u=0;for(;e<a;){s&&(t[e]===10&&(u=++e),s=!1);let c=-1;for(;e<a&&c===-1;++e)switch(t[e]){case 58:r===-1&&(r=e-u);break;case 13:s=!0;case 10:c=e;break}if(c===-1)break;n(t.subarray(u,c),r),u=e,r=-1}u===a?t=void 0:u!==0&&(t=t.subarray(u),e-=u)}}function cn(n,t,e){let r=$e();const s=new TextDecoder;return function(o,a){if(o.length===0)e?.(r),r=$e();else if(a>0){const u=s.decode(o.subarray(0,a)),c=a+(o[a+1]===32?2:1),h=s.decode(o.subarray(c));switch(u){case"data":r.data=r.data?r.data+`
4
- `+h:h;break;case"event":r.event=h;break;case"id":n(r.id=h);break;case"retry":const m=parseInt(h,10);isNaN(m)||t(r.retry=m);break}}}}function un(n,t){const e=new Uint8Array(n.length+t.length);return e.set(n),e.set(t,n.length),e}function $e(){return{data:"",event:"",id:"",retry:void 0}}var ln=function(n,t){var e={};for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&t.indexOf(r)<0&&(e[r]=n[r]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,r=Object.getOwnPropertySymbols(n);s<r.length;s++)t.indexOf(r[s])<0&&Object.prototype.propertyIsEnumerable.call(n,r[s])&&(e[r[s]]=n[r[s]]);return e};const re="text/event-stream",dn=1e3,je="last-event-id";function hn(n,t){var{signal:e,headers:r,onopen:s,onmessage:i,onclose:o,onerror:a,openWhenHidden:u,fetch:c}=t,h=ln(t,["signal","headers","onopen","onmessage","onclose","onerror","openWhenHidden","fetch"]);return new Promise((m,b)=>{const l=Object.assign({},r);l.accept||(l.accept=re);let f;function g(){f.abort(),document.hidden||ie()}u||document.addEventListener("visibilitychange",g);let k=dn,T=0;function P(){document.removeEventListener("visibilitychange",g),window.clearTimeout(T),f.abort()}e?.addEventListener("abort",()=>{P(),m()});const wn=c??window.fetch,Tn=s??fn;async function ie(){var oe;f=new AbortController;try{const Y=await wn(n,Object.assign(Object.assign({},h),{headers:l,signal:f.signal}));await Tn(Y),await on(Y.body,an(cn(M=>{M?l[je]=M:delete l[je]},M=>{k=M},i))),o?.(),P(),m()}catch(Y){if(!f.signal.aborted)try{const M=(oe=a?.(Y))!==null&&oe!==void 0?oe:k;window.clearTimeout(T),T=window.setTimeout(ie,M)}catch(M){P(),b(M)}}}ie()})}function fn(n){const t=n.headers.get("content-type");if(!t?.startsWith(re))throw new Error(`Expected content-type to be ${re}, Actual: ${t}`)}function De(n){const{endpoint:t,apiKey:e,payload:r,debugMode:s,customHeaders:i}=n,o=n.method??"POST";return new E(a=>{const u=new AbortController;let c,h=!1;const m={"Content-Type":"application/json",...i};e&&(m["X-API-KEY"]=e);const b=new URL(t);return s&&b.searchParams.set("is_debug","true"),hn(b.toString(),{method:o,headers:m,body:o==="POST"&&r?JSON.stringify(r):void 0,signal:u.signal,openWhenHidden:!0,onopen:async l=>{if(l.ok)c=l.headers.get("X-Trace-Id")??void 0;else{let f;try{f=await l.json()}catch{try{f=await l.text()}catch{f=null}}a.error(new C(l.status,l.statusText,f)),u.abort()}},onmessage:l=>{l.id&&(h=!0);const f=JSON.parse(l.data);c?f.traceId=c:f.requestId&&(f.traceId=f.requestId,c||(c=f.requestId)),a.next(f)},onclose:()=>{a.complete()},onerror:l=>{if(!h)throw a.error(l),u.abort(),l}}),()=>{u.abort()}})}class pn{listeners={};on(t,e){this.listeners=Object.assign({},this.listeners,{[t]:(this.listeners[t]??[]).concat(e)})}off(t,e){this.listeners[t]&&(this.listeners=Object.assign({},this.listeners,{[t]:(this.listeners[t]??[]).filter(r=>r!==e)}))}remove(t){delete this.listeners[t]}emit(t,...e){this.listeners[t]&&this.listeners[t].forEach(r=>r(...e))}}class gn{apiKey;endpoint;botProviderEndpoint;debugMode;destroy$=new ee;closed=!1;detached=!1;detachTimer;inFlight=0;sseEmitter=new pn;transformSsePayload;customHeaders;constructor(t){if(!t.endpoint&&!t.botProviderEndpoint)throw new Error("Either endpoint or botProviderEndpoint must be provided");if(this.apiKey=t.apiKey,this.debugMode=t.debugMode,this.transformSsePayload=t.transformSsePayload,this.botProviderEndpoint=t.botProviderEndpoint,this.customHeaders={...t.customHeaders,...t.userIdentityHint?{"X-ASGARD-USER-IDENTITY-HINT":t.userIdentityHint}:{}},!t.endpoint&&t.botProviderEndpoint){const e=t.botProviderEndpoint.replace(/\/+$/,"");this.endpoint=`${e}/message/sse`}else t.endpoint&&(this.endpoint=t.endpoint,this.debugMode&&console.warn('[AsgardServiceClient] The "endpoint" option is deprecated and will be removed in the next major version. Please use "botProviderEndpoint" instead. The SSE endpoint will be automatically derived as "${botProviderEndpoint}/message/sse".'))}on(t,e){this.sseEmitter.remove(t),this.sseEmitter.on(t,e)}handleEvent(t){switch(t.eventType){case d.INIT:this.sseEmitter.emit(d.INIT,t);break;case d.PROCESS_START:case d.PROCESS_COMPLETE:this.sseEmitter.emit(d.PROCESS,t);break;case d.MESSAGE_START:case d.MESSAGE_DELTA:case d.MESSAGE_COMPLETE:this.sseEmitter.emit(d.MESSAGE,t);break;case d.TOOL_CALL_START:case d.TOOL_CALL_COMPLETE:this.sseEmitter.emit(d.TOOL_CALL,t);break;case d.TOOL_CALL_CONSENT:this.sseEmitter.emit(d.TOOL_CALL_CONSENT,t);break;case d.DONE:this.sseEmitter.emit(d.DONE,t);break;case d.ERROR:this.sseEmitter.emit(d.ERROR,t);break}}fetchSse(t,e){return e?.onSseStart?.(),this.inFlight+=1,this.runSse(De({apiKey:this.apiKey,endpoint:this.endpoint,debugMode:this.debugMode,payload:this.transformSsePayload?.(t)??t,customHeaders:this.customHeaders}),e)}rejoinSse(t,e){e?.onSseStart?.(),this.inFlight+=1;const r=new URL(this.endpoint);return r.searchParams.set("custom_channel_id",t),this.runSse(De({apiKey:this.apiKey,endpoint:r.toString(),debugMode:this.debugMode,method:"GET",customHeaders:this.customHeaders}),e)}deriveChannelMetadataEndpoint(){const t=this.getBaseEndpoint();return t?`${t}/channel/metadata`:null}async channelMetadata(t){const e=this.deriveChannelMetadataEndpoint();if(!e)throw new Error("Unable to derive channel metadata endpoint. Please provide botProviderEndpoint in config.");const r=new URL(e);r.searchParams.set("custom_channel_id",t);const s={...this.customHeaders};this.apiKey&&(s["X-API-KEY"]=this.apiKey);const i=await fetch(r.toString(),{method:"GET",headers:s});if(i.status===404)return null;if(!i.ok)throw new C(i.status,i.statusText,await i.text().catch(()=>{}));const o=await i.json(),a=o.data??o;return{title:a.title??null,runState:a.runState??"IDLE",lastActivityAt:a.lastActivityAt}}runSse(t,e){return t.pipe(Jt(r=>Nt(r).pipe(tn(e?.delayTime??50))),sn(this.destroy$),rn(()=>this.onRunSettled())).subscribe({next:r=>{this.detached||(e?.onSseMessage?.(r),this.handleEvent(r))},error:r=>{this.detached||e?.onSseError?.(r)},complete:()=>{this.detached||e?.onSseCompleted?.()}})}detach(t){if(!(this.detached||this.closed)){if(this.detached=!0,this.inFlight===0){this.close();return}this.detachTimer=setTimeout(()=>this.close(),t.timeoutMs)}}onRunSettled(){this.inFlight=Math.max(0,this.inFlight-1),this.detached&&this.inFlight===0&&this.close()}close(){this.closed||(this.closed=!0,this.detachTimer&&(clearTimeout(this.detachTimer),this.detachTimer=void 0),this.destroy$.next(),this.destroy$.complete())}async uploadFile(t,e){const r=this.deriveBlobEndpoint();if(!r)throw new Error("Unable to derive blob endpoint. Please provide botProviderEndpoint in config.");const s=new FormData;s.append("file",t),s.append("customChannelId",e);const i={...this.customHeaders};this.apiKey&&(i["X-API-KEY"]=this.apiKey);try{const o=await fetch(r,{method:"POST",headers:i,body:s});if(!o.ok)throw new Error(`Upload failed: ${o.status} ${o.statusText}`);const a=await o.json();return this.debugMode&&console.log("[AsgardServiceClient] File upload response:",a),a}catch(o){throw console.error("[AsgardServiceClient] File upload error:",o),o}}async downloadChannelHomeFile(t,e){const r=this.getBaseEndpoint();if(!r)throw new Error("Unable to derive channel-home download endpoint. Please provide botProviderEndpoint in config.");const s=`custom_channel_id=${encodeURIComponent(e)}&relative_path=${encodeURIComponent(t)}`,i=`${r}/channel-home/download?${s}`,o={...this.customHeaders};this.apiKey&&(o["X-API-KEY"]=this.apiKey);try{const a=await fetch(i,{method:"GET",headers:o});if(!a.ok)throw new Error(`Channel Home download failed: ${a.status} ${a.statusText}`);const u=await a.blob(),c=t.split("/").pop()||"download";return this.debugMode&&console.log("[AsgardServiceClient] Channel Home download response:",{filename:c,size:u.size}),{blob:u,filename:c}}catch(a){throw console.error("[AsgardServiceClient] Channel Home download error:",a),a}}deriveBlobEndpoint(){const t=this.getBaseEndpoint();return t?`${t}/blob`:null}getBaseEndpoint(){let t=this.botProviderEndpoint;return!t&&this.endpoint&&(t=this.endpoint.replace("/message/sse","")),t?t.replace(/\/+$/,""):null}}const S=[];for(let n=0;n<256;++n)S.push((n+256).toString(16).slice(1));function mn(n,t=0){return(S[n[t+0]]+S[n[t+1]]+S[n[t+2]]+S[n[t+3]]+"-"+S[n[t+4]]+S[n[t+5]]+"-"+S[n[t+6]]+S[n[t+7]]+"-"+S[n[t+8]]+S[n[t+9]]+"-"+S[n[t+10]]+S[n[t+11]]+S[n[t+12]]+S[n[t+13]]+S[n[t+14]]+S[n[t+15]]).toLowerCase()}let se;const vn=new Uint8Array(16);function yn(){if(!se){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");se=crypto.getRandomValues.bind(crypto)}return se(vn)}const He={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function bn(n,t,e){n=n||{};const r=n.random??n.rng?.()??yn();if(r.length<16)throw new Error("Random bytes length must be >= 16");return r[6]=r[6]&15|64,r[8]=r[8]&63|128,mn(r)}function Ge(n,t,e){return He.randomUUID&&!n?He.randomUUID():bn(n)}class y{messages=null;pendingConsent=null;constructor({messages:t,pendingConsent:e=null}){this.messages=t,this.pendingConsent=e??null}pushMessage(t){const e=new Map(this.messages);return e.set(t.messageId,t),new y({messages:e,pendingConsent:this.pendingConsent})}clearPendingConsent(){return this.pendingConsent?new y({messages:this.messages,pendingConsent:null}):this}cancelInFlightToolCalls(){if(!this.messages)return this;let t=!1;const e=new Map(this.messages);for(const[r,s]of e)s.type==="tool-call"&&!s.isComplete&&(e.set(r,{...s,isComplete:!0,isCancelled:!0}),t=!0);return t?new y({messages:e,pendingConsent:this.pendingConsent}):this}onMessage(t){switch(t.eventType){case d.MESSAGE_START:return this.onMessageStart(t);case d.MESSAGE_DELTA:return this.onMessageDelta(t);case d.MESSAGE_COMPLETE:return this.onMessageComplete(t);case d.MESSAGE_USER:return this.onMessageUser(t);case d.MESSAGE_THINKING_START:return this.onThinkingStart(t);case d.MESSAGE_THINKING_DELTA:return this.onThinkingDelta(t);case d.MESSAGE_THINKING_COMPLETE:return this.onThinkingComplete(t);case d.TOOL_CALL_START:return this.onToolCallStart(t);case d.TOOL_CALL_COMPLETE:return this.onToolCallComplete(t);case d.TOOL_CALL_CONSENT:return this.onToolCallConsent(t);case d.SUBAGENT_START:return this.onSubagentStart(t);case d.SUBAGENT_COMPLETE:return this.onSubagentComplete(t);case d.ERROR:return this.onMessageError(t);default:return this}}isTerminalBot(t){return t?.type==="bot"&&!t.isTyping}isTerminalThinking(t){return t?.type==="thinking"&&!t.isThinking}onMessageStart(t){const e=t.fact.messageStart.message;if(this.isTerminalBot(this.messages?.get(e.messageId)))return this;const r=new Map(this.messages);return r.set(e.messageId,{type:"bot",eventType:d.MESSAGE_START,isTyping:!0,typingText:"",messageId:e.messageId,message:e,time:new Date,traceId:t.traceId,raw:""}),new y({messages:r,pendingConsent:this.pendingConsent})}onMessageDelta(t){const e=t.fact.messageDelta.message,r=this.messages?.get(e.messageId);if(this.isTerminalBot(r))return this;const s=r?.type==="bot"?r:void 0,i=new Map(this.messages);return i.set(e.messageId,{type:"bot",eventType:d.MESSAGE_DELTA,isTyping:!0,typingText:`${s?.typingText??""}${e.text}`,messageId:e.messageId,message:e,time:new Date,traceId:t.traceId??s?.traceId,raw:s?.raw??""}),new y({messages:i,pendingConsent:this.pendingConsent})}onMessageComplete(t){const e=t.fact.messageComplete.message,r=new Map(this.messages),s=r.get(e.messageId);return r.set(e.messageId,{type:"bot",eventType:d.MESSAGE_COMPLETE,isTyping:!1,typingText:null,messageId:e.messageId,message:e,time:new Date,traceId:t.traceId??(s?.type==="bot"?s.traceId:void 0),raw:JSON.stringify(t)}),new y({messages:r,pendingConsent:this.pendingConsent})}onThinkingStart(t){const e=t.fact.messageThinkingStart.message;if(this.isTerminalThinking(this.messages?.get(e.messageId)))return this;const r=new Map(this.messages),s={type:"thinking",messageId:e.messageId,text:e.text,isThinking:!0,time:new Date,traceId:t.traceId};return r.set(e.messageId,s),new y({messages:r,pendingConsent:this.pendingConsent})}onThinkingDelta(t){const e=t.fact.messageThinkingDelta.message,r=this.messages?.get(e.messageId);if(this.isTerminalThinking(r))return this;const s=r?.type==="thinking"?r:void 0,i=new Map(this.messages),o={type:"thinking",messageId:e.messageId,text:`${s?.text??""}${e.text}`,isThinking:!0,time:s?.time??new Date,traceId:t.traceId??s?.traceId};return i.set(e.messageId,o),new y({messages:i,pendingConsent:this.pendingConsent})}onThinkingComplete(t){const e=t.fact.messageThinkingComplete.message,r=this.messages?.get(e.messageId),s=r?.type==="thinking"?r:void 0,i=new Map(this.messages),o={type:"thinking",messageId:e.messageId,text:e.text,isThinking:!1,time:s?.time??new Date,traceId:t.traceId??s?.traceId};return i.set(e.messageId,o),new y({messages:i,pendingConsent:this.pendingConsent})}onMessageUser(t){const e=t.fact.messageUser;if((this.messages?.get(e.messageId)??(e.customMessageId?this.messages?.get(e.customMessageId):void 0))?.type==="user")return this;const s=new Map(this.messages),i={type:"user",messageId:e.messageId,text:e.text,blobIds:e.blobIds,customMessageId:e.customMessageId,identityHint:e.identityHint,time:new Date,traceId:t.traceId};return s.set(e.messageId,i),new y({messages:s,pendingConsent:this.pendingConsent})}onMessageError(t){const e=Ge(),r=t.fact.runError.error,s=new Map(this.messages);return s.set(e,{type:"error",eventType:d.ERROR,messageId:e,error:r,time:new Date,traceId:t.traceId}),new y({messages:s,pendingConsent:this.pendingConsent})}onToolCallStart(t){const e=t.fact.toolCallStart,r=new Map(this.messages),s=`${e.processId}-${e.callSeq}`,i={type:"tool-call",eventType:d.TOOL_CALL_START,messageId:s,processId:e.processId,callSeq:e.callSeq,toolName:e.toolCall.toolName,reason:e.toolCall.reason,toolsetName:e.toolCall.toolsetName,parameter:e.toolCall.parameter,toolUseId:e.toolUseId,parentToolUseId:e.parentToolUseId,isComplete:!1,time:new Date,traceId:t.traceId};return r.set(s,i),new y({messages:r,pendingConsent:this.pendingConsent})}onToolCallComplete(t){const e=t.fact.toolCallComplete,r=new Map(this.messages),s=`${e.processId}-${e.callSeq}`,i=r.get(s);if(i?.type==="tool-call"){const o={...i,eventType:d.TOOL_CALL_COMPLETE,result:e.toolCallResult,isError:e.isError,sidecar:e.toolUseResultSidecar,isComplete:!0,traceId:t.traceId??i.traceId};r.set(s,o)}return new y({messages:r,pendingConsent:this.pendingConsent})}onToolCallConsent(t){const e=t.fact.toolCallConsent;return new y({messages:this.messages,pendingConsent:e})}onSubagentStart(t){const e=t.fact.subagentStart,r=new Map(this.messages),s=`subagent:${e.parentToolUseId}:start`,i={type:"subagent",messageId:s,kind:"start",parentToolUseId:e.parentToolUseId,agentId:e.agentId,subagentType:e.subagentType,description:e.description,time:new Date,traceId:t.traceId};return r.set(s,i),new y({messages:r,pendingConsent:this.pendingConsent})}onSubagentComplete(t){const e=t.fact.subagentComplete,r=new Map(this.messages),s=`subagent:${e.parentToolUseId}:complete`,i={type:"subagent",messageId:s,kind:"complete",parentToolUseId:e.parentToolUseId,agentId:e.agentId,subagentType:e.subagentType,status:e.status,summary:e.summary,time:new Date,traceId:t.traceId};return r.set(s,i),new y({messages:r,pendingConsent:this.pendingConsent})}}const Sn=new Set(["TaskCreate","TaskUpdate"]);function Fe(n){return n.toolsetName===""&&Sn.has(n.toolName)}function Ke(n){return typeof n=="object"&&n!==null?n:void 0}function w(n){return typeof n=="string"?n:void 0}function Be(n){const t=[],e=new Map;for(const r of n){const s=r.parameter??{},i=r.sidecar??{};if(r.toolName==="TaskCreate"){const o=Ke(i.task),a=w(o?.id);if(!a)continue;e.has(a)||t.push(a),e.set(a,{id:a,subject:w(s.subject)||w(o?.subject)||"",activeForm:w(s.activeForm),description:w(s.description),status:e.get(a)?.status??"pending"})}else if(r.toolName==="TaskUpdate"){const o=Ke(i.statusChange),a=w(s.taskId)||w(i.taskId),u=w(o?.to)||w(s.status);if(!a||!u)continue;const c=e.get(a);c&&e.set(a,{...c,status:u})}}return t.map(r=>e.get(r))}function qe(n){return n.toolsetName===""&&n.toolName==="Agent"}function Ve(n){return!!n}function Ye(n){const t=[],e=new Map,r=new Map,s=i=>(e.has(i)||(t.push(i),e.set(i,{status:"running"}),r.set(i,new Map)),e.get(i));for(const i of n)switch(i.kind){case"agentStart":{const o=s(i.toolUseId);i.description&&!o.description&&(o.description=i.description);break}case"subagentStart":{const o=s(i.parentToolUseId);o.agentId=i.agentId??o.agentId,o.subagentType=i.subagentType??o.subagentType,o.description=i.description??o.description;break}case"toolStart":{s(i.parentToolUseId),r.get(i.parentToolUseId).set(i.toolUseId,{toolsetName:i.toolsetName,toolName:i.toolName,parameter:i.parameter??{},reason:i.reason,status:"running"});break}case"toolComplete":{const o=r.get(i.parentToolUseId)?.get(i.toolUseId);o&&(o.status=i.isError?"error":"completed");break}case"subagentComplete":{const o=s(i.parentToolUseId);o.status=i.status,o.summary=i.summary;break}}return t.map(i=>({parentToolUseId:i,...e.get(i),tools:Array.from(r.get(i).values())}))}function En(n){return typeof n=="string"?n:void 0}function We(n){const t=[];for(const e of n){if(e.type==="tool-call"&&qe(e)){t.push({kind:"agentStart",toolUseId:e.toolUseId??e.messageId,description:En(e.parameter.description)});continue}if(e.type==="tool-call"&&Ve(e.parentToolUseId)){const r=e.toolUseId??e.messageId;t.push({kind:"toolStart",parentToolUseId:e.parentToolUseId,toolUseId:r,toolsetName:e.toolsetName,toolName:e.toolName,parameter:e.parameter,reason:e.reason}),e.isComplete&&t.push({kind:"toolComplete",parentToolUseId:e.parentToolUseId,toolUseId:r,isError:e.isError});continue}if(e.type==="subagent"&&e.kind==="start"){t.push({kind:"subagentStart",parentToolUseId:e.parentToolUseId,agentId:e.agentId,subagentType:e.subagentType,description:e.description});continue}e.type==="subagent"&&e.kind==="complete"&&e.status&&t.push({kind:"subagentComplete",parentToolUseId:e.parentToolUseId,status:e.status,summary:e.summary})}return t}function Xe(n){const t=Array.from(n.messages?.values()??[]).filter(e=>e.type==="tool-call"&&e.isComplete&&Fe(e));return Be(t)}function ze(n){return Ye(We(Array.from(n.messages?.values()??[])))}function Je(n,t){return n===t?!0:n.length!==t.length?!1:n.every((e,r)=>{const s=t[r];return e.id===s.id&&e.status===s.status&&e.subject===s.subject&&e.activeForm===s.activeForm&&e.description===s.description})}function In(n,t){return n.length!==t.length?!1:n.every((e,r)=>{const s=t[r];return e.toolName===s.toolName&&e.toolsetName===s.toolsetName&&e.status===s.status&&e.reason===s.reason})}function Qe(n,t){return n===t?!0:n.length!==t.length?!1:n.every((e,r)=>{const s=t[r];return e.parentToolUseId===s.parentToolUseId&&e.status===s.status&&e.subagentType===s.subagentType&&e.description===s.description&&e.summary===s.summary&&In(e.tools,s.tools)})}function Ze(n){const t=new H([]),e=new H([]),r=new N;return r.add(n.pipe(R(Xe),ne(Je)).subscribe(t)),r.add(n.pipe(R(ze),ne(Qe)).subscribe(e)),{tasks$:t.asObservable(),subagents$:e.asObservable(),getTasks:()=>t.value,getSubagents:()=>e.value,teardown:()=>r.unsubscribe()}}class G{client;customChannelId;customMessageId;isConnecting$;conversation$;channelTitleSubject;derivedStores;statesObserver;statesSubscription;tasks$;subagents$;channelTitle$;currentUserMessageId;lastSentMessageId;currentRun;constructor(t){if(!t.client)throw new Error("client must be required");if(!t.customChannelId)throw new Error("customChannelId must be required");this.client=t.client,this.customChannelId=t.customChannelId,this.customMessageId=t.customMessageId,this.isConnecting$=new H(!1),this.conversation$=new H(t.conversation),this.channelTitleSubject=new H(t.channelTitle??null),this.derivedStores=Ze(this.conversation$),this.tasks$=this.derivedStores.tasks$,this.subagents$=this.derivedStores.subagents$,this.channelTitle$=this.channelTitleSubject.pipe(ne()),this.statesObserver=t.statesObserver}getTasks(){return this.derivedStores.getTasks()}getSubagents(){return this.derivedStores.getSubagents()}getChannelTitle(){return this.channelTitleSubject.value}setChannelTitle(t){this.channelTitleSubject.next(t)}static create(t){const e=new G(t);return e.subscribe(),e}static async reset(t,e,r,s){const i=new G(t);try{return i.subscribe(),s?.(i),await i.resetChannel(e,r),i}catch(o){throw i.close(),o}}static async restore(t,e,r){const s=new G(t);try{return s.subscribe(),r?.(s),await s.rejoinChannel(e),s}catch(i){throw s.close(),i}}subscribe(){this.statesSubscription=Yt([this.isConnecting$,this.conversation$,this.derivedStores.tasks$,this.derivedStores.subagents$,this.channelTitle$]).pipe(R(([t,e,r,s,i])=>({isConnecting:t,conversation:e,tasks:r,subagents:s,channelTitle:i}))).subscribe(this.statesObserver)}resolvePayload(t){if(typeof t=="function")try{return t()}catch(e){throw new Error(`Failed to resolve payload function: ${e instanceof Error?e.message:String(e)}`)}return t}buildRunHandlers(t,e,r){return{onSseStart:t?.onSseStart,onSseMessage:s=>{if(t?.onSseMessage?.(s),s.eventType===d.CHANNEL_TITLE_UPDATE&&this.channelTitleSubject.next(s.fact.channelTitleUpdate.title),this.currentUserMessageId&&s.traceId){const i=new Map(this.conversation$.value.messages),o=i.get(this.currentUserMessageId);o&&o.type==="user"&&(i.set(this.currentUserMessageId,{...o,traceId:s.traceId}),this.conversation$.next(new y({messages:i}))),this.currentUserMessageId=void 0}this.conversation$.next(this.conversation$.value.onMessage(s))},onSseError:s=>{t?.onSseError?.(s),this.isConnecting$.next(!1),this.currentUserMessageId=void 0,this.currentRun=void 0,r(s)},onSseCompleted:()=>{t?.onSseCompleted?.(),this.isConnecting$.next(!1),this.currentUserMessageId=void 0,this.currentRun=void 0,e()}}}fetchSse(t,e){return new Promise((r,s)=>{this.isConnecting$.next(!0),this.currentRun=this.client.fetchSse(t,this.buildRunHandlers(e,r,s))})}rejoinChannel(t){return new Promise((e,r)=>{if(!this.client.rejoinSse){e();return}this.isConnecting$.next(!0),this.currentRun=this.client.rejoinSse(this.customChannelId,this.buildRunHandlers(t,e,r))})}resetChannel(t,e){return this.fetchSse({action:$.RESET_CHANNEL,customChannelId:this.customChannelId,customMessageId:this.customMessageId,text:t?.text||"",payload:this.resolvePayload(t?.payload)},e)}sendMessage(t,e){const r=t.text.trim(),s=t.customMessageId??Ge();return this.currentUserMessageId=s,this.lastSentMessageId=s,this.conversation$.next(this.conversation$.value.pushMessage({type:"user",messageId:s,text:r,blobIds:t.blobIds,filePreviewUrls:t.filePreviewUrls,documentNames:t.documentNames,time:new Date})),this.fetchSse({action:$.NONE,customChannelId:this.customChannelId,customMessageId:s,payload:this.resolvePayload(t?.payload),text:r,blobIds:t?.blobIds},e)}replyToolCallConsents(t,e,r){return this.conversation$.next(this.conversation$.value.clearPendingConsent()),this.fetchSse({action:$.RESPONSE_TOOL_CALL_CONSENT,customChannelId:this.customChannelId,customMessageId:this.lastSentMessageId??this.customMessageId,payload:this.resolvePayload(r),text:"",toolCallConsents:t},e)}stopGeneration(){this.currentRun&&(this.currentRun.unsubscribe(),this.currentRun=void 0,this.isConnecting$.next(!1),this.currentUserMessageId=void 0,this.conversation$.next(this.conversation$.value.cancelInFlightToolCalls()))}close(){this.currentRun?.unsubscribe(),this.currentRun=void 0,this.isConnecting$.complete(),this.conversation$.complete(),this.channelTitleSubject.complete(),this.derivedStores.teardown(),this.statesSubscription?.unsubscribe()}}p.AsgardServiceClient=gn,p.Channel=G,p.Conversation=y,p.EventType=d,p.FetchSseAction=$,p.HttpError=C,p.MessageTemplateType=ce,p.ToolCallConsentResult=ae,p.conversationToSubagentEvents=We,p.createDerivedStores=Ze,p.deriveSubagents=ze,p.deriveTasks=Xe,p.isAgentTool=qe,p.isHttpError=et,p.isSubagentChildTool=Ve,p.isTaskTool=Fe,p.reduceSubagents=Ye,p.reduceTaskEvents=Be,p.subagentsEqual=Qe,p.tasksEqual=Je,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})}));
3
+ `):"",this.name="UnsubscriptionError",this.errors=e}});function F(n,t){if(n){var e=n.indexOf(t);0<=e&&n.splice(e,1)}}var N=(function(){function n(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return n.prototype.unsubscribe=function(){var t,e,r,s,i;if(!this.closed){this.closed=!0;var o=this._parentage;if(o)if(this._parentage=null,Array.isArray(o))try{for(var a=k(o),u=a.next();!u.done;u=a.next()){var c=u.value;c.remove(this)}}catch(g){t={error:g}}finally{try{u&&!u.done&&(e=a.return)&&e.call(a)}finally{if(t)throw t.error}}else o.remove(this);var h=this.initialTeardown;if(v(h))try{h()}catch(g){i=g instanceof z?g.errors:[g]}var m=this._finalizers;if(m){this._finalizers=null;try{for(var y=k(m),l=y.next();!l.done;l=y.next()){var f=l.value;try{fe(f)}catch(g){i=i??[],g instanceof z?i=H(H([],D(i)),D(g.errors)):i.push(g)}}}catch(g){r={error:g}}finally{try{l&&!l.done&&(s=y.return)&&s.call(y)}finally{if(r)throw r.error}}}if(i)throw new z(i)}},n.prototype.add=function(t){var e;if(t&&t!==this)if(this.closed)fe(t);else{if(t instanceof n){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(e=this._finalizers)!==null&&e!==void 0?e:[]).push(t)}},n.prototype._hasParent=function(t){var e=this._parentage;return e===t||Array.isArray(e)&&e.includes(t)},n.prototype._addParent=function(t){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(t),e):e?[e,t]:t},n.prototype._removeParent=function(t){var e=this._parentage;e===t?this._parentage=null:Array.isArray(e)&&F(e,t)},n.prototype.remove=function(t){var e=this._finalizers;e&&F(e,t),t instanceof n&&t._removeParent(this)},n.EMPTY=(function(){var t=new n;return t.closed=!0,t})(),n})(),de=N.EMPTY;function he(n){return n instanceof N||n&&"closed"in n&&v(n.remove)&&v(n.add)&&v(n.unsubscribe)}function fe(n){v(n)?n():n.unsubscribe()}var st={Promise:void 0},it={setTimeout:function(n,t){for(var e=[],r=2;r<arguments.length;r++)e[r-2]=arguments[r];return setTimeout.apply(void 0,H([n,t],D(e)))},clearTimeout:function(n){return clearTimeout(n)},delegate:void 0};function pe(n){it.setTimeout(function(){throw n})}function J(){}function K(n){n()}var Q=(function(n){I(t,n);function t(e){var r=n.call(this)||this;return r.isStopped=!1,e?(r.destination=e,he(e)&&e.add(r)):r.destination=ct,r}return t.create=function(e,r,s){return new Z(e,r,s)},t.prototype.next=function(e){this.isStopped||this._next(e)},t.prototype.error=function(e){this.isStopped||(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,n.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(e){this.destination.next(e)},t.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t})(N),ot=(function(){function n(t){this.partialObserver=t}return n.prototype.next=function(t){var e=this.partialObserver;if(e.next)try{e.next(t)}catch(r){B(r)}},n.prototype.error=function(t){var e=this.partialObserver;if(e.error)try{e.error(t)}catch(r){B(r)}else B(t)},n.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(e){B(e)}},n})(),Z=(function(n){I(t,n);function t(e,r,s){var i=n.call(this)||this,o;return v(e)||!e?o={next:e??void 0,error:r??void 0,complete:s??void 0}:o=e,i.destination=new ot(o),i}return t})(Q);function B(n){pe(n)}function at(n){throw n}var ct={closed:!0,next:J,error:at,complete:J},ee=(function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"})();function q(n){return n}function ut(n){return n.length===0?q:n.length===1?n[0]:function(e){return n.reduce(function(r,s){return s(r)},e)}}var E=(function(){function n(t){t&&(this._subscribe=t)}return n.prototype.lift=function(t){var e=new n;return e.source=this,e.operator=t,e},n.prototype.subscribe=function(t,e,r){var s=this,i=dt(t)?t:new Z(t,e,r);return K(function(){var o=s,a=o.operator,u=o.source;i.add(a?a.call(i,u):u?s._subscribe(i):s._trySubscribe(i))}),i},n.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(e){t.error(e)}},n.prototype.forEach=function(t,e){var r=this;return e=ge(e),new e(function(s,i){var o=new Z({next:function(a){try{t(a)}catch(u){i(u),o.unsubscribe()}},error:i,complete:s});r.subscribe(o)})},n.prototype._subscribe=function(t){var e;return(e=this.source)===null||e===void 0?void 0:e.subscribe(t)},n.prototype[ee]=function(){return this},n.prototype.pipe=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return ut(t)(this)},n.prototype.toPromise=function(t){var e=this;return t=ge(t),new t(function(r,s){var i;e.subscribe(function(o){return i=o},function(o){return s(o)},function(){return r(i)})})},n.create=function(t){return new n(t)},n})();function ge(n){var t;return(t=n??st.Promise)!==null&&t!==void 0?t:Promise}function lt(n){return n&&v(n.next)&&v(n.error)&&v(n.complete)}function dt(n){return n&&n instanceof Q||lt(n)&&he(n)}function ht(n){return v(n?.lift)}function O(n){return function(t){if(ht(t))return t.lift(function(e){try{return n(e,this)}catch(r){this.error(r)}});throw new TypeError("Unable to lift unknown Observable type")}}function A(n,t,e,r,s){return new ft(n,t,e,r,s)}var ft=(function(n){I(t,n);function t(e,r,s,i,o,a){var u=n.call(this,e)||this;return u.onFinalize=o,u.shouldUnsubscribe=a,u._next=r?function(c){try{r(c)}catch(h){e.error(h)}}:n.prototype._next,u._error=i?function(c){try{i(c)}catch(h){e.error(h)}finally{this.unsubscribe()}}:n.prototype._error,u._complete=s?function(){try{s()}catch(c){e.error(c)}finally{this.unsubscribe()}}:n.prototype._complete,u}return t.prototype.unsubscribe=function(){var e;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var r=this.closed;n.prototype.unsubscribe.call(this),!r&&((e=this.onFinalize)===null||e===void 0||e.call(this))}},t})(Q),pt=le(function(n){return function(){n(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),te=(function(n){I(t,n);function t(){var e=n.call(this)||this;return e.closed=!1,e.currentObservers=null,e.observers=[],e.isStopped=!1,e.hasError=!1,e.thrownError=null,e}return t.prototype.lift=function(e){var r=new me(this,this);return r.operator=e,r},t.prototype._throwIfClosed=function(){if(this.closed)throw new pt},t.prototype.next=function(e){var r=this;K(function(){var s,i;if(r._throwIfClosed(),!r.isStopped){r.currentObservers||(r.currentObservers=Array.from(r.observers));try{for(var o=k(r.currentObservers),a=o.next();!a.done;a=o.next()){var u=a.value;u.next(e)}}catch(c){s={error:c}}finally{try{a&&!a.done&&(i=o.return)&&i.call(o)}finally{if(s)throw s.error}}}})},t.prototype.error=function(e){var r=this;K(function(){if(r._throwIfClosed(),!r.isStopped){r.hasError=r.isStopped=!0,r.thrownError=e;for(var s=r.observers;s.length;)s.shift().error(e)}})},t.prototype.complete=function(){var e=this;K(function(){if(e._throwIfClosed(),!e.isStopped){e.isStopped=!0;for(var r=e.observers;r.length;)r.shift().complete()}})},t.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(t.prototype,"observed",{get:function(){var e;return((e=this.observers)===null||e===void 0?void 0:e.length)>0},enumerable:!1,configurable:!0}),t.prototype._trySubscribe=function(e){return this._throwIfClosed(),n.prototype._trySubscribe.call(this,e)},t.prototype._subscribe=function(e){return this._throwIfClosed(),this._checkFinalizedStatuses(e),this._innerSubscribe(e)},t.prototype._innerSubscribe=function(e){var r=this,s=this,i=s.hasError,o=s.isStopped,a=s.observers;return i||o?de:(this.currentObservers=null,a.push(e),new N(function(){r.currentObservers=null,F(a,e)}))},t.prototype._checkFinalizedStatuses=function(e){var r=this,s=r.hasError,i=r.thrownError,o=r.isStopped;s?e.error(i):o&&e.complete()},t.prototype.asObservable=function(){var e=new E;return e.source=this,e},t.create=function(e,r){return new me(e,r)},t})(E),me=(function(n){I(t,n);function t(e,r){var s=n.call(this)||this;return s.destination=e,s.source=r,s}return t.prototype.next=function(e){var r,s;(s=(r=this.destination)===null||r===void 0?void 0:r.next)===null||s===void 0||s.call(r,e)},t.prototype.error=function(e){var r,s;(s=(r=this.destination)===null||r===void 0?void 0:r.error)===null||s===void 0||s.call(r,e)},t.prototype.complete=function(){var e,r;(r=(e=this.destination)===null||e===void 0?void 0:e.complete)===null||r===void 0||r.call(e)},t.prototype._subscribe=function(e){var r,s;return(s=(r=this.source)===null||r===void 0?void 0:r.subscribe(e))!==null&&s!==void 0?s:de},t})(te),R=(function(n){I(t,n);function t(e){var r=n.call(this)||this;return r._value=e,r}return Object.defineProperty(t.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),t.prototype._subscribe=function(e){var r=n.prototype._subscribe.call(this,e);return!r.closed&&e.next(this._value),r},t.prototype.getValue=function(){var e=this,r=e.hasError,s=e.thrownError,i=e._value;if(r)throw s;return this._throwIfClosed(),i},t.prototype.next=function(e){n.prototype.next.call(this,this._value=e)},t})(te),gt={now:function(){return Date.now()}},mt=(function(n){I(t,n);function t(e,r){return n.call(this)||this}return t.prototype.schedule=function(e,r){return this},t})(N),ve={setInterval:function(n,t){for(var e=[],r=2;r<arguments.length;r++)e[r-2]=arguments[r];return setInterval.apply(void 0,H([n,t],D(e)))},clearInterval:function(n){return clearInterval(n)},delegate:void 0},vt=(function(n){I(t,n);function t(e,r){var s=n.call(this,e,r)||this;return s.scheduler=e,s.work=r,s.pending=!1,s}return t.prototype.schedule=function(e,r){var s;if(r===void 0&&(r=0),this.closed)return this;this.state=e;var i=this.id,o=this.scheduler;return i!=null&&(this.id=this.recycleAsyncId(o,i,r)),this.pending=!0,this.delay=r,this.id=(s=this.id)!==null&&s!==void 0?s:this.requestAsyncId(o,this.id,r),this},t.prototype.requestAsyncId=function(e,r,s){return s===void 0&&(s=0),ve.setInterval(e.flush.bind(e,this),s)},t.prototype.recycleAsyncId=function(e,r,s){if(s===void 0&&(s=0),s!=null&&this.delay===s&&this.pending===!1)return r;r!=null&&ve.clearInterval(r)},t.prototype.execute=function(e,r){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var s=this._execute(e,r);if(s)return s;this.pending===!1&&this.id!=null&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},t.prototype._execute=function(e,r){var s=!1,i;try{this.work(e)}catch(o){s=!0,i=o||new Error("Scheduled action threw falsy error")}if(s)return this.unsubscribe(),i},t.prototype.unsubscribe=function(){if(!this.closed){var e=this,r=e.id,s=e.scheduler,i=s.actions;this.work=this.state=this.scheduler=null,this.pending=!1,F(i,this),r!=null&&(this.id=this.recycleAsyncId(s,r,null)),this.delay=null,n.prototype.unsubscribe.call(this)}},t})(mt),be=(function(){function n(t,e){e===void 0&&(e=n.now),this.schedulerActionCtor=t,this.now=e}return n.prototype.schedule=function(t,e,r){return e===void 0&&(e=0),new this.schedulerActionCtor(this,t).schedule(r,e)},n.now=gt.now,n})(),bt=(function(n){I(t,n);function t(e,r){r===void 0&&(r=be.now);var s=n.call(this,e,r)||this;return s.actions=[],s._active=!1,s}return t.prototype.flush=function(e){var r=this.actions;if(this._active){r.push(e);return}var s;this._active=!0;do if(s=e.execute(e.state,e.delay))break;while(e=r.shift());if(this._active=!1,s){for(;e=r.shift();)e.unsubscribe();throw s}},t})(be),ye=new bt(vt),yt=ye,St=new E(function(n){return n.complete()});function Se(n){return n&&v(n.schedule)}function Ee(n){return n[n.length-1]}function Et(n){return v(Ee(n))?n.pop():void 0}function Ie(n){return Se(Ee(n))?n.pop():void 0}var we=(function(n){return n&&typeof n.length=="number"&&typeof n!="function"});function Te(n){return v(n?.then)}function Ce(n){return v(n[ee])}function Oe(n){return Symbol.asyncIterator&&v(n?.[Symbol.asyncIterator])}function Ae(n){return new TypeError("You provided "+(n!==null&&typeof n=="object"?"an invalid object":"'"+n+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function It(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var _e=It();function Me(n){return v(n?.[_e])}function xe(n){return nt(this,arguments,function(){var e,r,s,i;return ue(this,function(o){switch(o.label){case 0:e=n.getReader(),o.label=1;case 1:o.trys.push([1,,9,10]),o.label=2;case 2:return[4,U(e.read())];case 3:return r=o.sent(),s=r.value,i=r.done,i?[4,U(void 0)]:[3,5];case 4:return[2,o.sent()];case 5:return[4,U(s)];case 6:return[4,o.sent()];case 7:return o.sent(),[3,2];case 8:return[3,10];case 9:return e.releaseLock(),[7];case 10:return[2]}})})}function Pe(n){return v(n?.getReader)}function x(n){if(n instanceof E)return n;if(n!=null){if(Ce(n))return wt(n);if(we(n))return Tt(n);if(Te(n))return Ct(n);if(Oe(n))return Le(n);if(Me(n))return Ot(n);if(Pe(n))return At(n)}throw Ae(n)}function wt(n){return new E(function(t){var e=n[ee]();if(v(e.subscribe))return e.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function Tt(n){return new E(function(t){for(var e=0;e<n.length&&!t.closed;e++)t.next(n[e]);t.complete()})}function Ct(n){return new E(function(t){n.then(function(e){t.closed||(t.next(e),t.complete())},function(e){return t.error(e)}).then(null,pe)})}function Ot(n){return new E(function(t){var e,r;try{for(var s=k(n),i=s.next();!i.done;i=s.next()){var o=i.value;if(t.next(o),t.closed)return}}catch(a){e={error:a}}finally{try{i&&!i.done&&(r=s.return)&&r.call(s)}finally{if(e)throw e.error}}t.complete()})}function Le(n){return new E(function(t){_t(n,t).catch(function(e){return t.error(e)})})}function At(n){return Le(xe(n))}function _t(n,t){var e,r,s,i;return tt(this,void 0,void 0,function(){var o,a;return ue(this,function(u){switch(u.label){case 0:u.trys.push([0,5,6,11]),e=rt(n),u.label=1;case 1:return[4,e.next()];case 2:if(r=u.sent(),!!r.done)return[3,4];if(o=r.value,t.next(o),t.closed)return[2];u.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return a=u.sent(),s={error:a},[3,11];case 6:return u.trys.push([6,,9,10]),r&&!r.done&&(i=e.return)?[4,i.call(e)]:[3,8];case 7:u.sent(),u.label=8;case 8:return[3,10];case 9:if(s)throw s.error;return[7];case 10:return[7];case 11:return t.complete(),[2]}})})}function _(n,t,e,r,s){r===void 0&&(r=0),s===void 0&&(s=!1);var i=t.schedule(function(){e(),s?n.add(this.schedule(null,r)):this.unsubscribe()},r);if(n.add(i),!s)return i}function ke(n,t){return t===void 0&&(t=0),O(function(e,r){e.subscribe(A(r,function(s){return _(r,n,function(){return r.next(s)},t)},function(){return _(r,n,function(){return r.complete()},t)},function(s){return _(r,n,function(){return r.error(s)},t)}))})}function Ue(n,t){return t===void 0&&(t=0),O(function(e,r){r.add(n.schedule(function(){return e.subscribe(r)},t))})}function Mt(n,t){return x(n).pipe(Ue(t),ke(t))}function xt(n,t){return x(n).pipe(Ue(t),ke(t))}function Pt(n,t){return new E(function(e){var r=0;return t.schedule(function(){r===n.length?e.complete():(e.next(n[r++]),e.closed||this.schedule())})})}function Lt(n,t){return new E(function(e){var r;return _(e,t,function(){r=n[_e](),_(e,t,function(){var s,i,o;try{s=r.next(),i=s.value,o=s.done}catch(a){e.error(a);return}o?e.complete():e.next(i)},0,!0)}),function(){return v(r?.return)&&r.return()}})}function Ne(n,t){if(!n)throw new Error("Iterable cannot be null");return new E(function(e){_(e,t,function(){var r=n[Symbol.asyncIterator]();_(e,t,function(){r.next().then(function(s){s.done?e.complete():e.next(s.value)})},0,!0)})})}function kt(n,t){return Ne(xe(n),t)}function Ut(n,t){if(n!=null){if(Ce(n))return Mt(n,t);if(we(n))return Pt(n,t);if(Te(n))return xt(n,t);if(Oe(n))return Ne(n,t);if(Me(n))return Lt(n,t);if(Pe(n))return kt(n,t)}throw Ae(n)}function ne(n,t){return t?Ut(n,t):x(n)}function Nt(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var e=Ie(n);return ne(n,e)}function Rt(n){return n instanceof Date&&!isNaN(n)}function $(n,t){return O(function(e,r){var s=0;e.subscribe(A(r,function(i){r.next(n.call(t,i,s++))}))})}var $t=Array.isArray;function jt(n,t){return $t(t)?n.apply(void 0,H([],D(t))):n(t)}function Dt(n){return $(function(t){return jt(n,t)})}var Ht=Array.isArray,Gt=Object.getPrototypeOf,Ft=Object.prototype,Kt=Object.keys;function Bt(n){if(n.length===1){var t=n[0];if(Ht(t))return{args:t,keys:null};if(qt(t)){var e=Kt(t);return{args:e.map(function(r){return t[r]}),keys:e}}}return{args:n,keys:null}}function qt(n){return n&&typeof n=="object"&&Gt(n)===Ft}function Yt(n,t){return n.reduce(function(e,r,s){return e[r]=t[s],e},{})}function Vt(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var e=Ie(n),r=Et(n),s=Bt(n),i=s.args,o=s.keys;if(i.length===0)return ne([],e);var a=new E(Xt(i,e,o?function(u){return Yt(o,u)}:q));return r?a.pipe(Dt(r)):a}function Xt(n,t,e){return e===void 0&&(e=q),function(r){Re(t,function(){for(var s=n.length,i=new Array(s),o=s,a=s,u=function(h){Re(t,function(){var m=ne(n[h],t),y=!1;m.subscribe(A(r,function(l){i[h]=l,y||(y=!0,a--),a||r.next(e(i.slice()))},function(){--o||r.complete()}))},r)},c=0;c<s;c++)u(c)},r)}}function Re(n,t,e){n?_(e,n,t):t()}function Wt(n,t,e,r,s,i,o,a){var u=[],c=0,h=0,m=!1,y=function(){m&&!u.length&&!c&&t.complete()},l=function(g){return c<r?f(g):u.push(g)},f=function(g){c++;var P=!1;x(e(g,h++)).subscribe(A(t,function(T){t.next(T)},function(){P=!0},void 0,function(){if(P)try{c--;for(var T=function(){var L=u.shift();o||f(L)};u.length&&c<r;)T();y()}catch(L){t.error(L)}}))};return n.subscribe(A(t,l,function(){m=!0,y()})),function(){}}function Y(n,t,e){return e===void 0&&(e=1/0),v(t)?Y(function(r,s){return $(function(i,o){return t(r,i,s,o)})(x(n(r,s)))},e):(typeof t=="number"&&(e=t),O(function(r,s){return Wt(r,s,n,e)}))}function zt(n,t,e){n===void 0&&(n=0),e===void 0&&(e=yt);var r=-1;return t!=null&&(Se(t)?e=t:r=t),new E(function(s){var i=Rt(n)?+n-e.now():n;i<0&&(i=0);var o=0;return e.schedule(function(){s.closed||(s.next(o++),0<=r?this.schedule(void 0,r):s.complete())},i)})}function Jt(n,t){return v(t)?Y(n,t,1):Y(n,1)}function Qt(n){return n<=0?function(){return St}:O(function(t,e){var r=0;t.subscribe(A(e,function(s){++r<=n&&(e.next(s),n<=r&&e.complete())}))})}function Zt(n){return $(function(){return n})}function en(n,t){return Y(function(e,r){return x(n(e,r)).pipe(Qt(1),Zt(e))})}function tn(n,t){t===void 0&&(t=ye);var e=zt(n,t);return en(function(){return e})}function V(n,t){return t===void 0&&(t=q),n=n??nn,O(function(e,r){var s,i=!0;e.subscribe(A(r,function(o){var a=t(o);(i||!n(s,a))&&(i=!1,s=a,r.next(o))}))})}function nn(n,t){return n===t}function rn(n){return O(function(t,e){try{t.subscribe(e)}finally{e.add(n)}})}function sn(n){return O(function(t,e){x(n).subscribe(A(e,function(){return e.complete()},J)),!e.closed&&t.subscribe(e)})}async function on(n,t){const e=n.getReader();let r;for(;!(r=await e.read()).done;)t(r.value)}function an(n){let t,e,r,s=!1;return function(o){t===void 0?(t=o,e=0,r=-1):t=un(t,o);const a=t.length;let u=0;for(;e<a;){s&&(t[e]===10&&(u=++e),s=!1);let c=-1;for(;e<a&&c===-1;++e)switch(t[e]){case 58:r===-1&&(r=e-u);break;case 13:s=!0;case 10:c=e;break}if(c===-1)break;n(t.subarray(u,c),r),u=e,r=-1}u===a?t=void 0:u!==0&&(t=t.subarray(u),e-=u)}}function cn(n,t,e){let r=$e();const s=new TextDecoder;return function(o,a){if(o.length===0)e?.(r),r=$e();else if(a>0){const u=s.decode(o.subarray(0,a)),c=a+(o[a+1]===32?2:1),h=s.decode(o.subarray(c));switch(u){case"data":r.data=r.data?r.data+`
4
+ `+h:h;break;case"event":r.event=h;break;case"id":n(r.id=h);break;case"retry":const m=parseInt(h,10);isNaN(m)||t(r.retry=m);break}}}}function un(n,t){const e=new Uint8Array(n.length+t.length);return e.set(n),e.set(t,n.length),e}function $e(){return{data:"",event:"",id:"",retry:void 0}}var ln=function(n,t){var e={};for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&t.indexOf(r)<0&&(e[r]=n[r]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,r=Object.getOwnPropertySymbols(n);s<r.length;s++)t.indexOf(r[s])<0&&Object.prototype.propertyIsEnumerable.call(n,r[s])&&(e[r[s]]=n[r[s]]);return e};const re="text/event-stream",dn=1e3,je="last-event-id";function hn(n,t){var{signal:e,headers:r,onopen:s,onmessage:i,onclose:o,onerror:a,openWhenHidden:u,fetch:c}=t,h=ln(t,["signal","headers","onopen","onmessage","onclose","onerror","openWhenHidden","fetch"]);return new Promise((m,y)=>{const l=Object.assign({},r);l.accept||(l.accept=re);let f;function g(){f.abort(),document.hidden||ie()}u||document.addEventListener("visibilitychange",g);let P=dn,T=0;function L(){document.removeEventListener("visibilitychange",g),window.clearTimeout(T),f.abort()}e?.addEventListener("abort",()=>{L(),m()});const wn=c??window.fetch,Tn=s??fn;async function ie(){var oe;f=new AbortController;try{const X=await wn(n,Object.assign(Object.assign({},h),{headers:l,signal:f.signal}));await Tn(X),await on(X.body,an(cn(M=>{M?l[je]=M:delete l[je]},M=>{P=M},i))),o?.(),L(),m()}catch(X){if(!f.signal.aborted)try{const M=(oe=a?.(X))!==null&&oe!==void 0?oe:P;window.clearTimeout(T),T=window.setTimeout(ie,M)}catch(M){L(),y(M)}}}ie()})}function fn(n){const t=n.headers.get("content-type");if(!t?.startsWith(re))throw new Error(`Expected content-type to be ${re}, Actual: ${t}`)}function De(n){const{endpoint:t,apiKey:e,payload:r,debugMode:s,customHeaders:i}=n,o=n.method??"POST";return new E(a=>{const u=new AbortController;let c,h=!1;const m={"Content-Type":"application/json",...i};e&&(m["X-API-KEY"]=e);const y=new URL(t);return s&&y.searchParams.set("is_debug","true"),hn(y.toString(),{method:o,headers:m,body:o==="POST"&&r?JSON.stringify(r):void 0,signal:u.signal,openWhenHidden:!0,onopen:async l=>{if(l.ok)c=l.headers.get("X-Trace-Id")??void 0;else{let f;try{f=await l.json()}catch{try{f=await l.text()}catch{f=null}}a.error(new C(l.status,l.statusText,f)),u.abort()}},onmessage:l=>{l.id&&(h=!0);const f=JSON.parse(l.data);c?f.traceId=c:f.requestId&&(f.traceId=f.requestId,c||(c=f.requestId)),a.next(f)},onclose:()=>{a.complete()},onerror:l=>{if(!h)throw a.error(l),u.abort(),l}}),()=>{u.abort()}})}class pn{listeners={};on(t,e){this.listeners=Object.assign({},this.listeners,{[t]:(this.listeners[t]??[]).concat(e)})}off(t,e){this.listeners[t]&&(this.listeners=Object.assign({},this.listeners,{[t]:(this.listeners[t]??[]).filter(r=>r!==e)}))}remove(t){delete this.listeners[t]}emit(t,...e){this.listeners[t]&&this.listeners[t].forEach(r=>r(...e))}}class gn{apiKey;endpoint;botProviderEndpoint;debugMode;destroy$=new te;closed=!1;detached=!1;detachTimer;inFlight=0;sseEmitter=new pn;transformSsePayload;customHeaders;constructor(t){if(!t.endpoint&&!t.botProviderEndpoint)throw new Error("Either endpoint or botProviderEndpoint must be provided");if(this.apiKey=t.apiKey,this.debugMode=t.debugMode,this.transformSsePayload=t.transformSsePayload,this.botProviderEndpoint=t.botProviderEndpoint,this.customHeaders={...t.customHeaders,...t.userIdentityHint?{"X-ASGARD-USER-IDENTITY-HINT":t.userIdentityHint}:{}},!t.endpoint&&t.botProviderEndpoint){const e=t.botProviderEndpoint.replace(/\/+$/,"");this.endpoint=`${e}/message/sse`}else t.endpoint&&(this.endpoint=t.endpoint,this.debugMode&&console.warn('[AsgardServiceClient] The "endpoint" option is deprecated and will be removed in the next major version. Please use "botProviderEndpoint" instead. The SSE endpoint will be automatically derived as "${botProviderEndpoint}/message/sse".'))}on(t,e){this.sseEmitter.remove(t),this.sseEmitter.on(t,e)}handleEvent(t){switch(t.eventType){case d.INIT:this.sseEmitter.emit(d.INIT,t);break;case d.PROCESS_START:case d.PROCESS_COMPLETE:this.sseEmitter.emit(d.PROCESS,t);break;case d.MESSAGE_START:case d.MESSAGE_DELTA:case d.MESSAGE_COMPLETE:this.sseEmitter.emit(d.MESSAGE,t);break;case d.TOOL_CALL_START:case d.TOOL_CALL_COMPLETE:this.sseEmitter.emit(d.TOOL_CALL,t);break;case d.TOOL_CALL_CONSENT:this.sseEmitter.emit(d.TOOL_CALL_CONSENT,t);break;case d.DONE:this.sseEmitter.emit(d.DONE,t);break;case d.ERROR:this.sseEmitter.emit(d.ERROR,t);break}}fetchSse(t,e){return e?.onSseStart?.(),this.inFlight+=1,this.runSse(De({apiKey:this.apiKey,endpoint:this.endpoint,debugMode:this.debugMode,payload:this.transformSsePayload?.(t)??t,customHeaders:this.customHeaders}),e)}rejoinSse(t,e){e?.onSseStart?.(),this.inFlight+=1;const r=new URL(this.endpoint);return r.searchParams.set("custom_channel_id",t),this.runSse(De({apiKey:this.apiKey,endpoint:r.toString(),debugMode:this.debugMode,method:"GET",customHeaders:this.customHeaders}),e)}deriveChannelMetadataEndpoint(){const t=this.getBaseEndpoint();return t?`${t}/channel/metadata`:null}async channelMetadata(t){const e=this.deriveChannelMetadataEndpoint();if(!e)throw new Error("Unable to derive channel metadata endpoint. Please provide botProviderEndpoint in config.");const r=new URL(e);r.searchParams.set("custom_channel_id",t);const s={...this.customHeaders};this.apiKey&&(s["X-API-KEY"]=this.apiKey);const i=await fetch(r.toString(),{method:"GET",headers:s});if(i.status===404)return null;if(!i.ok)throw new C(i.status,i.statusText,await i.text().catch(()=>{}));const o=await i.json(),a=o.data??o;return{title:a.title??null,runState:a.runState??"IDLE",lastActivityAt:a.lastActivityAt}}runSse(t,e){return t.pipe(Jt(r=>Nt(r).pipe(tn(e?.delayTime??50))),sn(this.destroy$),rn(()=>this.onRunSettled())).subscribe({next:r=>{this.detached||(e?.onSseMessage?.(r),this.handleEvent(r))},error:r=>{this.detached||e?.onSseError?.(r)},complete:()=>{this.detached||e?.onSseCompleted?.()}})}detach(t){if(!(this.detached||this.closed)){if(this.detached=!0,this.inFlight===0){this.close();return}this.detachTimer=setTimeout(()=>this.close(),t.timeoutMs)}}onRunSettled(){this.inFlight=Math.max(0,this.inFlight-1),this.detached&&this.inFlight===0&&this.close()}close(){this.closed||(this.closed=!0,this.detachTimer&&(clearTimeout(this.detachTimer),this.detachTimer=void 0),this.destroy$.next(),this.destroy$.complete())}async uploadFile(t,e){const r=this.deriveBlobEndpoint();if(!r)throw new Error("Unable to derive blob endpoint. Please provide botProviderEndpoint in config.");const s=new FormData;s.append("file",t),s.append("customChannelId",e);const i={...this.customHeaders};this.apiKey&&(i["X-API-KEY"]=this.apiKey);try{const o=await fetch(r,{method:"POST",headers:i,body:s});if(!o.ok)throw new Error(`Upload failed: ${o.status} ${o.statusText}`);const a=await o.json();return this.debugMode&&console.log("[AsgardServiceClient] File upload response:",a),a}catch(o){throw console.error("[AsgardServiceClient] File upload error:",o),o}}async downloadChannelHomeFile(t,e){const r=this.getBaseEndpoint();if(!r)throw new Error("Unable to derive channel-home download endpoint. Please provide botProviderEndpoint in config.");const s=`custom_channel_id=${encodeURIComponent(e)}&relative_path=${encodeURIComponent(t)}`,i=`${r}/channel-home/download?${s}`,o={...this.customHeaders};this.apiKey&&(o["X-API-KEY"]=this.apiKey);try{const a=await fetch(i,{method:"GET",headers:o});if(!a.ok)throw new Error(`Channel Home download failed: ${a.status} ${a.statusText}`);const u=await a.blob(),c=t.split("/").pop()||"download";return this.debugMode&&console.log("[AsgardServiceClient] Channel Home download response:",{filename:c,size:u.size}),{blob:u,filename:c}}catch(a){throw console.error("[AsgardServiceClient] Channel Home download error:",a),a}}deriveBlobEndpoint(){const t=this.getBaseEndpoint();return t?`${t}/blob`:null}getBaseEndpoint(){let t=this.botProviderEndpoint;return!t&&this.endpoint&&(t=this.endpoint.replace("/message/sse","")),t?t.replace(/\/+$/,""):null}}const S=[];for(let n=0;n<256;++n)S.push((n+256).toString(16).slice(1));function mn(n,t=0){return(S[n[t+0]]+S[n[t+1]]+S[n[t+2]]+S[n[t+3]]+"-"+S[n[t+4]]+S[n[t+5]]+"-"+S[n[t+6]]+S[n[t+7]]+"-"+S[n[t+8]]+S[n[t+9]]+"-"+S[n[t+10]]+S[n[t+11]]+S[n[t+12]]+S[n[t+13]]+S[n[t+14]]+S[n[t+15]]).toLowerCase()}let se;const vn=new Uint8Array(16);function bn(){if(!se){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");se=crypto.getRandomValues.bind(crypto)}return se(vn)}const He={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function yn(n,t,e){n=n||{};const r=n.random??n.rng?.()??bn();if(r.length<16)throw new Error("Random bytes length must be >= 16");return r[6]=r[6]&15|64,r[8]=r[8]&63|128,mn(r)}function Ge(n,t,e){return He.randomUUID&&!n?He.randomUUID():yn(n)}class b{messages=null;pendingConsent=null;constructor({messages:t,pendingConsent:e=null}){this.messages=t,this.pendingConsent=e??null}pushMessage(t){const e=new Map(this.messages);return e.set(t.messageId,t),new b({messages:e,pendingConsent:this.pendingConsent})}clearPendingConsent(){return this.pendingConsent?new b({messages:this.messages,pendingConsent:null}):this}cancelInFlightToolCalls(){if(!this.messages)return this;let t=!1;const e=new Map(this.messages);for(const[r,s]of e)s.type==="tool-call"&&!s.isComplete&&(e.set(r,{...s,isComplete:!0,isCancelled:!0}),t=!0);return t?new b({messages:e,pendingConsent:this.pendingConsent}):this}onMessage(t){switch(t.eventType){case d.MESSAGE_START:return this.onMessageStart(t);case d.MESSAGE_DELTA:return this.onMessageDelta(t);case d.MESSAGE_COMPLETE:return this.onMessageComplete(t);case d.MESSAGE_USER:return this.onMessageUser(t);case d.MESSAGE_THINKING_START:return this.onThinkingStart(t);case d.MESSAGE_THINKING_DELTA:return this.onThinkingDelta(t);case d.MESSAGE_THINKING_COMPLETE:return this.onThinkingComplete(t);case d.TOOL_CALL_START:return this.onToolCallStart(t);case d.TOOL_CALL_COMPLETE:return this.onToolCallComplete(t);case d.TOOL_CALL_CONSENT:return this.onToolCallConsent(t);case d.SUBAGENT_START:return this.onSubagentStart(t);case d.SUBAGENT_COMPLETE:return this.onSubagentComplete(t);case d.ERROR:return this.onMessageError(t);default:return this}}isTerminalBot(t){return t?.type==="bot"&&!t.isTyping}isTerminalThinking(t){return t?.type==="thinking"&&!t.isThinking}onMessageStart(t){const e=t.fact.messageStart.message;if(this.isTerminalBot(this.messages?.get(e.messageId)))return this;const r=new Map(this.messages);return r.set(e.messageId,{type:"bot",eventType:d.MESSAGE_START,isTyping:!0,typingText:"",messageId:e.messageId,message:e,time:new Date,traceId:t.traceId,raw:""}),new b({messages:r,pendingConsent:this.pendingConsent})}onMessageDelta(t){const e=t.fact.messageDelta.message,r=this.messages?.get(e.messageId);if(this.isTerminalBot(r))return this;const s=r?.type==="bot"?r:void 0,i=new Map(this.messages);return i.set(e.messageId,{type:"bot",eventType:d.MESSAGE_DELTA,isTyping:!0,typingText:`${s?.typingText??""}${e.text}`,messageId:e.messageId,message:e,time:new Date,traceId:t.traceId??s?.traceId,raw:s?.raw??""}),new b({messages:i,pendingConsent:this.pendingConsent})}onMessageComplete(t){const e=t.fact.messageComplete.message,r=new Map(this.messages),s=r.get(e.messageId);return r.set(e.messageId,{type:"bot",eventType:d.MESSAGE_COMPLETE,isTyping:!1,typingText:null,messageId:e.messageId,message:e,time:new Date,traceId:t.traceId??(s?.type==="bot"?s.traceId:void 0),raw:JSON.stringify(t)}),new b({messages:r,pendingConsent:this.pendingConsent})}onThinkingStart(t){const e=t.fact.messageThinkingStart.message;if(this.isTerminalThinking(this.messages?.get(e.messageId)))return this;const r=new Map(this.messages),s={type:"thinking",messageId:e.messageId,text:e.text,isThinking:!0,time:new Date,traceId:t.traceId};return r.set(e.messageId,s),new b({messages:r,pendingConsent:this.pendingConsent})}onThinkingDelta(t){const e=t.fact.messageThinkingDelta.message,r=this.messages?.get(e.messageId);if(this.isTerminalThinking(r))return this;const s=r?.type==="thinking"?r:void 0,i=new Map(this.messages),o={type:"thinking",messageId:e.messageId,text:`${s?.text??""}${e.text}`,isThinking:!0,time:s?.time??new Date,traceId:t.traceId??s?.traceId};return i.set(e.messageId,o),new b({messages:i,pendingConsent:this.pendingConsent})}onThinkingComplete(t){const e=t.fact.messageThinkingComplete.message,r=this.messages?.get(e.messageId),s=r?.type==="thinking"?r:void 0,i=new Map(this.messages),o={type:"thinking",messageId:e.messageId,text:e.text,isThinking:!1,time:s?.time??new Date,traceId:t.traceId??s?.traceId};return i.set(e.messageId,o),new b({messages:i,pendingConsent:this.pendingConsent})}onMessageUser(t){const e=t.fact.messageUser;if((this.messages?.get(e.messageId)??(e.customMessageId?this.messages?.get(e.customMessageId):void 0))?.type==="user")return this;const s=new Map(this.messages),i={type:"user",messageId:e.messageId,text:e.text,blobIds:e.blobIds,customMessageId:e.customMessageId,identityHint:e.identityHint,time:new Date,traceId:t.traceId};return s.set(e.messageId,i),new b({messages:s,pendingConsent:this.pendingConsent})}onMessageError(t){const e=Ge(),r=t.fact.runError.error,s=new Map(this.messages);return s.set(e,{type:"error",eventType:d.ERROR,messageId:e,error:r,time:new Date,traceId:t.traceId}),new b({messages:s,pendingConsent:this.pendingConsent})}onToolCallStart(t){const e=t.fact.toolCallStart,r=new Map(this.messages),s=`${e.processId}-${e.callSeq}`,i={type:"tool-call",eventType:d.TOOL_CALL_START,messageId:s,processId:e.processId,callSeq:e.callSeq,toolName:e.toolCall.toolName,reason:e.toolCall.reason,toolsetName:e.toolCall.toolsetName,parameter:e.toolCall.parameter,toolUseId:e.toolUseId,parentToolUseId:e.parentToolUseId,isComplete:!1,time:new Date,traceId:t.traceId};return r.set(s,i),new b({messages:r,pendingConsent:this.pendingConsent})}onToolCallComplete(t){const e=t.fact.toolCallComplete,r=new Map(this.messages),s=`${e.processId}-${e.callSeq}`,i=r.get(s);if(i?.type==="tool-call"){const o={...i,eventType:d.TOOL_CALL_COMPLETE,result:e.toolCallResult,isError:e.isError,sidecar:e.toolUseResultSidecar,isComplete:!0,traceId:t.traceId??i.traceId};r.set(s,o)}return new b({messages:r,pendingConsent:this.pendingConsent})}onToolCallConsent(t){const e=t.fact.toolCallConsent;return new b({messages:this.messages,pendingConsent:e})}onSubagentStart(t){const e=t.fact.subagentStart,r=new Map(this.messages),s=`subagent:${e.parentToolUseId}:start`,i={type:"subagent",messageId:s,kind:"start",parentToolUseId:e.parentToolUseId,agentId:e.agentId,subagentType:e.subagentType,description:e.description,time:new Date,traceId:t.traceId};return r.set(s,i),new b({messages:r,pendingConsent:this.pendingConsent})}onSubagentComplete(t){const e=t.fact.subagentComplete,r=new Map(this.messages),s=`subagent:${e.parentToolUseId}:complete`,i={type:"subagent",messageId:s,kind:"complete",parentToolUseId:e.parentToolUseId,agentId:e.agentId,subagentType:e.subagentType,status:e.status,summary:e.summary,time:new Date,traceId:t.traceId};return r.set(s,i),new b({messages:r,pendingConsent:this.pendingConsent})}}const Sn=new Set(["TaskCreate","TaskUpdate"]);function Fe(n){return n.toolsetName===""&&Sn.has(n.toolName)}function Ke(n){return typeof n=="object"&&n!==null?n:void 0}function w(n){return typeof n=="string"?n:void 0}function Be(n){const t=[],e=new Map;for(const r of n){const s=r.parameter??{},i=r.sidecar??{};if(r.toolName==="TaskCreate"){const o=Ke(i.task),a=w(o?.id);if(!a)continue;e.has(a)||t.push(a),e.set(a,{id:a,subject:w(s.subject)||w(o?.subject)||"",activeForm:w(s.activeForm),description:w(s.description),status:e.get(a)?.status??"pending"})}else if(r.toolName==="TaskUpdate"){const o=Ke(i.statusChange),a=w(s.taskId)||w(i.taskId),u=w(o?.to)||w(s.status);if(!a||!u)continue;const c=e.get(a);c&&e.set(a,{...c,status:u})}}return t.map(r=>e.get(r))}function qe(n){return n.toolsetName===""&&n.toolName==="Agent"}function Ye(n){return!!n}function Ve(n){const t=[],e=new Map,r=new Map,s=i=>(e.has(i)||(t.push(i),e.set(i,{status:"running"}),r.set(i,new Map)),e.get(i));for(const i of n)switch(i.kind){case"agentStart":{const o=s(i.toolUseId);i.description&&!o.description&&(o.description=i.description);break}case"subagentStart":{const o=s(i.parentToolUseId);o.agentId=i.agentId??o.agentId,o.subagentType=i.subagentType??o.subagentType,o.description=i.description??o.description;break}case"toolStart":{s(i.parentToolUseId),r.get(i.parentToolUseId).set(i.toolUseId,{toolsetName:i.toolsetName,toolName:i.toolName,parameter:i.parameter??{},reason:i.reason,status:"running"});break}case"toolComplete":{const o=r.get(i.parentToolUseId)?.get(i.toolUseId);o&&(o.status=i.isError?"error":"completed");break}case"subagentComplete":{const o=s(i.parentToolUseId);o.status=i.status,o.summary=i.summary;break}}return t.map(i=>({parentToolUseId:i,...e.get(i),tools:Array.from(r.get(i).values())}))}function En(n){return typeof n=="string"?n:void 0}function Xe(n){const t=[];for(const e of n){if(e.type==="tool-call"&&qe(e)){t.push({kind:"agentStart",toolUseId:e.toolUseId??e.messageId,description:En(e.parameter.description)});continue}if(e.type==="tool-call"&&Ye(e.parentToolUseId)){const r=e.toolUseId??e.messageId;t.push({kind:"toolStart",parentToolUseId:e.parentToolUseId,toolUseId:r,toolsetName:e.toolsetName,toolName:e.toolName,parameter:e.parameter,reason:e.reason}),e.isComplete&&t.push({kind:"toolComplete",parentToolUseId:e.parentToolUseId,toolUseId:r,isError:e.isError});continue}if(e.type==="subagent"&&e.kind==="start"){t.push({kind:"subagentStart",parentToolUseId:e.parentToolUseId,agentId:e.agentId,subagentType:e.subagentType,description:e.description});continue}e.type==="subagent"&&e.kind==="complete"&&e.status&&t.push({kind:"subagentComplete",parentToolUseId:e.parentToolUseId,status:e.status,summary:e.summary})}return t}function We(n){const t=Array.from(n.messages?.values()??[]).filter(e=>e.type==="tool-call"&&e.isComplete&&Fe(e));return Be(t)}function ze(n){return Ve(Xe(Array.from(n.messages?.values()??[])))}function Je(n,t){return n===t?!0:n.length!==t.length?!1:n.every((e,r)=>{const s=t[r];return e.id===s.id&&e.status===s.status&&e.subject===s.subject&&e.activeForm===s.activeForm&&e.description===s.description})}function In(n,t){return n.length!==t.length?!1:n.every((e,r)=>{const s=t[r];return e.toolName===s.toolName&&e.toolsetName===s.toolsetName&&e.status===s.status&&e.reason===s.reason})}function Qe(n,t){return n===t?!0:n.length!==t.length?!1:n.every((e,r)=>{const s=t[r];return e.parentToolUseId===s.parentToolUseId&&e.status===s.status&&e.subagentType===s.subagentType&&e.description===s.description&&e.summary===s.summary&&In(e.tools,s.tools)})}function Ze(n){const t=new R([]),e=new R([]),r=new N;return r.add(n.pipe($(We),V(Je)).subscribe(t)),r.add(n.pipe($(ze),V(Qe)).subscribe(e)),{tasks$:t.asObservable(),subagents$:e.asObservable(),getTasks:()=>t.value,getSubagents:()=>e.value,teardown:()=>r.unsubscribe()}}class G{client;customChannelId;customMessageId;isConnecting$;conversation$;channelTitleSubject;sandboxPhaseSubject;derivedStores;statesObserver;statesSubscription;tasks$;subagents$;channelTitle$;sandboxPhase$;currentUserMessageId;lastSentMessageId;currentRun;constructor(t){if(!t.client)throw new Error("client must be required");if(!t.customChannelId)throw new Error("customChannelId must be required");this.client=t.client,this.customChannelId=t.customChannelId,this.customMessageId=t.customMessageId,this.isConnecting$=new R(!1),this.conversation$=new R(t.conversation),this.channelTitleSubject=new R(t.channelTitle??null),this.sandboxPhaseSubject=new R("idle"),this.derivedStores=Ze(this.conversation$),this.tasks$=this.derivedStores.tasks$,this.subagents$=this.derivedStores.subagents$,this.channelTitle$=this.channelTitleSubject.pipe(V()),this.sandboxPhase$=this.sandboxPhaseSubject.pipe(V()),this.statesObserver=t.statesObserver}getTasks(){return this.derivedStores.getTasks()}getSubagents(){return this.derivedStores.getSubagents()}getChannelTitle(){return this.channelTitleSubject.value}getSandboxPhase(){return this.sandboxPhaseSubject.value}setChannelTitle(t){this.channelTitleSubject.next(t)}static create(t){const e=new G(t);return e.subscribe(),e}static async reset(t,e,r,s){const i=new G(t);try{return i.subscribe(),s?.(i),await i.resetChannel(e,r),i}catch(o){throw i.close(),o}}static async restore(t,e,r){const s=new G(t);try{return s.subscribe(),r?.(s),await s.rejoinChannel(e),s}catch(i){throw s.close(),i}}subscribe(){this.statesSubscription=Vt([this.isConnecting$,this.conversation$,this.derivedStores.tasks$,this.derivedStores.subagents$,this.channelTitle$,this.sandboxPhase$]).pipe($(([t,e,r,s,i,o])=>({isConnecting:t,conversation:e,tasks:r,subagents:s,channelTitle:i,sandboxPhase:o}))).subscribe(this.statesObserver)}resolvePayload(t){if(typeof t=="function")try{return t()}catch(e){throw new Error(`Failed to resolve payload function: ${e instanceof Error?e.message:String(e)}`)}return t}updateSandboxPhase(t){switch(t){case d.SANDBOX_LAUNCH:this.sandboxPhaseSubject.next("launching");break;case d.SANDBOX_READY:this.sandboxPhaseSubject.next("ready");break;case d.INIT:case d.ERROR:this.sandboxPhaseSubject.next("idle");break}}buildRunHandlers(t,e,r){return{onSseStart:t?.onSseStart,onSseMessage:s=>{if(t?.onSseMessage?.(s),s.eventType===d.CHANNEL_TITLE_UPDATE&&this.channelTitleSubject.next(s.fact.channelTitleUpdate.title),this.updateSandboxPhase(s.eventType),this.currentUserMessageId&&s.traceId){const i=new Map(this.conversation$.value.messages),o=i.get(this.currentUserMessageId);o&&o.type==="user"&&(i.set(this.currentUserMessageId,{...o,traceId:s.traceId}),this.conversation$.next(new b({messages:i}))),this.currentUserMessageId=void 0}this.conversation$.next(this.conversation$.value.onMessage(s))},onSseError:s=>{t?.onSseError?.(s),this.isConnecting$.next(!1),this.currentUserMessageId=void 0,this.currentRun=void 0,r(s)},onSseCompleted:()=>{t?.onSseCompleted?.(),this.isConnecting$.next(!1),this.currentUserMessageId=void 0,this.currentRun=void 0,e()}}}fetchSse(t,e){return new Promise((r,s)=>{this.isConnecting$.next(!0),this.currentRun=this.client.fetchSse(t,this.buildRunHandlers(e,r,s))})}rejoinChannel(t){return new Promise((e,r)=>{if(!this.client.rejoinSse){e();return}this.isConnecting$.next(!0),this.currentRun=this.client.rejoinSse(this.customChannelId,this.buildRunHandlers(t,e,r))})}resetChannel(t,e){return this.fetchSse({action:j.RESET_CHANNEL,customChannelId:this.customChannelId,customMessageId:this.customMessageId,text:t?.text||"",payload:this.resolvePayload(t?.payload)},e)}sendMessage(t,e){const r=t.text.trim(),s=t.customMessageId??Ge();return this.currentUserMessageId=s,this.lastSentMessageId=s,this.conversation$.next(this.conversation$.value.pushMessage({type:"user",messageId:s,text:r,blobIds:t.blobIds,filePreviewUrls:t.filePreviewUrls,documentNames:t.documentNames,time:new Date})),this.fetchSse({action:j.NONE,customChannelId:this.customChannelId,customMessageId:s,payload:this.resolvePayload(t?.payload),text:r,blobIds:t?.blobIds},e)}replyToolCallConsents(t,e,r){return this.conversation$.next(this.conversation$.value.clearPendingConsent()),this.fetchSse({action:j.RESPONSE_TOOL_CALL_CONSENT,customChannelId:this.customChannelId,customMessageId:this.lastSentMessageId??this.customMessageId,payload:this.resolvePayload(r),text:"",toolCallConsents:t},e)}stopGeneration(){this.currentRun&&(this.currentRun.unsubscribe(),this.currentRun=void 0,this.isConnecting$.next(!1),this.currentUserMessageId=void 0,this.conversation$.next(this.conversation$.value.cancelInFlightToolCalls()))}close(){this.currentRun?.unsubscribe(),this.currentRun=void 0,this.isConnecting$.complete(),this.conversation$.complete(),this.channelTitleSubject.complete(),this.sandboxPhaseSubject.complete(),this.derivedStores.teardown(),this.statesSubscription?.unsubscribe()}}p.AsgardServiceClient=gn,p.Channel=G,p.Conversation=b,p.EventType=d,p.FetchSseAction=j,p.HttpError=C,p.MessageTemplateType=ce,p.ToolCallConsentResult=ae,p.conversationToSubagentEvents=Xe,p.createDerivedStores=Ze,p.deriveSubagents=ze,p.deriveTasks=We,p.isAgentTool=qe,p.isHttpError=et,p.isSubagentChildTool=Ye,p.isTaskTool=Fe,p.reduceSubagents=Ve,p.reduceTaskEvents=Be,p.subagentsEqual=Qe,p.tasksEqual=Je,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})}));
5
5
  //# sourceMappingURL=index.js.map