@mastra/core 0.1.27-alpha.11 → 0.1.27-alpha.13
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/core.cjs.development.js +155 -131
- 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 +153 -131
- package/dist/core.esm.js.map +1 -1
- package/dist/engine/index.d.ts +3 -3
- package/dist/engine/types.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/integration/test-integration.d.ts +12 -0
- package/dist/llm/index.d.ts +1 -1
- package/dist/mastra/index.d.ts +4 -3
- package/dist/mastra/types.d.ts +1 -0
- package/dist/sync/index.d.ts +2 -0
- package/dist/sync/types.d.ts +23 -10
- package/dist/tools/types.d.ts +3 -2
- package/dist/workflows/index.d.ts +2 -1
- package/dist/workflows/step.d.ts +15 -0
- package/dist/workflows/types.d.ts +25 -23
- package/dist/workflows/{main.d.ts → workflow.d.ts} +11 -12
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ var ai = require('ai');
|
|
|
18
18
|
var zod = require('zod');
|
|
19
19
|
var sift = require('sift');
|
|
20
20
|
var xstate = require('xstate');
|
|
21
|
-
var get = require('lodash/get');
|
|
21
|
+
var get = require('lodash-es/get');
|
|
22
22
|
|
|
23
23
|
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
24
24
|
try {
|
|
@@ -847,6 +847,7 @@ var LLM = /*#__PURE__*/function () {
|
|
|
847
847
|
COHERE: 'cohere',
|
|
848
848
|
AZURE: 'azure',
|
|
849
849
|
AMAZON: 'amazon',
|
|
850
|
+
//
|
|
850
851
|
ANTHROPIC_VERTEX: 'anthropic-vertex'
|
|
851
852
|
};
|
|
852
853
|
var type = (_providerToType$model = providerToType[model.provider]) != null ? _providerToType$model : model.provider;
|
|
@@ -1729,7 +1730,6 @@ var Agent = /*#__PURE__*/function () {
|
|
|
1729
1730
|
return Agent;
|
|
1730
1731
|
}();
|
|
1731
1732
|
|
|
1732
|
-
// TODO: Passing the In/out generics works but seems to break on plugin to mastra, fix.
|
|
1733
1733
|
function createTool(opts) {
|
|
1734
1734
|
return opts;
|
|
1735
1735
|
}
|
|
@@ -1956,6 +1956,10 @@ function MastraEngine(config) {};
|
|
|
1956
1956
|
|
|
1957
1957
|
var MastraVector = function MastraVector() {};
|
|
1958
1958
|
|
|
1959
|
+
function createSync(opts) {
|
|
1960
|
+
return opts;
|
|
1961
|
+
}
|
|
1962
|
+
|
|
1959
1963
|
var Mastra = /*#__PURE__*/function () {
|
|
1960
1964
|
function Mastra(config) {
|
|
1961
1965
|
var _config$integrations,
|
|
@@ -2007,8 +2011,12 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
2007
2011
|
memo[key] = _extends({}, val, {
|
|
2008
2012
|
executor: function executor(params) {
|
|
2009
2013
|
return val.executor(_extends({}, params, {
|
|
2010
|
-
|
|
2011
|
-
return
|
|
2014
|
+
integrationsRegistry: function integrationsRegistry() {
|
|
2015
|
+
return {
|
|
2016
|
+
get: function get(name) {
|
|
2017
|
+
return _this.getIntegration(name);
|
|
2018
|
+
}
|
|
2019
|
+
};
|
|
2012
2020
|
},
|
|
2013
2021
|
agents: _this.agents,
|
|
2014
2022
|
llm: _this.llm,
|
|
@@ -2053,8 +2061,9 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
2053
2061
|
var _proto = Mastra.prototype;
|
|
2054
2062
|
_proto.sync = /*#__PURE__*/function () {
|
|
2055
2063
|
var _sync = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(key, params) {
|
|
2056
|
-
var _this$syncs
|
|
2057
|
-
|
|
2064
|
+
var _this$syncs,
|
|
2065
|
+
_this2 = this;
|
|
2066
|
+
var sync, syncFn;
|
|
2058
2067
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
2059
2068
|
while (1) switch (_context.prev = _context.next) {
|
|
2060
2069
|
case 0:
|
|
@@ -2062,25 +2071,47 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
2062
2071
|
_context.next = 2;
|
|
2063
2072
|
break;
|
|
2064
2073
|
}
|
|
2065
|
-
throw new Error("
|
|
2074
|
+
throw new Error("Engine is required to run syncs");
|
|
2066
2075
|
case 2:
|
|
2067
|
-
|
|
2068
|
-
if (
|
|
2076
|
+
sync = (_this$syncs = this.syncs) == null ? void 0 : _this$syncs[key];
|
|
2077
|
+
if (sync) {
|
|
2069
2078
|
_context.next = 5;
|
|
2070
2079
|
break;
|
|
2071
2080
|
}
|
|
2072
2081
|
throw new Error("Sync function " + key + " not found");
|
|
2073
2082
|
case 5:
|
|
2074
|
-
|
|
2083
|
+
syncFn = sync['executor'];
|
|
2084
|
+
if (syncFn) {
|
|
2085
|
+
_context.next = 8;
|
|
2086
|
+
break;
|
|
2087
|
+
}
|
|
2088
|
+
throw new Error("Sync function " + key + " not found");
|
|
2089
|
+
case 8:
|
|
2090
|
+
_context.next = 10;
|
|
2075
2091
|
return syncFn({
|
|
2076
|
-
|
|
2077
|
-
params: params,
|
|
2092
|
+
data: params,
|
|
2078
2093
|
engine: this.engine,
|
|
2079
2094
|
agents: this.agents,
|
|
2080
2095
|
vectors: this.vectors,
|
|
2081
|
-
llm: this.llm
|
|
2096
|
+
llm: this.llm,
|
|
2097
|
+
integrationsRegistry: function integrationsRegistry() {
|
|
2098
|
+
return {
|
|
2099
|
+
get: function get(name) {
|
|
2100
|
+
return _this2.getIntegration(name);
|
|
2101
|
+
}
|
|
2102
|
+
};
|
|
2103
|
+
},
|
|
2104
|
+
toolsRegistry: function toolsRegistry() {
|
|
2105
|
+
return {
|
|
2106
|
+
get: function get(name) {
|
|
2107
|
+
return _this2.getTool(name);
|
|
2108
|
+
}
|
|
2109
|
+
};
|
|
2110
|
+
}
|
|
2082
2111
|
});
|
|
2083
|
-
case
|
|
2112
|
+
case 10:
|
|
2113
|
+
return _context.abrupt("return", _context.sent);
|
|
2114
|
+
case 11:
|
|
2084
2115
|
case "end":
|
|
2085
2116
|
return _context.stop();
|
|
2086
2117
|
}
|
|
@@ -2107,7 +2138,7 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
2107
2138
|
return integration;
|
|
2108
2139
|
};
|
|
2109
2140
|
_proto.getTool = function getTool(name) {
|
|
2110
|
-
var
|
|
2141
|
+
var _this3 = this;
|
|
2111
2142
|
var tool = this.tools[name];
|
|
2112
2143
|
if (!tool) {
|
|
2113
2144
|
throw new Error("Tool with name " + String(name) + " not found");
|
|
@@ -2123,13 +2154,13 @@ var Mastra = /*#__PURE__*/function () {
|
|
|
2123
2154
|
integrationsRegistry: function integrationsRegistry() {
|
|
2124
2155
|
return {
|
|
2125
2156
|
get: function get(name) {
|
|
2126
|
-
return
|
|
2157
|
+
return _this3.getIntegration(name);
|
|
2127
2158
|
}
|
|
2128
2159
|
};
|
|
2129
2160
|
},
|
|
2130
|
-
agents:
|
|
2131
|
-
llm:
|
|
2132
|
-
engine:
|
|
2161
|
+
agents: _this3.agents,
|
|
2162
|
+
llm: _this3.llm,
|
|
2163
|
+
engine: _this3.engine
|
|
2133
2164
|
}));
|
|
2134
2165
|
case 1:
|
|
2135
2166
|
case "end":
|
|
@@ -2176,13 +2207,14 @@ function isTransitionEvent(stateEvent) {
|
|
|
2176
2207
|
}
|
|
2177
2208
|
|
|
2178
2209
|
var _logger = /*#__PURE__*/_classPrivateFieldLooseKey("logger");
|
|
2210
|
+
var _triggerSchema = /*#__PURE__*/_classPrivateFieldLooseKey("triggerSchema");
|
|
2179
2211
|
var _steps = /*#__PURE__*/_classPrivateFieldLooseKey("steps");
|
|
2212
|
+
var _transitions = /*#__PURE__*/_classPrivateFieldLooseKey("transitions");
|
|
2180
2213
|
var _machine = /*#__PURE__*/_classPrivateFieldLooseKey("machine");
|
|
2181
2214
|
var _actor = /*#__PURE__*/_classPrivateFieldLooseKey("actor");
|
|
2182
2215
|
var _log = /*#__PURE__*/_classPrivateFieldLooseKey("log");
|
|
2183
2216
|
var _buildStateHierarchy = /*#__PURE__*/_classPrivateFieldLooseKey("buildStateHierarchy");
|
|
2184
2217
|
var _isVariableReference = /*#__PURE__*/_classPrivateFieldLooseKey("isVariableReference");
|
|
2185
|
-
var _createStepId = /*#__PURE__*/_classPrivateFieldLooseKey("createStepId");
|
|
2186
2218
|
var _resolveVariables = /*#__PURE__*/_classPrivateFieldLooseKey("resolveVariables");
|
|
2187
2219
|
var _cleanup = /*#__PURE__*/_classPrivateFieldLooseKey("cleanup");
|
|
2188
2220
|
var _evaluateCondition = /*#__PURE__*/_classPrivateFieldLooseKey("evaluateCondition");
|
|
@@ -2196,7 +2228,11 @@ var Workflow = /*#__PURE__*/function () {
|
|
|
2196
2228
|
* @param name - Identifier for the workflow (not necessarily unique)
|
|
2197
2229
|
* @param logger - Optional logger instance
|
|
2198
2230
|
*/
|
|
2199
|
-
function Workflow(
|
|
2231
|
+
function Workflow(_ref) {
|
|
2232
|
+
var name = _ref.name,
|
|
2233
|
+
logger = _ref.logger,
|
|
2234
|
+
steps = _ref.steps,
|
|
2235
|
+
triggerSchema = _ref.triggerSchema;
|
|
2200
2236
|
/**
|
|
2201
2237
|
* Detects unreachable steps in the workflow
|
|
2202
2238
|
* @returns Array of ValidationError objects
|
|
@@ -2247,15 +2283,6 @@ var Workflow = /*#__PURE__*/function () {
|
|
|
2247
2283
|
Object.defineProperty(this, _resolveVariables, {
|
|
2248
2284
|
value: _resolveVariables2
|
|
2249
2285
|
});
|
|
2250
|
-
/**
|
|
2251
|
-
* Creates a validated step ID, ensuring uniqueness within the workflow
|
|
2252
|
-
* @param id - Proposed step ID
|
|
2253
|
-
* @returns The validated and branded step ID
|
|
2254
|
-
* @throws Error if ID is invalid or duplicate
|
|
2255
|
-
*/
|
|
2256
|
-
Object.defineProperty(this, _createStepId, {
|
|
2257
|
-
value: _createStepId2
|
|
2258
|
-
});
|
|
2259
2286
|
/**
|
|
2260
2287
|
* Type guard to check if a value is a valid VariableReference
|
|
2261
2288
|
* @param value - Value to check
|
|
@@ -2286,10 +2313,17 @@ var Workflow = /*#__PURE__*/function () {
|
|
|
2286
2313
|
writable: true,
|
|
2287
2314
|
value: void 0
|
|
2288
2315
|
});
|
|
2289
|
-
this
|
|
2316
|
+
Object.defineProperty(this, _triggerSchema, {
|
|
2317
|
+
writable: true,
|
|
2318
|
+
value: void 0
|
|
2319
|
+
});
|
|
2290
2320
|
Object.defineProperty(this, _steps, {
|
|
2291
2321
|
writable: true,
|
|
2292
|
-
value:
|
|
2322
|
+
value: void 0
|
|
2323
|
+
});
|
|
2324
|
+
Object.defineProperty(this, _transitions, {
|
|
2325
|
+
writable: true,
|
|
2326
|
+
value: {}
|
|
2293
2327
|
});
|
|
2294
2328
|
/** XState machine instance that orchestrates the workflow execution */
|
|
2295
2329
|
Object.defineProperty(this, _machine, {
|
|
@@ -2303,6 +2337,8 @@ var Workflow = /*#__PURE__*/function () {
|
|
|
2303
2337
|
});
|
|
2304
2338
|
this.name = name;
|
|
2305
2339
|
_classPrivateFieldLooseBase(this, _logger)[_logger] = logger;
|
|
2340
|
+
_classPrivateFieldLooseBase(this, _steps)[_steps] = steps;
|
|
2341
|
+
_classPrivateFieldLooseBase(this, _triggerSchema)[_triggerSchema] = triggerSchema;
|
|
2306
2342
|
this.initializeMachine();
|
|
2307
2343
|
}
|
|
2308
2344
|
var _proto = Workflow.prototype;
|
|
@@ -2319,10 +2355,10 @@ var Workflow = /*#__PURE__*/function () {
|
|
|
2319
2355
|
types: {},
|
|
2320
2356
|
actions: {
|
|
2321
2357
|
updateStepResult: xstate.assign({
|
|
2322
|
-
stepResults: function stepResults(
|
|
2358
|
+
stepResults: function stepResults(_ref2) {
|
|
2323
2359
|
var _event$output, _event$output2;
|
|
2324
|
-
var context =
|
|
2325
|
-
event =
|
|
2360
|
+
var context = _ref2.context,
|
|
2361
|
+
event = _ref2.event;
|
|
2326
2362
|
if (!isTransitionEvent(event)) return context.stepResults;
|
|
2327
2363
|
var stepId = (_event$output = event.output) == null ? void 0 : _event$output.stepId;
|
|
2328
2364
|
if (!stepId) return context.stepResults;
|
|
@@ -2332,9 +2368,7 @@ var Workflow = /*#__PURE__*/function () {
|
|
|
2332
2368
|
var _extends2;
|
|
2333
2369
|
var newResults = _extends({}, context.stepResults, (_extends2 = {}, _extends2[stepId] = result, _extends2));
|
|
2334
2370
|
// Get the step configuration
|
|
2335
|
-
var step = _classPrivateFieldLooseBase(_this,
|
|
2336
|
-
return s.id === stepId;
|
|
2337
|
-
});
|
|
2371
|
+
var step = _classPrivateFieldLooseBase(_this, _transitions)[_transitions][stepId];
|
|
2338
2372
|
// Evaluate transitions and send events
|
|
2339
2373
|
if (step != null && step.transitions) {
|
|
2340
2374
|
var fullContext = _extends({}, context, {
|
|
@@ -2342,12 +2376,12 @@ var Workflow = /*#__PURE__*/function () {
|
|
|
2342
2376
|
});
|
|
2343
2377
|
var hasMatchingCondition = false;
|
|
2344
2378
|
_classPrivateFieldLooseBase(_this, _log)[_log](LogLevel.DEBUG, 'Evaluating transitions with context:', fullContext);
|
|
2345
|
-
Object.entries(step.transitions).forEach(function (
|
|
2346
|
-
var targetId =
|
|
2347
|
-
config =
|
|
2379
|
+
Object.entries(step.transitions).forEach(function (_ref3) {
|
|
2380
|
+
var targetId = _ref3[0],
|
|
2381
|
+
config = _ref3[1];
|
|
2348
2382
|
_classPrivateFieldLooseBase(_this, _log)[_log](LogLevel.DEBUG, "Checking transition to: " + targetId);
|
|
2349
|
-
_classPrivateFieldLooseBase(_this, _log)[_log](LogLevel.DEBUG, "With condition: " + config.condition);
|
|
2350
|
-
if (!config.condition || _classPrivateFieldLooseBase(_this, _evaluateCondition)[_evaluateCondition](config.condition, fullContext)) {
|
|
2383
|
+
_classPrivateFieldLooseBase(_this, _log)[_log](LogLevel.DEBUG, "With condition: " + (config == null ? void 0 : config.condition));
|
|
2384
|
+
if (!(config != null && config.condition) || _classPrivateFieldLooseBase(_this, _evaluateCondition)[_evaluateCondition](config == null ? void 0 : config.condition, fullContext)) {
|
|
2351
2385
|
hasMatchingCondition = true;
|
|
2352
2386
|
_classPrivateFieldLooseBase(_this, _log)[_log](LogLevel.DEBUG, 'Condition passed, sending transition to:', targetId);
|
|
2353
2387
|
Promise.resolve().then(function () {
|
|
@@ -2376,16 +2410,16 @@ var Workflow = /*#__PURE__*/function () {
|
|
|
2376
2410
|
}
|
|
2377
2411
|
}),
|
|
2378
2412
|
setError: xstate.assign({
|
|
2379
|
-
error: function error(
|
|
2380
|
-
var event =
|
|
2413
|
+
error: function error(_ref4) {
|
|
2414
|
+
var event = _ref4.event;
|
|
2381
2415
|
if (!isErrorEvent(event)) return null;
|
|
2382
2416
|
_classPrivateFieldLooseBase(_this, _log)[_log](LogLevel.ERROR, "Workflow error", event.error);
|
|
2383
2417
|
return event.error;
|
|
2384
2418
|
}
|
|
2385
2419
|
}),
|
|
2386
2420
|
initializeTriggerData: xstate.assign({
|
|
2387
|
-
triggerData: function triggerData(
|
|
2388
|
-
var context =
|
|
2421
|
+
triggerData: function triggerData(_ref5) {
|
|
2422
|
+
var context = _ref5.context;
|
|
2389
2423
|
_classPrivateFieldLooseBase(_this, _log)[_log](LogLevel.INFO, 'Workflow started', context == null ? void 0 : context.triggerData);
|
|
2390
2424
|
return context == null ? void 0 : context.triggerData;
|
|
2391
2425
|
}
|
|
@@ -2393,20 +2427,20 @@ var Workflow = /*#__PURE__*/function () {
|
|
|
2393
2427
|
},
|
|
2394
2428
|
actors: {
|
|
2395
2429
|
resolverFunction: xstate.fromPromise(/*#__PURE__*/function () {
|
|
2396
|
-
var
|
|
2397
|
-
var input, step, context, resolvedData, result;
|
|
2430
|
+
var _ref7 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref6) {
|
|
2431
|
+
var input, step, context, stepId, resolvedData, result;
|
|
2398
2432
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
2399
2433
|
while (1) switch (_context.prev = _context.next) {
|
|
2400
2434
|
case 0:
|
|
2401
|
-
input =
|
|
2402
|
-
step = input.step, context = input.context;
|
|
2435
|
+
input = _ref6.input;
|
|
2436
|
+
step = input.step, context = input.context, stepId = input.stepId;
|
|
2403
2437
|
resolvedData = _classPrivateFieldLooseBase(_this, _resolveVariables)[_resolveVariables](step, context);
|
|
2404
2438
|
_context.next = 5;
|
|
2405
2439
|
return step.handler(resolvedData);
|
|
2406
2440
|
case 5:
|
|
2407
2441
|
result = _context.sent;
|
|
2408
2442
|
return _context.abrupt("return", {
|
|
2409
|
-
stepId:
|
|
2443
|
+
stepId: stepId,
|
|
2410
2444
|
result: result
|
|
2411
2445
|
});
|
|
2412
2446
|
case 7:
|
|
@@ -2416,15 +2450,15 @@ var Workflow = /*#__PURE__*/function () {
|
|
|
2416
2450
|
}, _callee);
|
|
2417
2451
|
}));
|
|
2418
2452
|
return function (_x) {
|
|
2419
|
-
return
|
|
2453
|
+
return _ref7.apply(this, arguments);
|
|
2420
2454
|
};
|
|
2421
2455
|
}())
|
|
2422
2456
|
}
|
|
2423
2457
|
}).createMachine({
|
|
2424
2458
|
id: this.name,
|
|
2425
2459
|
initial: ((_classPrivateFieldLoo = _classPrivateFieldLooseBase(this, _steps)[_steps][0]) == null ? void 0 : _classPrivateFieldLoo.id) || 'idle',
|
|
2426
|
-
context: function context(
|
|
2427
|
-
var input =
|
|
2460
|
+
context: function context(_ref8) {
|
|
2461
|
+
var input = _ref8.input;
|
|
2428
2462
|
return _extends({}, input, {
|
|
2429
2463
|
stepResults: {},
|
|
2430
2464
|
error: null
|
|
@@ -2449,15 +2483,6 @@ var Workflow = /*#__PURE__*/function () {
|
|
|
2449
2483
|
this.initializeMachine();
|
|
2450
2484
|
return this;
|
|
2451
2485
|
};
|
|
2452
|
-
/**
|
|
2453
|
-
* Sets the schema for validating trigger data
|
|
2454
|
-
* @param schema - Zod schema for trigger data validation
|
|
2455
|
-
* @returns this instance for method chaining
|
|
2456
|
-
*/
|
|
2457
|
-
_proto.setTriggerSchema = function setTriggerSchema(schema) {
|
|
2458
|
-
this.triggerSchema = schema;
|
|
2459
|
-
return this;
|
|
2460
|
-
};
|
|
2461
2486
|
/**
|
|
2462
2487
|
* Adds a new step to the workflow
|
|
2463
2488
|
* @param id - Unique identifier for the step
|
|
@@ -2465,27 +2490,13 @@ var Workflow = /*#__PURE__*/function () {
|
|
|
2465
2490
|
* @returns this instance for method chaining (builder pattern baybyyyy)
|
|
2466
2491
|
* @throws Error if step ID is duplicate or variable resolution fails
|
|
2467
2492
|
*/
|
|
2468
|
-
_proto.
|
|
2493
|
+
_proto.step = function step(id, config) {
|
|
2469
2494
|
var _this2 = this;
|
|
2470
|
-
var
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
_config$payload = config.payload,
|
|
2476
|
-
payload = _config$payload === void 0 ? {} : _config$payload,
|
|
2477
|
-
transitions = config.transitions;
|
|
2478
|
-
// Validate transitions reference existing steps
|
|
2479
|
-
if (transitions) {
|
|
2480
|
-
Object.keys(transitions).forEach(function (targetId) {
|
|
2481
|
-
// Skip validation for steps that will be added later
|
|
2482
|
-
if (!_classPrivateFieldLooseBase(_this2, _steps)[_steps].some(function (s) {
|
|
2483
|
-
return s.id === targetId;
|
|
2484
|
-
})) {
|
|
2485
|
-
_classPrivateFieldLooseBase(_this2, _log)[_log](LogLevel.DEBUG, "Step " + targetId + " not found yet, will be validated when workflow starts");
|
|
2486
|
-
}
|
|
2487
|
-
});
|
|
2488
|
-
}
|
|
2495
|
+
var _ref9 = config || {},
|
|
2496
|
+
_ref9$variables = _ref9.variables,
|
|
2497
|
+
variables = _ref9$variables === void 0 ? {} : _ref9$variables,
|
|
2498
|
+
_ref9$transitions = _ref9.transitions,
|
|
2499
|
+
transitions = _ref9$transitions === void 0 ? undefined : _ref9$transitions;
|
|
2489
2500
|
var requiredData = {};
|
|
2490
2501
|
// Add valid variables to requiredData
|
|
2491
2502
|
for (var _i = 0, _Object$entries = Object.entries(variables); _i < _Object$entries.length; _i++) {
|
|
@@ -2496,21 +2507,30 @@ var Workflow = /*#__PURE__*/function () {
|
|
|
2496
2507
|
requiredData[key] = variable;
|
|
2497
2508
|
}
|
|
2498
2509
|
}
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2510
|
+
_classPrivateFieldLooseBase(this, _transitions)[_transitions][id] = {
|
|
2511
|
+
transitions: transitions,
|
|
2512
|
+
data: requiredData,
|
|
2502
2513
|
handler: function () {
|
|
2503
2514
|
var _handler = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(data) {
|
|
2504
|
-
var mergedData, validatedData;
|
|
2515
|
+
var step, inputSchema, payload, action, mergedData, validatedData;
|
|
2505
2516
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
2506
2517
|
while (1) switch (_context2.prev = _context2.next) {
|
|
2507
2518
|
case 0:
|
|
2508
|
-
|
|
2519
|
+
step = _classPrivateFieldLooseBase(_this2, _steps)[_steps].find(function (s) {
|
|
2520
|
+
return s.id === id;
|
|
2521
|
+
});
|
|
2522
|
+
if (step) {
|
|
2523
|
+
_context2.next = 3;
|
|
2524
|
+
break;
|
|
2525
|
+
}
|
|
2526
|
+
throw new Error("Step " + id + " not found");
|
|
2527
|
+
case 3:
|
|
2528
|
+
inputSchema = step.inputSchema, payload = step.payload, action = step.action; // Merge static payload with dynamically resolved variables
|
|
2509
2529
|
// Variables take precedence over payload values
|
|
2510
2530
|
mergedData = _extends({}, payload, data); // Validate complete input data
|
|
2511
2531
|
validatedData = inputSchema ? inputSchema.parse(mergedData) : mergedData;
|
|
2512
|
-
return _context2.abrupt("return", action(validatedData));
|
|
2513
|
-
case
|
|
2532
|
+
return _context2.abrupt("return", action ? action(validatedData) : {});
|
|
2533
|
+
case 7:
|
|
2514
2534
|
case "end":
|
|
2515
2535
|
return _context2.stop();
|
|
2516
2536
|
}
|
|
@@ -2520,12 +2540,8 @@ var Workflow = /*#__PURE__*/function () {
|
|
|
2520
2540
|
return _handler.apply(this, arguments);
|
|
2521
2541
|
}
|
|
2522
2542
|
return handler;
|
|
2523
|
-
}()
|
|
2524
|
-
inputSchema: inputSchema,
|
|
2525
|
-
requiredData: requiredData,
|
|
2526
|
-
transitions: transitions
|
|
2543
|
+
}()
|
|
2527
2544
|
};
|
|
2528
|
-
_classPrivateFieldLooseBase(this, _steps)[_steps].push(stepConfig);
|
|
2529
2545
|
return this;
|
|
2530
2546
|
};
|
|
2531
2547
|
/**
|
|
@@ -2547,12 +2563,12 @@ var Workflow = /*#__PURE__*/function () {
|
|
|
2547
2563
|
triggerData: triggerData
|
|
2548
2564
|
});
|
|
2549
2565
|
case 2:
|
|
2550
|
-
if (!this
|
|
2566
|
+
if (!_classPrivateFieldLooseBase(this, _triggerSchema)[_triggerSchema]) {
|
|
2551
2567
|
_context3.next = 14;
|
|
2552
2568
|
break;
|
|
2553
2569
|
}
|
|
2554
2570
|
_context3.prev = 3;
|
|
2555
|
-
this.
|
|
2571
|
+
_classPrivateFieldLooseBase(this, _triggerSchema)[_triggerSchema].parse(triggerData);
|
|
2556
2572
|
_context3.next = 7;
|
|
2557
2573
|
return _classPrivateFieldLooseBase(this, _log)[_log](LogLevel.DEBUG, 'Trigger schema validation passed');
|
|
2558
2574
|
case 7:
|
|
@@ -2621,7 +2637,7 @@ function _log2(_x4, _x5, _x6, _x7) {
|
|
|
2621
2637
|
}
|
|
2622
2638
|
function _log3() {
|
|
2623
2639
|
_log3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(level, message, data, stepId) {
|
|
2624
|
-
var
|
|
2640
|
+
var _classPrivateFieldLoo5, _classPrivateFieldLoo6;
|
|
2625
2641
|
var logMessage, logMethod;
|
|
2626
2642
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
2627
2643
|
while (1) switch (_context4.prev = _context4.next) {
|
|
@@ -2642,7 +2658,7 @@ function _log3() {
|
|
|
2642
2658
|
};
|
|
2643
2659
|
logMethod = level.toLowerCase();
|
|
2644
2660
|
_context4.next = 6;
|
|
2645
|
-
return (
|
|
2661
|
+
return (_classPrivateFieldLoo5 = (_classPrivateFieldLoo6 = _classPrivateFieldLooseBase(this, _logger)[_logger])[logMethod]) == null ? void 0 : _classPrivateFieldLoo5.call(_classPrivateFieldLoo6, logMessage);
|
|
2646
2662
|
case 6:
|
|
2647
2663
|
case "end":
|
|
2648
2664
|
return _context4.stop();
|
|
@@ -2664,6 +2680,7 @@ function _buildStateHierarchy2() {
|
|
|
2664
2680
|
};
|
|
2665
2681
|
// Helper to build nested state structure
|
|
2666
2682
|
var buildState = function buildState(currentStepId, visited) {
|
|
2683
|
+
var _classPrivateFieldLoo2, _classPrivateFieldLoo3;
|
|
2667
2684
|
if (visited.has(currentStepId)) return null;
|
|
2668
2685
|
visited.add(currentStepId);
|
|
2669
2686
|
var currentStep = _classPrivateFieldLooseBase(_this4, _steps)[_steps].find(function (s) {
|
|
@@ -2673,17 +2690,18 @@ function _buildStateHierarchy2() {
|
|
|
2673
2690
|
var state = {
|
|
2674
2691
|
invoke: {
|
|
2675
2692
|
src: 'resolverFunction',
|
|
2676
|
-
input: function input(
|
|
2677
|
-
var context =
|
|
2693
|
+
input: function input(_ref10) {
|
|
2694
|
+
var context = _ref10.context;
|
|
2678
2695
|
return {
|
|
2679
|
-
|
|
2680
|
-
|
|
2696
|
+
context: context,
|
|
2697
|
+
stepId: currentStepId,
|
|
2698
|
+
step: _classPrivateFieldLooseBase(_this4, _transitions)[_transitions][currentStepId]
|
|
2681
2699
|
};
|
|
2682
2700
|
},
|
|
2683
2701
|
onDone: {
|
|
2684
2702
|
actions: ['updateStepResult'],
|
|
2685
2703
|
// If no transitions, go to success state
|
|
2686
|
-
target:
|
|
2704
|
+
target: (_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(_this4, _transitions)[_transitions][currentStepId]) != null && _classPrivateFieldLoo2.transitions ? undefined : 'success'
|
|
2687
2705
|
},
|
|
2688
2706
|
onError: {
|
|
2689
2707
|
target: 'failure',
|
|
@@ -2704,16 +2722,17 @@ function _buildStateHierarchy2() {
|
|
|
2704
2722
|
}
|
|
2705
2723
|
};
|
|
2706
2724
|
// Handle transitions
|
|
2707
|
-
if (
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2725
|
+
if ((_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(_this4, _transitions)[_transitions][currentStepId]) != null && _classPrivateFieldLoo3.transitions) {
|
|
2726
|
+
var _classPrivateFieldLoo4;
|
|
2727
|
+
Object.entries((_classPrivateFieldLoo4 = _classPrivateFieldLooseBase(_this4, _transitions)[_transitions][currentStepId]) == null ? void 0 : _classPrivateFieldLoo4.transitions).forEach(function (_ref11) {
|
|
2728
|
+
var targetId = _ref11[0],
|
|
2729
|
+
config = _ref11[1];
|
|
2711
2730
|
// Create flat state structure with transitions
|
|
2712
2731
|
state.on["TRANSITION_" + targetId] = {
|
|
2713
2732
|
target: targetId,
|
|
2714
|
-
guard: function guard(
|
|
2715
|
-
var context =
|
|
2716
|
-
return !config.condition || _classPrivateFieldLooseBase(_this4, _evaluateCondition)[_evaluateCondition](config.condition, context);
|
|
2733
|
+
guard: function guard(_ref12) {
|
|
2734
|
+
var context = _ref12.context;
|
|
2735
|
+
return !(config != null && config.condition) || _classPrivateFieldLooseBase(_this4, _evaluateCondition)[_evaluateCondition](config == null ? void 0 : config.condition, context);
|
|
2717
2736
|
}
|
|
2718
2737
|
};
|
|
2719
2738
|
});
|
|
@@ -2733,18 +2752,9 @@ function _buildStateHierarchy2() {
|
|
|
2733
2752
|
function _isVariableReference2(value) {
|
|
2734
2753
|
return typeof value === 'object' && 'stepId' in value && 'path' in value;
|
|
2735
2754
|
}
|
|
2736
|
-
function _createStepId2(id) {
|
|
2737
|
-
// Check for duplicates
|
|
2738
|
-
if (_classPrivateFieldLooseBase(this, _steps)[_steps].some(function (step) {
|
|
2739
|
-
return step.id === id;
|
|
2740
|
-
})) {
|
|
2741
|
-
throw new Error("Step with ID \"" + id + "\" already exists in workflow \"" + this.name + "\"");
|
|
2742
|
-
}
|
|
2743
|
-
return id;
|
|
2744
|
-
}
|
|
2745
2755
|
function _resolveVariables2(stepConfig, context) {
|
|
2746
2756
|
var resolvedData = {};
|
|
2747
|
-
for (var _i2 = 0, _Object$entries2 = Object.entries(stepConfig.
|
|
2757
|
+
for (var _i2 = 0, _Object$entries2 = Object.entries(stepConfig.data); _i2 < _Object$entries2.length; _i2++) {
|
|
2748
2758
|
var _Object$entries2$_i = _Object$entries2[_i2],
|
|
2749
2759
|
key = _Object$entries2$_i[0],
|
|
2750
2760
|
variable = _Object$entries2$_i[1];
|
|
@@ -2827,9 +2837,7 @@ function _detectCircularDependencies2() {
|
|
|
2827
2837
|
return;
|
|
2828
2838
|
}
|
|
2829
2839
|
stack.push(stepId);
|
|
2830
|
-
var step = _classPrivateFieldLooseBase(_this6,
|
|
2831
|
-
return s.id === stepId;
|
|
2832
|
-
});
|
|
2840
|
+
var step = _classPrivateFieldLooseBase(_this6, _transitions)[_transitions][stepId];
|
|
2833
2841
|
if (step != null && step.transitions) {
|
|
2834
2842
|
Object.keys(step.transitions).forEach(function (targetId) {
|
|
2835
2843
|
_dfs(targetId);
|
|
@@ -2855,9 +2863,7 @@ function _validateTerminalPaths2() {
|
|
|
2855
2863
|
if (hasTerminalPath.has(stepId)) return true;
|
|
2856
2864
|
if (visited.has(stepId) && !hasTerminalPath.has(stepId)) return false;
|
|
2857
2865
|
visited.add(stepId);
|
|
2858
|
-
var step = _classPrivateFieldLooseBase(_this7,
|
|
2859
|
-
return s.id === stepId;
|
|
2860
|
-
});
|
|
2866
|
+
var step = _classPrivateFieldLooseBase(_this7, _transitions)[_transitions][stepId];
|
|
2861
2867
|
if (!step) return false;
|
|
2862
2868
|
// Terminal step
|
|
2863
2869
|
if (!step.transitions) {
|
|
@@ -2900,9 +2906,7 @@ function _detectUnreachableSteps2() {
|
|
|
2900
2906
|
var _dfs3 = function dfs(stepId) {
|
|
2901
2907
|
if (reachableSteps.has(stepId)) return;
|
|
2902
2908
|
reachableSteps.add(stepId);
|
|
2903
|
-
var step = _classPrivateFieldLooseBase(_this8,
|
|
2904
|
-
return s.id === stepId;
|
|
2905
|
-
});
|
|
2909
|
+
var step = _classPrivateFieldLooseBase(_this8, _transitions)[_transitions][stepId];
|
|
2906
2910
|
if (step != null && step.transitions) {
|
|
2907
2911
|
Object.keys(step.transitions).forEach(function (targetId) {
|
|
2908
2912
|
_dfs3(targetId);
|
|
@@ -2928,6 +2932,24 @@ function _detectUnreachableSteps2() {
|
|
|
2928
2932
|
return errors;
|
|
2929
2933
|
}
|
|
2930
2934
|
|
|
2935
|
+
var Step = function Step(_ref) {
|
|
2936
|
+
var id = _ref.id,
|
|
2937
|
+
inputSchema = _ref.inputSchema,
|
|
2938
|
+
outputSchema = _ref.outputSchema,
|
|
2939
|
+
payload = _ref.payload,
|
|
2940
|
+
action = _ref.action;
|
|
2941
|
+
this.id = void 0;
|
|
2942
|
+
this.inputSchema = void 0;
|
|
2943
|
+
this.outputSchema = void 0;
|
|
2944
|
+
this.payload = void 0;
|
|
2945
|
+
this.action = void 0;
|
|
2946
|
+
this.id = id;
|
|
2947
|
+
this.inputSchema = inputSchema;
|
|
2948
|
+
this.payload = payload;
|
|
2949
|
+
this.outputSchema = outputSchema;
|
|
2950
|
+
this.action = action;
|
|
2951
|
+
};
|
|
2952
|
+
|
|
2931
2953
|
exports.Agent = Agent;
|
|
2932
2954
|
exports.BaseLogger = BaseLogger;
|
|
2933
2955
|
exports.FieldTypePrimitiveMap = FieldTypePrimitiveMap;
|
|
@@ -2938,10 +2960,12 @@ exports.MastraEngine = MastraEngine;
|
|
|
2938
2960
|
exports.MastraVector = MastraVector;
|
|
2939
2961
|
exports.MultiLogger = MultiLogger;
|
|
2940
2962
|
exports.RegisteredLogger = RegisteredLogger;
|
|
2963
|
+
exports.Step = Step;
|
|
2941
2964
|
exports.Workflow = Workflow;
|
|
2942
2965
|
exports.buildQueryString = buildQueryString;
|
|
2943
2966
|
exports.createLogger = createLogger;
|
|
2944
2967
|
exports.createMultiLogger = createMultiLogger;
|
|
2968
|
+
exports.createSync = createSync;
|
|
2945
2969
|
exports.createTool = createTool;
|
|
2946
2970
|
exports.filterQuerySchema = filterQuerySchema;
|
|
2947
2971
|
exports.getJSONField = getJSONField;
|