@mastra/core 0.1.27-alpha.9 → 0.1.27-unstable.2
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/README.md +1 -1
- package/dist/agent/index.d.ts +20 -2
- package/dist/core.cjs.development.js +597 -208
- package/dist/core.cjs.development.js.map +1 -1
- package/dist/core.cjs.production.min.js +1 -1
- package/dist/core.cjs.production.min.js.map +1 -1
- package/dist/core.esm.js +596 -209
- package/dist/core.esm.js.map +1 -1
- package/dist/engine/index.d.ts +3 -4
- package/dist/engine/schema.d.ts +0 -1
- package/dist/engine/types.d.ts +1 -2
- package/dist/engine/utils.d.ts +0 -1
- package/dist/index.d.ts +1 -2
- package/dist/integration/index.d.ts +0 -1
- package/dist/integration/test-integration.d.ts +12 -0
- package/dist/llm/index.d.ts +32 -2
- package/dist/llm/types.d.ts +33 -1
- package/dist/logger/index.d.ts +0 -1
- package/dist/mastra/index.d.ts +4 -4
- package/dist/mastra/types.d.ts +1 -0
- package/dist/sync/index.d.ts +2 -0
- package/dist/sync/types.d.ts +23 -11
- package/dist/tools/index.d.ts +0 -1
- package/dist/tools/types.d.ts +3 -3
- package/dist/utils.d.ts +0 -1
- package/dist/vector/index.d.ts +0 -1
- package/dist/workflows/index.d.ts +2 -2
- package/dist/workflows/step.d.ts +15 -0
- package/dist/workflows/types.d.ts +25 -24
- package/dist/workflows/utils.d.ts +0 -1
- package/dist/workflows/{main.d.ts → workflow.d.ts} +13 -13
- package/package.json +16 -8
- package/dist/agent/index.d.ts.map +0 -1
- package/dist/engine/index.d.ts.map +0 -1
- package/dist/engine/schema.d.ts.map +0 -1
- package/dist/engine/types.d.ts.map +0 -1
- package/dist/engine/utils.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/integration/index.d.ts.map +0 -1
- package/dist/llm/index.d.ts.map +0 -1
- package/dist/llm/types.d.ts.map +0 -1
- package/dist/logger/index.d.ts.map +0 -1
- package/dist/mastra/index.d.ts.map +0 -1
- package/dist/sync/types.d.ts.map +0 -1
- package/dist/tools/index.d.ts.map +0 -1
- package/dist/tools/types.d.ts.map +0 -1
- package/dist/utils.d.ts.map +0 -1
- package/dist/vector/index.d.ts.map +0 -1
- package/dist/workflows/index.d.ts.map +0 -1
- package/dist/workflows/main.d.ts.map +0 -1
- package/dist/workflows/types.d.ts.map +0 -1
- package/dist/workflows/utils.d.ts.map +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@upstash/redis"),t=require("fs"),r=require("path"),n=require("@ai-sdk/anthropic"),i=require("@ai-sdk/openai"),o=require("@ai-sdk/google"),a=require("@ai-sdk/mistral"),s=require("@ai-sdk/amazon-bedrock"),u=require("@ai-sdk/azure"),l=require("@ai-sdk/xai"),c=require("@ai-sdk/cohere"),p=require("anthropic-vertex-ai"),f=require("ai"),h=require("zod"),g=require("sift"),d=require("xstate"),v=require("lodash/get");function m(e,t,r,n,i,o,a){try{var s=e[o](a),u=s.value}catch(e){return void r(e)}s.done?t(u):Promise.resolve(u).then(n,i)}function y(e){return function(){var t=this,r=arguments;return new Promise((function(n,i){var o=e.apply(t,r);function a(e){m(o,n,i,a,s,"next",e)}function s(e){m(o,n,i,a,s,"throw",e)}a(void 0)}))}}function w(e,t){if(!{}.hasOwnProperty.call(e,t))throw new TypeError("attempted to use private field on non-instance");return e}var E=0;function O(e){return"__private_"+E+++"_"+e}function b(){return b=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)({}).hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},b.apply(null,arguments)}function x(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,I(e,t)}function T(){T=function(){return t};var e,t={},r=Object.prototype,n=r.hasOwnProperty,i=Object.defineProperty||function(e,t,r){e[t]=r.value},o="function"==typeof Symbol?Symbol:{},a=o.iterator||"@@iterator",s=o.asyncIterator||"@@asyncIterator",u=o.toStringTag||"@@toStringTag";function l(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{l({},"")}catch(e){l=function(e,t,r){return e[t]=r}}function c(e,t,r,n){var o=Object.create((t&&t.prototype instanceof m?t:m).prototype),a=new R(n||[]);return i(o,"_invoke",{value:_(e,r,a)}),o}function p(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}t.wrap=c;var f="suspendedStart",h="suspendedYield",g="executing",d="completed",v={};function m(){}function y(){}function w(){}var E={};l(E,a,(function(){return this}));var O=Object.getPrototypeOf,b=O&&O(O(P([])));b&&b!==r&&n.call(b,a)&&(E=b);var x=w.prototype=m.prototype=Object.create(E);function I(e){["next","throw","return"].forEach((function(t){l(e,t,(function(e){return this._invoke(t,e)}))}))}function S(e,t){function r(i,o,a,s){var u=p(e[i],e,o);if("throw"!==u.type){var l=u.arg,c=l.value;return c&&"object"==typeof c&&n.call(c,"__await")?t.resolve(c.__await).then((function(e){r("next",e,a,s)}),(function(e){r("throw",e,a,s)})):t.resolve(c).then((function(e){l.value=e,a(l)}),(function(e){return r("throw",e,a,s)}))}s(u.arg)}var o;i(this,"_invoke",{value:function(e,n){function i(){return new t((function(t,i){r(e,n,t,i)}))}return o=o?o.then(i,i):i()}})}function _(t,r,n){var i=f;return function(o,a){if(i===g)throw Error("Generator is already running");if(i===d){if("throw"===o)throw a;return{value:e,done:!0}}for(n.method=o,n.arg=a;;){var s=n.delegate;if(s){var u=N(s,n);if(u){if(u===v)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(i===f)throw i=d,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);i=g;var l=p(t,r,n);if("normal"===l.type){if(i=n.done?d:h,l.arg===v)continue;return{value:l.arg,done:n.done}}"throw"===l.type&&(i=d,n.method="throw",n.arg=l.arg)}}}function N(t,r){var n=r.method,i=t.iterator[n];if(i===e)return r.delegate=null,"throw"===n&&t.iterator.return&&(r.method="return",r.arg=e,N(t,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),v;var o=p(i,t.iterator,r.arg);if("throw"===o.type)return r.method="throw",r.arg=o.arg,r.delegate=null,v;var a=o.arg;return a?a.done?(r[t.resultName]=a.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,v):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,v)}function A(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function L(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function R(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(A,this),this.reset(!0)}function P(t){if(t||""===t){var r=t[a];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var i=-1,o=function r(){for(;++i<t.length;)if(n.call(t,i))return r.value=t[i],r.done=!1,r;return r.value=e,r.done=!0,r};return o.next=o}}throw new TypeError(typeof t+" is not iterable")}return y.prototype=w,i(x,"constructor",{value:w,configurable:!0}),i(w,"constructor",{value:y,configurable:!0}),y.displayName=l(w,u,"GeneratorFunction"),t.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===y||"GeneratorFunction"===(t.displayName||t.name))},t.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,w):(e.__proto__=w,l(e,u,"GeneratorFunction")),e.prototype=Object.create(x),e},t.awrap=function(e){return{__await:e}},I(S.prototype),l(S.prototype,s,(function(){return this})),t.AsyncIterator=S,t.async=function(e,r,n,i,o){void 0===o&&(o=Promise);var a=new S(c(e,r,n,i),o);return t.isGeneratorFunction(r)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},I(x),l(x,u,"Generator"),l(x,a,(function(){return this})),l(x,"toString",(function(){return"[object Generator]"})),t.keys=function(e){var t=Object(e),r=[];for(var n in t)r.push(n);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=P,R.prototype={constructor:R,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(L),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function i(n,i){return s.type="throw",s.arg=t,r.next=n,i&&(r.method="next",r.arg=e),!!i}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],s=a.completion;if("root"===a.tryLoc)return i("end");if(a.tryLoc<=this.prev){var u=n.call(a,"catchLoc"),l=n.call(a,"finallyLoc");if(u&&l){if(this.prev<a.catchLoc)return i(a.catchLoc,!0);if(this.prev<a.finallyLoc)return i(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return i(a.catchLoc,!0)}else{if(!l)throw Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return i(a.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=e,a.arg=t,o?(this.method="next",this.next=o.finallyLoc,v):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),v},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),L(r),v}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var i=n.arg;L(r)}return i}}throw Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:P(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),v}},t}function I(e,t){return I=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},I(e,t)}function S(e){var t=function(e){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:t+""}var _={AGENT:"AGENT",WORKFLOW:"WORKFLOW"},N={DEBUG:"DEBUG",INFO:"INFO",WARN:"WARN",ERROR:"ERROR"},A=function(){function e(e){void 0===e&&(e=N.INFO),this.level=void 0,this.level=e}var t=e.prototype;return t.debug=function(e){if(this.level<=N.DEBUG){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return this.log.apply(this,[N.DEBUG,e].concat(r))}},t.info=function(e){if(this.level<=N.INFO){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return this.log.apply(this,[N.INFO,e].concat(r))}},t.warn=function(e){if(this.level<=N.WARN){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return this.log.apply(this,[N.WARN,e].concat(r))}},t.error=function(e){if(this.level<=N.ERROR){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return this.log.apply(this,[N.ERROR,e].concat(r))}},t.formatMessage=function(e){return"string"==typeof e?e:JSON.stringify(e)},t.formatLogEntry=function(e,t){return{timestamp:(new Date).toISOString(),level:N[e],message:this.formatMessage(t)}},e}(),L=function(e){function t(t){return e.call(this,null!=t?t:N.INFO)||this}return x(t,e),t.prototype.log=function(e,t){for(var r,n=this.formatLogEntry(e,t),i=arguments.length,o=new Array(i>2?i-2:0),a=2;a<i;a++)o[a-2]=arguments[a];(r=console).log.apply(r,["["+n.timestamp+"] ["+n.level+"] "+n.message].concat(o))},t}(A),R=O("dirPath"),P=function(e){function n(t,r){var n;return void 0===t&&(t="logs"),n=e.call(this,null!=r?r:N.INFO)||this,Object.defineProperty(n,R,{writable:!0,value:void 0}),w(n,R)[R]=t,n}x(n,e);var i=n.prototype;return i.log=function(e,t){if("string"==typeof t)throw new Error("FileLogger requires a BaseLogMessage object");var n=r.join(w(this,R)[R],t.destinationPath+".json");this.ensureDirectoryExists(),this.writeLogToFile(n,e,t)},i.ensureDirectoryExists=function(){t.existsSync(w(this,R)[R])||t.mkdirSync(w(this,R)[R],{recursive:!0})},i.writeLogToFile=function(e,r,n){var i=b({},n,{level:N[r],createdAt:new Date}),o=[];t.existsSync(e)&&(o=JSON.parse(t.readFileSync(e,"utf-8"))),o.push(i),t.writeFileSync(e,JSON.stringify(o,null,2))},n}(A),k=O("redis"),C=O("key"),z=function(e){function t(t,r,n){var i;return void 0===r&&(r="logs"),i=e.call(this,null!=n?n:N.INFO)||this,Object.defineProperty(i,k,{writable:!0,value:void 0}),Object.defineProperty(i,C,{writable:!0,value:void 0}),w(i,k)[k]=t,w(i,C)[C]=r,i}x(t,e);var r=t.prototype;return r.log=function(){var e=y(T().mark((function e(t,r){var n;return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("string"!=typeof r){e.next=2;break}throw new Error("UpstashRedisLogger requires a BaseLogMessage object");case 2:return n=b({},r,{level:N[t],createdAt:new Date}),e.next=5,w(this,k)[k].lpush(w(this,C)[C],JSON.stringify(n));case 5:case"end":return e.stop()}}),e,this)})));return function(t,r){return e.apply(this,arguments)}}(),r.getLogs=function(){var e=y(T().mark((function e(){return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",w(this,k)[k].lrange(w(this,C)[C],0,-1));case 1:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),r.cleanup=function(){var e=y(T().mark((function e(){return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),t}(A),M=function(){function e(e){this.loggers=void 0,this.loggers=e}var t=e.prototype;return t.debug=function(){var e=y(T().mark((function e(t){var r,n,i,o=arguments;return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(r=o.length,n=new Array(r>1?r-1:0),i=1;i<r;i++)n[i-1]=o[i];return e.next=3,Promise.all(this.loggers.map((function(e){return e.debug.apply(e,[t].concat(n))})));case 3:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.info=function(){var e=y(T().mark((function e(t){var r,n,i,o=arguments;return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(r=o.length,n=new Array(r>1?r-1:0),i=1;i<r;i++)n[i-1]=o[i];return e.next=3,Promise.all(this.loggers.map((function(e){return e.info.apply(e,[t].concat(n))})));case 3:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.warn=function(){var e=y(T().mark((function e(t){var r,n,i,o=arguments;return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(r=o.length,n=new Array(r>1?r-1:0),i=1;i<r;i++)n[i-1]=o[i];return e.next=3,Promise.all(this.loggers.map((function(e){return e.warn.apply(e,[t].concat(n))})));case 3:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.error=function(){var e=y(T().mark((function e(t){var r,n,i,o=arguments;return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(r=o.length,n=new Array(r>1?r-1:0),i=1;i<r;i++)n[i-1]=o[i];return e.next=3,Promise.all(this.loggers.map((function(e){return e.error.apply(e,[t].concat(n))})));case 3:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.cleanup=function(){var e=y(T().mark((function e(){return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,Promise.all(this.loggers.map(function(){var e=y(T().mark((function e(t){return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.cleanup){e.next=3;break}return e.next=3,t.cleanup();case 3:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()));case 2:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),e}();function j(t){switch(t.type){case"CONSOLE":return new L(t.level);case"FILE":return new P(t.dirPath,t.level);case"UPSTASH":var r=new e.Redis({url:t.url,token:t.token});return new z(r,t.key,t.level);default:throw new Error("Unsupported logger type")}}var U,G,K,F=function(e){return new Promise((function(t){return setTimeout(t,e)}))},D=O("tools"),q=function(){function e(e){Object.defineProperty(this,D,{writable:!0,value:void 0}),this.logger=void 0,w(this,D)[D]={},this.logger=e||j({type:"CONSOLE"})}var t=e.prototype;return t.__setTools=function(e){w(this,D)[D]=e,this.logger.debug("Tools set for LLM",e)},t.getModelType=function(e){var t;if(!("provider"in e))throw new Error("Model provider is required");var r=null!=(t={OPEN_AI:"openai",ANTHROPIC:"anthropic",GROQ:"groq",PERPLEXITY:"perplexity",FIREWORKS:"fireworks",TOGETHER_AI:"togetherai",LM_STUDIO:"lmstuido",BASETEN:"baseten",GOOGLE:"google",MISTRAL:"mistral",X_GROK:"grok",COHERE:"cohere",AZURE:"azure",AMAZON:"amazon",ANTHROPIC_VERTEX:"anthropic-vertex"}[e.provider])?t:e.provider;return this.logger.debug("Model type resolved to "+r+" for provider "+e.provider),r},t.createOpenAICompatibleModel=function(e){var t=e.baseURL,r=e.apiKey,n=e.defaultModelName,o=e.modelName,a=e.fetch;return this.logger.debug("Creating OpenAI compatible model with baseURL: "+t),i.createOpenAI({baseURL:t,apiKey:r,fetch:a})(o||n)},t.createModelDef=function(e){var t,r=e.model;if("openai"===r.type)this.logger.info("Initializing OpenAI model "+(r.name||"gpt-4o-2024-08-06")),t=i.createOpenAI({apiKey:(null==r?void 0:r.apiKey)||process.env.OPENAI_API_KEY})(r.name||"gpt-4o-2024-08-06",{structuredOutputs:!0});else if("anthropic"===r.type)this.logger.info("Initializing Anthropic model "+(r.name||"claude-3-5-sonnet-20240620")),t=n.createAnthropic({apiKey:(null==r?void 0:r.apiKey)||process.env.ANTHROPIC_API_KEY})(r.name||"claude-3-5-sonnet-20240620");else if("google"===r.type)this.logger.info("Initializing Google model "+(r.name||"gemini-1.5-pro-latest")),t=o.createGoogleGenerativeAI({baseURL:"https://generativelanguage.googleapis.com/v1beta",apiKey:(null==r?void 0:r.apiKey)||process.env.GOOGLE_GENERATIVE_AI_API_KEY||""})(r.name||"gemini-1.5-pro-latest");else if("groq"===r.type)this.logger.info("Initializing Groq model "+(r.name||"llama-3.2-90b-text-preview")),t=this.createOpenAICompatibleModel({baseURL:"https://api.groq.com/openai/v1",apiKey:(null==r?void 0:r.apiKey)||process.env.GROQ_API_KEY||"",defaultModelName:"llama-3.2-90b-text-preview",modelName:r.name});else if("perplexity"===r.type)this.logger.info("Initializing Perplexity model "+(r.name||"llama-3.1-sonar-large-128k-chat")),t=this.createOpenAICompatibleModel({baseURL:"https://api.perplexity.ai/",apiKey:(null==r?void 0:r.apiKey)||process.env.PERPLEXITY_API_KEY||"",defaultModelName:"llama-3.1-sonar-large-128k-chat",modelName:r.name});else if("fireworks"===r.type)this.logger.info("Initializing Fireworks model "+(r.name||"llama-v3p1-70b-instruct")),t=this.createOpenAICompatibleModel({baseURL:"https://api.fireworks.ai/inference/v1",apiKey:(null==r?void 0:r.apiKey)||process.env.FIREWORKS_API_KEY||"",defaultModelName:"llama-v3p1-70b-instruct",modelName:r.name});else if("togetherai"===r.type)this.logger.info("Initializing TogetherAI model "+(r.name||"google/gemma-2-9b-it")),t=this.createOpenAICompatibleModel({baseURL:"https://api.together.xyz/v1/",apiKey:(null==r?void 0:r.apiKey)||process.env.TOGETHER_AI_API_KEY||"",defaultModelName:"google/gemma-2-9b-it",modelName:r.name});else if("lmstudio"===r.type){if(this.logger.info("Initializing LMStudio model "+(r.name||"llama-3.2-1b")),null==r||!r.baseURL){var f="LMStudio model requires a baseURL";throw this.logger.error(f),new Error(f)}t=this.createOpenAICompatibleModel({baseURL:r.baseURL,apiKey:"not-needed",defaultModelName:"llama-3.2-1b",modelName:r.name})}else if("baseten"===r.type){if(this.logger.info("Initializing BaseTen model "+(r.name||"llama-3.1-70b-instruct")),null!=r&&r.fetch){var h="Custom fetch is required to use "+r.type+". see https://docs.baseten.co/api-reference/openai for more information";throw this.logger.error(h),new Error(h)}t=this.createOpenAICompatibleModel({baseURL:"https://bridge.baseten.co/v1/direct",apiKey:(null==r?void 0:r.apiKey)||process.env.BASETEN_API_KEY||"",defaultModelName:"llama-3.1-70b-instruct",modelName:r.name})}else if("mistral"===r.type)this.logger.info("Initializing Mistral model "+(r.name||"pixtral-large-latest")),t=a.createMistral({baseURL:"https://api.mistral.ai/v1",apiKey:(null==r?void 0:r.apiKey)||process.env.MISTRAL_API_KEY||""})(r.name||"pixtral-large-latest");else if("grok"===r.type){var g;this.logger.info("Initializing X Grok model "+(r.name||"grok-beta")),t=l.createXai({baseURL:"https://api.x.ai/v1",apiKey:null!=(g=process.env.XAI_API_KEY)?g:""})(r.name||"grok-beta")}else if("cohere"===r.type)this.logger.info("Initializing Cohere model "+(r.name||"command-r-plus")),t=c.createCohere({baseURL:"https://api.cohere.com/v2",apiKey:(null==r?void 0:r.apiKey)||process.env.COHERE_API_KEY||""})(r.name||"command-r-plus");else if("azure"===r.type)this.logger.info("Initializing Azure model "+(r.name||"gpt-35-turbo-instruct")),t=u.createAzure({resourceName:process.env.AZURE_RESOURCE_NAME||"",apiKey:(null==r?void 0:r.apiKey)||process.env.AZURE_API_KEY||""})(r.name||"gpt-35-turbo-instruct");else if("amazon"===r.type)this.logger.info("Initializing Amazon model "+(r.name||"amazon-titan-tg1-large")),t=s.createAmazonBedrock({region:process.env.AWS_REGION||"",accessKeyId:process.env.AWS_ACCESS_KEY_ID||"",secretAccessKey:process.env.AWS_SECRET_ACCESS_KEY||"",sessionToken:process.env.AWS_SESSION_TOKEN||""})(r.name||"amazon-titan-tg1-large");else{if("anthropic-vertex"!==r.type){var d="Invalid model type: "+r.type;throw this.logger.error(d),new Error(d)}var v;this.logger.info("Initializing Anthropic Vertex model "+(r.name||"claude-3-5-sonnet@20240620")),t=p.createAnthropicVertex({region:process.env.GOOGLE_VERTEX_REGION,projectId:process.env.GOOGLE_VERTEX_PROJECT_ID,apiKey:null!=(v=process.env.ANTHROPIC_API_KEY)?v:""})(r.name||"claude-3-5-sonnet@20240620")}return t},t.getParams=function(){var e=y(T().mark((function e(t){var r,n,i,o,a;return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=t.resultTool,n=t.model,i=Object.entries(t.tools).reduce((function(e,t){return e[t[0]]=f.tool(t[1]),e}),{}),o={},r&&(o={answer:f.tool(r)}),!("type"in n)){e.next=8;break}a=this.createModelDef({model:n}),e.next=15;break;case 8:if(!(n.model instanceof Function)){e.next=14;break}return e.next=11,n.model();case 11:a=e.sent,e.next=15;break;case 14:a=n.model;case 15:return e.abrupt("return",{toolsConverted:i,modelDef:a,answerTool:o,toolChoice:n.toolChoice||"required"});case 16:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.convertTools=function(e){var t=this,r=Object.entries(e||{}).reduce((function(e,r){var n=r[0],i=r[1],o=w(t,D)[D][n];return i&&o&&(e[n]={description:o.description,parameters:h.z.object({data:o.schema}),execute:o.executor}),e}),{});return this.logger.debug("Converted tools for LLM",r),r},t.text=function(){var e=y(T().mark((function e(t){var r,n,i,o,a,s,u,l,c,p=this;return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.messages,i=t.onStepFinish,a=void 0===(o=t.maxSteps)?5:o,s=t.enabledTools,u="name"in(r=t.model)?{type:this.getModelType(r),name:r.name,toolChoice:r.toolChoice,apiKey:"LM_STUDIO"!==r.provider?null==r?void 0:r.apiKey:void 0,baseURL:"LM_STUDIO"===r.provider?r.baseURL:void 0,fetch:"BASETEN"===r.provider?r.fetch:void 0}:r,e.next=4,this.getParams({tools:this.convertTools(s||{}),model:u});case 4:return c={model:(l=e.sent).modelDef,tools:b({},l.toolsConverted,l.answerTool),toolChoice:l.toolChoice,maxSteps:a,onStepFinish:function(){var e=y(T().mark((function e(t){var r,n;return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null==i||i(JSON.stringify(t,null,2)),!(null!=t&&null!=(r=t.response)&&null!=(r=r.headers)&&r["x-ratelimit-remaining-tokens"]&&parseInt(null==t||null==(n=t.response)||null==(n=n.headers)?void 0:n["x-ratelimit-remaining-tokens"],10)<2e3)){e.next=5;break}return p.logger.warn("Rate limit approaching, waiting 10 seconds"),e.next=5,F(1e4);case 5:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()},this.logger.debug("Generating text with "+n.length+" messages"),e.next=9,f.generateText(b({messages:n},c));case 9:return e.abrupt("return",e.sent);case 10:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.stream=function(){var e=y(T().mark((function e(t){var r,n,i,o,a,s,u,l,c,p,h=this;return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.messages,i=t.onStepFinish,o=t.onFinish,s=void 0===(a=t.maxSteps)?5:a,u=t.enabledTools,l="name"in(r=t.model)?{type:this.getModelType(r),name:r.name,toolChoice:r.toolChoice,apiKey:"LM_STUDIO"!==r.provider?null==r?void 0:r.apiKey:void 0,baseURL:"LM_STUDIO"===r.provider?r.baseURL:void 0,fetch:"BASETEN"===r.provider?r.fetch:void 0}:r,e.next=4,this.getParams({tools:this.convertTools(u),model:l});case 4:return p={model:(c=e.sent).modelDef,tools:b({},c.toolsConverted,c.answerTool),toolChoice:c.toolChoice,maxSteps:s,onStepFinish:function(){var e=y(T().mark((function e(t){var r,n;return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null==i||i(JSON.stringify(t,null,2)),!(null!=t&&null!=(r=t.response)&&null!=(r=r.headers)&&r["x-ratelimit-remaining-tokens"]&&parseInt(null==t||null==(n=t.response)||null==(n=n.headers)?void 0:n["x-ratelimit-remaining-tokens"],10)<2e3)){e.next=5;break}return h.logger.warn("Rate limit approaching, waiting 10 seconds"),e.next=5,F(1e4);case 5:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),onFinish:function(){var e=y(T().mark((function e(t){return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:null==o||o(JSON.stringify(t,null,2));case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()},this.logger.debug("Streaming text with "+n.length+" messages"),e.next=9,f.streamText(b({messages:n},p));case 9:return e.abrupt("return",e.sent);case 10:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),e}(),B=function(){function e(e){this.name=void 0,this.llm=void 0,this.instructions=void 0,this.model=void 0,this.enabledTools=void 0,this.logger=void 0,this.name=e.name,this.instructions=e.instructions,this.llm=new q,this.model=e.model,this.enabledTools=e.enabledTools||{},this.logger=j({type:"CONSOLE"}),this.logger.info("Agent "+this.name+" initialized with model "+this.model.provider)}var t=e.prototype;return t.__setTools=function(e){this.llm.__setTools(e),this.logger.debug("Tools set for agent "+this.name,e)},t.__setLogger=function(e){this.logger=e,this.logger.debug("Logger updated for agent "+this.name)},t.text=function(){var e=y(T().mark((function e(t){var r,n,i,o,a,s,u;return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.messages,n=t.onStepFinish,o=void 0===(i=t.maxSteps)?5:i,this.logger.info("Starting text generation for agent "+this.name),a={role:"system",content:this.instructions},s=r.map((function(e){return{role:"user",content:e}})),u=[a].concat(s),e.abrupt("return",this.llm.text({model:this.model,messages:u,enabledTools:this.enabledTools,onStepFinish:n,maxSteps:o}));case 6:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.stream=function(){var e=y(T().mark((function e(t){var r,n,i,o,a,s,u,l;return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.messages,n=t.onStepFinish,i=t.onFinish,a=void 0===(o=t.maxSteps)?5:o,this.logger.info("Starting stream generation for agent "+this.name),s={role:"system",content:this.instructions},u=r.map((function(e){return{role:"user",content:e}})),l=[s].concat(u),e.abrupt("return",this.llm.stream({messages:l,model:this.model,enabledTools:this.enabledTools,onStepFinish:n,onFinish:i,maxSteps:a}));case 6:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),e}(),W=["client"],Y=function(){function e(){this.authType="API_KEY"}var t,r,n=e.prototype;return n.getApiClient=function(){var e=y(T().mark((function e(){return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:throw new Error("API not implemented");case 1:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),n._generateIntegrationTools=function(){var e=this,t=function(e,t){if(null==e)return{};var r={};for(var n in e)if({}.hasOwnProperty.call(e,n)){if(t.includes(n))continue;r[n]=e[n]}return r}(this.baseClient,W),r=this.toolSchemas,n=this.toolDocumentations,i=Object.keys(t).reduce((function(t,i){var o,a,s,u,l=null==(o=n[i])?void 0:o.comment,c=null==(a=n[i])?void 0:a.doc,p="Execute "+i,f={label:i,schema:r[i]||h.z.object({}),description:l||p,documentation:c||p,executor:(u=y(T().mark((function t(r){var n;return T().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=r.data,t.next=3,e.getApiClient();case 3:return t.abrupt("return",(0,t.sent[i])(b({},n)));case 6:case"end":return t.stop()}}),t)}))),function(e){return u.apply(this,arguments)})};return b({},t,((s={})[i]=f,s))}),{});return i},t=e,(r=[{key:"toolSchemas",get:function(){return{}}},{key:"toolDocumentations",get:function(){return{}}},{key:"baseClient",get:function(){return{}}}])&&function(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,S(n.key),n)}}(t.prototype,r),Object.defineProperty(t,"prototype",{writable:!1}),t}();exports.PropertyType=void 0,(U=exports.PropertyType||(exports.PropertyType={})).LONG_TEXT="LONG_TEXT",U.SINGLE_LINE_TEXT="SINGLE_LINE_TEXT",U.SINGLE_SELECT="SINGLE_SELECT",U.MULTI_SELECT="MULTI_SELECT",U.CHECKBOX="CHECKBOX",U.DATE="DATE",U.USER="USER",U.BADGE_LIST="BADGE_LIST",U.CURRENCY="CURRENCY",U.URL="URL",U.PHONE="PHONE",U.CONTACT="CONTACT",U.COMPANY="COMPANY",U.PERSON="PERSON",U.ENRICHMENT="ENRICHMENT",U.COMPOSITE="COMPOSITE",U.BOOLEAN="BOOLEAN",U.NUMBER="NUMBER",U.FLOAT="FLOAT",U.JSON_OBJECT="JSON_OBJECT",U.JSON_ARRAY="JSON_ARRAY",exports.FilterOperators=void 0,(G=exports.FilterOperators||(exports.FilterOperators={})).IS="is",G.EQUAL="eq",G.NOT_EQUAL="not_eq",G.CONTAINS="contains",G.IN="in",G.NOT_IN="not_in",G.GREATER_THAN="gt",G.LESS_THAN="lt",G.NOT_CONTAINS="not_contains",G.GREATER_THAN_OR_EQUAL="gte",G.LESS_THAN_OR_EQUAL="lte",G.OP="op",G.SET="set",G.NOT_SET="not_set";var H=((K={})[exports.PropertyType.BADGE_LIST]="string",K[exports.PropertyType.CHECKBOX]="boolean",K[exports.PropertyType.BOOLEAN]="boolean",K[exports.PropertyType.NUMBER]="number",K[exports.PropertyType.FLOAT]="number",K[exports.PropertyType.JSON_ARRAY]="string",K[exports.PropertyType.JSON_OBJECT]="string",K[exports.PropertyType.CURRENCY]="number",K[exports.PropertyType.DATE]="date",K[exports.PropertyType.LONG_TEXT]="string",K[exports.PropertyType.MULTI_SELECT]="string",K[exports.PropertyType.PHONE]="string",K[exports.PropertyType.SINGLE_LINE_TEXT]="string",K[exports.PropertyType.SINGLE_SELECT]="string",K[exports.PropertyType.URL]="string",K[exports.PropertyType.USER]="string",K[exports.PropertyType.CONTACT]="string",K[exports.PropertyType.COMPANY]="string",K[exports.PropertyType.COMPOSITE]="string",K[exports.PropertyType.PERSON]="string",K[exports.PropertyType.ENRICHMENT]="string",K),J=function(e){return"string"==typeof e?e.split(","):e},X=function(e){return"string"==typeof e?"true"===e:e},Q=h.z.object({is:h.z.array(h.z.string()).or(h.z.string()).optional(),eq:h.z.array(h.z.string()).or(h.z.string()).optional(),not_eq:h.z.array(h.z.string()).or(h.z.string()).optional(),contains:h.z.array(h.z.string()).or(h.z.string()).optional(),not_contains:h.z.array(h.z.string()).or(h.z.string()).optional(),gt:h.z.array(h.z.string()).or(h.z.string()).optional(),gte:h.z.array(h.z.string()).or(h.z.string()).optional(),lt:h.z.array(h.z.string()).or(h.z.string()).optional(),lte:h.z.array(h.z.string()).or(h.z.string()).optional(),in:h.z.array(h.z.string()).or(h.z.string()).optional(),not_in:h.z.array(h.z.string()).or(h.z.string()).optional(),op:h.z.enum(["or","and"]).optional().default("or"),set:h.z.string().optional().transform(X),not_set:h.z.string().optional().transform(X)}),V=h.z.string().transform(J),Z=function(){function e(e){var t,r,n,i,o=this;this.engine=void 0,this.vectors=void 0,this.tools=void 0,this.agents=void 0,this.llm=void 0,this.integrations=void 0,this.logger=void 0,this.syncs=void 0,this.workflows=new Map,this.logger=new Map;var a=j({type:"CONSOLE"});e.logger&&(a=e.logger),this.setLogger({key:"AGENT",logger:a}),this.setLogger({key:"WORKFLOW",logger:a}),this.integrations=new Map,null==(t=e.integrations)||t.forEach((function(e){if(o.integrations.has(e.name))throw new Error("Integration with name "+e.name+" already exists");o.integrations.set(e.name,e)}));var s=(null==(r=e.integrations)?void 0:r.reduce((function(e,t){return b({},e,t.tools)}),{}))||{},u=b({},(null==e?void 0:e.tools)||{},s),l=Object.entries(null!=u?u:{}).reduce((function(e,t){var r=t[1];return e[t[0]]=b({},r,{executor:function(e){return r.executor(b({},e,{getIntegration:function(e){return o.getIntegration(e)},agents:o.agents,llm:o.llm,engine:o.engine}))}}),e}),{});if(this.tools=l,this.agents=new Map,this.llm=new q,this.llm.__setTools(this.tools),null==(n=e.agents)||n.forEach((function(e){if(o.agents.has(e.name))throw new Error("Agent with name "+e.name+" already exists");o.agents.set(e.name,e),e.__setTools(o.tools);var t=o.getLogger("AGENT");t&&e.__setLogger(t)})),null==(i=e.workflows)||i.forEach((function(e){if(o.workflows.has(e.name))throw new Error("Workflow with name "+e.name+" already exists");o.workflows.set(e.name,e)})),e.syncs&&!e.engine)throw new Error("Engine is required to run syncs");this.syncs=e.syncs||{},e.engine&&(this.engine=e.engine),e.vectors&&(this.vectors=e.vectors)}var t=e.prototype;return t.sync=function(){var e=y(T().mark((function e(t,r){var n,i;return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.engine){e.next=2;break}throw new Error("Sync function "+t+" not found");case 2:if(i=null==(n=this.syncs)?void 0:n[t]){e.next=5;break}throw new Error("Sync function "+t+" not found");case 5:return e.next=7,i({tools:this.tools,params:r,engine:this.engine,agents:this.agents,vectors:this.vectors,llm:this.llm});case 7:case"end":return e.stop()}}),e,this)})));return function(t,r){return e.apply(this,arguments)}}(),t.getAgent=function(e){var t=this.agents.get(e);if(!t)throw new Error("Agent with name "+e+" not found");return t},t.getIntegration=function(e){var t=String(e),r=this.integrations.get(t.toUpperCase());if(!r)throw new Error("Integration with name "+t+" not found");return r},t.getTool=function(e){var t,r=this,n=this.tools[e];if(!n)throw new Error("Tool with name "+String(e)+" not found");return b({},n,{execute:(t=y(T().mark((function e(t){return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",n.executor({data:t,integrationsRegistry:function(){return{get:function(e){return r.getIntegration(e)}}},agents:r.agents,llm:r.llm,engine:r.engine}));case 1:case"end":return e.stop()}}),e)}))),function(e){return t.apply(this,arguments)})})},t.availableIntegrations=function(){return Array.from(this.integrations.entries()).map((function(e){return{name:e[0],integration:e[1]}}))},t.getTools=function(){return this.tools},t.setLogger=function(e){this.logger.set(e.key,e.logger)},t.getLogger=function(e){return this.logger.get(e)},e}(),$=O("logger"),ee=O("steps"),te=O("machine"),re=O("actor"),ne=O("log"),ie=O("buildStateHierarchy"),oe=O("isVariableReference"),ae=O("createStepId"),se=O("resolveVariables"),ue=O("cleanup"),le=O("evaluateCondition"),ce=O("validateWorkflow"),pe=O("detectCircularDependencies"),fe=O("validateTerminalPaths"),he=O("detectUnreachableSteps"),ge=function(){function e(e,t){Object.defineProperty(this,he,{value:Se}),Object.defineProperty(this,fe,{value:Ie}),Object.defineProperty(this,pe,{value:Te}),Object.defineProperty(this,ce,{value:xe}),Object.defineProperty(this,le,{value:be}),Object.defineProperty(this,ue,{value:Oe}),Object.defineProperty(this,se,{value:Ee}),Object.defineProperty(this,ae,{value:we}),Object.defineProperty(this,oe,{value:ye}),Object.defineProperty(this,ie,{value:me}),Object.defineProperty(this,ne,{value:de}),this.name=void 0,Object.defineProperty(this,$,{writable:!0,value:void 0}),this.triggerSchema=void 0,Object.defineProperty(this,ee,{writable:!0,value:[]}),Object.defineProperty(this,te,{writable:!0,value:void 0}),Object.defineProperty(this,re,{writable:!0,value:null}),this.name=e,w(this,$)[$]=t,this.initializeMachine()}var t=e.prototype;return t.initializeMachine=function(){var e,t=this,r=d.setup({types:{},actions:{updateStepResult:d.assign({stepResults:function(e){var r,n,i=e.context,o=e.event;if(!o.type.startsWith("xstate.done.actor."))return i.stepResults;var a=null==(r=o.output)?void 0:r.stepId;if(!a)return i.stepResults;w(t,ne)[ne](N.INFO,"Step "+a+" completed",o.output,a);var s=null==(n=o.output)?void 0:n.result;if(void 0!==s){var u,l=b({},i.stepResults,((u={})[a]=s,u)),c=w(t,ee)[ee].find((function(e){return e.id===a}));if(null!=c&&c.transitions){var p=b({},i,{stepResults:l}),f=!1;w(t,ne)[ne](N.DEBUG,"Evaluating transitions with context:",p),Object.entries(c.transitions).forEach((function(e){var r=e[0],n=e[1];w(t,ne)[ne](N.DEBUG,"Checking transition to: "+r),w(t,ne)[ne](N.DEBUG,"With condition: "+n.condition),n.condition&&!w(t,le)[le](n.condition,p)||(f=!0,w(t,ne)[ne](N.DEBUG,"Condition passed, sending transition to:",r),Promise.resolve().then((function(){w(t,re)[re]&&w(t,re)[re].send({type:"TRANSITION_"+r})})))})),f||Promise.resolve().then((function(){w(t,re)[re]&&w(t,re)[re].send({type:"NO_MATCHING_CONDITIONS"})}))}return l}return i.stepResults}}),setError:d.assign({error:function(e){var r=e.event;return r.type.startsWith("xstate.error.actor.")?(w(t,ne)[ne](N.ERROR,"Workflow error",r.error),r.error):null}}),initializeTriggerData:d.assign({triggerData:function(e){var r=e.context;return w(t,ne)[ne](N.INFO,"Workflow started",null==r?void 0:r.triggerData),null==r?void 0:r.triggerData}})},actors:{resolverFunction:d.fromPromise(function(){var e=y(T().mark((function e(r){var n,i,o,a;return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=(n=r.input).step,o=n.context,a=w(t,se)[se](i,o),e.next=5,i.handler(a);case 5:return e.abrupt("return",{stepId:i.id,result:e.sent});case 7:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}())}}).createMachine({id:this.name,initial:(null==(e=w(this,ee)[ee][0])?void 0:e.id)||"idle",context:function(e){return b({},e.input,{stepResults:{},error:null})},entry:["initializeTriggerData"],states:w(this,ie)[ie]()});return w(this,te)[te]=r,r},t.commit=function(){w(this,ce)[ce](),this.initializeMachine()},t.setTriggerSchema=function(e){return this.triggerSchema=e,this},t.addStep=function(e,t){var r=this,n=w(this,ae)[ae](e),i=t.action,o=t.inputSchema,a=t.variables,s=void 0===a?{}:a,u=t.payload,l=void 0===u?{}:u,c=t.transitions;c&&Object.keys(c).forEach((function(e){w(r,ee)[ee].some((function(t){return t.id===e}))||w(r,ne)[ne](N.DEBUG,"Step "+e+" not found yet, will be validated when workflow starts")}));for(var p={},f=0,h=Object.entries(s);f<h.length;f++){var g=h[f],d=g[0],v=g[1];v&&w(this,oe)[oe](v)&&(p[d]=v)}var m,E={id:n,handler:(m=y(T().mark((function e(t){var r,n;return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=b({},l,t),n=o?o.parse(r):r,e.abrupt("return",i(n));case 3:case"end":return e.stop()}}),e)}))),function(e){return m.apply(this,arguments)}),inputSchema:o,requiredData:p,transitions:c};return w(this,ee)[ee].push(E),this},t.executeWorkflow=function(){var e=y(T().mark((function e(t){var r=this;return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,w(this,ne)[ne](N.INFO,"Executing workflow",{triggerData:t});case 2:if(!this.triggerSchema){e.next=14;break}return e.prev=3,this.triggerSchema.parse(t),e.next=7,w(this,ne)[ne](N.DEBUG,"Trigger schema validation passed");case 7:e.next=14;break;case 9:return e.prev=9,e.t0=e.catch(3),e.next=13,w(this,ne)[ne](N.ERROR,"Trigger schema validation failed",{error:e.t0});case 13:throw e.t0;case 14:return w(this,re)[re]=d.createActor(w(this,te)[te],{input:{error:null,stepResults:{},triggerData:t||{}}}),w(this,re)[re].start(),e.abrupt("return",new Promise((function(e,n){w(r,re)[re]?w(r,re)[re].subscribe((function(i){if(i.matches("success"))w(r,ne)[ne](N.INFO,"Workflow completed successfully",{results:i.context.stepResults}),w(r,ue)[ue](),e({triggerData:t,results:i.context.stepResults});else if(i.matches("failure")){var o,a;w(r,ne)[ne](N.ERROR,"Workflow failed",{error:null==(o=i.context.error)?void 0:o.message}),w(r,ue)[ue](),n({error:null==(a=i.context.error)?void 0:a.message})}})):n(new Error("Actor not initialized"))})));case 17:case"end":return e.stop()}}),e,this,[[3,9]])})));return function(t){return e.apply(this,arguments)}}(),e}();function de(e,t,r,n){return ve.apply(this,arguments)}function ve(){return(ve=y(T().mark((function e(t,r,n,i){var o,a,s,u;return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(w(this,$)[$]){e.next=2;break}return e.abrupt("return");case 2:return s={type:_.WORKFLOW,message:r,workflowName:this.name,destinationPath:"workflows/"+this.name,stepId:i,data:n},u=t.toLowerCase(),e.next=6,null==(o=(a=w(this,$)[$])[u])?void 0:o.call(a,s);case 6:case"end":return e.stop()}}),e,this)})))).apply(this,arguments)}function me(){var e=this,t={idle:{},success:{type:"final"},failure:{type:"final"}},r=new Set;return w(this,ee)[ee].forEach((function(n){var i=function(t,r){if(r.has(t))return null;r.add(t);var n=w(e,ee)[ee].find((function(e){return e.id===t}));if(!n)return null;var i={invoke:{src:"resolverFunction",input:function(e){return{step:n,context:e.context}},onDone:{actions:["updateStepResult"],target:n.transitions?void 0:"success"},onError:{target:"failure",actions:["setError"]}},on:{NO_MATCHING_CONDITIONS:{target:"failure",actions:d.assign({error:function(){return console.log("No matching transition conditions"),new Error("No matching transition conditions")}})}}};return n.transitions&&Object.entries(n.transitions).forEach((function(t){var r=t[0],n=t[1];i.on["TRANSITION_"+r]={target:r,guard:function(t){var r=t.context;return!n.condition||w(e,le)[le](n.condition,r)}}})),i}(n.id,r);i&&(t[n.id]=i)})),t}function ye(e){return"object"==typeof e&&"stepId"in e&&"path"in e}function we(e){if(w(this,ee)[ee].some((function(t){return t.id===e})))throw new Error('Step with ID "'+e+'" already exists in workflow "'+this.name+'"');return e}function Ee(e,t){for(var r={},n=0,i=Object.entries(e.requiredData);n<i.length;n++){var o=i[n],a=o[0],s=o[1],u="trigger"===s.stepId?t.triggerData:t.stepResults[s.stepId];if(!u&&"trigger"!==s.stepId)throw new Error("Cannot resolve variable: Step "+s.stepId+" has not been executed yet");var l=""===s.path||"."===s.path?u[a]:v(u,s.path);if(void 0===l)throw new Error('Cannot resolve path "'+s.path+'" from '+s.stepId);r[a]=l}return r}function Oe(){w(this,re)[re]&&(w(this,re)[re].stop(),w(this,re)[re]=null)}function be(e,t){var r=this,n=!0,i=!0,o=!0;if("ref"in e){var a=e.ref,s=e.query,u="trigger"===a.stepId?t.triggerData:t.stepResults[a.stepId];if(!u)throw new Error("Cannot evaluate condition: Step "+a.stepId+" has not been executed yet");var l=v(u,a.path);i=g(s)(l)}return"and"in e&&(n=e.and.every((function(e){return w(r,le)[le](e,t)}))),"or"in e&&(o=e.or.some((function(e){return w(r,le)[le](e,t)}))),i&&n&&o}function xe(){var e=[].concat(w(this,pe)[pe](),w(this,fe)[fe](),w(this,he)[he]());if(e.length>0){var t=e.map((function(e){return"["+e.type+"] "+e.message+(e.details.path?" (Path: "+e.details.path.join(" → ")+")":"")+(e.details.stepId?" (Step: "+e.details.stepId+")":"")}));throw new Error("Workflow validation failed:\n"+t.join("\n"))}}function Te(){var e=this,t=[],r=[],n=function(i){if(r.includes(i)){var o=r.indexOf(i),a=[].concat(r.slice(o),[i]);t.push({type:"circular_dependency",message:"Circular dependency detected in workflow",details:{path:a}})}else{r.push(i);var s=w(e,ee)[ee].find((function(e){return e.id===i}));null!=s&&s.transitions&&Object.keys(s.transitions).forEach((function(e){n(e)})),r.pop()}};return w(this,ee)[ee].length>0&&n(w(this,ee)[ee][0].id),t}function Ie(){var e=this,t=[],r=new Set,n=new Set,i=function(o,a){if(void 0===a&&(a=[]),n.has(o))return!0;if(r.has(o)&&!n.has(o))return!1;r.add(o);var s=w(e,ee)[ee].find((function(e){return e.id===o}));if(!s)return!1;if(!s.transitions)return n.add(o),!0;var u=Object.keys(s.transitions);if(0===u.length)return n.add(o),!0;var l=u.some((function(e){return!a.includes(e)&&i(e,[].concat(a,[o]))}));return l?n.add(o):t.push({type:"no_terminal_path",message:"No path to terminal state found",details:{stepId:o,path:[].concat(a,[o])}}),l};return w(this,ee)[ee].length>0&&i(w(this,ee)[ee][0].id),t}function Se(){var e=this,t=[],r=new Set,n=function(t){if(!r.has(t)){r.add(t);var i=w(e,ee)[ee].find((function(e){return e.id===t}));null!=i&&i.transitions&&Object.keys(i.transitions).forEach((function(e){n(e)}))}};return w(this,ee)[ee].length>0&&n(w(this,ee)[ee][0].id),w(this,ee)[ee].forEach((function(e){r.has(e.id)||t.push({type:"unreachable_step",message:"Step is not reachable from the initial step",details:{stepId:e.id}})})),t}exports.Agent=B,exports.BaseLogger=A,exports.FieldTypePrimitiveMap=H,exports.Integration=Y,exports.LogLevel=N,exports.Mastra=Z,exports.MastraEngine=function(e){},exports.MastraVector=function(){},exports.MultiLogger=M,exports.RegisteredLogger=_,exports.Workflow=ge,exports.buildQueryString=function(e){var t=e.filterQueryString,r=e.sortQueryString;return t||r?t?r?t+"&"+r:""+t:""+r:""},exports.createLogger=j,exports.createMultiLogger=function(e){return new M(e)},exports.createTool=function(e){return e},exports.filterQuerySchema=Q,exports.getJSONField=function(e,t){switch(H[t]){case"number":return"("+e+")::bigint";case"boolean":return"("+e+")::boolean";case"date":return"("+e+")::timestamp"}return"("+e+")::text"},exports.sortQuerySchema=V,exports.splitAndStripQuotes=function(e){return e.split(/,\s*(?=(?:[^"]*"[^"]*")*[^"]*$)/).map((function(e){return e.trim().replace(/^"|"$/g,"")}))},exports.transformFilterValueArray=J,exports.transformFilterValueBoolean=X;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@upstash/redis"),t=require("fs"),r=require("path"),n=require("@ai-sdk/anthropic"),i=require("@ai-sdk/openai"),o=require("@ai-sdk/google"),a=require("@ai-sdk/mistral"),s=require("@ai-sdk/amazon-bedrock"),u=require("@ai-sdk/azure"),c=require("@ai-sdk/xai"),l=require("@ai-sdk/cohere"),p=require("anthropic-vertex-ai"),h=require("ai"),f=require("zod"),g=require("sift"),d=require("xstate"),v=require("lodash-es/get");function m(e,t,r,n,i,o,a){try{var s=e[o](a),u=s.value}catch(e){return void r(e)}s.done?t(u):Promise.resolve(u).then(n,i)}function y(e){return function(){var t=this,r=arguments;return new Promise((function(n,i){var o=e.apply(t,r);function a(e){m(o,n,i,a,s,"next",e)}function s(e){m(o,n,i,a,s,"throw",e)}a(void 0)}))}}function w(e,t){if(!{}.hasOwnProperty.call(e,t))throw new TypeError("attempted to use private field on non-instance");return e}var b=0;function E(e){return"__private_"+b+++"_"+e}function x(){return x=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)({}).hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},x.apply(null,arguments)}function O(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,S(e,t)}function T(){T=function(){return t};var e,t={},r=Object.prototype,n=r.hasOwnProperty,i=Object.defineProperty||function(e,t,r){e[t]=r.value},o="function"==typeof Symbol?Symbol:{},a=o.iterator||"@@iterator",s=o.asyncIterator||"@@asyncIterator",u=o.toStringTag||"@@toStringTag";function c(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=function(e,t,r){return e[t]=r}}function l(e,t,r,n){var o=Object.create((t&&t.prototype instanceof m?t:m).prototype),a=new L(n||[]);return i(o,"_invoke",{value:_(e,r,a)}),o}function p(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}t.wrap=l;var h="suspendedStart",f="suspendedYield",g="executing",d="completed",v={};function m(){}function y(){}function w(){}var b={};c(b,a,(function(){return this}));var E=Object.getPrototypeOf,x=E&&E(E(P([])));x&&x!==r&&n.call(x,a)&&(b=x);var O=w.prototype=m.prototype=Object.create(b);function S(e){["next","throw","return"].forEach((function(t){c(e,t,(function(e){return this._invoke(t,e)}))}))}function I(e,t){function r(i,o,a,s){var u=p(e[i],e,o);if("throw"!==u.type){var c=u.arg,l=c.value;return l&&"object"==typeof l&&n.call(l,"__await")?t.resolve(l.__await).then((function(e){r("next",e,a,s)}),(function(e){r("throw",e,a,s)})):t.resolve(l).then((function(e){c.value=e,a(c)}),(function(e){return r("throw",e,a,s)}))}s(u.arg)}var o;i(this,"_invoke",{value:function(e,n){function i(){return new t((function(t,i){r(e,n,t,i)}))}return o=o?o.then(i,i):i()}})}function _(t,r,n){var i=h;return function(o,a){if(i===g)throw Error("Generator is already running");if(i===d){if("throw"===o)throw a;return{value:e,done:!0}}for(n.method=o,n.arg=a;;){var s=n.delegate;if(s){var u=N(s,n);if(u){if(u===v)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(i===h)throw i=d,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);i=g;var c=p(t,r,n);if("normal"===c.type){if(i=n.done?d:f,c.arg===v)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(i=d,n.method="throw",n.arg=c.arg)}}}function N(t,r){var n=r.method,i=t.iterator[n];if(i===e)return r.delegate=null,"throw"===n&&t.iterator.return&&(r.method="return",r.arg=e,N(t,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),v;var o=p(i,t.iterator,r.arg);if("throw"===o.type)return r.method="throw",r.arg=o.arg,r.delegate=null,v;var a=o.arg;return a?a.done?(r[t.resultName]=a.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,v):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,v)}function R(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function A(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function L(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(R,this),this.reset(!0)}function P(t){if(t||""===t){var r=t[a];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var i=-1,o=function r(){for(;++i<t.length;)if(n.call(t,i))return r.value=t[i],r.done=!1,r;return r.value=e,r.done=!0,r};return o.next=o}}throw new TypeError(typeof t+" is not iterable")}return y.prototype=w,i(O,"constructor",{value:w,configurable:!0}),i(w,"constructor",{value:y,configurable:!0}),y.displayName=c(w,u,"GeneratorFunction"),t.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===y||"GeneratorFunction"===(t.displayName||t.name))},t.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,w):(e.__proto__=w,c(e,u,"GeneratorFunction")),e.prototype=Object.create(O),e},t.awrap=function(e){return{__await:e}},S(I.prototype),c(I.prototype,s,(function(){return this})),t.AsyncIterator=I,t.async=function(e,r,n,i,o){void 0===o&&(o=Promise);var a=new I(l(e,r,n,i),o);return t.isGeneratorFunction(r)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},S(O),c(O,u,"Generator"),c(O,a,(function(){return this})),c(O,"toString",(function(){return"[object Generator]"})),t.keys=function(e){var t=Object(e),r=[];for(var n in t)r.push(n);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=P,L.prototype={constructor:L,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(A),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function i(n,i){return s.type="throw",s.arg=t,r.next=n,i&&(r.method="next",r.arg=e),!!i}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],s=a.completion;if("root"===a.tryLoc)return i("end");if(a.tryLoc<=this.prev){var u=n.call(a,"catchLoc"),c=n.call(a,"finallyLoc");if(u&&c){if(this.prev<a.catchLoc)return i(a.catchLoc,!0);if(this.prev<a.finallyLoc)return i(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return i(a.catchLoc,!0)}else{if(!c)throw Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return i(a.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=e,a.arg=t,o?(this.method="next",this.next=o.finallyLoc,v):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),v},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),A(r),v}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var i=n.arg;A(r)}return i}}throw Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:P(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),v}},t}function S(e,t){return S=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},S(e,t)}function I(e){var t=function(e){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:t+""}var _={AGENT:"AGENT",WORKFLOW:"WORKFLOW"},N={DEBUG:"DEBUG",INFO:"INFO",WARN:"WARN",ERROR:"ERROR"},R=function(){function e(e){void 0===e&&(e=N.INFO),this.level=void 0,this.level=e}var t=e.prototype;return t.debug=function(e){if(this.level<=N.DEBUG){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return this.log.apply(this,[N.DEBUG,e].concat(r))}},t.info=function(e){if(this.level<=N.INFO){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return this.log.apply(this,[N.INFO,e].concat(r))}},t.warn=function(e){if(this.level<=N.WARN){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return this.log.apply(this,[N.WARN,e].concat(r))}},t.error=function(e){if(this.level<=N.ERROR){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return this.log.apply(this,[N.ERROR,e].concat(r))}},t.formatMessage=function(e){return"string"==typeof e?e:JSON.stringify(e)},t.formatLogEntry=function(e,t){return{timestamp:(new Date).toISOString(),level:N[e],message:this.formatMessage(t)}},e}(),A=function(e){function t(t){return e.call(this,null!=t?t:N.INFO)||this}return O(t,e),t.prototype.log=function(e,t){for(var r,n=this.formatLogEntry(e,t),i=arguments.length,o=new Array(i>2?i-2:0),a=2;a<i;a++)o[a-2]=arguments[a];(r=console).log.apply(r,["["+n.timestamp+"] ["+n.level+"] "+n.message].concat(o))},t}(R),L=E("dirPath"),P=function(e){function n(t,r){var n;return void 0===t&&(t="logs"),n=e.call(this,null!=r?r:N.INFO)||this,Object.defineProperty(n,L,{writable:!0,value:void 0}),w(n,L)[L]=t,n}O(n,e);var i=n.prototype;return i.log=function(e,t){if("string"==typeof t)throw new Error("FileLogger requires a BaseLogMessage object");var n=r.join(w(this,L)[L],t.destinationPath+".json");this.ensureDirectoryExists(),this.writeLogToFile(n,e,t)},i.ensureDirectoryExists=function(){t.existsSync(w(this,L)[L])||t.mkdirSync(w(this,L)[L],{recursive:!0})},i.writeLogToFile=function(e,r,n){var i=x({},n,{level:N[r],createdAt:new Date}),o=[];t.existsSync(e)&&(o=JSON.parse(t.readFileSync(e,"utf-8"))),o.push(i),t.writeFileSync(e,JSON.stringify(o,null,2))},n}(R),k=E("redis"),C=E("key"),z=function(e){function t(t,r,n){var i;return void 0===r&&(r="logs"),i=e.call(this,null!=n?n:N.INFO)||this,Object.defineProperty(i,k,{writable:!0,value:void 0}),Object.defineProperty(i,C,{writable:!0,value:void 0}),w(i,k)[k]=t,w(i,C)[C]=r,i}O(t,e);var r=t.prototype;return r.log=function(){var e=y(T().mark((function e(t,r){var n;return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("string"!=typeof r){e.next=2;break}throw new Error("UpstashRedisLogger requires a BaseLogMessage object");case 2:return n=x({},r,{level:N[t],createdAt:new Date}),e.next=5,w(this,k)[k].lpush(w(this,C)[C],JSON.stringify(n));case 5:case"end":return e.stop()}}),e,this)})));return function(t,r){return e.apply(this,arguments)}}(),r.getLogs=function(){var e=y(T().mark((function e(){return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",w(this,k)[k].lrange(w(this,C)[C],0,-1));case 1:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),r.cleanup=function(){var e=y(T().mark((function e(){return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),t}(R),j=function(){function e(e){this.loggers=void 0,this.loggers=e}var t=e.prototype;return t.debug=function(){var e=y(T().mark((function e(t){var r,n,i,o=arguments;return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(r=o.length,n=new Array(r>1?r-1:0),i=1;i<r;i++)n[i-1]=o[i];return e.next=3,Promise.all(this.loggers.map((function(e){return e.debug.apply(e,[t].concat(n))})));case 3:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.info=function(){var e=y(T().mark((function e(t){var r,n,i,o=arguments;return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(r=o.length,n=new Array(r>1?r-1:0),i=1;i<r;i++)n[i-1]=o[i];return e.next=3,Promise.all(this.loggers.map((function(e){return e.info.apply(e,[t].concat(n))})));case 3:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.warn=function(){var e=y(T().mark((function e(t){var r,n,i,o=arguments;return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(r=o.length,n=new Array(r>1?r-1:0),i=1;i<r;i++)n[i-1]=o[i];return e.next=3,Promise.all(this.loggers.map((function(e){return e.warn.apply(e,[t].concat(n))})));case 3:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.error=function(){var e=y(T().mark((function e(t){var r,n,i,o=arguments;return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(r=o.length,n=new Array(r>1?r-1:0),i=1;i<r;i++)n[i-1]=o[i];return e.next=3,Promise.all(this.loggers.map((function(e){return e.error.apply(e,[t].concat(n))})));case 3:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.cleanup=function(){var e=y(T().mark((function e(){return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,Promise.all(this.loggers.map(function(){var e=y(T().mark((function e(t){return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.cleanup){e.next=3;break}return e.next=3,t.cleanup();case 3:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()));case 2:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),e}();function M(t){switch(t.type){case"CONSOLE":return new A(t.level);case"FILE":return new P(t.dirPath,t.level);case"UPSTASH":var r=new e.Redis({url:t.url,token:t.token});return new z(r,t.key,t.level);default:throw new Error("Unsupported logger type")}}var U,K,F,G=function(e){return new Promise((function(t){return setTimeout(t,e)}))},D=E("tools"),B=function(){function e(e){Object.defineProperty(this,D,{writable:!0,value:void 0}),this.logger=void 0,w(this,D)[D]={},this.logger=e||M({type:"CONSOLE"})}var t=e.prototype;return t.__setTools=function(e){w(this,D)[D]=e,this.logger.debug("Tools set for LLM",e)},t.getModelType=function(e){var t;if(!("provider"in e))throw new Error("Model provider is required");var r=null!=(t={OPEN_AI:"openai",ANTHROPIC:"anthropic",GROQ:"groq",PERPLEXITY:"perplexity",FIREWORKS:"fireworks",TOGETHER_AI:"togetherai",LM_STUDIO:"lmstuido",BASETEN:"baseten",GOOGLE:"google",MISTRAL:"mistral",X_GROK:"grok",COHERE:"cohere",AZURE:"azure",AMAZON:"amazon",ANTHROPIC_VERTEX:"anthropic-vertex"}[e.provider])?t:e.provider;return this.logger.debug("Model type resolved to "+r+" for provider "+e.provider),r},t.createOpenAICompatibleModel=function(e){var t=e.baseURL,r=e.apiKey,n=e.defaultModelName,o=e.modelName,a=e.fetch;return this.logger.debug("Creating OpenAI compatible model with baseURL: "+t),i.createOpenAI({baseURL:t,apiKey:r,fetch:a})(o||n)},t.createModelDef=function(e){var t,r=e.model;if("openai"===r.type)this.logger.info("Initializing OpenAI model "+(r.name||"gpt-4o-2024-08-06")),t=i.createOpenAI({apiKey:(null==r?void 0:r.apiKey)||process.env.OPENAI_API_KEY})(r.name||"gpt-4o-2024-08-06",{structuredOutputs:!0});else if("anthropic"===r.type)this.logger.info("Initializing Anthropic model "+(r.name||"claude-3-5-sonnet-20240620")),t=n.createAnthropic({apiKey:(null==r?void 0:r.apiKey)||process.env.ANTHROPIC_API_KEY})(r.name||"claude-3-5-sonnet-20240620");else if("google"===r.type)this.logger.info("Initializing Google model "+(r.name||"gemini-1.5-pro-latest")),t=o.createGoogleGenerativeAI({baseURL:"https://generativelanguage.googleapis.com/v1beta",apiKey:(null==r?void 0:r.apiKey)||process.env.GOOGLE_GENERATIVE_AI_API_KEY||""})(r.name||"gemini-1.5-pro-latest");else if("groq"===r.type)this.logger.info("Initializing Groq model "+(r.name||"llama-3.2-90b-text-preview")),t=this.createOpenAICompatibleModel({baseURL:"https://api.groq.com/openai/v1",apiKey:(null==r?void 0:r.apiKey)||process.env.GROQ_API_KEY||"",defaultModelName:"llama-3.2-90b-text-preview",modelName:r.name});else if("perplexity"===r.type)this.logger.info("Initializing Perplexity model "+(r.name||"llama-3.1-sonar-large-128k-chat")),t=this.createOpenAICompatibleModel({baseURL:"https://api.perplexity.ai/",apiKey:(null==r?void 0:r.apiKey)||process.env.PERPLEXITY_API_KEY||"",defaultModelName:"llama-3.1-sonar-large-128k-chat",modelName:r.name});else if("fireworks"===r.type)this.logger.info("Initializing Fireworks model "+(r.name||"llama-v3p1-70b-instruct")),t=this.createOpenAICompatibleModel({baseURL:"https://api.fireworks.ai/inference/v1",apiKey:(null==r?void 0:r.apiKey)||process.env.FIREWORKS_API_KEY||"",defaultModelName:"llama-v3p1-70b-instruct",modelName:r.name});else if("togetherai"===r.type)this.logger.info("Initializing TogetherAI model "+(r.name||"google/gemma-2-9b-it")),t=this.createOpenAICompatibleModel({baseURL:"https://api.together.xyz/v1/",apiKey:(null==r?void 0:r.apiKey)||process.env.TOGETHER_AI_API_KEY||"",defaultModelName:"google/gemma-2-9b-it",modelName:r.name});else if("lmstudio"===r.type){if(this.logger.info("Initializing LMStudio model "+(r.name||"llama-3.2-1b")),null==r||!r.baseURL){var h="LMStudio model requires a baseURL";throw this.logger.error(h),new Error(h)}t=this.createOpenAICompatibleModel({baseURL:r.baseURL,apiKey:"not-needed",defaultModelName:"llama-3.2-1b",modelName:r.name})}else if("baseten"===r.type){if(this.logger.info("Initializing BaseTen model "+(r.name||"llama-3.1-70b-instruct")),null!=r&&r.fetch){var f="Custom fetch is required to use "+r.type+". see https://docs.baseten.co/api-reference/openai for more information";throw this.logger.error(f),new Error(f)}t=this.createOpenAICompatibleModel({baseURL:"https://bridge.baseten.co/v1/direct",apiKey:(null==r?void 0:r.apiKey)||process.env.BASETEN_API_KEY||"",defaultModelName:"llama-3.1-70b-instruct",modelName:r.name})}else if("mistral"===r.type)this.logger.info("Initializing Mistral model "+(r.name||"pixtral-large-latest")),t=a.createMistral({baseURL:"https://api.mistral.ai/v1",apiKey:(null==r?void 0:r.apiKey)||process.env.MISTRAL_API_KEY||""})(r.name||"pixtral-large-latest");else if("grok"===r.type){var g;this.logger.info("Initializing X Grok model "+(r.name||"grok-beta")),t=c.createXai({baseURL:"https://api.x.ai/v1",apiKey:null!=(g=process.env.XAI_API_KEY)?g:""})(r.name||"grok-beta")}else if("cohere"===r.type)this.logger.info("Initializing Cohere model "+(r.name||"command-r-plus")),t=l.createCohere({baseURL:"https://api.cohere.com/v2",apiKey:(null==r?void 0:r.apiKey)||process.env.COHERE_API_KEY||""})(r.name||"command-r-plus");else if("azure"===r.type)this.logger.info("Initializing Azure model "+(r.name||"gpt-35-turbo-instruct")),t=u.createAzure({resourceName:process.env.AZURE_RESOURCE_NAME||"",apiKey:(null==r?void 0:r.apiKey)||process.env.AZURE_API_KEY||""})(r.name||"gpt-35-turbo-instruct");else if("amazon"===r.type)this.logger.info("Initializing Amazon model "+(r.name||"amazon-titan-tg1-large")),t=s.createAmazonBedrock({region:process.env.AWS_REGION||"",accessKeyId:process.env.AWS_ACCESS_KEY_ID||"",secretAccessKey:process.env.AWS_SECRET_ACCESS_KEY||"",sessionToken:process.env.AWS_SESSION_TOKEN||""})(r.name||"amazon-titan-tg1-large");else{if("anthropic-vertex"!==r.type){var d="Invalid model type: "+r.type;throw this.logger.error(d),new Error(d)}var v;this.logger.info("Initializing Anthropic Vertex model "+(r.name||"claude-3-5-sonnet@20240620")),t=p.createAnthropicVertex({region:process.env.GOOGLE_VERTEX_REGION,projectId:process.env.GOOGLE_VERTEX_PROJECT_ID,apiKey:null!=(v=process.env.ANTHROPIC_API_KEY)?v:""})(r.name||"claude-3-5-sonnet@20240620")}return t},t.createEmbedding=function(){var e=y(T().mark((function e(t){var r,n,o,a,s,u;return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=t.value,o=t.maxRetries,"OPEN_AI"!==(r=t.model).provider){e.next=6;break}s=i.createOpenAI({apiKey:process.env.OPENAI_API_KEY}),a=s.embedding(r.name),e.next=12;break;case 6:if("COHERE"!==r.provider){e.next=11;break}u=l.createCohere({apiKey:process.env.COHERE_API_KEY}),a=u.embedding(r.name),e.next=12;break;case 11:throw new Error("Invalid embedding model");case 12:if(!(n instanceof Array)){e.next=16;break}return e.next=15,h.embedMany({model:a,values:n,maxRetries:o});case 15:case 18:return e.abrupt("return",e.sent);case 16:return e.next=18,h.embed({model:a,value:n,maxRetries:o});case 19:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),t.getParams=function(){var e=y(T().mark((function e(t){var r,n,i,o,a;return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=t.resultTool,n=t.model,i=Object.entries(t.tools).reduce((function(e,t){return e[t[0]]=h.tool(t[1]),e}),{}),o={},r&&(o={answer:h.tool(r)}),!("type"in n)){e.next=8;break}a=this.createModelDef({model:n}),e.next=15;break;case 8:if(!(n.model instanceof Function)){e.next=14;break}return e.next=11,n.model();case 11:a=e.sent,e.next=15;break;case 14:a=n.model;case 15:return e.abrupt("return",{toolsConverted:i,modelDef:a,answerTool:o,toolChoice:n.toolChoice||"required"});case 16:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.convertTools=function(e){var t=this,r=Object.entries(e||{}).reduce((function(e,r){var n=r[0],i=r[1],o=w(t,D)[D][n];return i&&o&&(e[n]={description:o.description,parameters:f.z.object({data:o.schema}),execute:o.executor}),e}),{});return this.logger.debug("Converted tools for LLM",r),r},t.isBaseOutputType=function(e){return"string"===e||"number"===e||"boolean"===e||"date"===e},t.baseOutputTypeSchema=function(e){switch(e){case"string":default:return f.z.string();case"number":return f.z.number();case"boolean":return f.z.boolean();case"date":return f.z.string().datetime()}},t.createOutputSchema=function(e){var t=this,r=Object.entries(e).reduce((function(e,r){var n=r[0],i=r[1];if(t.isBaseOutputType(i.type)&&(e[n]=t.baseOutputTypeSchema(i.type)),"object"===i.type){var o=t.createOutputSchema(i.items);e[n]=o}if("array"===i.type){var a=i.items;if(t.isBaseOutputType(a.type)){var s=t.baseOutputTypeSchema(a.type);e[n]=f.z.array(s)}if("object"===a.type){var u=t.createOutputSchema(a.items);e[n]=f.z.array(u)}}return e}),{});return f.z.object(r)},t.text=function(){var e=y(T().mark((function e(t){var r,n,i,o,a,s,u,c,l,p=this;return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.messages,i=t.onStepFinish,a=void 0===(o=t.maxSteps)?5:o,s=t.enabledTools,u="name"in(r=t.model)?{type:this.getModelType(r),name:r.name,toolChoice:r.toolChoice,apiKey:"LM_STUDIO"!==r.provider?null==r?void 0:r.apiKey:void 0,baseURL:"LM_STUDIO"===r.provider?r.baseURL:void 0,fetch:"BASETEN"===r.provider?r.fetch:void 0}:r,e.next=4,this.getParams({tools:this.convertTools(s||{}),model:u});case 4:return l={model:(c=e.sent).modelDef,tools:x({},c.toolsConverted,c.answerTool),toolChoice:c.toolChoice,maxSteps:a,onStepFinish:function(){var e=y(T().mark((function e(t){var r,n;return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null==i||i(JSON.stringify(t,null,2)),!(null!=t&&null!=(r=t.response)&&null!=(r=r.headers)&&r["x-ratelimit-remaining-tokens"]&&parseInt(null==t||null==(n=t.response)||null==(n=n.headers)?void 0:n["x-ratelimit-remaining-tokens"],10)<2e3)){e.next=5;break}return p.logger.warn("Rate limit approaching, waiting 10 seconds"),e.next=5,G(1e4);case 5:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()},this.logger.debug("Generating text with "+n.length+" messages"),e.next=9,h.generateText(x({messages:n},l));case 9:return e.abrupt("return",e.sent);case 10:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.textObject=function(){var e=y(T().mark((function e(t){var r,n,i,o,a,s,u,c,l,p,f,g=this;return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.messages,i=t.onStepFinish,a=void 0===(o=t.maxSteps)?5:o,s=t.enabledTools,u=t.structuredOutput,c="name"in(r=t.model)?{type:this.getModelType(r),name:r.name,toolChoice:r.toolChoice,apiKey:"LM_STUDIO"!==r.provider?null==r?void 0:r.apiKey:void 0,baseURL:"LM_STUDIO"===r.provider?r.baseURL:void 0,fetch:"BASETEN"===r.provider?r.fetch:void 0}:r,e.next=4,this.getParams({tools:this.convertTools(s||{}),model:c});case 4:return p={model:(l=e.sent).modelDef,tools:x({},l.toolsConverted,l.answerTool),toolChoice:l.toolChoice,maxSteps:a,onStepFinish:function(){var e=y(T().mark((function e(t){var r,n;return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null==i||i(JSON.stringify(t,null,2)),!(null!=t&&null!=(r=t.response)&&null!=(r=r.headers)&&r["x-ratelimit-remaining-tokens"]&&parseInt(null==t||null==(n=t.response)||null==(n=n.headers)?void 0:n["x-ratelimit-remaining-tokens"],10)<2e3)){e.next=5;break}return g.logger.warn("Rate limit approaching, waiting 10 seconds"),e.next=5,G(1e4);case 5:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()},this.logger.debug("Generating text with "+n.length+" messages"),f=this.createOutputSchema(u),e.next=10,h.generateObject(x({messages:n},p,{output:"object",schema:f}));case 10:return e.abrupt("return",e.sent);case 11:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.stream=function(){var e=y(T().mark((function e(t){var r,n,i,o,a,s,u,c,l,p,f=this;return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.messages,i=t.onStepFinish,o=t.onFinish,s=void 0===(a=t.maxSteps)?5:a,u=t.enabledTools,c="name"in(r=t.model)?{type:this.getModelType(r),name:r.name,toolChoice:r.toolChoice,apiKey:"LM_STUDIO"!==r.provider?null==r?void 0:r.apiKey:void 0,baseURL:"LM_STUDIO"===r.provider?r.baseURL:void 0,fetch:"BASETEN"===r.provider?r.fetch:void 0}:r,e.next=4,this.getParams({tools:this.convertTools(u),model:c});case 4:return p={model:(l=e.sent).modelDef,tools:x({},l.toolsConverted,l.answerTool),toolChoice:l.toolChoice,maxSteps:s,onStepFinish:function(){var e=y(T().mark((function e(t){var r,n;return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null==i||i(JSON.stringify(t,null,2)),!(null!=t&&null!=(r=t.response)&&null!=(r=r.headers)&&r["x-ratelimit-remaining-tokens"]&&parseInt(null==t||null==(n=t.response)||null==(n=n.headers)?void 0:n["x-ratelimit-remaining-tokens"],10)<2e3)){e.next=5;break}return f.logger.warn("Rate limit approaching, waiting 10 seconds"),e.next=5,G(1e4);case 5:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),onFinish:function(){var e=y(T().mark((function e(t){return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:null==o||o(JSON.stringify(t,null,2));case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()},this.logger.debug("Streaming text with "+n.length+" messages"),e.next=9,h.streamText(x({messages:n},p));case 9:return e.abrupt("return",e.sent);case 10:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.streamObject=function(){var e=y(T().mark((function e(t){var r,n,i,o,a,s,u,c,l,p,f,g,d=this;return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.messages,i=t.onStepFinish,o=t.onFinish,s=void 0===(a=t.maxSteps)?5:a,u=t.enabledTools,c=t.structuredOutput,l="name"in(r=t.model)?{type:this.getModelType(r),name:r.name,toolChoice:r.toolChoice,apiKey:"LM_STUDIO"!==r.provider?null==r?void 0:r.apiKey:void 0,baseURL:"LM_STUDIO"===r.provider?r.baseURL:void 0,fetch:"BASETEN"===r.provider?r.fetch:void 0}:r,e.next=4,this.getParams({tools:this.convertTools(u),model:l});case 4:return f={model:(p=e.sent).modelDef,tools:x({},p.toolsConverted,p.answerTool),toolChoice:p.toolChoice,maxSteps:s,onStepFinish:function(){var e=y(T().mark((function e(t){var r,n;return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null==i||i(JSON.stringify(t,null,2)),!(null!=t&&null!=(r=t.response)&&null!=(r=r.headers)&&r["x-ratelimit-remaining-tokens"]&&parseInt(null==t||null==(n=t.response)||null==(n=n.headers)?void 0:n["x-ratelimit-remaining-tokens"],10)<2e3)){e.next=5;break}return d.logger.warn("Rate limit approaching, waiting 10 seconds"),e.next=5,G(1e4);case 5:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),onFinish:function(){var e=y(T().mark((function e(t){return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:null==o||o(JSON.stringify(t,null,2));case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()},this.logger.debug("Streaming text with "+n.length+" messages"),g=this.createOutputSchema(c),e.next=10,h.streamObject(x({messages:n},f,{output:"object",schema:g}));case 10:return e.abrupt("return",e.sent);case 11:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),e}(),q=function(){function e(e){this.name=void 0,this.llm=void 0,this.instructions=void 0,this.model=void 0,this.enabledTools=void 0,this.logger=void 0,this.name=e.name,this.instructions=e.instructions,this.llm=new B,this.model=e.model,this.enabledTools=e.enabledTools||{},this.logger=M({type:"CONSOLE"}),this.logger.info("Agent "+this.name+" initialized with model "+this.model.provider)}var t=e.prototype;return t.__setTools=function(e){this.llm.__setTools(e),this.logger.debug("Tools set for agent "+this.name,e)},t.__setLogger=function(e){this.logger=e,this.logger.debug("Logger updated for agent "+this.name)},t.text=function(){var e=y(T().mark((function e(t){var r,n,i,o,a,s,u;return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.messages,n=t.onStepFinish,o=void 0===(i=t.maxSteps)?5:i,this.logger.info("Starting text generation for agent "+this.name),a={role:"system",content:this.instructions},s=r.map((function(e){return{role:"user",content:e}})),u=[a].concat(s),e.abrupt("return",this.llm.text({model:this.model,messages:u,enabledTools:this.enabledTools,onStepFinish:n,maxSteps:o}));case 6:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.textObject=function(){var e=y(T().mark((function e(t){var r,n,i,o,a,s,u,c;return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.messages,n=t.structuredOutput,i=t.onStepFinish,a=void 0===(o=t.maxSteps)?5:o,this.logger.info("Starting text generation for agent "+this.name),s={role:"system",content:this.instructions},u=r.map((function(e){return{role:"user",content:e}})),c=[s].concat(u),e.abrupt("return",this.llm.textObject({model:this.model,messages:c,structuredOutput:n,enabledTools:this.enabledTools,onStepFinish:i,maxSteps:a}));case 6:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.stream=function(){var e=y(T().mark((function e(t){var r,n,i,o,a,s,u,c;return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.messages,n=t.onStepFinish,i=t.onFinish,a=void 0===(o=t.maxSteps)?5:o,this.logger.info("Starting stream generation for agent "+this.name),s={role:"system",content:this.instructions},u=r.map((function(e){return{role:"user",content:e}})),c=[s].concat(u),e.abrupt("return",this.llm.stream({messages:c,model:this.model,enabledTools:this.enabledTools,onStepFinish:n,onFinish:i,maxSteps:a}));case 6:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),t.streamObject=function(){var e=y(T().mark((function e(t){var r,n,i,o,a,s,u,c,l;return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.messages,n=t.structuredOutput,i=t.onStepFinish,o=t.onFinish,s=void 0===(a=t.maxSteps)?5:a,this.logger.info("Starting stream generation for agent "+this.name),u={role:"system",content:this.instructions},c=r.map((function(e){return{role:"user",content:e}})),l=[u].concat(c),e.abrupt("return",this.llm.streamObject({messages:l,structuredOutput:n,model:this.model,enabledTools:this.enabledTools,onStepFinish:i,onFinish:o,maxSteps:s}));case 6:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),e}(),Y=["client"],W=function(){function e(){this.authType="API_KEY"}var t,r,n=e.prototype;return n.getApiClient=function(){var e=y(T().mark((function e(){return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:throw new Error("API not implemented");case 1:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),n._generateIntegrationTools=function(){var e=this,t=function(e,t){if(null==e)return{};var r={};for(var n in e)if({}.hasOwnProperty.call(e,n)){if(t.includes(n))continue;r[n]=e[n]}return r}(this.baseClient,Y),r=this.toolSchemas,n=this.toolDocumentations,i=Object.keys(t).reduce((function(t,i){var o,a,s,u,c=null==(o=n[i])?void 0:o.comment,l=null==(a=n[i])?void 0:a.doc,p="Execute "+i,h={label:i,schema:r[i]||f.z.object({}),description:c||p,documentation:l||p,executor:(u=y(T().mark((function t(r){var n;return T().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=r.data,t.next=3,e.getApiClient();case 3:return t.abrupt("return",(0,t.sent[i])(x({},n)));case 6:case"end":return t.stop()}}),t)}))),function(e){return u.apply(this,arguments)})};return x({},t,((s={})[i]=h,s))}),{});return i},t=e,(r=[{key:"toolSchemas",get:function(){return{}}},{key:"toolDocumentations",get:function(){return{}}},{key:"baseClient",get:function(){return{}}}])&&function(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,I(n.key),n)}}(t.prototype,r),Object.defineProperty(t,"prototype",{writable:!1}),t}();exports.PropertyType=void 0,(U=exports.PropertyType||(exports.PropertyType={})).LONG_TEXT="LONG_TEXT",U.SINGLE_LINE_TEXT="SINGLE_LINE_TEXT",U.SINGLE_SELECT="SINGLE_SELECT",U.MULTI_SELECT="MULTI_SELECT",U.CHECKBOX="CHECKBOX",U.DATE="DATE",U.USER="USER",U.BADGE_LIST="BADGE_LIST",U.CURRENCY="CURRENCY",U.URL="URL",U.PHONE="PHONE",U.CONTACT="CONTACT",U.COMPANY="COMPANY",U.PERSON="PERSON",U.ENRICHMENT="ENRICHMENT",U.COMPOSITE="COMPOSITE",U.BOOLEAN="BOOLEAN",U.NUMBER="NUMBER",U.FLOAT="FLOAT",U.JSON_OBJECT="JSON_OBJECT",U.JSON_ARRAY="JSON_ARRAY",exports.FilterOperators=void 0,(K=exports.FilterOperators||(exports.FilterOperators={})).IS="is",K.EQUAL="eq",K.NOT_EQUAL="not_eq",K.CONTAINS="contains",K.IN="in",K.NOT_IN="not_in",K.GREATER_THAN="gt",K.LESS_THAN="lt",K.NOT_CONTAINS="not_contains",K.GREATER_THAN_OR_EQUAL="gte",K.LESS_THAN_OR_EQUAL="lte",K.OP="op",K.SET="set",K.NOT_SET="not_set";var H=((F={})[exports.PropertyType.BADGE_LIST]="string",F[exports.PropertyType.CHECKBOX]="boolean",F[exports.PropertyType.BOOLEAN]="boolean",F[exports.PropertyType.NUMBER]="number",F[exports.PropertyType.FLOAT]="number",F[exports.PropertyType.JSON_ARRAY]="string",F[exports.PropertyType.JSON_OBJECT]="string",F[exports.PropertyType.CURRENCY]="number",F[exports.PropertyType.DATE]="date",F[exports.PropertyType.LONG_TEXT]="string",F[exports.PropertyType.MULTI_SELECT]="string",F[exports.PropertyType.PHONE]="string",F[exports.PropertyType.SINGLE_LINE_TEXT]="string",F[exports.PropertyType.SINGLE_SELECT]="string",F[exports.PropertyType.URL]="string",F[exports.PropertyType.USER]="string",F[exports.PropertyType.CONTACT]="string",F[exports.PropertyType.COMPANY]="string",F[exports.PropertyType.COMPOSITE]="string",F[exports.PropertyType.PERSON]="string",F[exports.PropertyType.ENRICHMENT]="string",F),J=function(e){return"string"==typeof e?e.split(","):e},X=function(e){return"string"==typeof e?"true"===e:e},Q=f.z.object({is:f.z.array(f.z.string()).or(f.z.string()).optional(),eq:f.z.array(f.z.string()).or(f.z.string()).optional(),not_eq:f.z.array(f.z.string()).or(f.z.string()).optional(),contains:f.z.array(f.z.string()).or(f.z.string()).optional(),not_contains:f.z.array(f.z.string()).or(f.z.string()).optional(),gt:f.z.array(f.z.string()).or(f.z.string()).optional(),gte:f.z.array(f.z.string()).or(f.z.string()).optional(),lt:f.z.array(f.z.string()).or(f.z.string()).optional(),lte:f.z.array(f.z.string()).or(f.z.string()).optional(),in:f.z.array(f.z.string()).or(f.z.string()).optional(),not_in:f.z.array(f.z.string()).or(f.z.string()).optional(),op:f.z.enum(["or","and"]).optional().default("or"),set:f.z.string().optional().transform(X),not_set:f.z.string().optional().transform(X)}),V=f.z.string().transform(J),Z=function(){function e(e){var t,r,n,i,o=this;this.engine=void 0,this.vectors=void 0,this.tools=void 0,this.agents=void 0,this.llm=void 0,this.integrations=void 0,this.logger=void 0,this.syncs=void 0,this.workflows=new Map,this.logger=new Map;var a=M({type:"CONSOLE"});e.logger&&(a=e.logger),this.setLogger({key:"AGENT",logger:a}),this.setLogger({key:"WORKFLOW",logger:a}),this.integrations=new Map,null==(t=e.integrations)||t.forEach((function(e){if(o.integrations.has(e.name))throw new Error("Integration with name "+e.name+" already exists");o.integrations.set(e.name,e)}));var s=(null==(r=e.integrations)?void 0:r.reduce((function(e,t){return x({},e,t.tools)}),{}))||{},u=x({},(null==e?void 0:e.tools)||{},s),c=Object.entries(null!=u?u:{}).reduce((function(e,t){var r=t[1];return e[t[0]]=x({},r,{executor:function(e){return r.executor(x({},e,{integrationsRegistry:function(){return{get:function(e){return o.getIntegration(e)}}},agents:o.agents,llm:o.llm,engine:o.engine}))}}),e}),{});if(this.tools=c,this.agents=new Map,this.llm=new B,this.llm.__setTools(this.tools),null==(n=e.agents)||n.forEach((function(e){if(o.agents.has(e.name))throw new Error("Agent with name "+e.name+" already exists");o.agents.set(e.name,e),e.__setTools(o.tools);var t=o.getLogger("AGENT");t&&e.__setLogger(t)})),null==(i=e.workflows)||i.forEach((function(e){if(o.workflows.has(e.name))throw new Error("Workflow with name "+e.name+" already exists");o.workflows.set(e.name,e)})),e.syncs&&!e.engine)throw new Error("Engine is required to run syncs");this.syncs=e.syncs||{},e.engine&&(this.engine=e.engine),e.vectors&&(this.vectors=e.vectors)}var t=e.prototype;return t.sync=function(){var e=y(T().mark((function e(t,r){var n,i,o,a=this;return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.engine){e.next=2;break}throw new Error("Engine is required to run syncs");case 2:if(i=null==(n=this.syncs)?void 0:n[t]){e.next=5;break}throw new Error("Sync function "+t+" not found");case 5:if(o=i.executor){e.next=8;break}throw new Error("Sync function "+t+" not found");case 8:return e.next=10,o({data:r,engine:this.engine,agents:this.agents,vectors:this.vectors,llm:this.llm,integrationsRegistry:function(){return{get:function(e){return a.getIntegration(e)}}},toolsRegistry:function(){return{get:function(e){return a.getTool(e)}}}});case 10:return e.abrupt("return",e.sent);case 11:case"end":return e.stop()}}),e,this)})));return function(t,r){return e.apply(this,arguments)}}(),t.getAgent=function(e){var t=this.agents.get(e);if(!t)throw new Error("Agent with name "+e+" not found");return t},t.getIntegration=function(e){var t=String(e),r=this.integrations.get(t.toUpperCase());if(!r)throw new Error("Integration with name "+t+" not found");return r},t.getTool=function(e){var t,r=this,n=this.tools[e];if(!n)throw new Error("Tool with name "+String(e)+" not found");return x({},n,{execute:(t=y(T().mark((function e(t){return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",n.executor({data:t,integrationsRegistry:function(){return{get:function(e){return r.getIntegration(e)}}},agents:r.agents,llm:r.llm,engine:r.engine}));case 1:case"end":return e.stop()}}),e)}))),function(e){return t.apply(this,arguments)})})},t.availableIntegrations=function(){return Array.from(this.integrations.entries()).map((function(e){return{name:e[0],integration:e[1]}}))},t.getTools=function(){return this.tools},t.setLogger=function(e){this.logger.set(e.key,e.logger)},t.getLogger=function(e){return this.logger.get(e)},e}(),$=E("logger"),ee=E("triggerSchema"),te=E("steps"),re=E("transitions"),ne=E("machine"),ie=E("actor"),oe=E("log"),ae=E("buildStateHierarchy"),se=E("isVariableReference"),ue=E("resolveVariables"),ce=E("cleanup"),le=E("evaluateCondition"),pe=E("validateWorkflow"),he=E("detectCircularDependencies"),fe=E("validateTerminalPaths"),ge=E("detectUnreachableSteps"),de=function(){function e(e){var t=e.name,r=e.logger,n=e.steps,i=e.triggerSchema;Object.defineProperty(this,ge,{value:Ie}),Object.defineProperty(this,fe,{value:Se}),Object.defineProperty(this,he,{value:Te}),Object.defineProperty(this,pe,{value:Oe}),Object.defineProperty(this,le,{value:xe}),Object.defineProperty(this,ce,{value:Ee}),Object.defineProperty(this,ue,{value:be}),Object.defineProperty(this,se,{value:we}),Object.defineProperty(this,ae,{value:ye}),Object.defineProperty(this,oe,{value:ve}),this.name=void 0,Object.defineProperty(this,$,{writable:!0,value:void 0}),Object.defineProperty(this,ee,{writable:!0,value:void 0}),Object.defineProperty(this,te,{writable:!0,value:void 0}),Object.defineProperty(this,re,{writable:!0,value:{}}),Object.defineProperty(this,ne,{writable:!0,value:void 0}),Object.defineProperty(this,ie,{writable:!0,value:null}),this.name=t,w(this,$)[$]=r,w(this,te)[te]=n,w(this,ee)[ee]=i,this.initializeMachine()}var t=e.prototype;return t.initializeMachine=function(){var e,t=this,r=d.setup({types:{},actions:{updateStepResult:d.assign({stepResults:function(e){var r,n,i=e.context,o=e.event;if(!o.type.startsWith("xstate.done.actor."))return i.stepResults;var a=null==(r=o.output)?void 0:r.stepId;if(!a)return i.stepResults;w(t,oe)[oe](N.INFO,"Step "+a+" completed",o.output,a);var s=null==(n=o.output)?void 0:n.result;if(void 0!==s){var u,c=x({},i.stepResults,((u={})[a]=s,u)),l=w(t,re)[re][a];if(null!=l&&l.transitions){var p=x({},i,{stepResults:c}),h=!1;w(t,oe)[oe](N.DEBUG,"Evaluating transitions with context:",p),Object.entries(l.transitions).forEach((function(e){var r=e[0],n=e[1];w(t,oe)[oe](N.DEBUG,"Checking transition to: "+r),w(t,oe)[oe](N.DEBUG,"With condition: "+(null==n?void 0:n.condition)),null!=n&&n.condition&&!w(t,le)[le](null==n?void 0:n.condition,p)||(h=!0,w(t,oe)[oe](N.DEBUG,"Condition passed, sending transition to:",r),Promise.resolve().then((function(){w(t,ie)[ie]&&w(t,ie)[ie].send({type:"TRANSITION_"+r})})))})),h||Promise.resolve().then((function(){w(t,ie)[ie]&&w(t,ie)[ie].send({type:"NO_MATCHING_CONDITIONS"})}))}return c}return i.stepResults}}),setError:d.assign({error:function(e){var r=e.event;return r.type.startsWith("xstate.error.actor.")?(w(t,oe)[oe](N.ERROR,"Workflow error",r.error),r.error):null}}),initializeTriggerData:d.assign({triggerData:function(e){var r=e.context;return w(t,oe)[oe](N.INFO,"Workflow started",null==r?void 0:r.triggerData),null==r?void 0:r.triggerData}})},actors:{resolverFunction:d.fromPromise(function(){var e=y(T().mark((function e(r){var n,i,o,a,s;return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=(n=r.input).step,o=n.context,a=n.stepId,s=w(t,ue)[ue](i,o),e.next=5,i.handler(s);case 5:return e.abrupt("return",{stepId:a,result:e.sent});case 7:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}())}}).createMachine({id:this.name,initial:(null==(e=w(this,te)[te][0])?void 0:e.id)||"idle",context:function(e){return x({},e.input,{stepResults:{},error:null})},entry:["initializeTriggerData"],states:w(this,ae)[ae]()});return w(this,ne)[ne]=r,r},t.commit=function(){return w(this,pe)[pe](),this.initializeMachine(),this},t.step=function(e,t){for(var r,n=this,i=t||{},o=i.variables,a=i.transitions,s=void 0===a?void 0:a,u={},c=0,l=Object.entries(void 0===o?{}:o);c<l.length;c++){var p=l[c],h=p[0],f=p[1];f&&w(this,se)[se](f)&&(u[h]=f)}return w(this,re)[re][e]={transitions:s,data:u,handler:(r=y(T().mark((function t(r){var i,o,a,s,u;return T().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(i=w(n,te)[te].find((function(t){return t.id===e}))){t.next=3;break}throw new Error("Step "+e+" not found");case 3:return o=i.inputSchema,a=i.action,s=x({},i.payload,r),u=o?o.parse(s):s,t.abrupt("return",a?a(u):{});case 7:case"end":return t.stop()}}),t)}))),function(e){return r.apply(this,arguments)})},this},t.execute=function(){var e=y(T().mark((function e(t){var r=this;return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,w(this,oe)[oe](N.INFO,"Executing workflow",{triggerData:t});case 2:if(!w(this,ee)[ee]){e.next=14;break}return e.prev=3,w(this,ee)[ee].parse(t),e.next=7,w(this,oe)[oe](N.DEBUG,"Trigger schema validation passed");case 7:e.next=14;break;case 9:return e.prev=9,e.t0=e.catch(3),e.next=13,w(this,oe)[oe](N.ERROR,"Trigger schema validation failed",{error:e.t0});case 13:throw e.t0;case 14:return w(this,ie)[ie]=d.createActor(w(this,ne)[ne],{input:{error:null,stepResults:{},triggerData:t||{}}}),w(this,ie)[ie].start(),e.abrupt("return",new Promise((function(e,n){w(r,ie)[ie]?w(r,ie)[ie].subscribe((function(i){if(i.matches("success"))w(r,oe)[oe](N.INFO,"Workflow completed successfully",{results:i.context.stepResults}),w(r,ce)[ce](),e({triggerData:t,results:i.context.stepResults});else if(i.matches("failure")){var o,a;w(r,oe)[oe](N.ERROR,"Workflow failed",{error:null==(o=i.context.error)?void 0:o.message}),w(r,ce)[ce](),n({error:null==(a=i.context.error)?void 0:a.message})}})):n(new Error("Actor not initialized"))})));case 17:case"end":return e.stop()}}),e,this,[[3,9]])})));return function(t){return e.apply(this,arguments)}}(),e}();function ve(e,t,r,n){return me.apply(this,arguments)}function me(){return(me=y(T().mark((function e(t,r,n,i){var o,a,s,u;return T().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(w(this,$)[$]){e.next=2;break}return e.abrupt("return");case 2:return s={type:_.WORKFLOW,message:r,workflowName:this.name,destinationPath:"workflows/"+this.name,stepId:i,data:n},u=t.toLowerCase(),e.next=6,null==(o=(a=w(this,$)[$])[u])?void 0:o.call(a,s);case 6:case"end":return e.stop()}}),e,this)})))).apply(this,arguments)}function ye(){var e=this,t={idle:{},success:{type:"final"},failure:{type:"final"}},r=new Set;return w(this,te)[te].forEach((function(n){var i=function(t,r){var n,i;if(r.has(t))return null;if(r.add(t),!w(e,te)[te].find((function(e){return e.id===t})))return null;var o,a={invoke:{src:"resolverFunction",input:function(r){return{context:r.context,stepId:t,step:w(e,re)[re][t]}},onDone:{actions:["updateStepResult"],target:null!=(n=w(e,re)[re][t])&&n.transitions?void 0:"success"},onError:{target:"failure",actions:["setError"]}},on:{NO_MATCHING_CONDITIONS:{target:"failure",actions:d.assign({error:function(){return console.log("No matching transition conditions"),new Error("No matching transition conditions")}})}}};return null!=(i=w(e,re)[re][t])&&i.transitions&&Object.entries(null==(o=w(e,re)[re][t])?void 0:o.transitions).forEach((function(t){var r=t[0],n=t[1];a.on["TRANSITION_"+r]={target:r,guard:function(t){var r=t.context;return!(null!=n&&n.condition)||w(e,le)[le](null==n?void 0:n.condition,r)}}})),a}(n.id,r);i&&(t[n.id]=i)})),t}function we(e){return"object"==typeof e&&"stepId"in e&&"path"in e}function be(e,t){for(var r={},n=0,i=Object.entries(e.data);n<i.length;n++){var o=i[n],a=o[0],s=o[1],u="trigger"===s.stepId?t.triggerData:t.stepResults[s.stepId];if(!u&&"trigger"!==s.stepId)throw new Error("Cannot resolve variable: Step "+s.stepId+" has not been executed yet");var c=""===s.path||"."===s.path?u[a]:v(u,s.path);if(void 0===c)throw new Error('Cannot resolve path "'+s.path+'" from '+s.stepId);r[a]=c}return r}function Ee(){w(this,ie)[ie]&&(w(this,ie)[ie].stop(),w(this,ie)[ie]=null)}function xe(e,t){var r=this,n=!0,i=!0,o=!0;if("ref"in e){var a=e.ref,s=e.query,u="trigger"===a.stepId?t.triggerData:t.stepResults[a.stepId];if(!u)throw new Error("Cannot evaluate condition: Step "+a.stepId+" has not been executed yet");var c=v(u,a.path);i=g(s)(c)}return"and"in e&&(n=e.and.every((function(e){return w(r,le)[le](e,t)}))),"or"in e&&(o=e.or.some((function(e){return w(r,le)[le](e,t)}))),i&&n&&o}function Oe(){var e=[].concat(w(this,he)[he](),w(this,fe)[fe](),w(this,ge)[ge]());if(e.length>0){var t=e.map((function(e){return"["+e.type+"] "+e.message+(e.details.path?" (Path: "+e.details.path.join(" → ")+")":"")+(e.details.stepId?" (Step: "+e.details.stepId+")":"")}));throw new Error("Workflow validation failed:\n"+t.join("\n"))}}function Te(){var e=this,t=[],r=[],n=function(i){if(r.includes(i)){var o=r.indexOf(i),a=[].concat(r.slice(o),[i]);t.push({type:"circular_dependency",message:"Circular dependency detected in workflow",details:{path:a}})}else{r.push(i);var s=w(e,re)[re][i];null!=s&&s.transitions&&Object.keys(s.transitions).forEach((function(e){n(e)})),r.pop()}};return w(this,te)[te].length>0&&n(w(this,te)[te][0].id),t}function Se(){var e=this,t=[],r=new Set,n=new Set,i=function(o,a){if(void 0===a&&(a=[]),n.has(o))return!0;if(r.has(o)&&!n.has(o))return!1;r.add(o);var s=w(e,re)[re][o];if(!s)return!1;if(!s.transitions)return n.add(o),!0;var u=Object.keys(s.transitions);if(0===u.length)return n.add(o),!0;var c=u.some((function(e){return!a.includes(e)&&i(e,[].concat(a,[o]))}));return c?n.add(o):t.push({type:"no_terminal_path",message:"No path to terminal state found",details:{stepId:o,path:[].concat(a,[o])}}),c};return w(this,te)[te].length>0&&i(w(this,te)[te][0].id),t}function Ie(){var e=this,t=[],r=new Set,n=function(t){if(!r.has(t)){r.add(t);var i=w(e,re)[re][t];null!=i&&i.transitions&&Object.keys(i.transitions).forEach((function(e){n(e)}))}};return w(this,te)[te].length>0&&n(w(this,te)[te][0].id),w(this,te)[te].forEach((function(e){r.has(e.id)||t.push({type:"unreachable_step",message:"Step is not reachable from the initial step",details:{stepId:e.id}})})),t}exports.Agent=q,exports.BaseLogger=R,exports.FieldTypePrimitiveMap=H,exports.Integration=W,exports.LogLevel=N,exports.Mastra=Z,exports.MastraEngine=function(e){},exports.MastraVector=function(){},exports.MultiLogger=j,exports.RegisteredLogger=_,exports.Step=function(e){var t=e.id,r=e.inputSchema,n=e.outputSchema,i=e.payload,o=e.action;this.id=void 0,this.inputSchema=void 0,this.outputSchema=void 0,this.payload=void 0,this.action=void 0,this.id=t,this.inputSchema=r,this.payload=i,this.outputSchema=n,this.action=o},exports.Workflow=de,exports.buildQueryString=function(e){var t=e.filterQueryString,r=e.sortQueryString;return t||r?t?r?t+"&"+r:""+t:""+r:""},exports.createLogger=M,exports.createMultiLogger=function(e){return new j(e)},exports.createSync=function(e){return e},exports.createTool=function(e){return e},exports.filterQuerySchema=Q,exports.getJSONField=function(e,t){switch(H[t]){case"number":return"("+e+")::bigint";case"boolean":return"("+e+")::boolean";case"date":return"("+e+")::timestamp"}return"("+e+")::text"},exports.sortQuerySchema=V,exports.splitAndStripQuotes=function(e){return e.split(/,\s*(?=(?:[^"]*"[^"]*")*[^"]*$)/).map((function(e){return e.trim().replace(/^"|"$/g,"")}))},exports.transformFilterValueArray=J,exports.transformFilterValueBoolean=X;
|
|
2
2
|
//# sourceMappingURL=core.cjs.production.min.js.map
|