@mastra/temporal 0.6.0-alpha.0 → 0.6.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/worker.js CHANGED
@@ -2,13 +2,13 @@ import { t as toWorkflowType } from "./utils-R6cB86BM.js";
2
2
  import { builtinModules } from "module";
3
3
  import { validateStepInput, validateStepRequestContext } from "@mastra/core/workflows";
4
4
  import { RequestContext } from "@mastra/core/di";
5
+ import { MastraError, getErrorFromUnknown } from "@mastra/core/error";
5
6
  import { readFileSync } from "fs";
6
7
  import { writeFile } from "fs/promises";
7
8
  import path, { basename, join } from "path";
8
9
  import { fileURLToPath, pathToFileURL } from "url";
9
- import { MastraError } from "@mastra/core/error";
10
10
  import { toStandardSchema } from "@mastra/core/schema";
11
- import { ApplicationFailure } from "@temporalio/activity";
11
+ import { ApplicationFailure, CancelledFailure } from "@temporalio/activity";
12
12
  import { generate } from "@babel/generator";
13
13
  import { parse } from "@babel/parser";
14
14
  import * as t from "@babel/types";
@@ -1188,6 +1188,44 @@ function getActivityBindingsPath(outputDir) {
1188
1188
  return path.join(outputDir, ACTIVITY_BINDINGS_FILE_NAME);
1189
1189
  }
1190
1190
  /**
1191
+ * Temporal reduces a thrown error to its class name and message, so the step's own fields go in
1192
+ * the failure's `details` for start() to rebuild the result a local run returns.
1193
+ */
1194
+ function toStepFailureDetails(error) {
1195
+ const serialized = getErrorFromUnknown(error, { serializeStack: false }).toJSON();
1196
+ let details;
1197
+ try {
1198
+ details = JSON.parse(JSON.stringify(serialized));
1199
+ } catch {
1200
+ details = {
1201
+ name: serialized.name,
1202
+ message: serialized.message
1203
+ };
1204
+ }
1205
+ if (error instanceof Error && error.name === "TripWire") {
1206
+ const { options, processorId } = error;
1207
+ return {
1208
+ error: details,
1209
+ tripwire: {
1210
+ reason: error.message,
1211
+ retry: options?.retry,
1212
+ metadata: options?.metadata,
1213
+ processorId
1214
+ }
1215
+ };
1216
+ }
1217
+ return { error: details };
1218
+ }
1219
+ /** Fails as Temporal's own conversion would (same type, message and retries), plus the details. */
1220
+ async function runStep(execute) {
1221
+ try {
1222
+ return await execute();
1223
+ } catch (error) {
1224
+ if (error instanceof ApplicationFailure || error instanceof CancelledFailure) throw error;
1225
+ throw ApplicationFailure.fromError(error, { details: [toStepFailureDetails(error)] });
1226
+ }
1227
+ }
1228
+ /**
1191
1229
  * Activities queued by a Workflow built before `validateInputs` existed carry no flag and run
1192
1230
  * unchecked. A mismatch is non-retryable because a retry gets the same input.
1193
1231
  */
@@ -1210,7 +1248,8 @@ async function checkStepParams(stepId, { inputSchema, requestContextSchema }, {
1210
1248
  type: error instanceof MastraError ? error.id : error.name,
1211
1249
  message: error.message,
1212
1250
  nonRetryable: true,
1213
- cause: error
1251
+ cause: error,
1252
+ details: [toStepFailureDetails(error)]
1214
1253
  });
1215
1254
  return {
1216
1255
  ...params,
@@ -1274,9 +1313,10 @@ var MastraPlugin = class {
1274
1313
  if (generatedActivities[binding.stepId]) continue;
1275
1314
  generatedActivities[binding.stepId] = async (params) => {
1276
1315
  const activity = (await this.#loadCompiledActivitiesModule(compiledActivitiesPath))[binding.exportName];
1277
- if (typeof activity === "function") return activity(params);
1316
+ if (typeof activity === "function") return runStep(() => activity(params));
1278
1317
  if (typeof activity?.execute !== "function") throw new Error(`Unable to load activity '${binding.exportName}' from ${compiledActivitiesPath}`);
1279
- return activity.execute(await checkStepParams(binding.stepId, activity, params));
1318
+ const checkedParams = await checkStepParams(binding.stepId, activity, params);
1319
+ return runStep(() => activity.execute(checkedParams));
1280
1320
  };
1281
1321
  }
1282
1322
  return generatedActivities;