@mastra/inngest 1.0.0-beta.10 → 1.0.0-beta.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +187 -0
- package/dist/__tests__/adapters/_utils.d.ts +18 -0
- package/dist/__tests__/adapters/_utils.d.ts.map +1 -0
- package/dist/execution-engine.d.ts +14 -3
- package/dist/execution-engine.d.ts.map +1 -1
- package/dist/index.cjs +118 -88
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +13 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +119 -90
- package/dist/index.js.map +1 -1
- package/dist/run.d.ts +0 -13
- package/dist/run.d.ts.map +1 -1
- package/dist/serve.d.ts +66 -3
- package/dist/serve.d.ts.map +1 -1
- package/dist/types.d.ts +7 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/workflow.d.ts +4 -2
- package/dist/workflow.d.ts.map +1 -1
- package/package.json +19 -8
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Agent } from '@mastra/core/agent';
|
|
2
|
+
import type { MastraScorers } from '@mastra/core/evals';
|
|
2
3
|
import type { ToolExecutionContext } from '@mastra/core/tools';
|
|
4
|
+
import type { DynamicArgument } from '@mastra/core/types';
|
|
3
5
|
import type { Step, AgentStepOptions, StepParams, ToolStep } from '@mastra/core/workflows';
|
|
4
6
|
import { Workflow } from '@mastra/core/workflows';
|
|
5
7
|
import type { Inngest } from 'inngest';
|
|
@@ -17,6 +19,8 @@ export declare function createStep<TStepId extends string, TStepOutput extends z
|
|
|
17
19
|
structuredOutput: {
|
|
18
20
|
schema: TStepOutput;
|
|
19
21
|
};
|
|
22
|
+
retries?: number;
|
|
23
|
+
scorers?: DynamicArgument<MastraScorers>;
|
|
20
24
|
}): Step<TStepId, any, z.ZodObject<{
|
|
21
25
|
prompt: z.ZodString;
|
|
22
26
|
}>, TStepOutput, z.ZodType<any>, z.ZodType<any>, InngestEngineType>;
|
|
@@ -24,8 +28,14 @@ export declare function createStep<TStepId extends string, TStepInput extends z.
|
|
|
24
28
|
prompt: z.ZodString;
|
|
25
29
|
}>, TStepOutput extends z.ZodObject<{
|
|
26
30
|
text: z.ZodString;
|
|
27
|
-
}>, TResumeSchema extends z.ZodType<any>, TSuspendSchema extends z.ZodType<any>>(agent: Agent<TStepId, any>, agentOptions?: AgentStepOptions
|
|
28
|
-
|
|
31
|
+
}>, TResumeSchema extends z.ZodType<any>, TSuspendSchema extends z.ZodType<any>>(agent: Agent<TStepId, any>, agentOptions?: AgentStepOptions & {
|
|
32
|
+
retries?: number;
|
|
33
|
+
scorers?: DynamicArgument<MastraScorers>;
|
|
34
|
+
}): Step<TStepId, any, TStepInput, TStepOutput, TResumeSchema, TSuspendSchema, InngestEngineType>;
|
|
35
|
+
export declare function createStep<TSchemaIn extends z.ZodType<any>, TSuspendSchema extends z.ZodType<any>, TResumeSchema extends z.ZodType<any>, TSchemaOut extends z.ZodType<any>, TContext extends ToolExecutionContext<TSuspendSchema, TResumeSchema>>(tool: ToolStep<TSchemaIn, TSuspendSchema, TResumeSchema, TSchemaOut, TContext>, toolOptions?: {
|
|
36
|
+
retries?: number;
|
|
37
|
+
scorers?: DynamicArgument<MastraScorers>;
|
|
38
|
+
}): Step<string, any, TSchemaIn, TSchemaOut, z.ZodType<any>, z.ZodType<any>, InngestEngineType>;
|
|
29
39
|
export declare function init(inngest: Inngest): {
|
|
30
40
|
createWorkflow<TWorkflowId extends string = string, TState extends z.ZodObject<any> = z.ZodObject<any, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
31
41
|
[x: string]: any;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d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CAAC;;cAOnE,OAAO,SAAS,MAAM,QACxB,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,iBAAiB,CAAC,QACzD;QAAE,EAAE,EAAE,OAAO,CAAA;KAAE,GACpB,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,iBAAiB,CAAC;kBAgB1D,WAAW,SAAS,MAAM,WAC1B,MAAM,SAAS,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC;;;;QAC/B,MAAM,SAAS,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,sCAC7B,OAAO,SAAS,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,sCAC9B,MAAM,SAAS,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,iBAAiB,CAAC,EAAE,+DASzE,WAAW,SAAS,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,qBAExB,QAAQ,CAAC,iBAAiB,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,CAAC,QACrF;QAAE,EAAE,EAAE,WAAW,CAAA;KAAE,GACxB,QAAQ,CAAC,iBAAiB,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,CAAC;EAe5F"}
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { Agent } from '@mastra/core/agent';
|
|
1
2
|
import { Tool } from '@mastra/core/tools';
|
|
2
3
|
import { DefaultExecutionEngine, createTimeTravelExecutionParams, Run, hydrateSerializedStepErrors, Workflow } from '@mastra/core/workflows';
|
|
3
4
|
import { PUBSUB_SYMBOL, STREAM_FORMAT_SYMBOL } from '@mastra/core/workflows/_constants';
|
|
4
5
|
import { z } from 'zod';
|
|
5
6
|
import { randomUUID } from 'crypto';
|
|
6
7
|
import { RequestContext } from '@mastra/core/di';
|
|
7
|
-
import {
|
|
8
|
+
import { NonRetriableError } from 'inngest';
|
|
8
9
|
import { getErrorFromUnknown } from '@mastra/core/error';
|
|
9
10
|
import { subscribe } from '@inngest/realtime';
|
|
10
11
|
import { PubSub } from '@mastra/core/events';
|
|
@@ -58,38 +59,46 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
58
59
|
* After retries exhausted, error propagates here and we return a failed result.
|
|
59
60
|
*/
|
|
60
61
|
async executeStepWithRetry(stepId, runStep, params) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
} catch (e) {
|
|
65
|
-
const cause = e?.cause;
|
|
66
|
-
if (cause?.status === "failed") {
|
|
67
|
-
params.stepSpan?.error({
|
|
68
|
-
error: e,
|
|
69
|
-
attributes: { status: "failed" }
|
|
70
|
-
});
|
|
71
|
-
if (cause.error && !(cause.error instanceof Error)) {
|
|
72
|
-
cause.error = getErrorFromUnknown(cause.error, { serializeStack: false });
|
|
73
|
-
}
|
|
74
|
-
return { ok: false, error: cause };
|
|
62
|
+
for (let i = 0; i < params.retries + 1; i++) {
|
|
63
|
+
if (i > 0 && params.delay) {
|
|
64
|
+
await new Promise((resolve) => setTimeout(resolve, params.delay));
|
|
75
65
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
66
|
+
try {
|
|
67
|
+
const result = await this.wrapDurableOperation(stepId, runStep);
|
|
68
|
+
return { ok: true, result };
|
|
69
|
+
} catch (e) {
|
|
70
|
+
if (i === params.retries) {
|
|
71
|
+
const cause = e?.cause;
|
|
72
|
+
if (cause?.status === "failed") {
|
|
73
|
+
params.stepSpan?.error({
|
|
74
|
+
error: e,
|
|
75
|
+
attributes: { status: "failed" }
|
|
76
|
+
});
|
|
77
|
+
if (cause.error && !(cause.error instanceof Error)) {
|
|
78
|
+
cause.error = getErrorFromUnknown(cause.error, { serializeStack: false });
|
|
79
|
+
}
|
|
80
|
+
return { ok: false, error: cause };
|
|
81
|
+
}
|
|
82
|
+
const errorInstance = getErrorFromUnknown(e, {
|
|
83
|
+
serializeStack: false,
|
|
84
|
+
fallbackMessage: "Unknown step execution error"
|
|
85
|
+
});
|
|
86
|
+
params.stepSpan?.error({
|
|
87
|
+
error: errorInstance,
|
|
88
|
+
attributes: { status: "failed" }
|
|
89
|
+
});
|
|
90
|
+
return {
|
|
91
|
+
ok: false,
|
|
92
|
+
error: {
|
|
93
|
+
status: "failed",
|
|
94
|
+
error: errorInstance,
|
|
95
|
+
endedAt: Date.now()
|
|
96
|
+
}
|
|
97
|
+
};
|
|
90
98
|
}
|
|
91
|
-
}
|
|
99
|
+
}
|
|
92
100
|
}
|
|
101
|
+
return { ok: false, error: { status: "failed", error: new Error("Unknown error"), endedAt: Date.now() } };
|
|
93
102
|
}
|
|
94
103
|
/**
|
|
95
104
|
* Use Inngest's sleep primitive for durability
|
|
@@ -108,24 +117,11 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
108
117
|
* If retryConfig is provided, throws RetryAfterError INSIDE step.run() to trigger
|
|
109
118
|
* Inngest's step-level retry mechanism (not function-level retry).
|
|
110
119
|
*/
|
|
111
|
-
async wrapDurableOperation(operationId, operationFn
|
|
120
|
+
async wrapDurableOperation(operationId, operationFn) {
|
|
112
121
|
return this.inngestStep.run(operationId, async () => {
|
|
113
122
|
try {
|
|
114
123
|
return await operationFn();
|
|
115
124
|
} catch (e) {
|
|
116
|
-
if (retryConfig) {
|
|
117
|
-
const errorInstance = getErrorFromUnknown(e, {
|
|
118
|
-
serializeStack: false,
|
|
119
|
-
fallbackMessage: "Unknown step execution error"
|
|
120
|
-
});
|
|
121
|
-
throw new RetryAfterError(errorInstance.message, retryConfig.delay, {
|
|
122
|
-
cause: {
|
|
123
|
-
status: "failed",
|
|
124
|
-
error: errorInstance,
|
|
125
|
-
endedAt: Date.now()
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
125
|
throw e;
|
|
130
126
|
}
|
|
131
127
|
});
|
|
@@ -1037,9 +1033,6 @@ var InngestRun = class extends Run {
|
|
|
1037
1033
|
});
|
|
1038
1034
|
return this.streamOutput;
|
|
1039
1035
|
}
|
|
1040
|
-
streamVNext(args = {}) {
|
|
1041
|
-
return this.stream(args);
|
|
1042
|
-
}
|
|
1043
1036
|
timeTravelStream({
|
|
1044
1037
|
inputData,
|
|
1045
1038
|
resumeData,
|
|
@@ -1130,9 +1123,11 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
1130
1123
|
#mastra;
|
|
1131
1124
|
inngest;
|
|
1132
1125
|
function;
|
|
1126
|
+
cronFunction;
|
|
1133
1127
|
flowControlConfig;
|
|
1128
|
+
cronConfig;
|
|
1134
1129
|
constructor(params, inngest) {
|
|
1135
|
-
const { concurrency, rateLimit, throttle, debounce, priority, ...workflowParams } = params;
|
|
1130
|
+
const { concurrency, rateLimit, throttle, debounce, priority, cron, inputData, initialState, ...workflowParams } = params;
|
|
1136
1131
|
super(workflowParams);
|
|
1137
1132
|
this.engineType = "inngest";
|
|
1138
1133
|
const flowControlEntries = Object.entries({ concurrency, rateLimit, throttle, debounce, priority }).filter(
|
|
@@ -1141,6 +1136,9 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
1141
1136
|
this.flowControlConfig = flowControlEntries.length > 0 ? Object.fromEntries(flowControlEntries) : void 0;
|
|
1142
1137
|
this.#mastra = params.mastra;
|
|
1143
1138
|
this.inngest = inngest;
|
|
1139
|
+
if (cron) {
|
|
1140
|
+
this.cronConfig = { cron, inputData, initialState };
|
|
1141
|
+
}
|
|
1144
1142
|
}
|
|
1145
1143
|
async listWorkflowRuns(args) {
|
|
1146
1144
|
const storage = this.#mastra?.getStorage();
|
|
@@ -1154,19 +1152,6 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
1154
1152
|
}
|
|
1155
1153
|
return workflowsStore.listWorkflowRuns({ workflowName: this.id, ...args ?? {} });
|
|
1156
1154
|
}
|
|
1157
|
-
async getWorkflowRunById(runId) {
|
|
1158
|
-
const storage = this.#mastra?.getStorage();
|
|
1159
|
-
if (!storage) {
|
|
1160
|
-
this.logger.debug("Cannot get workflow runs. Mastra engine is not initialized");
|
|
1161
|
-
return this.runs.get(runId) ? { ...this.runs.get(runId), workflowName: this.id } : null;
|
|
1162
|
-
}
|
|
1163
|
-
const workflowsStore = await storage.getStore("workflows");
|
|
1164
|
-
if (!workflowsStore) {
|
|
1165
|
-
return this.runs.get(runId) ? { ...this.runs.get(runId), workflowName: this.id } : null;
|
|
1166
|
-
}
|
|
1167
|
-
const run = await workflowsStore.getWorkflowRunById({ runId, workflowName: this.id });
|
|
1168
|
-
return run ?? (this.runs.get(runId) ? { ...this.runs.get(runId), workflowName: this.id } : null);
|
|
1169
|
-
}
|
|
1170
1155
|
__registerMastra(mastra) {
|
|
1171
1156
|
super.__registerMastra(mastra);
|
|
1172
1157
|
this.#mastra = mastra;
|
|
@@ -1210,10 +1195,11 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
1210
1195
|
workflowStatus: run.workflowRunStatus,
|
|
1211
1196
|
stepResults: {}
|
|
1212
1197
|
});
|
|
1213
|
-
const
|
|
1198
|
+
const existingRun = await this.getWorkflowRunById(runIdToUse, {
|
|
1214
1199
|
withNestedWorkflows: false
|
|
1215
1200
|
});
|
|
1216
|
-
|
|
1201
|
+
const existsInStorage = existingRun && !existingRun.isFromInMemory;
|
|
1202
|
+
if (!existsInStorage && shouldPersistSnapshot) {
|
|
1217
1203
|
const workflowsStore = await this.mastra?.getStorage()?.getStore("workflows");
|
|
1218
1204
|
await workflowsStore?.persistWorkflowSnapshot({
|
|
1219
1205
|
workflowName: this.id,
|
|
@@ -1238,6 +1224,30 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
1238
1224
|
}
|
|
1239
1225
|
return run;
|
|
1240
1226
|
}
|
|
1227
|
+
//createCronFunction is only called if cronConfig.cron is defined.
|
|
1228
|
+
createCronFunction() {
|
|
1229
|
+
if (this.cronFunction) {
|
|
1230
|
+
return this.cronFunction;
|
|
1231
|
+
}
|
|
1232
|
+
this.cronFunction = this.inngest.createFunction(
|
|
1233
|
+
{
|
|
1234
|
+
id: `workflow.${this.id}.cron`,
|
|
1235
|
+
retries: 0,
|
|
1236
|
+
cancelOn: [{ event: `cancel.workflow.${this.id}` }],
|
|
1237
|
+
...this.flowControlConfig
|
|
1238
|
+
},
|
|
1239
|
+
{ cron: this.cronConfig?.cron ?? "" },
|
|
1240
|
+
async () => {
|
|
1241
|
+
const run = await this.createRun();
|
|
1242
|
+
const result = await run.start({
|
|
1243
|
+
inputData: this.cronConfig?.inputData,
|
|
1244
|
+
initialState: this.cronConfig?.initialState
|
|
1245
|
+
});
|
|
1246
|
+
return { result, runId: run.runId };
|
|
1247
|
+
}
|
|
1248
|
+
);
|
|
1249
|
+
return this.cronFunction;
|
|
1250
|
+
}
|
|
1241
1251
|
getFunction() {
|
|
1242
1252
|
if (this.function) {
|
|
1243
1253
|
return this.function;
|
|
@@ -1245,7 +1255,7 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
1245
1255
|
this.function = this.inngest.createFunction(
|
|
1246
1256
|
{
|
|
1247
1257
|
id: `workflow.${this.id}`,
|
|
1248
|
-
retries:
|
|
1258
|
+
retries: 0,
|
|
1249
1259
|
cancelOn: [{ event: `cancel.workflow.${this.id}` }],
|
|
1250
1260
|
// Spread flow control configuration
|
|
1251
1261
|
...this.flowControlConfig
|
|
@@ -1259,6 +1269,7 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
1259
1269
|
});
|
|
1260
1270
|
}
|
|
1261
1271
|
const pubsub = new InngestPubSub(this.inngest, this.id, publish);
|
|
1272
|
+
const requestContext = new RequestContext(Object.entries(event.data.requestContext ?? {}));
|
|
1262
1273
|
const engine = new InngestExecutionEngine(this.#mastra, step, attempt, this.options);
|
|
1263
1274
|
const result = await engine.execute({
|
|
1264
1275
|
workflowId: this.id,
|
|
@@ -1270,7 +1281,7 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
1270
1281
|
initialState,
|
|
1271
1282
|
pubsub,
|
|
1272
1283
|
retryConfig: this.retryConfig,
|
|
1273
|
-
requestContext
|
|
1284
|
+
requestContext,
|
|
1274
1285
|
resume,
|
|
1275
1286
|
timeTravel,
|
|
1276
1287
|
perStep,
|
|
@@ -1292,7 +1303,19 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
1292
1303
|
});
|
|
1293
1304
|
await step.run(`workflow.${this.id}.finalize`, async () => {
|
|
1294
1305
|
if (result.status !== "paused") {
|
|
1295
|
-
await engine.invokeLifecycleCallbacksInternal(
|
|
1306
|
+
await engine.invokeLifecycleCallbacksInternal({
|
|
1307
|
+
status: result.status,
|
|
1308
|
+
result: "result" in result ? result.result : void 0,
|
|
1309
|
+
error: "error" in result ? result.error : void 0,
|
|
1310
|
+
steps: result.steps,
|
|
1311
|
+
tripwire: "tripwire" in result ? result.tripwire : void 0,
|
|
1312
|
+
runId,
|
|
1313
|
+
workflowId: this.id,
|
|
1314
|
+
resourceId,
|
|
1315
|
+
input: inputData,
|
|
1316
|
+
requestContext,
|
|
1317
|
+
state: result.state ?? initialState ?? {}
|
|
1318
|
+
});
|
|
1296
1319
|
}
|
|
1297
1320
|
if (result.status === "failed") {
|
|
1298
1321
|
throw new NonRetriableError(`Workflow failed`, {
|
|
@@ -1320,15 +1343,14 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
1320
1343
|
});
|
|
1321
1344
|
}
|
|
1322
1345
|
getFunctions() {
|
|
1323
|
-
return [
|
|
1346
|
+
return [
|
|
1347
|
+
this.getFunction(),
|
|
1348
|
+
...this.cronConfig?.cron ? [this.createCronFunction()] : [],
|
|
1349
|
+
...this.getNestedFunctions(this.executionGraph.steps)
|
|
1350
|
+
];
|
|
1324
1351
|
}
|
|
1325
1352
|
};
|
|
1326
|
-
function
|
|
1327
|
-
mastra,
|
|
1328
|
-
inngest,
|
|
1329
|
-
functions: userFunctions = [],
|
|
1330
|
-
registerOptions
|
|
1331
|
-
}) {
|
|
1353
|
+
function prepareServeOptions({ mastra, inngest, functions: userFunctions = [], registerOptions }) {
|
|
1332
1354
|
const wfs = mastra.listWorkflows();
|
|
1333
1355
|
const workflowFunctions = Array.from(
|
|
1334
1356
|
new Set(
|
|
@@ -1341,32 +1363,32 @@ function serve({
|
|
|
1341
1363
|
})
|
|
1342
1364
|
)
|
|
1343
1365
|
);
|
|
1344
|
-
return
|
|
1366
|
+
return {
|
|
1345
1367
|
...registerOptions,
|
|
1346
1368
|
client: inngest,
|
|
1347
1369
|
functions: [...workflowFunctions, ...userFunctions]
|
|
1348
|
-
}
|
|
1370
|
+
};
|
|
1371
|
+
}
|
|
1372
|
+
function createServe(adapter) {
|
|
1373
|
+
return (options) => {
|
|
1374
|
+
const serveOptions = prepareServeOptions(options);
|
|
1375
|
+
return adapter(serveOptions);
|
|
1376
|
+
};
|
|
1349
1377
|
}
|
|
1378
|
+
var serve = createServe(serve$1);
|
|
1350
1379
|
|
|
1351
1380
|
// src/types.ts
|
|
1352
1381
|
var _compatibilityCheck = true;
|
|
1353
1382
|
|
|
1354
1383
|
// src/index.ts
|
|
1355
|
-
function
|
|
1356
|
-
|
|
1357
|
-
}
|
|
1358
|
-
function isTool(params) {
|
|
1359
|
-
return params instanceof Tool;
|
|
1360
|
-
}
|
|
1361
|
-
function isInngestWorkflow(params) {
|
|
1362
|
-
return params instanceof InngestWorkflow;
|
|
1363
|
-
}
|
|
1364
|
-
function createStep(params, agentOptions) {
|
|
1365
|
-
if (isInngestWorkflow(params)) {
|
|
1384
|
+
function createStep(params, agentOrToolOptions) {
|
|
1385
|
+
if (params instanceof InngestWorkflow) {
|
|
1366
1386
|
return params;
|
|
1367
1387
|
}
|
|
1368
|
-
if (
|
|
1369
|
-
const
|
|
1388
|
+
if (params instanceof Agent) {
|
|
1389
|
+
const options = agentOrToolOptions;
|
|
1390
|
+
const outputSchema = options?.structuredOutput?.schema ?? z.object({ text: z.string() });
|
|
1391
|
+
const { retries, scorers, ...agentOptions } = options ?? {};
|
|
1370
1392
|
return {
|
|
1371
1393
|
id: params.name,
|
|
1372
1394
|
description: params.getDescription(),
|
|
@@ -1376,6 +1398,8 @@ function createStep(params, agentOptions) {
|
|
|
1376
1398
|
// threadId: z.string().optional(),
|
|
1377
1399
|
}),
|
|
1378
1400
|
outputSchema,
|
|
1401
|
+
retries,
|
|
1402
|
+
scorers,
|
|
1379
1403
|
execute: async ({
|
|
1380
1404
|
inputData,
|
|
1381
1405
|
runId,
|
|
@@ -1471,7 +1495,8 @@ function createStep(params, agentOptions) {
|
|
|
1471
1495
|
component: params.component
|
|
1472
1496
|
};
|
|
1473
1497
|
}
|
|
1474
|
-
if (
|
|
1498
|
+
if (params instanceof Tool) {
|
|
1499
|
+
const toolOpts = agentOrToolOptions;
|
|
1475
1500
|
if (!params.inputSchema || !params.outputSchema) {
|
|
1476
1501
|
throw new Error("Tool must have input and output schemas defined");
|
|
1477
1502
|
}
|
|
@@ -1483,6 +1508,8 @@ function createStep(params, agentOptions) {
|
|
|
1483
1508
|
outputSchema: params.outputSchema,
|
|
1484
1509
|
suspendSchema: params.suspendSchema,
|
|
1485
1510
|
resumeSchema: params.resumeSchema,
|
|
1511
|
+
retries: toolOpts?.retries,
|
|
1512
|
+
scorers: toolOpts?.scorers,
|
|
1486
1513
|
execute: async ({
|
|
1487
1514
|
inputData,
|
|
1488
1515
|
mastra,
|
|
@@ -1520,6 +1547,8 @@ function createStep(params, agentOptions) {
|
|
|
1520
1547
|
outputSchema: params.outputSchema,
|
|
1521
1548
|
resumeSchema: params.resumeSchema,
|
|
1522
1549
|
suspendSchema: params.suspendSchema,
|
|
1550
|
+
retries: params.retries,
|
|
1551
|
+
scorers: params.scorers,
|
|
1523
1552
|
execute: params.execute
|
|
1524
1553
|
};
|
|
1525
1554
|
}
|
|
@@ -1563,6 +1592,6 @@ function init(inngest) {
|
|
|
1563
1592
|
};
|
|
1564
1593
|
}
|
|
1565
1594
|
|
|
1566
|
-
export { InngestExecutionEngine, InngestPubSub, InngestRun, InngestWorkflow, _compatibilityCheck, createStep, init, serve };
|
|
1595
|
+
export { InngestExecutionEngine, InngestPubSub, InngestRun, InngestWorkflow, _compatibilityCheck, createServe, createStep, init, serve };
|
|
1567
1596
|
//# sourceMappingURL=index.js.map
|
|
1568
1597
|
//# sourceMappingURL=index.js.map
|