@mastra/temporal 0.5.0-alpha.1 → 0.5.0-alpha.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/dist/index.cjs +69 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +69 -14
- package/dist/index.js.map +1 -1
- package/dist/run.d.ts +2 -1
- package/dist/run.d.ts.map +1 -1
- package/dist/worker.cjs +1 -1
- package/dist/worker.js +1 -1
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_utils = require("./utils-BVE1AkTt.cjs");
|
|
3
3
|
let _mastra_core_workflows = require("@mastra/core/workflows");
|
|
4
|
+
let _mastra_core_di = require("@mastra/core/di");
|
|
5
|
+
let _temporalio_client = require("@temporalio/client");
|
|
4
6
|
// src/run.ts
|
|
5
7
|
function toStepResults(input, { steps, stepMeta }) {
|
|
6
8
|
if (!stepMeta) return {};
|
|
@@ -21,17 +23,16 @@ var TemporalRun = class extends _mastra_core_workflows.Run {
|
|
|
21
23
|
this.taskQueue = temporalParams.taskQueue;
|
|
22
24
|
}
|
|
23
25
|
async start(args = {}) {
|
|
24
|
-
const input = await this
|
|
25
|
-
|
|
26
|
-
await this._validateRequestContext(args.requestContext);
|
|
26
|
+
const { input, initialState, requestContext } = await this.#prepareStart(args);
|
|
27
|
+
let handle;
|
|
27
28
|
try {
|
|
28
|
-
|
|
29
|
+
handle = await this.client.workflow.start(require_utils.toWorkflowType(this.workflowId), {
|
|
29
30
|
taskQueue: this.taskQueue,
|
|
30
31
|
workflowId: this.runId,
|
|
31
32
|
args: [{
|
|
32
33
|
inputData: input,
|
|
33
34
|
initialState,
|
|
34
|
-
requestContext:
|
|
35
|
+
requestContext: Object.fromEntries(requestContext.entries()),
|
|
35
36
|
runId: this.runId,
|
|
36
37
|
resourceId: this.resourceId,
|
|
37
38
|
outputOptions: args.outputOptions,
|
|
@@ -40,7 +41,36 @@ var TemporalRun = class extends _mastra_core_workflows.Run {
|
|
|
40
41
|
recordStepMeta: true,
|
|
41
42
|
validateInputs: this.validateInputs
|
|
42
43
|
}]
|
|
43
|
-
})
|
|
44
|
+
});
|
|
45
|
+
} catch (error) {
|
|
46
|
+
return this.#failedResult(error, input, initialState);
|
|
47
|
+
}
|
|
48
|
+
const result = await this.#settle(handle, input, initialState);
|
|
49
|
+
await this.#invokeFinishCallbacks(result, input, requestContext);
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
async #prepareStart(args) {
|
|
53
|
+
const input = await this._validateInput(args.inputData);
|
|
54
|
+
const initialState = await this._validateInitialState(args.initialState) ?? {};
|
|
55
|
+
await this._validateRequestContext(args.requestContext);
|
|
56
|
+
const requestContext = args.requestContext ?? new _mastra_core_di.RequestContext();
|
|
57
|
+
await this.executionEngine.invokeStartCallback({
|
|
58
|
+
runId: this.runId,
|
|
59
|
+
workflowId: this.workflowId,
|
|
60
|
+
resourceId: this.resourceId,
|
|
61
|
+
getInitData: () => input,
|
|
62
|
+
requestContext,
|
|
63
|
+
state: initialState
|
|
64
|
+
});
|
|
65
|
+
return {
|
|
66
|
+
input,
|
|
67
|
+
initialState,
|
|
68
|
+
requestContext
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
async #settle(handle, input, initialState) {
|
|
72
|
+
try {
|
|
73
|
+
const result = await handle.result();
|
|
44
74
|
return {
|
|
45
75
|
status: "success",
|
|
46
76
|
input,
|
|
@@ -49,15 +79,38 @@ var TemporalRun = class extends _mastra_core_workflows.Run {
|
|
|
49
79
|
steps: toStepResults(input, result)
|
|
50
80
|
};
|
|
51
81
|
} catch (error) {
|
|
52
|
-
return {
|
|
53
|
-
status: "
|
|
82
|
+
if (error instanceof _temporalio_client.WorkflowFailedError && error.cause instanceof _temporalio_client.CancelledFailure) return {
|
|
83
|
+
status: "canceled",
|
|
54
84
|
input,
|
|
55
|
-
error: error instanceof Error ? error : new Error(String(error)),
|
|
56
85
|
state: initialState,
|
|
57
86
|
steps: {}
|
|
58
87
|
};
|
|
88
|
+
return this.#failedResult(error, input, initialState);
|
|
59
89
|
}
|
|
60
90
|
}
|
|
91
|
+
#failedResult(error, input, initialState) {
|
|
92
|
+
return {
|
|
93
|
+
status: "failed",
|
|
94
|
+
input,
|
|
95
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
96
|
+
state: initialState,
|
|
97
|
+
steps: {}
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
#invokeFinishCallbacks(result, input, requestContext) {
|
|
101
|
+
return this.executionEngine.invokeLifecycleCallbacks({
|
|
102
|
+
status: result.status,
|
|
103
|
+
result: result.status === "success" ? result.result : void 0,
|
|
104
|
+
error: result.status === "failed" ? result.error : void 0,
|
|
105
|
+
steps: result.steps,
|
|
106
|
+
runId: this.runId,
|
|
107
|
+
workflowId: this.workflowId,
|
|
108
|
+
resourceId: this.resourceId,
|
|
109
|
+
input,
|
|
110
|
+
requestContext,
|
|
111
|
+
state: result.state ?? {}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
61
114
|
async cancel() {
|
|
62
115
|
await this.client.workflow.getHandle(this.runId).cancel();
|
|
63
116
|
await super.cancel();
|
|
@@ -90,24 +143,26 @@ var TemporalRun = class extends _mastra_core_workflows.Run {
|
|
|
90
143
|
return this.unsupported("timeTravelStream");
|
|
91
144
|
}
|
|
92
145
|
async startAsync(args = {}) {
|
|
93
|
-
const input = await this
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
await this.client.workflow.start(require_utils.toWorkflowType(this.workflowId), {
|
|
146
|
+
const { input, initialState, requestContext } = await this.#prepareStart(args);
|
|
147
|
+
const { onFinish, onError } = this.executionEngine.options;
|
|
148
|
+
const hasFinishCallbacks = Boolean(onFinish || onError);
|
|
149
|
+
const handle = await this.client.workflow.start(require_utils.toWorkflowType(this.workflowId), {
|
|
97
150
|
taskQueue: this.taskQueue,
|
|
98
151
|
workflowId: this.runId,
|
|
99
152
|
args: [{
|
|
100
153
|
inputData: input,
|
|
101
154
|
initialState,
|
|
102
|
-
requestContext:
|
|
155
|
+
requestContext: Object.fromEntries(requestContext.entries()),
|
|
103
156
|
runId: this.runId,
|
|
104
157
|
resourceId: this.resourceId,
|
|
105
158
|
outputOptions: args.outputOptions,
|
|
106
159
|
tracingOptions: args.tracingOptions,
|
|
107
160
|
perStep: args.perStep,
|
|
161
|
+
...hasFinishCallbacks && { recordStepMeta: true },
|
|
108
162
|
validateInputs: this.validateInputs
|
|
109
163
|
}]
|
|
110
164
|
});
|
|
165
|
+
if (hasFinishCallbacks) this.#settle(handle, input, initialState).then((result) => this.#invokeFinishCallbacks(result, input, requestContext));
|
|
111
166
|
return { runId: this.runId };
|
|
112
167
|
}
|
|
113
168
|
};
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["Run","toWorkflowType","Workflow"],"sources":["../src/run.ts","../src/workflow.ts"],"sourcesContent":["import type { RequestContext } from '@mastra/core/di';\nimport { Run } from '@mastra/core/workflows';\nimport type { Step, WorkflowResult, WorkflowRunStartOptions } from '@mastra/core/workflows';\nimport type { Client } from '@temporalio/client';\nimport type { WorkflowExecutionResult } from './transforms/temporal-workflow-runtime';\nimport type { TemporalEngineType } from './types';\nimport { toWorkflowType } from './utils';\n\n// Builds Mastra step records from the Temporal result. Iterates `stepMeta` rather than `steps`\n// because a step that returned undefined has no key in `steps` once serialized. A result without\n// `stepMeta` came from a Worker that predates it, so `steps` stays empty instead of guessing times.\nfunction toStepResults(input: unknown, { steps, stepMeta }: WorkflowExecutionResult): Record<string, unknown> {\n if (!stepMeta) {\n return {};\n }\n\n const records: Record<string, unknown> = { input };\n for (const [stepId, times] of Object.entries(stepMeta)) {\n records[stepId] = { status: 'success', output: steps[stepId], ...times };\n }\n return records;\n}\n\ntype TemporalRunStartArgs<TState, TInput, TRequestContext> = {\n inputData?: TInput;\n initialState?: TState;\n requestContext?: RequestContext<TRequestContext>;\n} & WorkflowRunStartOptions;\n\nexport class TemporalRun<\n TSteps extends Step<string, any, any, any, any, any, TemporalEngineType, any>[] = Step<\n string,\n unknown,\n unknown,\n unknown,\n unknown,\n unknown,\n TemporalEngineType\n >[],\n TState = unknown,\n TInput = unknown,\n TOutput = unknown,\n TRequestContext extends Record<string, any> | unknown = unknown,\n> extends Run<TemporalEngineType, TSteps, TState, TInput, TOutput, TRequestContext> {\n private readonly client: Client;\n private readonly taskQueue: string;\n\n constructor(\n params: ConstructorParameters<typeof Run<TemporalEngineType, TSteps, TState, TInput, TOutput, TRequestContext>>[0],\n temporalParams: {\n client: Client;\n taskQueue: string;\n },\n ) {\n super(params);\n\n this.client = temporalParams.client;\n this.taskQueue = temporalParams.taskQueue;\n }\n\n async start(args: TemporalRunStartArgs<TState, TInput, TRequestContext> = {}) {\n const input = await this._validateInput(args.inputData);\n const initialState = await this._validateInitialState(args.initialState);\n await this._validateRequestContext(args.requestContext as RequestContext<unknown> | undefined);\n\n try {\n const handle = await this.client.workflow.start(toWorkflowType(this.workflowId), {\n taskQueue: this.taskQueue,\n workflowId: this.runId,\n args: [\n {\n inputData: input,\n initialState,\n requestContext: args.requestContext ? Object.fromEntries(args.requestContext.entries()) : {},\n runId: this.runId,\n resourceId: this.resourceId,\n outputOptions: args.outputOptions,\n tracingOptions: args.tracingOptions,\n perStep: args.perStep,\n recordStepMeta: true,\n validateInputs: this.validateInputs,\n },\n ],\n });\n const result = (await handle.result()) as WorkflowExecutionResult;\n\n return {\n status: 'success',\n input: input as TInput,\n result: result.result as TOutput,\n state: initialState,\n steps: toStepResults(input, result),\n } as WorkflowResult<TState, TInput, TOutput, TSteps>;\n } catch (error) {\n return {\n status: 'failed',\n input: input as TInput,\n error: error instanceof Error ? error : new Error(String(error)),\n state: initialState,\n steps: {},\n } as WorkflowResult<TState, TInput, TOutput, TSteps>;\n }\n }\n\n async cancel() {\n await this.client.workflow.getHandle(this.runId).cancel();\n await super.cancel();\n }\n\n private unsupported(method: string): never {\n throw new Error(`@mastra/temporal does not support ${method}() yet. Use start() or startAsync() instead.`);\n }\n\n override stream(\n ..._args: Parameters<Run<TemporalEngineType, TSteps, TState, TInput, TOutput, TRequestContext>['stream']>\n ): never {\n return this.unsupported('stream');\n }\n\n override streamLegacy(\n ..._args: Parameters<Run<TemporalEngineType, TSteps, TState, TInput, TOutput, TRequestContext>['streamLegacy']>\n ): never {\n return this.unsupported('streamLegacy');\n }\n\n override resumeStream(..._args: unknown[]): never {\n return this.unsupported('resumeStream');\n }\n\n override resume(..._args: unknown[]): never {\n return this.unsupported('resume');\n }\n\n override resumeAsync(..._args: unknown[]): never {\n return this.unsupported('resumeAsync');\n }\n\n override restart(\n ..._args: Parameters<Run<TemporalEngineType, TSteps, TState, TInput, TOutput, TRequestContext>['restart']>\n ): never {\n return this.unsupported('restart');\n }\n\n override timeTravel(..._args: unknown[]): never {\n return this.unsupported('timeTravel');\n }\n\n override timeTravelStream(..._args: unknown[]): never {\n return this.unsupported('timeTravelStream');\n }\n\n async startAsync(args: TemporalRunStartArgs<TState, TInput, TRequestContext> = {}) {\n const input = await this._validateInput(args.inputData);\n const initialState = await this._validateInitialState(args.initialState);\n await this._validateRequestContext(args.requestContext as RequestContext<unknown> | undefined);\n\n await this.client.workflow.start(toWorkflowType(this.workflowId), {\n taskQueue: this.taskQueue,\n workflowId: this.runId,\n args: [\n {\n inputData: input,\n initialState,\n requestContext: args.requestContext ? Object.fromEntries(args.requestContext.entries()) : {},\n runId: this.runId,\n resourceId: this.resourceId,\n outputOptions: args.outputOptions,\n tracingOptions: args.tracingOptions,\n perStep: args.perStep,\n validateInputs: this.validateInputs,\n },\n ],\n });\n\n return { runId: this.runId };\n }\n}\n","import { Workflow, createStep } from '@mastra/core/workflows';\nimport type { Step, WorkflowConfig } from '@mastra/core/workflows';\nimport type { Client } from '@temporalio/client';\nimport type { ActivityOptions } from '@temporalio/workflow';\nimport { TemporalRun } from './run';\nimport type { TemporalEngineType } from './types';\n\nexport type TemporalWorkflowParams = {\n client: Client;\n taskQueue: string;\n startToCloseTimeout?: string;\n retry?: ActivityOptions['retry'];\n};\n\nexport class TemporalWorkflow<\n TSteps extends Step<string, any, any, any, any, any, TemporalEngineType, any>[] = Step<\n string,\n unknown,\n unknown,\n unknown,\n unknown,\n unknown,\n TemporalEngineType\n >[],\n TWorkflowId extends string = string,\n TState = unknown,\n TInput = unknown,\n TOutput = unknown,\n TPrevSchema = TInput,\n TRequestContext extends Record<string, any> | unknown = unknown,\n> extends Workflow<TemporalEngineType, TSteps, TWorkflowId, TState, TInput, TOutput, TPrevSchema, TRequestContext> {\n private readonly temporalClient: Client;\n readonly taskQueue: string;\n readonly startToCloseTimeout: string;\n\n constructor(\n params: WorkflowConfig<TWorkflowId, TState, TInput, TOutput, TSteps, TRequestContext>,\n temporalParams: TemporalWorkflowParams,\n ) {\n super(params);\n\n this.engineType = 'temporal';\n this.temporalClient = temporalParams.client;\n this.taskQueue = temporalParams.taskQueue;\n this.startToCloseTimeout = temporalParams.startToCloseTimeout ?? '1 minute';\n }\n\n async createRun(options?: { runId?: string; resourceId?: string; disableScorers?: boolean }) {\n const runId = options?.runId ?? crypto.randomUUID();\n const run = new TemporalRun<TSteps, TState, TInput, TOutput, TRequestContext>(\n {\n workflowId: this.id,\n runId,\n resourceId: options?.resourceId,\n stateSchema: this.stateSchema,\n inputSchema: this.inputSchema,\n requestContextSchema: this.requestContextSchema,\n executionEngine: this.executionEngine,\n executionGraph: this.executionGraph,\n mastra: this.mastra,\n retryConfig: this.retryConfig,\n serializedStepGraph: this.serializedStepGraph,\n disableScorers: options?.disableScorers,\n tracingPolicy: this.options.tracingPolicy,\n workflowSteps: this.steps,\n validateInputs: this.options.validateInputs,\n workflowEngineType: this.engineType,\n cleanup: undefined,\n },\n {\n client: this.temporalClient,\n taskQueue: this.taskQueue,\n },\n );\n\n this.runs.set(runId, run);\n return run;\n }\n}\n\nexport function createWorkflow<\n TSteps extends Step<string, any, any, any, any, any, TemporalEngineType, any>[] = Step<\n string,\n unknown,\n unknown,\n unknown,\n unknown,\n unknown,\n TemporalEngineType\n >[],\n TWorkflowId extends string = string,\n TState = unknown,\n TInput = unknown,\n TOutput = unknown,\n TRequestContext extends Record<string, any> | unknown = unknown,\n>(\n config: WorkflowConfig<TWorkflowId, TState, TInput, TOutput, TSteps, TRequestContext>,\n temporal: TemporalWorkflowParams,\n) {\n return new TemporalWorkflow<TSteps, TWorkflowId, TState, TInput, TOutput, TInput, TRequestContext>(config, temporal);\n}\n\nexport function init(temporalParams: TemporalWorkflowParams) {\n return {\n createWorkflow: <\n TWorkflowId extends string,\n TState = unknown,\n TInput = unknown,\n TOutput = unknown,\n TSteps extends Step[] = Step[],\n TRequestContext extends Record<string, any> | unknown = unknown,\n >(\n config: WorkflowConfig<TWorkflowId, TState, TInput, TOutput, TSteps, TRequestContext>,\n ) => createWorkflow<TSteps, TWorkflowId, TState, TInput, TOutput, TRequestContext>(config, temporalParams),\n createStep,\n };\n}\n"],"mappings":";;;;AAWA,SAAS,cAAc,OAAgB,EAAE,OAAO,YAA8D;CAC5G,IAAI,CAAC,UACH,OAAO,CAAC;CAGV,MAAM,UAAmC,EAAE,MAAM;CACjD,KAAK,MAAM,CAAC,QAAQ,UAAU,OAAO,QAAQ,QAAQ,GACnD,QAAQ,UAAU;EAAE,QAAQ;EAAW,QAAQ,MAAM;EAAS,GAAG;CAAM;CAEzE,OAAO;AACT;AAQA,IAAa,cAAb,cAcUA,uBAAAA,IAA0E;CAClF;CACA;CAEA,YACE,QACA,gBAIA;EACA,MAAM,MAAM;EAEZ,KAAK,SAAS,eAAe;EAC7B,KAAK,YAAY,eAAe;CAClC;CAEA,MAAM,MAAM,OAA8D,CAAC,GAAG;EAC5E,MAAM,QAAQ,MAAM,KAAK,eAAe,KAAK,SAAS;EACtD,MAAM,eAAe,MAAM,KAAK,sBAAsB,KAAK,YAAY;EACvE,MAAM,KAAK,wBAAwB,KAAK,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,KAAK,QAAQ;GAC5B,eAAe,KAAK;GACpB,gBAAgB,KAAK,QAAQ;GAC7B,oBAAoB,KAAK;GACzB,SAAS,KAAA;EACX,GACA;GACE,QAAQ,KAAK;GACb,WAAW,KAAK;EAClB,CACF;EAEA,KAAK,KAAK,IAAI,OAAO,GAAG;EACxB,OAAO;CACT;AACF;AAEA,SAAgB,eAgBd,QACA,UACA;CACA,OAAO,IAAI,iBAAwF,QAAQ,QAAQ;AACrH;AAEA,SAAgB,KAAK,gBAAwC;CAC3D,OAAO;EACL,iBAQE,WACG,eAA8E,QAAQ,cAAc;EACzG,YAAA,uBAAA;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["Run","toWorkflowType","RequestContext","WorkflowFailedError","CancelledFailure","Workflow"],"sources":["../src/run.ts","../src/workflow.ts"],"sourcesContent":["import { RequestContext } from '@mastra/core/di';\nimport { Run } from '@mastra/core/workflows';\nimport type { Step, StepResult, WorkflowResult, WorkflowRunStartOptions } from '@mastra/core/workflows';\nimport { CancelledFailure, WorkflowFailedError } from '@temporalio/client';\nimport type { Client, WorkflowHandle } from '@temporalio/client';\nimport type { WorkflowExecutionResult } from './transforms/temporal-workflow-runtime';\nimport type { TemporalEngineType } from './types';\nimport { toWorkflowType } from './utils';\n\n// Builds Mastra step records from the Temporal result. Iterates `stepMeta` rather than `steps`\n// because a step that returned undefined has no key in `steps` once serialized. A result without\n// `stepMeta` came from a Worker that predates it, so `steps` stays empty instead of guessing times.\nfunction toStepResults(input: unknown, { steps, stepMeta }: WorkflowExecutionResult): Record<string, unknown> {\n if (!stepMeta) {\n return {};\n }\n\n const records: Record<string, unknown> = { input };\n for (const [stepId, times] of Object.entries(stepMeta)) {\n records[stepId] = { status: 'success', output: steps[stepId], ...times };\n }\n return records;\n}\n\ntype TemporalRunStartArgs<TState, TInput, TRequestContext> = {\n inputData?: TInput;\n initialState?: TState;\n requestContext?: RequestContext<TRequestContext>;\n} & WorkflowRunStartOptions;\n\nexport class TemporalRun<\n TSteps extends Step<string, any, any, any, any, any, TemporalEngineType, any>[] = Step<\n string,\n unknown,\n unknown,\n unknown,\n unknown,\n unknown,\n TemporalEngineType\n >[],\n TState = unknown,\n TInput = unknown,\n TOutput = unknown,\n TRequestContext extends Record<string, any> | unknown = unknown,\n> extends Run<TemporalEngineType, TSteps, TState, TInput, TOutput, TRequestContext> {\n private readonly client: Client;\n private readonly taskQueue: string;\n\n constructor(\n params: ConstructorParameters<typeof Run<TemporalEngineType, TSteps, TState, TInput, TOutput, TRequestContext>>[0],\n temporalParams: {\n client: Client;\n taskQueue: string;\n },\n ) {\n super(params);\n\n this.client = temporalParams.client;\n this.taskQueue = temporalParams.taskQueue;\n }\n\n async start(args: TemporalRunStartArgs<TState, TInput, TRequestContext> = {}) {\n const { input, initialState, requestContext } = await this.#prepareStart(args);\n\n let handle: WorkflowHandle;\n try {\n handle = await this.client.workflow.start(toWorkflowType(this.workflowId), {\n taskQueue: this.taskQueue,\n workflowId: this.runId,\n args: [\n {\n inputData: input,\n initialState,\n requestContext: Object.fromEntries(requestContext.entries()),\n runId: this.runId,\n resourceId: this.resourceId,\n outputOptions: args.outputOptions,\n tracingOptions: args.tracingOptions,\n perStep: args.perStep,\n recordStepMeta: true,\n validateInputs: this.validateInputs,\n },\n ],\n });\n } catch (error) {\n // Temporal did not start this run, for example because its id is already in use, so the\n // finish callbacks have no outcome to report.\n return this.#failedResult(error, input, initialState);\n }\n\n const result = await this.#settle(handle, input, initialState);\n await this.#invokeFinishCallbacks(result, input, requestContext);\n return result;\n }\n\n // Lifecycle hooks are closures that cannot run in the Temporal workflow sandbox, so they run\n // in the process that starts the run. onStart can change the state and request context, so\n // the caller sends both to Temporal only after it runs.\n async #prepareStart(args: TemporalRunStartArgs<TState, TInput, TRequestContext>) {\n const input = await this._validateInput(args.inputData);\n const initialState = (await this._validateInitialState(args.initialState)) ?? ({} as TState);\n await this._validateRequestContext(args.requestContext as RequestContext<unknown> | undefined);\n\n const requestContext = (args.requestContext ?? new RequestContext()) as RequestContext;\n await this.executionEngine.invokeStartCallback({\n runId: this.runId,\n workflowId: this.workflowId,\n resourceId: this.resourceId,\n getInitData: () => input,\n requestContext,\n state: initialState as Record<string, any>,\n });\n\n return { input, initialState, requestContext };\n }\n\n async #settle(\n handle: WorkflowHandle,\n input: TInput | undefined,\n initialState: TState | undefined,\n ): Promise<WorkflowResult<TState, TInput, TOutput, TSteps>> {\n try {\n const result = (await handle.result()) as WorkflowExecutionResult;\n\n return {\n status: 'success',\n input: input as TInput,\n result: result.result as TOutput,\n state: initialState,\n steps: toStepResults(input, result),\n } as WorkflowResult<TState, TInput, TOutput, TSteps>;\n } catch (error) {\n // Core reports a canceled run as `canceled` and does not call onError for it.\n if (error instanceof WorkflowFailedError && error.cause instanceof CancelledFailure) {\n return { status: 'canceled', input, state: initialState, steps: {} } as unknown as WorkflowResult<\n TState,\n TInput,\n TOutput,\n TSteps\n >;\n }\n\n return this.#failedResult(error, input, initialState);\n }\n }\n\n #failedResult(error: unknown, input: TInput | undefined, initialState: TState | undefined) {\n return {\n status: 'failed',\n input: input as TInput,\n error: error instanceof Error ? error : new Error(String(error)),\n state: initialState,\n steps: {},\n } as WorkflowResult<TState, TInput, TOutput, TSteps>;\n }\n\n #invokeFinishCallbacks(\n result: WorkflowResult<TState, TInput, TOutput, TSteps>,\n input: TInput | undefined,\n requestContext: RequestContext,\n ) {\n return this.executionEngine.invokeLifecycleCallbacks({\n status: result.status,\n result: result.status === 'success' ? result.result : undefined,\n error: result.status === 'failed' ? result.error : undefined,\n steps: result.steps as Record<string, StepResult<any, any, any, any>>,\n runId: this.runId,\n workflowId: this.workflowId,\n resourceId: this.resourceId,\n input,\n requestContext,\n state: (result.state ?? {}) as Record<string, any>,\n });\n }\n\n async cancel() {\n await this.client.workflow.getHandle(this.runId).cancel();\n await super.cancel();\n }\n\n private unsupported(method: string): never {\n throw new Error(`@mastra/temporal does not support ${method}() yet. Use start() or startAsync() instead.`);\n }\n\n override stream(\n ..._args: Parameters<Run<TemporalEngineType, TSteps, TState, TInput, TOutput, TRequestContext>['stream']>\n ): never {\n return this.unsupported('stream');\n }\n\n override streamLegacy(\n ..._args: Parameters<Run<TemporalEngineType, TSteps, TState, TInput, TOutput, TRequestContext>['streamLegacy']>\n ): never {\n return this.unsupported('streamLegacy');\n }\n\n override resumeStream(..._args: unknown[]): never {\n return this.unsupported('resumeStream');\n }\n\n override resume(..._args: unknown[]): never {\n return this.unsupported('resume');\n }\n\n override resumeAsync(..._args: unknown[]): never {\n return this.unsupported('resumeAsync');\n }\n\n override restart(\n ..._args: Parameters<Run<TemporalEngineType, TSteps, TState, TInput, TOutput, TRequestContext>['restart']>\n ): never {\n return this.unsupported('restart');\n }\n\n override timeTravel(..._args: unknown[]): never {\n return this.unsupported('timeTravel');\n }\n\n override timeTravelStream(..._args: unknown[]): never {\n return this.unsupported('timeTravelStream');\n }\n\n async startAsync(args: TemporalRunStartArgs<TState, TInput, TRequestContext> = {}) {\n const { input, initialState, requestContext } = await this.#prepareStart(args);\n const { onFinish, onError } = this.executionEngine.options;\n const hasFinishCallbacks = Boolean(onFinish || onError);\n\n const handle = await this.client.workflow.start(toWorkflowType(this.workflowId), {\n taskQueue: this.taskQueue,\n workflowId: this.runId,\n args: [\n {\n inputData: input,\n initialState,\n requestContext: Object.fromEntries(requestContext.entries()),\n runId: this.runId,\n resourceId: this.resourceId,\n outputOptions: args.outputOptions,\n tracingOptions: args.tracingOptions,\n perStep: args.perStep,\n ...(hasFinishCallbacks && { recordStepMeta: true }),\n validateInputs: this.validateInputs,\n },\n ],\n });\n\n // Best-effort, as with core startAsync(): the callbacks are lost if this process exits\n // before the workflow finishes (#24587).\n if (hasFinishCallbacks) {\n void this.#settle(handle, input, initialState).then(result =>\n this.#invokeFinishCallbacks(result, input, requestContext),\n );\n }\n\n return { runId: this.runId };\n }\n}\n","import { Workflow, createStep } from '@mastra/core/workflows';\nimport type { Step, WorkflowConfig } from '@mastra/core/workflows';\nimport type { Client } from '@temporalio/client';\nimport type { ActivityOptions } from '@temporalio/workflow';\nimport { TemporalRun } from './run';\nimport type { TemporalEngineType } from './types';\n\nexport type TemporalWorkflowParams = {\n client: Client;\n taskQueue: string;\n startToCloseTimeout?: string;\n retry?: ActivityOptions['retry'];\n};\n\nexport class TemporalWorkflow<\n TSteps extends Step<string, any, any, any, any, any, TemporalEngineType, any>[] = Step<\n string,\n unknown,\n unknown,\n unknown,\n unknown,\n unknown,\n TemporalEngineType\n >[],\n TWorkflowId extends string = string,\n TState = unknown,\n TInput = unknown,\n TOutput = unknown,\n TPrevSchema = TInput,\n TRequestContext extends Record<string, any> | unknown = unknown,\n> extends Workflow<TemporalEngineType, TSteps, TWorkflowId, TState, TInput, TOutput, TPrevSchema, TRequestContext> {\n private readonly temporalClient: Client;\n readonly taskQueue: string;\n readonly startToCloseTimeout: string;\n\n constructor(\n params: WorkflowConfig<TWorkflowId, TState, TInput, TOutput, TSteps, TRequestContext>,\n temporalParams: TemporalWorkflowParams,\n ) {\n super(params);\n\n this.engineType = 'temporal';\n this.temporalClient = temporalParams.client;\n this.taskQueue = temporalParams.taskQueue;\n this.startToCloseTimeout = temporalParams.startToCloseTimeout ?? '1 minute';\n }\n\n async createRun(options?: { runId?: string; resourceId?: string; disableScorers?: boolean }) {\n const runId = options?.runId ?? crypto.randomUUID();\n const run = new TemporalRun<TSteps, TState, TInput, TOutput, TRequestContext>(\n {\n workflowId: this.id,\n runId,\n resourceId: options?.resourceId,\n stateSchema: this.stateSchema,\n inputSchema: this.inputSchema,\n requestContextSchema: this.requestContextSchema,\n executionEngine: this.executionEngine,\n executionGraph: this.executionGraph,\n mastra: this.mastra,\n retryConfig: this.retryConfig,\n serializedStepGraph: this.serializedStepGraph,\n disableScorers: options?.disableScorers,\n tracingPolicy: this.options.tracingPolicy,\n workflowSteps: this.steps,\n validateInputs: this.options.validateInputs,\n workflowEngineType: this.engineType,\n cleanup: undefined,\n },\n {\n client: this.temporalClient,\n taskQueue: this.taskQueue,\n },\n );\n\n this.runs.set(runId, run);\n return run;\n }\n}\n\nexport function createWorkflow<\n TSteps extends Step<string, any, any, any, any, any, TemporalEngineType, any>[] = Step<\n string,\n unknown,\n unknown,\n unknown,\n unknown,\n unknown,\n TemporalEngineType\n >[],\n TWorkflowId extends string = string,\n TState = unknown,\n TInput = unknown,\n TOutput = unknown,\n TRequestContext extends Record<string, any> | unknown = unknown,\n>(\n config: WorkflowConfig<TWorkflowId, TState, TInput, TOutput, TSteps, TRequestContext>,\n temporal: TemporalWorkflowParams,\n) {\n return new TemporalWorkflow<TSteps, TWorkflowId, TState, TInput, TOutput, TInput, TRequestContext>(config, temporal);\n}\n\nexport function init(temporalParams: TemporalWorkflowParams) {\n return {\n createWorkflow: <\n TWorkflowId extends string,\n TState = unknown,\n TInput = unknown,\n TOutput = unknown,\n TSteps extends Step[] = Step[],\n TRequestContext extends Record<string, any> | unknown = unknown,\n >(\n config: WorkflowConfig<TWorkflowId, TState, TInput, TOutput, TSteps, TRequestContext>,\n ) => createWorkflow<TSteps, TWorkflowId, TState, TInput, TOutput, TRequestContext>(config, temporalParams),\n createStep,\n };\n}\n"],"mappings":";;;;;;AAYA,SAAS,cAAc,OAAgB,EAAE,OAAO,YAA8D;CAC5G,IAAI,CAAC,UACH,OAAO,CAAC;CAGV,MAAM,UAAmC,EAAE,MAAM;CACjD,KAAK,MAAM,CAAC,QAAQ,UAAU,OAAO,QAAQ,QAAQ,GACnD,QAAQ,UAAU;EAAE,QAAQ;EAAW,QAAQ,MAAM;EAAS,GAAG;CAAM;CAEzE,OAAO;AACT;AAQA,IAAa,cAAb,cAcUA,uBAAAA,IAA0E;CAClF;CACA;CAEA,YACE,QACA,gBAIA;EACA,MAAM,MAAM;EAEZ,KAAK,SAAS,eAAe;EAC7B,KAAK,YAAY,eAAe;CAClC;CAEA,MAAM,MAAM,OAA8D,CAAC,GAAG;EAC5E,MAAM,EAAE,OAAO,cAAc,mBAAmB,MAAM,KAAK,cAAc,IAAI;EAE7E,IAAI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qB,KAAK;GAC1B,gBAAgB,SAAS;GACzB,eAAe,KAAK,QAAQ;GAC5B,eAAe,KAAK;GACpB,gBAAgB,KAAK,QAAQ;GAC7B,oBAAoB,KAAK;GACzB,SAAS,KAAA;EACX,GACA;GACE,QAAQ,KAAK;GACb,WAAW,KAAK;EAClB,CACF;EAEA,KAAK,KAAK,IAAI,OAAO,GAAG;EACxB,OAAO;CACT;AACF;AAEA,SAAgB,eAgBd,QACA,UACA;CACA,OAAO,IAAI,iBAAwF,QAAQ,QAAQ;AACrH;AAEA,SAAgB,KAAK,gBAAwC;CAC3D,OAAO;EACL,iBAQE,WACG,eAA8E,QAAQ,cAAc;EACzG,YAAA,uBAAA;CACF;AACF"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { t as toWorkflowType } from "./utils-R6cB86BM.js";
|
|
2
2
|
import { Run, Workflow, createStep } from "@mastra/core/workflows";
|
|
3
|
+
import { RequestContext } from "@mastra/core/di";
|
|
4
|
+
import { CancelledFailure, WorkflowFailedError } from "@temporalio/client";
|
|
3
5
|
// src/run.ts
|
|
4
6
|
function toStepResults(input, { steps, stepMeta }) {
|
|
5
7
|
if (!stepMeta) return {};
|
|
@@ -20,17 +22,16 @@ var TemporalRun = class extends Run {
|
|
|
20
22
|
this.taskQueue = temporalParams.taskQueue;
|
|
21
23
|
}
|
|
22
24
|
async start(args = {}) {
|
|
23
|
-
const input = await this
|
|
24
|
-
|
|
25
|
-
await this._validateRequestContext(args.requestContext);
|
|
25
|
+
const { input, initialState, requestContext } = await this.#prepareStart(args);
|
|
26
|
+
let handle;
|
|
26
27
|
try {
|
|
27
|
-
|
|
28
|
+
handle = await this.client.workflow.start(toWorkflowType(this.workflowId), {
|
|
28
29
|
taskQueue: this.taskQueue,
|
|
29
30
|
workflowId: this.runId,
|
|
30
31
|
args: [{
|
|
31
32
|
inputData: input,
|
|
32
33
|
initialState,
|
|
33
|
-
requestContext:
|
|
34
|
+
requestContext: Object.fromEntries(requestContext.entries()),
|
|
34
35
|
runId: this.runId,
|
|
35
36
|
resourceId: this.resourceId,
|
|
36
37
|
outputOptions: args.outputOptions,
|
|
@@ -39,7 +40,36 @@ var TemporalRun = class extends Run {
|
|
|
39
40
|
recordStepMeta: true,
|
|
40
41
|
validateInputs: this.validateInputs
|
|
41
42
|
}]
|
|
42
|
-
})
|
|
43
|
+
});
|
|
44
|
+
} catch (error) {
|
|
45
|
+
return this.#failedResult(error, input, initialState);
|
|
46
|
+
}
|
|
47
|
+
const result = await this.#settle(handle, input, initialState);
|
|
48
|
+
await this.#invokeFinishCallbacks(result, input, requestContext);
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
async #prepareStart(args) {
|
|
52
|
+
const input = await this._validateInput(args.inputData);
|
|
53
|
+
const initialState = await this._validateInitialState(args.initialState) ?? {};
|
|
54
|
+
await this._validateRequestContext(args.requestContext);
|
|
55
|
+
const requestContext = args.requestContext ?? new RequestContext();
|
|
56
|
+
await this.executionEngine.invokeStartCallback({
|
|
57
|
+
runId: this.runId,
|
|
58
|
+
workflowId: this.workflowId,
|
|
59
|
+
resourceId: this.resourceId,
|
|
60
|
+
getInitData: () => input,
|
|
61
|
+
requestContext,
|
|
62
|
+
state: initialState
|
|
63
|
+
});
|
|
64
|
+
return {
|
|
65
|
+
input,
|
|
66
|
+
initialState,
|
|
67
|
+
requestContext
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
async #settle(handle, input, initialState) {
|
|
71
|
+
try {
|
|
72
|
+
const result = await handle.result();
|
|
43
73
|
return {
|
|
44
74
|
status: "success",
|
|
45
75
|
input,
|
|
@@ -48,15 +78,38 @@ var TemporalRun = class extends Run {
|
|
|
48
78
|
steps: toStepResults(input, result)
|
|
49
79
|
};
|
|
50
80
|
} catch (error) {
|
|
51
|
-
return {
|
|
52
|
-
status: "
|
|
81
|
+
if (error instanceof WorkflowFailedError && error.cause instanceof CancelledFailure) return {
|
|
82
|
+
status: "canceled",
|
|
53
83
|
input,
|
|
54
|
-
error: error instanceof Error ? error : new Error(String(error)),
|
|
55
84
|
state: initialState,
|
|
56
85
|
steps: {}
|
|
57
86
|
};
|
|
87
|
+
return this.#failedResult(error, input, initialState);
|
|
58
88
|
}
|
|
59
89
|
}
|
|
90
|
+
#failedResult(error, input, initialState) {
|
|
91
|
+
return {
|
|
92
|
+
status: "failed",
|
|
93
|
+
input,
|
|
94
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
95
|
+
state: initialState,
|
|
96
|
+
steps: {}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
#invokeFinishCallbacks(result, input, requestContext) {
|
|
100
|
+
return this.executionEngine.invokeLifecycleCallbacks({
|
|
101
|
+
status: result.status,
|
|
102
|
+
result: result.status === "success" ? result.result : void 0,
|
|
103
|
+
error: result.status === "failed" ? result.error : void 0,
|
|
104
|
+
steps: result.steps,
|
|
105
|
+
runId: this.runId,
|
|
106
|
+
workflowId: this.workflowId,
|
|
107
|
+
resourceId: this.resourceId,
|
|
108
|
+
input,
|
|
109
|
+
requestContext,
|
|
110
|
+
state: result.state ?? {}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
60
113
|
async cancel() {
|
|
61
114
|
await this.client.workflow.getHandle(this.runId).cancel();
|
|
62
115
|
await super.cancel();
|
|
@@ -89,24 +142,26 @@ var TemporalRun = class extends Run {
|
|
|
89
142
|
return this.unsupported("timeTravelStream");
|
|
90
143
|
}
|
|
91
144
|
async startAsync(args = {}) {
|
|
92
|
-
const input = await this
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
await this.client.workflow.start(toWorkflowType(this.workflowId), {
|
|
145
|
+
const { input, initialState, requestContext } = await this.#prepareStart(args);
|
|
146
|
+
const { onFinish, onError } = this.executionEngine.options;
|
|
147
|
+
const hasFinishCallbacks = Boolean(onFinish || onError);
|
|
148
|
+
const handle = await this.client.workflow.start(toWorkflowType(this.workflowId), {
|
|
96
149
|
taskQueue: this.taskQueue,
|
|
97
150
|
workflowId: this.runId,
|
|
98
151
|
args: [{
|
|
99
152
|
inputData: input,
|
|
100
153
|
initialState,
|
|
101
|
-
requestContext:
|
|
154
|
+
requestContext: Object.fromEntries(requestContext.entries()),
|
|
102
155
|
runId: this.runId,
|
|
103
156
|
resourceId: this.resourceId,
|
|
104
157
|
outputOptions: args.outputOptions,
|
|
105
158
|
tracingOptions: args.tracingOptions,
|
|
106
159
|
perStep: args.perStep,
|
|
160
|
+
...hasFinishCallbacks && { recordStepMeta: true },
|
|
107
161
|
validateInputs: this.validateInputs
|
|
108
162
|
}]
|
|
109
163
|
});
|
|
164
|
+
if (hasFinishCallbacks) this.#settle(handle, input, initialState).then((result) => this.#invokeFinishCallbacks(result, input, requestContext));
|
|
110
165
|
return { runId: this.runId };
|
|
111
166
|
}
|
|
112
167
|
};
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/run.ts","../src/workflow.ts"],"sourcesContent":["import type { RequestContext } from '@mastra/core/di';\nimport { Run } from '@mastra/core/workflows';\nimport type { Step, WorkflowResult, WorkflowRunStartOptions } from '@mastra/core/workflows';\nimport type { Client } from '@temporalio/client';\nimport type { WorkflowExecutionResult } from './transforms/temporal-workflow-runtime';\nimport type { TemporalEngineType } from './types';\nimport { toWorkflowType } from './utils';\n\n// Builds Mastra step records from the Temporal result. Iterates `stepMeta` rather than `steps`\n// because a step that returned undefined has no key in `steps` once serialized. A result without\n// `stepMeta` came from a Worker that predates it, so `steps` stays empty instead of guessing times.\nfunction toStepResults(input: unknown, { steps, stepMeta }: WorkflowExecutionResult): Record<string, unknown> {\n if (!stepMeta) {\n return {};\n }\n\n const records: Record<string, unknown> = { input };\n for (const [stepId, times] of Object.entries(stepMeta)) {\n records[stepId] = { status: 'success', output: steps[stepId], ...times };\n }\n return records;\n}\n\ntype TemporalRunStartArgs<TState, TInput, TRequestContext> = {\n inputData?: TInput;\n initialState?: TState;\n requestContext?: RequestContext<TRequestContext>;\n} & WorkflowRunStartOptions;\n\nexport class TemporalRun<\n TSteps extends Step<string, any, any, any, any, any, TemporalEngineType, any>[] = Step<\n string,\n unknown,\n unknown,\n unknown,\n unknown,\n unknown,\n TemporalEngineType\n >[],\n TState = unknown,\n TInput = unknown,\n TOutput = unknown,\n TRequestContext extends Record<string, any> | unknown = unknown,\n> extends Run<TemporalEngineType, TSteps, TState, TInput, TOutput, TRequestContext> {\n private readonly client: Client;\n private readonly taskQueue: string;\n\n constructor(\n params: ConstructorParameters<typeof Run<TemporalEngineType, TSteps, TState, TInput, TOutput, TRequestContext>>[0],\n temporalParams: {\n client: Client;\n taskQueue: string;\n },\n ) {\n super(params);\n\n this.client = temporalParams.client;\n this.taskQueue = temporalParams.taskQueue;\n }\n\n async start(args: TemporalRunStartArgs<TState, TInput, TRequestContext> = {}) {\n const input = await this._validateInput(args.inputData);\n const initialState = await this._validateInitialState(args.initialState);\n await this._validateRequestContext(args.requestContext as RequestContext<unknown> | undefined);\n\n try {\n const handle = await this.client.workflow.start(toWorkflowType(this.workflowId), {\n taskQueue: this.taskQueue,\n workflowId: this.runId,\n args: [\n {\n inputData: input,\n initialState,\n requestContext: args.requestContext ? Object.fromEntries(args.requestContext.entries()) : {},\n runId: this.runId,\n resourceId: this.resourceId,\n outputOptions: args.outputOptions,\n tracingOptions: args.tracingOptions,\n perStep: args.perStep,\n recordStepMeta: true,\n validateInputs: this.validateInputs,\n },\n ],\n });\n const result = (await handle.result()) as WorkflowExecutionResult;\n\n return {\n status: 'success',\n input: input as TInput,\n result: result.result as TOutput,\n state: initialState,\n steps: toStepResults(input, result),\n } as WorkflowResult<TState, TInput, TOutput, TSteps>;\n } catch (error) {\n return {\n status: 'failed',\n input: input as TInput,\n error: error instanceof Error ? error : new Error(String(error)),\n state: initialState,\n steps: {},\n } as WorkflowResult<TState, TInput, TOutput, TSteps>;\n }\n }\n\n async cancel() {\n await this.client.workflow.getHandle(this.runId).cancel();\n await super.cancel();\n }\n\n private unsupported(method: string): never {\n throw new Error(`@mastra/temporal does not support ${method}() yet. Use start() or startAsync() instead.`);\n }\n\n override stream(\n ..._args: Parameters<Run<TemporalEngineType, TSteps, TState, TInput, TOutput, TRequestContext>['stream']>\n ): never {\n return this.unsupported('stream');\n }\n\n override streamLegacy(\n ..._args: Parameters<Run<TemporalEngineType, TSteps, TState, TInput, TOutput, TRequestContext>['streamLegacy']>\n ): never {\n return this.unsupported('streamLegacy');\n }\n\n override resumeStream(..._args: unknown[]): never {\n return this.unsupported('resumeStream');\n }\n\n override resume(..._args: unknown[]): never {\n return this.unsupported('resume');\n }\n\n override resumeAsync(..._args: unknown[]): never {\n return this.unsupported('resumeAsync');\n }\n\n override restart(\n ..._args: Parameters<Run<TemporalEngineType, TSteps, TState, TInput, TOutput, TRequestContext>['restart']>\n ): never {\n return this.unsupported('restart');\n }\n\n override timeTravel(..._args: unknown[]): never {\n return this.unsupported('timeTravel');\n }\n\n override timeTravelStream(..._args: unknown[]): never {\n return this.unsupported('timeTravelStream');\n }\n\n async startAsync(args: TemporalRunStartArgs<TState, TInput, TRequestContext> = {}) {\n const input = await this._validateInput(args.inputData);\n const initialState = await this._validateInitialState(args.initialState);\n await this._validateRequestContext(args.requestContext as RequestContext<unknown> | undefined);\n\n await this.client.workflow.start(toWorkflowType(this.workflowId), {\n taskQueue: this.taskQueue,\n workflowId: this.runId,\n args: [\n {\n inputData: input,\n initialState,\n requestContext: args.requestContext ? Object.fromEntries(args.requestContext.entries()) : {},\n runId: this.runId,\n resourceId: this.resourceId,\n outputOptions: args.outputOptions,\n tracingOptions: args.tracingOptions,\n perStep: args.perStep,\n validateInputs: this.validateInputs,\n },\n ],\n });\n\n return { runId: this.runId };\n }\n}\n","import { Workflow, createStep } from '@mastra/core/workflows';\nimport type { Step, WorkflowConfig } from '@mastra/core/workflows';\nimport type { Client } from '@temporalio/client';\nimport type { ActivityOptions } from '@temporalio/workflow';\nimport { TemporalRun } from './run';\nimport type { TemporalEngineType } from './types';\n\nexport type TemporalWorkflowParams = {\n client: Client;\n taskQueue: string;\n startToCloseTimeout?: string;\n retry?: ActivityOptions['retry'];\n};\n\nexport class TemporalWorkflow<\n TSteps extends Step<string, any, any, any, any, any, TemporalEngineType, any>[] = Step<\n string,\n unknown,\n unknown,\n unknown,\n unknown,\n unknown,\n TemporalEngineType\n >[],\n TWorkflowId extends string = string,\n TState = unknown,\n TInput = unknown,\n TOutput = unknown,\n TPrevSchema = TInput,\n TRequestContext extends Record<string, any> | unknown = unknown,\n> extends Workflow<TemporalEngineType, TSteps, TWorkflowId, TState, TInput, TOutput, TPrevSchema, TRequestContext> {\n private readonly temporalClient: Client;\n readonly taskQueue: string;\n readonly startToCloseTimeout: string;\n\n constructor(\n params: WorkflowConfig<TWorkflowId, TState, TInput, TOutput, TSteps, TRequestContext>,\n temporalParams: TemporalWorkflowParams,\n ) {\n super(params);\n\n this.engineType = 'temporal';\n this.temporalClient = temporalParams.client;\n this.taskQueue = temporalParams.taskQueue;\n this.startToCloseTimeout = temporalParams.startToCloseTimeout ?? '1 minute';\n }\n\n async createRun(options?: { runId?: string; resourceId?: string; disableScorers?: boolean }) {\n const runId = options?.runId ?? crypto.randomUUID();\n const run = new TemporalRun<TSteps, TState, TInput, TOutput, TRequestContext>(\n {\n workflowId: this.id,\n runId,\n resourceId: options?.resourceId,\n stateSchema: this.stateSchema,\n inputSchema: this.inputSchema,\n requestContextSchema: this.requestContextSchema,\n executionEngine: this.executionEngine,\n executionGraph: this.executionGraph,\n mastra: this.mastra,\n retryConfig: this.retryConfig,\n serializedStepGraph: this.serializedStepGraph,\n disableScorers: options?.disableScorers,\n tracingPolicy: this.options.tracingPolicy,\n workflowSteps: this.steps,\n validateInputs: this.options.validateInputs,\n workflowEngineType: this.engineType,\n cleanup: undefined,\n },\n {\n client: this.temporalClient,\n taskQueue: this.taskQueue,\n },\n );\n\n this.runs.set(runId, run);\n return run;\n }\n}\n\nexport function createWorkflow<\n TSteps extends Step<string, any, any, any, any, any, TemporalEngineType, any>[] = Step<\n string,\n unknown,\n unknown,\n unknown,\n unknown,\n unknown,\n TemporalEngineType\n >[],\n TWorkflowId extends string = string,\n TState = unknown,\n TInput = unknown,\n TOutput = unknown,\n TRequestContext extends Record<string, any> | unknown = unknown,\n>(\n config: WorkflowConfig<TWorkflowId, TState, TInput, TOutput, TSteps, TRequestContext>,\n temporal: TemporalWorkflowParams,\n) {\n return new TemporalWorkflow<TSteps, TWorkflowId, TState, TInput, TOutput, TInput, TRequestContext>(config, temporal);\n}\n\nexport function init(temporalParams: TemporalWorkflowParams) {\n return {\n createWorkflow: <\n TWorkflowId extends string,\n TState = unknown,\n TInput = unknown,\n TOutput = unknown,\n TSteps extends Step[] = Step[],\n TRequestContext extends Record<string, any> | unknown = unknown,\n >(\n config: WorkflowConfig<TWorkflowId, TState, TInput, TOutput, TSteps, TRequestContext>,\n ) => createWorkflow<TSteps, TWorkflowId, TState, TInput, TOutput, TRequestContext>(config, temporalParams),\n createStep,\n };\n}\n"],"mappings":";;;AAWA,SAAS,cAAc,OAAgB,EAAE,OAAO,YAA8D;CAC5G,IAAI,CAAC,UACH,OAAO,CAAC;CAGV,MAAM,UAAmC,EAAE,MAAM;CACjD,KAAK,MAAM,CAAC,QAAQ,UAAU,OAAO,QAAQ,QAAQ,GACnD,QAAQ,UAAU;EAAE,QAAQ;EAAW,QAAQ,MAAM;EAAS,GAAG;CAAM;CAEzE,OAAO;AACT;AAQA,IAAa,cAAb,cAcU,IAA0E;CAClF;CACA;CAEA,YACE,QACA,gBAIA;EACA,MAAM,MAAM;EAEZ,KAAK,SAAS,eAAe;EAC7B,KAAK,YAAY,eAAe;CAClC;CAEA,MAAM,MAAM,OAA8D,CAAC,GAAG;EAC5E,MAAM,QAAQ,MAAM,KAAK,eAAe,KAAK,SAAS;EACtD,MAAM,eAAe,MAAM,KAAK,sBAAsB,KAAK,YAAY;EACvE,MAAM,KAAK,wBAAwB,KAAK,cAAqD;EAE7F,IAAI;GAmBF,MAAM,SA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AC7B,oBAAoB,KAAK;GACzB,SAAS,KAAA;EACX,GACA;GACE,QAAQ,KAAK;GACb,WAAW,KAAK;EAClB,CACF;EAEA,KAAK,KAAK,IAAI,OAAO,GAAG;EACxB,OAAO;CACT;AACF;AAEA,SAAgB,eAgBd,QACA,UACA;CACA,OAAO,IAAI,iBAAwF,QAAQ,QAAQ;AACrH;AAEA,SAAgB,KAAK,gBAAwC;CAC3D,OAAO;EACL,iBAQE,WACG,eAA8E,QAAQ,cAAc;EACzG;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/run.ts","../src/workflow.ts"],"sourcesContent":["import { RequestContext } from '@mastra/core/di';\nimport { Run } from '@mastra/core/workflows';\nimport type { Step, StepResult, WorkflowResult, WorkflowRunStartOptions } from '@mastra/core/workflows';\nimport { CancelledFailure, WorkflowFailedError } from '@temporalio/client';\nimport type { Client, WorkflowHandle } from '@temporalio/client';\nimport type { WorkflowExecutionResult } from './transforms/temporal-workflow-runtime';\nimport type { TemporalEngineType } from './types';\nimport { toWorkflowType } from './utils';\n\n// Builds Mastra step records from the Temporal result. Iterates `stepMeta` rather than `steps`\n// because a step that returned undefined has no key in `steps` once serialized. A result without\n// `stepMeta` came from a Worker that predates it, so `steps` stays empty instead of guessing times.\nfunction toStepResults(input: unknown, { steps, stepMeta }: WorkflowExecutionResult): Record<string, unknown> {\n if (!stepMeta) {\n return {};\n }\n\n const records: Record<string, unknown> = { input };\n for (const [stepId, times] of Object.entries(stepMeta)) {\n records[stepId] = { status: 'success', output: steps[stepId], ...times };\n }\n return records;\n}\n\ntype TemporalRunStartArgs<TState, TInput, TRequestContext> = {\n inputData?: TInput;\n initialState?: TState;\n requestContext?: RequestContext<TRequestContext>;\n} & WorkflowRunStartOptions;\n\nexport class TemporalRun<\n TSteps extends Step<string, any, any, any, any, any, TemporalEngineType, any>[] = Step<\n string,\n unknown,\n unknown,\n unknown,\n unknown,\n unknown,\n TemporalEngineType\n >[],\n TState = unknown,\n TInput = unknown,\n TOutput = unknown,\n TRequestContext extends Record<string, any> | unknown = unknown,\n> extends Run<TemporalEngineType, TSteps, TState, TInput, TOutput, TRequestContext> {\n private readonly client: Client;\n private readonly taskQueue: string;\n\n constructor(\n params: ConstructorParameters<typeof Run<TemporalEngineType, TSteps, TState, TInput, TOutput, TRequestContext>>[0],\n temporalParams: {\n client: Client;\n taskQueue: string;\n },\n ) {\n super(params);\n\n this.client = temporalParams.client;\n this.taskQueue = temporalParams.taskQueue;\n }\n\n async start(args: TemporalRunStartArgs<TState, TInput, TRequestContext> = {}) {\n const { input, initialState, requestContext } = await this.#prepareStart(args);\n\n let handle: WorkflowHandle;\n try {\n handle = await this.client.workflow.start(toWorkflowType(this.workflowId), {\n taskQueue: this.taskQueue,\n workflowId: this.runId,\n args: [\n {\n inputData: input,\n initialState,\n requestContext: Object.fromEntries(requestContext.entries()),\n runId: this.runId,\n resourceId: this.resourceId,\n outputOptions: args.outputOptions,\n tracingOptions: args.tracingOptions,\n perStep: args.perStep,\n recordStepMeta: true,\n validateInputs: this.validateInputs,\n },\n ],\n });\n } catch (error) {\n // Temporal did not start this run, for example because its id is already in use, so the\n // finish callbacks have no outcome to report.\n return this.#failedResult(error, input, initialState);\n }\n\n const result = await this.#settle(handle, input, initialState);\n await this.#invokeFinishCallbacks(result, input, requestContext);\n return result;\n }\n\n // Lifecycle hooks are closures that cannot run in the Temporal workflow sandbox, so they run\n // in the process that starts the run. onStart can change the state and request context, so\n // the caller sends both to Temporal only after it runs.\n async #prepareStart(args: TemporalRunStartArgs<TState, TInput, TRequestContext>) {\n const input = await this._validateInput(args.inputData);\n const initialState = (await this._validateInitialState(args.initialState)) ?? ({} as TState);\n await this._validateRequestContext(args.requestContext as RequestContext<unknown> | undefined);\n\n const requestContext = (args.requestContext ?? new RequestContext()) as RequestContext;\n await this.executionEngine.invokeStartCallback({\n runId: this.runId,\n workflowId: this.workflowId,\n resourceId: this.resourceId,\n getInitData: () => input,\n requestContext,\n state: initialState as Record<string, any>,\n });\n\n return { input, initialState, requestContext };\n }\n\n async #settle(\n handle: WorkflowHandle,\n input: TInput | undefined,\n initialState: TState | undefined,\n ): Promise<WorkflowResult<TState, TInput, TOutput, TSteps>> {\n try {\n const result = (await handle.result()) as WorkflowExecutionResult;\n\n return {\n status: 'success',\n input: input as TInput,\n result: result.result as TOutput,\n state: initialState,\n steps: toStepResults(input, result),\n } as WorkflowResult<TState, TInput, TOutput, TSteps>;\n } catch (error) {\n // Core reports a canceled run as `canceled` and does not call onError for it.\n if (error instanceof WorkflowFailedError && error.cause instanceof CancelledFailure) {\n return { status: 'canceled', input, state: initialState, steps: {} } as unknown as WorkflowResult<\n TState,\n TInput,\n TOutput,\n TSteps\n >;\n }\n\n return this.#failedResult(error, input, initialState);\n }\n }\n\n #failedResult(error: unknown, input: TInput | undefined, initialState: TState | undefined) {\n return {\n status: 'failed',\n input: input as TInput,\n error: error instanceof Error ? error : new Error(String(error)),\n state: initialState,\n steps: {},\n } as WorkflowResult<TState, TInput, TOutput, TSteps>;\n }\n\n #invokeFinishCallbacks(\n result: WorkflowResult<TState, TInput, TOutput, TSteps>,\n input: TInput | undefined,\n requestContext: RequestContext,\n ) {\n return this.executionEngine.invokeLifecycleCallbacks({\n status: result.status,\n result: result.status === 'success' ? result.result : undefined,\n error: result.status === 'failed' ? result.error : undefined,\n steps: result.steps as Record<string, StepResult<any, any, any, any>>,\n runId: this.runId,\n workflowId: this.workflowId,\n resourceId: this.resourceId,\n input,\n requestContext,\n state: (result.state ?? {}) as Record<string, any>,\n });\n }\n\n async cancel() {\n await this.client.workflow.getHandle(this.runId).cancel();\n await super.cancel();\n }\n\n private unsupported(method: string): never {\n throw new Error(`@mastra/temporal does not support ${method}() yet. Use start() or startAsync() instead.`);\n }\n\n override stream(\n ..._args: Parameters<Run<TemporalEngineType, TSteps, TState, TInput, TOutput, TRequestContext>['stream']>\n ): never {\n return this.unsupported('stream');\n }\n\n override streamLegacy(\n ..._args: Parameters<Run<TemporalEngineType, TSteps, TState, TInput, TOutput, TRequestContext>['streamLegacy']>\n ): never {\n return this.unsupported('streamLegacy');\n }\n\n override resumeStream(..._args: unknown[]): never {\n return this.unsupported('resumeStream');\n }\n\n override resume(..._args: unknown[]): never {\n return this.unsupported('resume');\n }\n\n override resumeAsync(..._args: unknown[]): never {\n return this.unsupported('resumeAsync');\n }\n\n override restart(\n ..._args: Parameters<Run<TemporalEngineType, TSteps, TState, TInput, TOutput, TRequestContext>['restart']>\n ): never {\n return this.unsupported('restart');\n }\n\n override timeTravel(..._args: unknown[]): never {\n return this.unsupported('timeTravel');\n }\n\n override timeTravelStream(..._args: unknown[]): never {\n return this.unsupported('timeTravelStream');\n }\n\n async startAsync(args: TemporalRunStartArgs<TState, TInput, TRequestContext> = {}) {\n const { input, initialState, requestContext } = await this.#prepareStart(args);\n const { onFinish, onError } = this.executionEngine.options;\n const hasFinishCallbacks = Boolean(onFinish || onError);\n\n const handle = await this.client.workflow.start(toWorkflowType(this.workflowId), {\n taskQueue: this.taskQueue,\n workflowId: this.runId,\n args: [\n {\n inputData: input,\n initialState,\n requestContext: Object.fromEntries(requestContext.entries()),\n runId: this.runId,\n resourceId: this.resourceId,\n outputOptions: args.outputOptions,\n tracingOptions: args.tracingOptions,\n perStep: args.perStep,\n ...(hasFinishCallbacks && { recordStepMeta: true }),\n validateInputs: this.validateInputs,\n },\n ],\n });\n\n // Best-effort, as with core startAsync(): the callbacks are lost if this process exits\n // before the workflow finishes (#24587).\n if (hasFinishCallbacks) {\n void this.#settle(handle, input, initialState).then(result =>\n this.#invokeFinishCallbacks(result, input, requestContext),\n );\n }\n\n return { runId: this.runId };\n }\n}\n","import { Workflow, createStep } from '@mastra/core/workflows';\nimport type { Step, WorkflowConfig } from '@mastra/core/workflows';\nimport type { Client } from '@temporalio/client';\nimport type { ActivityOptions } from '@temporalio/workflow';\nimport { TemporalRun } from './run';\nimport type { TemporalEngineType } from './types';\n\nexport type TemporalWorkflowParams = {\n client: Client;\n taskQueue: string;\n startToCloseTimeout?: string;\n retry?: ActivityOptions['retry'];\n};\n\nexport class TemporalWorkflow<\n TSteps extends Step<string, any, any, any, any, any, TemporalEngineType, any>[] = Step<\n string,\n unknown,\n unknown,\n unknown,\n unknown,\n unknown,\n TemporalEngineType\n >[],\n TWorkflowId extends string = string,\n TState = unknown,\n TInput = unknown,\n TOutput = unknown,\n TPrevSchema = TInput,\n TRequestContext extends Record<string, any> | unknown = unknown,\n> extends Workflow<TemporalEngineType, TSteps, TWorkflowId, TState, TInput, TOutput, TPrevSchema, TRequestContext> {\n private readonly temporalClient: Client;\n readonly taskQueue: string;\n readonly startToCloseTimeout: string;\n\n constructor(\n params: WorkflowConfig<TWorkflowId, TState, TInput, TOutput, TSteps, TRequestContext>,\n temporalParams: TemporalWorkflowParams,\n ) {\n super(params);\n\n this.engineType = 'temporal';\n this.temporalClient = temporalParams.client;\n this.taskQueue = temporalParams.taskQueue;\n this.startToCloseTimeout = temporalParams.startToCloseTimeout ?? '1 minute';\n }\n\n async createRun(options?: { runId?: string; resourceId?: string; disableScorers?: boolean }) {\n const runId = options?.runId ?? crypto.randomUUID();\n const run = new TemporalRun<TSteps, TState, TInput, TOutput, TRequestContext>(\n {\n workflowId: this.id,\n runId,\n resourceId: options?.resourceId,\n stateSchema: this.stateSchema,\n inputSchema: this.inputSchema,\n requestContextSchema: this.requestContextSchema,\n executionEngine: this.executionEngine,\n executionGraph: this.executionGraph,\n mastra: this.mastra,\n retryConfig: this.retryConfig,\n serializedStepGraph: this.serializedStepGraph,\n disableScorers: options?.disableScorers,\n tracingPolicy: this.options.tracingPolicy,\n workflowSteps: this.steps,\n validateInputs: this.options.validateInputs,\n workflowEngineType: this.engineType,\n cleanup: undefined,\n },\n {\n client: this.temporalClient,\n taskQueue: this.taskQueue,\n },\n );\n\n this.runs.set(runId, run);\n return run;\n }\n}\n\nexport function createWorkflow<\n TSteps extends Step<string, any, any, any, any, any, TemporalEngineType, any>[] = Step<\n string,\n unknown,\n unknown,\n unknown,\n unknown,\n unknown,\n TemporalEngineType\n >[],\n TWorkflowId extends string = string,\n TState = unknown,\n TInput = unknown,\n TOutput = unknown,\n TRequestContext extends Record<string, any> | unknown = unknown,\n>(\n config: WorkflowConfig<TWorkflowId, TState, TInput, TOutput, TSteps, TRequestContext>,\n temporal: TemporalWorkflowParams,\n) {\n return new TemporalWorkflow<TSteps, TWorkflowId, TState, TInput, TOutput, TInput, TRequestContext>(config, temporal);\n}\n\nexport function init(temporalParams: TemporalWorkflowParams) {\n return {\n createWorkflow: <\n TWorkflowId extends string,\n TState = unknown,\n TInput = unknown,\n TOutput = unknown,\n TSteps extends Step[] = Step[],\n TRequestContext extends Record<string, any> | unknown = unknown,\n >(\n config: WorkflowConfig<TWorkflowId, TState, TInput, TOutput, TSteps, TRequestContext>,\n ) => createWorkflow<TSteps, TWorkflowId, TState, TInput, TOutput, TRequestContext>(config, temporalParams),\n createStep,\n };\n}\n"],"mappings":";;;;;AAYA,SAAS,cAAc,OAAgB,EAAE,OAAO,YAA8D;CAC5G,IAAI,CAAC,UACH,OAAO,CAAC;CAGV,MAAM,UAAmC,EAAE,MAAM;CACjD,KAAK,MAAM,CAAC,QAAQ,UAAU,OAAO,QAAQ,QAAQ,GACnD,QAAQ,UAAU;EAAE,QAAQ;EAAW,QAAQ,MAAM;EAAS,GAAG;CAAM;CAEzE,OAAO;AACT;AAQA,IAAa,cAAb,cAcU,IAA0E;CAClF;CACA;CAEA,YACE,QACA,gBAIA;EACA,MAAM,MAAM;EAEZ,KAAK,SAAS,eAAe;EAC7B,KAAK,YAAY,eAAe;CAClC;CAEA,MAAM,MAAM,OAA8D,CAAC,GAAG;EAC5E,MAAM,EAAE,OAAO,cAAc,mBAAmB,MAAM,KAAK,cAAc,IAAI;EAE7E,IAAI;EACJ,IAAI;GACF,SAAS,MAAM,KAAK,OAAO,SAAS,MAAM,eAAe,KAAK,UAAU,GAAG;IACzE,WAAW,KAAK;IAChB,YAAY,KAAK;IACjB,MAAM,CACJ;KACE,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,CACF;EAEA,KAAK,KAAK,IAAI,OAAO,GAAG;EACxB,OAAO;CACT;AACF;AAEA,SAAgB,eAgBd,QACA,UACA;CACA,OAAO,IAAI,iBAAwF,QAAQ,QAAQ;AACrH;AAEA,SAAgB,KAAK,gBAAwC;CAC3D,OAAO;EACL,iBAQE,WACG,eAA8E,QAAQ,cAAc;EACzG;CACF;AACF"}
|
package/dist/run.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { RequestContext } from '@mastra/core/di';
|
|
2
2
|
import { Run } from '@mastra/core/workflows';
|
|
3
3
|
import type { Step, WorkflowResult, WorkflowRunStartOptions } from '@mastra/core/workflows';
|
|
4
4
|
import type { Client } from '@temporalio/client';
|
|
@@ -9,6 +9,7 @@ type TemporalRunStartArgs<TState, TInput, TRequestContext> = {
|
|
|
9
9
|
requestContext?: RequestContext<TRequestContext>;
|
|
10
10
|
} & WorkflowRunStartOptions;
|
|
11
11
|
export declare class TemporalRun<TSteps extends Step<string, any, any, any, any, any, TemporalEngineType, any>[] = Step<string, unknown, unknown, unknown, unknown, unknown, TemporalEngineType>[], TState = unknown, TInput = unknown, TOutput = unknown, TRequestContext extends Record<string, any> | unknown = unknown> extends Run<TemporalEngineType, TSteps, TState, TInput, TOutput, TRequestContext> {
|
|
12
|
+
#private;
|
|
12
13
|
private readonly client;
|
|
13
14
|
private readonly taskQueue;
|
|
14
15
|
constructor(params: ConstructorParameters<typeof Run<TemporalEngineType, TSteps, TState, TInput, TOutput, TRequestContext>>[0], temporalParams: {
|
package/dist/run.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,E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odeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
22
|
}) : target, mod));
|
|
23
23
|
const require_utils = require("./utils-BVE1AkTt.cjs");
|
|
24
24
|
let _mastra_core_workflows = require("@mastra/core/workflows");
|
|
25
|
+
let _mastra_core_di = require("@mastra/core/di");
|
|
25
26
|
let fs = require("fs");
|
|
26
27
|
let fs_promises = require("fs/promises");
|
|
27
28
|
let path = require("path");
|
|
28
29
|
path = __toESM(path, 1);
|
|
29
30
|
let url = require("url");
|
|
30
|
-
let _mastra_core_di = require("@mastra/core/di");
|
|
31
31
|
let _mastra_core_error = require("@mastra/core/error");
|
|
32
32
|
let _mastra_core_schema = require("@mastra/core/schema");
|
|
33
33
|
let _temporalio_activity = require("@temporalio/activity");
|
package/dist/worker.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { t as toWorkflowType } from "./utils-R6cB86BM.js";
|
|
2
2
|
import { builtinModules } from "module";
|
|
3
3
|
import { validateStepInput, validateStepRequestContext } from "@mastra/core/workflows";
|
|
4
|
+
import { RequestContext } from "@mastra/core/di";
|
|
4
5
|
import { readFileSync } from "fs";
|
|
5
6
|
import { writeFile } from "fs/promises";
|
|
6
7
|
import path, { basename, join } from "path";
|
|
7
8
|
import { fileURLToPath, pathToFileURL } from "url";
|
|
8
|
-
import { RequestContext } from "@mastra/core/di";
|
|
9
9
|
import { MastraError } from "@mastra/core/error";
|
|
10
10
|
import { toStandardSchema } from "@mastra/core/schema";
|
|
11
11
|
import { ApplicationFailure } from "@temporalio/activity";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/temporal",
|
|
3
|
-
"version": "0.5.0-alpha.
|
|
3
|
+
"version": "0.5.0-alpha.2",
|
|
4
4
|
"description": "Mastra Temporal workflows integration - run Mastra workflows on the Temporal durable execution platform",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"@temporalio/worker": "^1.24.0",
|
|
51
51
|
"@temporalio/workflow": "^1.24.0",
|
|
52
52
|
"rollup": "^4.65.0",
|
|
53
|
-
"@mastra/deployer": "1.82.0-alpha.
|
|
53
|
+
"@mastra/deployer": "1.82.0-alpha.2"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
56
|
"@mastra/core": ">=1.81.0-0 <2.0.0-0",
|
|
@@ -63,10 +63,10 @@
|
|
|
63
63
|
"vitest": "4.1.12",
|
|
64
64
|
"webpack": "^5.112.2",
|
|
65
65
|
"zod": "^4.6.7",
|
|
66
|
-
"@internal/lint": "0.0.147",
|
|
67
|
-
"@internal/types-builder": "0.0.122",
|
|
68
66
|
"@internal/workflow-test-utils": "0.0.31",
|
|
69
|
-
"@
|
|
67
|
+
"@internal/types-builder": "0.0.122",
|
|
68
|
+
"@internal/lint": "0.0.147",
|
|
69
|
+
"@mastra/core": "1.82.0-alpha.2"
|
|
70
70
|
},
|
|
71
71
|
"homepage": "https://mastra.ai",
|
|
72
72
|
"repository": {
|