@mastra/temporal 0.4.6-alpha.0 → 0.4.6-alpha.6
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 +27 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -1
- package/dist/run.d.ts +9 -0
- package/dist/run.d.ts.map +1 -1
- package/dist/temporal-workflow-runtime.mjs +22 -12
- package/dist/transforms/activities.d.ts.map +1 -1
- package/dist/transforms/temporal-workflow-runtime.d.mts +8 -1
- package/dist/transforms/temporal-workflow-runtime.d.mts.map +1 -1
- package/dist/transforms/workflows.d.ts.map +1 -1
- package/dist/worker.cjs +110 -11
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.js +110 -11
- package/dist/worker.js.map +1 -1
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -49,6 +49,33 @@ var TemporalRun = class extends _mastra_core_workflows.Run {
|
|
|
49
49
|
await this.client.workflow.getHandle(this.runId).cancel();
|
|
50
50
|
await super.cancel();
|
|
51
51
|
}
|
|
52
|
+
unsupported(method) {
|
|
53
|
+
throw new Error(`@mastra/temporal does not support ${method}() yet. Use start() or startAsync() instead.`);
|
|
54
|
+
}
|
|
55
|
+
stream(..._args) {
|
|
56
|
+
return this.unsupported("stream");
|
|
57
|
+
}
|
|
58
|
+
streamLegacy(..._args) {
|
|
59
|
+
return this.unsupported("streamLegacy");
|
|
60
|
+
}
|
|
61
|
+
resumeStream(..._args) {
|
|
62
|
+
return this.unsupported("resumeStream");
|
|
63
|
+
}
|
|
64
|
+
resume(..._args) {
|
|
65
|
+
return this.unsupported("resume");
|
|
66
|
+
}
|
|
67
|
+
resumeAsync(..._args) {
|
|
68
|
+
return this.unsupported("resumeAsync");
|
|
69
|
+
}
|
|
70
|
+
restart(..._args) {
|
|
71
|
+
return this.unsupported("restart");
|
|
72
|
+
}
|
|
73
|
+
timeTravel(..._args) {
|
|
74
|
+
return this.unsupported("timeTravel");
|
|
75
|
+
}
|
|
76
|
+
timeTravelStream(..._args) {
|
|
77
|
+
return this.unsupported("timeTravelStream");
|
|
78
|
+
}
|
|
52
79
|
async startAsync(args = {}) {
|
|
53
80
|
const input = await this._validateInput(args.inputData);
|
|
54
81
|
const initialState = await this._validateInitialState(args.initialState);
|
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 { TemporalEngineType } from './types';\nimport { toWorkflowType } from './utils';\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 },\n ],\n });\n const result = await handle.result();\n\n return {\n status: 'success',\n input: input as TInput,\n result: result as TOutput,\n state: initialState,\n steps: {},\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 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 },\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 { TemporalRun } from './run';\nimport type { TemporalEngineType } from './types';\n\nexport type TemporalWorkflowParams = {\n client: Client;\n taskQueue: string;\n startToCloseTimeout?: string;\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":";;;;AAaA,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,cAAqD;EAE7F,IAAI;GAmBF,OAAO;IACL,QAAQ;IACD;IACP,QAAQ,OALW,MAhBA,KAAK,OAAO,SAAS,MAAMC,cAAAA,eAAe,KAAK,UAAU,GAAG;KAC/E,WAAW,KAAK;KAChB,YAAY,KAAK;KACjB,MAAM,CACJ;MACE,WAAW;MACX;MACA,gBAAgB,KAAK,iBAAiB,OAAO,YAAY,KAAK,eAAe,QAAQ,CAAC,IAAI,CAAC;MAC3F,OAAO,KAAK;MACZ,YAAY,KAAK;MACjB,eAAe,KAAK;MACpB,gBAAgB,KAAK;MACrB,SAAS,KAAK;KAChB,CACF;IACF,CAAC,EAAA,CAC2B,OAAO;IAMjC,OAAO;IACP,OAAO,CAAC;GACV;EACF,SAAS,OAAO;GACd,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B,gBAAgB,KAAK;GACrB,QAAQ,KAAK;GACb,aAAa,KAAK;GAClB,qBAAqB,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"}
|
|
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 { TemporalEngineType } from './types';\nimport { toWorkflowType } from './utils';\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 },\n ],\n });\n const result = await handle.result();\n\n return {\n status: 'success',\n input: input as TInput,\n result: result as TOutput,\n state: initialState,\n steps: {},\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 },\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 { TemporalRun } from './run';\nimport type { TemporalEngineType } from './types';\n\nexport type TemporalWorkflowParams = {\n client: Client;\n taskQueue: string;\n startToCloseTimeout?: string;\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":";;;;AAaA,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,cAAqD;EAE7F,IAAI;GAmBF,OAAO;IACL,QAAQ;IACD;IACP,QAAQ,OALW,MAhBA,KAAK,OAAO,SAAS,MAAMC,cAAAA,eAAe,KAAK,UAAU,GAAG;KAC/E,WAAW,KAAK;KAChB,YAAY,KAAK;KACjB,MAAM,CACJ;MACE,WAAW;MACX;MACA,gBAAgB,KAAK,iBAAiB,OAAO,YAAY,KAAK,eAAe,QAAQ,CAAC,IAAI,CAAC;MAC3F,OAAO,KAAK;MACZ,YAAY,KAAK;MACjB,eAAe,KAAK;MACpB,gBAAgB,KAAK;MACrB,SAAS,KAAK;KAChB,CACF;IACF,CAAC,EAAA,CAC2B,OAAO;IAMjC,OAAO;IACP,OAAO,CAAC;GACV;EACF,SAAS,OAAO;GACd,OAAO;IACL,QAAQ;IACD;IACP,OAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC;IAC/D,OAAO;IACP,OAAO,CAAC;GACV;EACF;CACF;CAEA,MAAM,SAAS;EACb,MAAM,KAAK,OAAO,SAAS,UAAU,KAAK,KAAK,CAAC,CAAC,OAAO;EACxD,MAAM,MAAM,OAAO;CACrB;CAEA,YAAoB,QAAuB;EACzC,MAAM,IAAI,MAAM,qCAAqC,OAAO,6CAA6C;CAC3G;CAEA,OACE,GAA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uBAAuB;CACnE;CAEA,MAAM,UAAU,SAA6E;EAC3F,MAAM,QAAQ,SAAS,SAAS,OAAO,WAAW;EAClD,MAAM,MAAM,IAAI,YACd;GACE,YAAY,KAAK;GACjB;GACA,YAAY,SAAS;GACrB,aAAa,KAAK;GAClB,aAAa,KAAK;GAClB,sBAAsB,KAAK;GAC3B,iBAAiB,KAAK;GACtB,gBAAgB,KAAK;GACrB,QAAQ,KAAK;GACb,aAAa,KAAK;GAClB,qBAAqB,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
|
@@ -48,6 +48,33 @@ var TemporalRun = class extends Run {
|
|
|
48
48
|
await this.client.workflow.getHandle(this.runId).cancel();
|
|
49
49
|
await super.cancel();
|
|
50
50
|
}
|
|
51
|
+
unsupported(method) {
|
|
52
|
+
throw new Error(`@mastra/temporal does not support ${method}() yet. Use start() or startAsync() instead.`);
|
|
53
|
+
}
|
|
54
|
+
stream(..._args) {
|
|
55
|
+
return this.unsupported("stream");
|
|
56
|
+
}
|
|
57
|
+
streamLegacy(..._args) {
|
|
58
|
+
return this.unsupported("streamLegacy");
|
|
59
|
+
}
|
|
60
|
+
resumeStream(..._args) {
|
|
61
|
+
return this.unsupported("resumeStream");
|
|
62
|
+
}
|
|
63
|
+
resume(..._args) {
|
|
64
|
+
return this.unsupported("resume");
|
|
65
|
+
}
|
|
66
|
+
resumeAsync(..._args) {
|
|
67
|
+
return this.unsupported("resumeAsync");
|
|
68
|
+
}
|
|
69
|
+
restart(..._args) {
|
|
70
|
+
return this.unsupported("restart");
|
|
71
|
+
}
|
|
72
|
+
timeTravel(..._args) {
|
|
73
|
+
return this.unsupported("timeTravel");
|
|
74
|
+
}
|
|
75
|
+
timeTravelStream(..._args) {
|
|
76
|
+
return this.unsupported("timeTravelStream");
|
|
77
|
+
}
|
|
51
78
|
async startAsync(args = {}) {
|
|
52
79
|
const input = await this._validateInput(args.inputData);
|
|
53
80
|
const initialState = await this._validateInitialState(args.initialState);
|
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 { TemporalEngineType } from './types';\nimport { toWorkflowType } from './utils';\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 },\n ],\n });\n const result = await handle.result();\n\n return {\n status: 'success',\n input: input as TInput,\n result: result as TOutput,\n state: initialState,\n steps: {},\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 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 },\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 { TemporalRun } from './run';\nimport type { TemporalEngineType } from './types';\n\nexport type TemporalWorkflowParams = {\n client: Client;\n taskQueue: string;\n startToCloseTimeout?: string;\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":";;;AAaA,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,OAAO;IACL,QAAQ;IACD;IACP,QAAQ,OALW,MAhBA,KAAK,OAAO,SAAS,MAAM,eAAe,KAAK,UAAU,GAAG;KAC/E,WAAW,KAAK;KAChB,YAAY,KAAK;KACjB,MAAM,CACJ;MACE,WAAW;MACX;MACA,gBAAgB,KAAK,iBAAiB,OAAO,YAAY,KAAK,eAAe,QAAQ,CAAC,IAAI,CAAC;MAC3F,OAAO,KAAK;MACZ,YAAY,KAA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MAAM,IAAI,YACd;GACE,YAAY,KAAK;GACjB;GACA,YAAY,SAAS;GACrB,aAAa,KAAK;GAClB,aAAa,KAAK;GAClB,sBAAsB,KAAK;GAC3B,iBAAiB,KAAK;GACtB,gBAAgB,KAAK;GACrB,QAAQ,KAAK;GACb,aAAa,KAAK;GAClB,qBAAqB,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;CACF;AACF"}
|
|
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 { TemporalEngineType } from './types';\nimport { toWorkflowType } from './utils';\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 },\n ],\n });\n const result = await handle.result();\n\n return {\n status: 'success',\n input: input as TInput,\n result: result as TOutput,\n state: initialState,\n steps: {},\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 },\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 { TemporalRun } from './run';\nimport type { TemporalEngineType } from './types';\n\nexport type TemporalWorkflowParams = {\n client: Client;\n taskQueue: string;\n startToCloseTimeout?: string;\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":";;;AAaA,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,OAAO;IACL,QAAQ;IACD;IACP,QAAQ,OALW,MAhBA,KAAK,OAAO,SAAS,MAAM,eAAe,KAAK,UAAU,GAAG;KAC/E,WAAW,KAAK;KAChB,YAAY,KAAK;KACjB,MAAM,CACJ;MACE,WAAW;MACX;MACA,gBAAgB,KAAK,iBAAiB,OAAO,YAAY,KAAK,eAAe,QAAQ,CAAC,IAAI,CAAC;MAC3F,OAAO,KAAK;MACZ,YAAY,KAAK;MACjB,eAAe,KAAK;MACpB,gBAAgB,KAAK;MACrB,SAAS,KAAK;KAChB,CACF;IACF,CAAC,EAAA,CAC2B,OAAO;IAMjC,OAAO;IACP,OAAO,CAAC;GACV;EACF,SAAS,OAAO;GACd,OAAO;IACL,QAAQ;IACD;IACP,OAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC;IAC/D,OAAO;IACP,OAAO,CAAC;GACV;EACF;CACF;CAEA,MAAM,SAAS;EACb,MAAM,KAAK,OAAO,SAAS,UAAU,KAAK,KAAK,CAAC,CAAC,OAAO;EACxD,MAAM,MAAM,OAAO;CACrB;CAEA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,iBAAiB,eAAe;EACrC,KAAK,YAAY,eAAe;EAChC,KAAK,sBAAsB,eAAe,uBAAuB;CACnE;CAEA,MAAM,UAAU,SAA6E;EAC3F,MAAM,QAAQ,SAAS,SAAS,OAAO,WAAW;EAClD,MAAM,MAAM,IAAI,YACd;GACE,YAAY,KAAK;GACjB;GACA,YAAY,SAAS;GACrB,aAAa,KAAK;GAClB,aAAa,KAAK;GAClB,sBAAsB,KAAK;GAC3B,iBAAiB,KAAK;GACtB,gBAAgB,KAAK;GACrB,QAAQ,KAAK;GACb,aAAa,KAAK;GAClB,qBAAqB,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;CACF;AACF"}
|
package/dist/run.d.ts
CHANGED
|
@@ -17,6 +17,15 @@ export declare class TemporalRun<TSteps extends Step<string, any, any, any, any,
|
|
|
17
17
|
});
|
|
18
18
|
start(args?: TemporalRunStartArgs<TState, TInput, TRequestContext>): Promise<WorkflowResult<TState, TInput, TOutput, TSteps>>;
|
|
19
19
|
cancel(): Promise<void>;
|
|
20
|
+
private unsupported;
|
|
21
|
+
stream(..._args: Parameters<Run<TemporalEngineType, TSteps, TState, TInput, TOutput, TRequestContext>['stream']>): never;
|
|
22
|
+
streamLegacy(..._args: Parameters<Run<TemporalEngineType, TSteps, TState, TInput, TOutput, TRequestContext>['streamLegacy']>): never;
|
|
23
|
+
resumeStream(..._args: unknown[]): never;
|
|
24
|
+
resume(..._args: unknown[]): never;
|
|
25
|
+
resumeAsync(..._args: unknown[]): never;
|
|
26
|
+
restart(..._args: Parameters<Run<TemporalEngineType, TSteps, TState, TInput, TOutput, TRequestContext>['restart']>): never;
|
|
27
|
+
timeTravel(..._args: unknown[]): never;
|
|
28
|
+
timeTravelStream(..._args: unknown[]): never;
|
|
20
29
|
startAsync(args?: TemporalRunStartArgs<TState, TInput, TRequestContext>): Promise<{
|
|
21
30
|
runId: string;
|
|
22
31
|
}>;
|
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,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,GAAG,EAAE,MAAM,wBAAwB,CAAC;AAC7C,OAAO,KAAK,EAAE,IAAI,EAAE,cAAc,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAC5F,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAGlD,KAAK,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,eAAe,IAAI;IAC3D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,CAAC,EAAE,cAAc,CAAC,eAAe,CAAC,CAAC;CAClD,GAAG,uBAAuB,CAAC;AAE5B,qBAAa,WAAW,CACtB,MAAM,SAAS,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,kBAAkB,EAAE,GAAG,CAAC,EAAE,GAAG,IAAI,CACpF,MAAM,EACN,OAAO,EACP,OAAO,EACP,OAAO,EACP,OAAO,EACP,OAAO,EACP,kBAAkB,CACnB,EAAE,EACH,MAAM,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eAAe,CAAC,CAAC,QAAQ,CAAC,CAAC,GACxG,KAAK,CAEP;IAEQ,YAAY,CACnB,GAAG,KAAK,EAAE,UAAU,CAAC,GAAG,CAAC,kBAAkB,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,CAAC,CAAC,cAAc,CAAC,CAAC,GAC9G,KAAK,CAEP;IAEQ,YAAY,CAAC,GAAG,KAAK,EAAE,OAAO,EAAE,GAAG,KAAK,CAEhD;IAEQ,MAAM,CAAC,GAAG,KAAK,EAAE,OAAO,EAAE,GAAG,KAAK,CAE1C;IAEQ,WAAW,CAAC,GAAG,KAAK,EAAE,OAAO,EAAE,GAAG,KAAK,CAE/C;IAEQ,OAAO,CACd,GAAG,KAAK,EAAE,UAAU,CAAC,GAAG,CAAC,kBAAkB,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,CAAC,CAAC,SAAS,CAAC,CAAC,GACzG,KAAK,CAEP;IAEQ,UAAU,CAAC,GAAG,KAAK,EAAE,OAAO,EAAE,GAAG,KAAK,CAE9C;IAEQ,gBAAgB,CAAC,GAAG,KAAK,EAAE,OAAO,EAAE,GAAG,KAAK,CAEpD;IAEK,UAAU,CAAC,IAAI,GAAE,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,eAAe,CAAM;;OAuBhF;CACF"}
|
|
@@ -44,6 +44,13 @@ export class TemporalExecutionEngine {
|
|
|
44
44
|
return out;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
case 'mapping': {
|
|
48
|
+
log.info('mapping', { mappingId: entry.id });
|
|
49
|
+
const out = await this.activityHandle[entry.id]({ inputData, initData: this.initData });
|
|
50
|
+
stepResults[entry.id] = out;
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
|
|
47
54
|
case 'sleep': {
|
|
48
55
|
const duration = entry.duration ?? (entry.fn ? await this.activityHandle[entry.fn]({ inputData }) : 0);
|
|
49
56
|
log.info('sleep', { id: entry.id, duration });
|
|
@@ -65,13 +72,14 @@ export class TemporalExecutionEngine {
|
|
|
65
72
|
}
|
|
66
73
|
|
|
67
74
|
case 'parallel': {
|
|
68
|
-
|
|
69
|
-
|
|
75
|
+
const entryId = parallelEntry =>
|
|
76
|
+
parallelEntry.type === 'childWorkflow' ? parallelEntry.workflowType : parallelEntry.step.id;
|
|
77
|
+
log.info('parallel', { steps: entry.steps.map(entryId) });
|
|
78
|
+
const results = await Promise.all(entry.steps.map(step => this.executeEntry(step, inputData, stepResults)));
|
|
70
79
|
const out = {};
|
|
71
80
|
|
|
72
|
-
entry.steps.forEach((
|
|
73
|
-
out[
|
|
74
|
-
stepResults[s.step.id] = results[i];
|
|
81
|
+
entry.steps.forEach((step, i) => {
|
|
82
|
+
out[entryId(step)] = results[i];
|
|
75
83
|
});
|
|
76
84
|
|
|
77
85
|
return out;
|
|
@@ -187,6 +195,13 @@ export function createWorkflow(workflowId, options) {
|
|
|
187
195
|
});
|
|
188
196
|
return workflow;
|
|
189
197
|
},
|
|
198
|
+
map(mappingId) {
|
|
199
|
+
stepFlow.push({
|
|
200
|
+
type: 'mapping',
|
|
201
|
+
id: mappingId,
|
|
202
|
+
});
|
|
203
|
+
return workflow;
|
|
204
|
+
},
|
|
190
205
|
sleep(durationOrFnId) {
|
|
191
206
|
if (typeof durationOrFnId === 'number') {
|
|
192
207
|
stepFlow.push({
|
|
@@ -225,15 +240,10 @@ export function createWorkflow(workflowId, options) {
|
|
|
225
240
|
}
|
|
226
241
|
return workflow;
|
|
227
242
|
},
|
|
228
|
-
parallel(
|
|
243
|
+
parallel(entries) {
|
|
229
244
|
stepFlow.push({
|
|
230
245
|
type: 'parallel',
|
|
231
|
-
steps:
|
|
232
|
-
type: 'step',
|
|
233
|
-
step: {
|
|
234
|
-
id,
|
|
235
|
-
},
|
|
236
|
-
})),
|
|
246
|
+
steps: entries,
|
|
237
247
|
});
|
|
238
248
|
return workflow;
|
|
239
249
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"activities.d.ts","sourceRoot":"","sources":["../../src/transforms/activities.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"activities.d.ts","sourceRoot":"","sources":["../../src/transforms/activities.ts"],"names":[],"mappings":"AA0BA,MAAM,WAAW,uBAAuB;IACtC,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,mCAAmC;IAClD,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,EAAE,uBAAuB,EAAE,CAAC;CAC7C;AAED,wBAAgB,+BAA+B,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,uBAAuB,EAAE,CAmE/G;AAmRD,wBAAsB,6BAA6B,CACjD,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,MAAM,EACvB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,mCAAmC,CAAC,CAoY9C"}
|
|
@@ -33,6 +33,13 @@ export declare function createWorkflow(workflowId: any, options: any): ((startAr
|
|
|
33
33
|
state: any;
|
|
34
34
|
steps: {};
|
|
35
35
|
}>;
|
|
36
|
+
map(mappingId: any): (startArgs: any) => Promise<{
|
|
37
|
+
status: string;
|
|
38
|
+
input: any;
|
|
39
|
+
result: any;
|
|
40
|
+
state: any;
|
|
41
|
+
steps: {};
|
|
42
|
+
}>;
|
|
36
43
|
sleep(durationOrFnId: any): (startArgs: any) => Promise<{
|
|
37
44
|
status: string;
|
|
38
45
|
input: any;
|
|
@@ -47,7 +54,7 @@ export declare function createWorkflow(workflowId: any, options: any): ((startAr
|
|
|
47
54
|
state: any;
|
|
48
55
|
steps: {};
|
|
49
56
|
}>;
|
|
50
|
-
parallel(
|
|
57
|
+
parallel(entries: any): (startArgs: any) => Promise<{
|
|
51
58
|
status: string;
|
|
52
59
|
input: any;
|
|
53
60
|
result: any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"temporal-workflow-runtime.d.mts","sourceRoot":"","sources":["../../src/transforms/temporal-workflow-runtime.mjs"],"names":[],"mappings":"AAEA,qBAAa,uBAAuB;IAU3B,QAAQ;IATf,mBAAmB,MAAC;IACpB,cAAc,wGAAC;IAEf,YAAY,MAAM,KAAA,EAGjB;IAEK,OAAO,CAAC,MAAM,KAAA;;;;;;OAgBnB;IAEK,YAAY,CAAC,KAAK,KAAA,EAAE,SAAS,KAAA,EAAE,WAAW,KAAA,
|
|
1
|
+
{"version":3,"file":"temporal-workflow-runtime.d.mts","sourceRoot":"","sources":["../../src/transforms/temporal-workflow-runtime.mjs"],"names":[],"mappings":"AAEA,qBAAa,uBAAuB;IAU3B,QAAQ;IATf,mBAAmB,MAAC;IACpB,cAAc,wGAAC;IAEf,YAAY,MAAM,KAAA,EAGjB;IAEK,OAAO,CAAC,MAAM,KAAA;;;;;;OAgBnB;IAEK,YAAY,CAAC,KAAK,KAAA,EAAE,SAAS,KAAA,EAAE,WAAW,KAAA,gBA+H/C;CACF;AAED,wBAAgB,cAAc,CAAC,UAAU,KAAA,EAAE,OAAO,KAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmJjD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflows.d.ts","sourceRoot":"","sources":["../../src/transforms/workflows.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"workflows.d.ts","sourceRoot":"","sources":["../../src/transforms/workflows.ts"],"names":[],"mappings":"AAufA,MAAM,WAAW,4BAA4B;CAE5C;AAED,MAAM,WAAW,sBAAsB;IACrC,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,iCAAiC;IAChD,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,sBAAsB,EAAE,CAAC;CACrC;AAyUD;;;;;GAKG;AACH,wBAAsB,2BAA2B,CAC/C,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,MAAM,EACvB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC,CAwCjC"}
|
package/dist/worker.cjs
CHANGED
|
@@ -301,6 +301,80 @@ function rebaseModulePath(modulePath, sourceFilePath, outputFilePath) {
|
|
|
301
301
|
const resolvedPath = path.default.resolve(path.default.dirname(sourceFilePath), modulePath);
|
|
302
302
|
return normalizeImportPath(path.default.relative(path.default.dirname(outputFilePath), resolvedPath), path.default.extname(resolvedPath));
|
|
303
303
|
}
|
|
304
|
+
function parseWorkflowChain$1(node) {
|
|
305
|
+
const methods = [];
|
|
306
|
+
let current = node;
|
|
307
|
+
while (_babel_types.isCallExpression(current) && _babel_types.isMemberExpression(current.callee) && !current.callee.computed) {
|
|
308
|
+
if (!_babel_types.isIdentifier(current.callee.property)) return null;
|
|
309
|
+
methods.unshift({
|
|
310
|
+
name: current.callee.property.name,
|
|
311
|
+
args: current.arguments
|
|
312
|
+
});
|
|
313
|
+
current = current.callee.object;
|
|
314
|
+
}
|
|
315
|
+
if (!_babel_types.isCallExpression(current) || !_babel_types.isIdentifier(current.callee, { name: "createWorkflow" })) return null;
|
|
316
|
+
return {
|
|
317
|
+
createWorkflowCall: current,
|
|
318
|
+
methods
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
function getStaticWorkflowId(call, filePath) {
|
|
322
|
+
const [config] = call.arguments;
|
|
323
|
+
if (!_babel_types.isObjectExpression(config)) throw new Error(`Unable to determine workflow config in ${filePath}`);
|
|
324
|
+
for (const property of config.properties) {
|
|
325
|
+
if (!_babel_types.isObjectProperty(property) || getObjectPropertyName(property) !== "id") continue;
|
|
326
|
+
if (_babel_types.isStringLiteral(property.value)) return property.value.value;
|
|
327
|
+
if (_babel_types.isTemplateLiteral(property.value) && property.value.expressions.length === 0) return property.value.quasis[0]?.value.cooked ?? "";
|
|
328
|
+
}
|
|
329
|
+
throw new Error(`Workflow id must be a static string in ${filePath}`);
|
|
330
|
+
}
|
|
331
|
+
function toExportName(id) {
|
|
332
|
+
return id.replace(/[^a-zA-Z0-9]+(.)/g, (_match, char) => char.toUpperCase()).replace(/^[^a-zA-Z_$]+/, "").replace(/^(.)/, (char) => char.toLowerCase());
|
|
333
|
+
}
|
|
334
|
+
function collectStaticFunctionBindings(program) {
|
|
335
|
+
const bindings = /* @__PURE__ */ new Set();
|
|
336
|
+
for (const statement of program.body) {
|
|
337
|
+
const declaration = _babel_types.isExportNamedDeclaration(statement) ? statement.declaration : statement;
|
|
338
|
+
if (_babel_types.isFunctionDeclaration(declaration) && declaration.id) {
|
|
339
|
+
bindings.add(declaration.id.name);
|
|
340
|
+
continue;
|
|
341
|
+
}
|
|
342
|
+
if (!_babel_types.isVariableDeclaration(declaration) || declaration.kind !== "const") continue;
|
|
343
|
+
for (const declarator of declaration.declarations) if (_babel_types.isIdentifier(declarator.id) && (_babel_types.isArrowFunctionExpression(declarator.init) || _babel_types.isFunctionExpression(declarator.init))) bindings.add(declarator.id.name);
|
|
344
|
+
}
|
|
345
|
+
return bindings;
|
|
346
|
+
}
|
|
347
|
+
function collectTopLevelBindingNames(program) {
|
|
348
|
+
const bindings = /* @__PURE__ */ new Set();
|
|
349
|
+
for (const statement of program.body) for (const name of Object.keys(_babel_types.getBindingIdentifiers(statement))) bindings.add(name);
|
|
350
|
+
return bindings;
|
|
351
|
+
}
|
|
352
|
+
function createMappingActivityStatements(workflowExpression, filePath, staticFunctionBindings, usedExportNames, addBinding) {
|
|
353
|
+
const chain = parseWorkflowChain$1(workflowExpression);
|
|
354
|
+
if (!chain) return [];
|
|
355
|
+
const workflowId = getStaticWorkflowId(chain.createWorkflowCall, filePath);
|
|
356
|
+
const statements = [];
|
|
357
|
+
let mappingOrdinal = 0;
|
|
358
|
+
for (const method of chain.methods) {
|
|
359
|
+
if (method.name !== "map") continue;
|
|
360
|
+
const [callback] = method.args;
|
|
361
|
+
if (_babel_types.isObjectExpression(callback)) throw new Error(`.map() in workflow ${workflowId} (${filePath}) does not yet support declarative object mappings`);
|
|
362
|
+
if (!_babel_types.isArrowFunctionExpression(callback) && !_babel_types.isFunctionExpression(callback) && !(_babel_types.isIdentifier(callback) && staticFunctionBindings.has(callback.name))) throw new Error(`.map() in workflow ${workflowId} (${filePath}) requires an inline function or a statically declared function identifier`);
|
|
363
|
+
const mappingId = `mapping_${workflowId}_${mappingOrdinal++}`;
|
|
364
|
+
const baseExportName = toExportName(mappingId);
|
|
365
|
+
let exportName = baseExportName;
|
|
366
|
+
let exportSuffix = 1;
|
|
367
|
+
while (usedExportNames.has(exportName)) exportName = `${baseExportName}${exportSuffix++}`;
|
|
368
|
+
usedExportNames.add(exportName);
|
|
369
|
+
const params = _babel_types.objectPattern([_babel_types.objectProperty(_babel_types.identifier("inputData"), _babel_types.identifier("inputData"), false, true), _babel_types.objectProperty(_babel_types.identifier("initData"), _babel_types.identifier("initData"), false, true)]);
|
|
370
|
+
const callbackContext = _babel_types.objectExpression([_babel_types.objectProperty(_babel_types.identifier("inputData"), _babel_types.identifier("inputData"), false, true), _babel_types.objectProperty(_babel_types.identifier("getInitData"), _babel_types.arrowFunctionExpression([], _babel_types.identifier("initData")))]);
|
|
371
|
+
const callbackExpression = _babel_types.cloneNode(callback, true);
|
|
372
|
+
const body = _babel_types.callExpression(callbackExpression, [callbackContext]);
|
|
373
|
+
statements.push(_babel_types.exportNamedDeclaration(_babel_types.variableDeclaration("const", [_babel_types.variableDeclarator(_babel_types.identifier(exportName), _babel_types.arrowFunctionExpression([params], body, true))])));
|
|
374
|
+
addBinding(exportName, mappingId);
|
|
375
|
+
}
|
|
376
|
+
return statements;
|
|
377
|
+
}
|
|
304
378
|
function collectWorkflowBindingNames(ast) {
|
|
305
379
|
const workflowNames = /* @__PURE__ */ new Set();
|
|
306
380
|
for (const statement of ast.program.body) {
|
|
@@ -360,15 +434,18 @@ function createTemporalActivitiesHelperStatements(mastraImportPath, hasMastraBin
|
|
|
360
434
|
async function buildTemporalActivitiesModule(entryFile, outputDirectory, outputFileName) {
|
|
361
435
|
const activityBindings = [];
|
|
362
436
|
const seenActivityBindingNames = /* @__PURE__ */ new Set();
|
|
363
|
-
const
|
|
364
|
-
|
|
365
|
-
if (!stepId || seenActivityBindingNames.has(exportName)) return;
|
|
437
|
+
const addGeneratedActivityBinding = (exportName, stepId) => {
|
|
438
|
+
if (seenActivityBindingNames.has(exportName)) return;
|
|
366
439
|
seenActivityBindingNames.add(exportName);
|
|
367
440
|
activityBindings.push({
|
|
368
441
|
exportName,
|
|
369
442
|
stepId
|
|
370
443
|
});
|
|
371
444
|
};
|
|
445
|
+
const addActivityBinding = (exportName, call) => {
|
|
446
|
+
const stepId = getCreateStepId(call);
|
|
447
|
+
if (stepId) addGeneratedActivityBinding(exportName, stepId);
|
|
448
|
+
};
|
|
372
449
|
const bundle = await (0, rollup.rollup)({
|
|
373
450
|
input: entryFile,
|
|
374
451
|
treeshake: "smallest",
|
|
@@ -386,6 +463,8 @@ async function buildTemporalActivitiesModule(entryFile, outputDirectory, outputF
|
|
|
386
463
|
const strippedNames = /* @__PURE__ */ new Set();
|
|
387
464
|
const workflowBindingNames = collectWorkflowBindingNames(ast);
|
|
388
465
|
const stepFactoryBindings = collectCreateStepFactoryBindings(ast.program);
|
|
466
|
+
const staticFunctionBindings = collectStaticFunctionBindings(ast.program);
|
|
467
|
+
const usedExportNames = collectTopLevelBindingNames(ast.program);
|
|
389
468
|
const sourceFilePath = id;
|
|
390
469
|
const hasMastraBinding = hasLocalMastraBinding(ast);
|
|
391
470
|
let helperInserted = false;
|
|
@@ -447,6 +526,7 @@ async function buildTemporalActivitiesModule(entryFile, outputDirectory, outputF
|
|
|
447
526
|
if (hasCreateWorkflowCall(declaration.init)) {
|
|
448
527
|
workflowBindingNames.add(declaration.id.name);
|
|
449
528
|
strippedNames.add(declaration.id.name);
|
|
529
|
+
statements.push(...createMappingActivityStatements(declaration.init, sourceFilePath, staticFunctionBindings, usedExportNames, addGeneratedActivityBinding));
|
|
450
530
|
collectInlineCreateSteps(declaration.init, seenNames, statements, addActivityBinding);
|
|
451
531
|
continue;
|
|
452
532
|
}
|
|
@@ -486,6 +566,7 @@ async function buildTemporalActivitiesModule(entryFile, outputDirectory, outputF
|
|
|
486
566
|
if (hasCreateWorkflowCall(declaration.init)) {
|
|
487
567
|
workflowBindingNames.add(declaration.id.name);
|
|
488
568
|
strippedNames.add(declaration.id.name);
|
|
569
|
+
statements.push(...createMappingActivityStatements(declaration.init, sourceFilePath, staticFunctionBindings, usedExportNames, addGeneratedActivityBinding));
|
|
489
570
|
collectInlineCreateSteps(declaration.init, seenNames, statements, addActivityBinding);
|
|
490
571
|
continue;
|
|
491
572
|
}
|
|
@@ -685,7 +766,7 @@ function getWorkflowStepName(node, stepBindings) {
|
|
|
685
766
|
* Most step references collapse down to step ids so the generated workflow can call
|
|
686
767
|
* activities by id instead of keeping the original `createStep` definitions around.
|
|
687
768
|
*/
|
|
688
|
-
function rewriteChainMethod(method, filePath, workflowName, stepBindings, workflowBindings) {
|
|
769
|
+
function rewriteChainMethod(method, filePath, workflowName, workflowId, mappingOrdinal, stepBindings, workflowBindings) {
|
|
689
770
|
const argNode = (index) => method.args[index];
|
|
690
771
|
const rewritten = (args, name = method.name) => ({
|
|
691
772
|
name,
|
|
@@ -720,9 +801,16 @@ function rewriteChainMethod(method, filePath, workflowName, stepBindings, workfl
|
|
|
720
801
|
case "parallel": {
|
|
721
802
|
const arg = argNode(0);
|
|
722
803
|
if (!_babel_types.isArrayExpression(arg)) throw new Error(`.parallel() in ${workflowName} (${filePath}) requires an array literal argument`);
|
|
723
|
-
const
|
|
724
|
-
|
|
725
|
-
|
|
804
|
+
const entries = arg.elements.map((element) => {
|
|
805
|
+
if (_babel_types.isIdentifier(element)) {
|
|
806
|
+
const workflowType = workflowBindings.get(element.name);
|
|
807
|
+
if (workflowType) return _babel_types.objectExpression([_babel_types.objectProperty(_babel_types.identifier("type"), _babel_types.stringLiteral("childWorkflow")), _babel_types.objectProperty(_babel_types.identifier("workflowType"), _babel_types.stringLiteral(workflowType))]);
|
|
808
|
+
}
|
|
809
|
+
const stepId = getWorkflowStepName(element, stepBindings);
|
|
810
|
+
if (!stepId) throw new Error(`Unable to determine step names inside .parallel() in ${workflowName} (${filePath})`);
|
|
811
|
+
return _babel_types.objectExpression([_babel_types.objectProperty(_babel_types.identifier("type"), _babel_types.stringLiteral("step")), _babel_types.objectProperty(_babel_types.identifier("step"), _babel_types.objectExpression([_babel_types.objectProperty(_babel_types.identifier("id"), _babel_types.stringLiteral(stepId))]))]);
|
|
812
|
+
});
|
|
813
|
+
return rewritten([_babel_types.arrayExpression(entries)]);
|
|
726
814
|
}
|
|
727
815
|
case "branch": {
|
|
728
816
|
const arg = argNode(0);
|
|
@@ -751,6 +839,15 @@ function rewriteChainMethod(method, filePath, workflowName, stepBindings, workfl
|
|
|
751
839
|
if (optsArg && _babel_types.isExpression(optsArg)) args.push(_babel_types.cloneNode(optsArg, true));
|
|
752
840
|
return rewritten(args);
|
|
753
841
|
}
|
|
842
|
+
case "map": {
|
|
843
|
+
const callback = argNode(0);
|
|
844
|
+
if (_babel_types.isObjectExpression(callback)) throw new Error(`.map() in ${workflowName} (${filePath}) does not yet support declarative object mappings; use a callback mapping`);
|
|
845
|
+
if (!_babel_types.isArrowFunctionExpression(callback) && !_babel_types.isFunctionExpression(callback) && !_babel_types.isIdentifier(callback)) throw new Error(`.map() in ${workflowName} (${filePath}) requires an inline function or a statically declared function identifier`);
|
|
846
|
+
const args = [_babel_types.stringLiteral(`mapping_${workflowId}_${mappingOrdinal}`)];
|
|
847
|
+
const optsArg = method.args[1];
|
|
848
|
+
if (optsArg && _babel_types.isExpression(optsArg)) args.push(_babel_types.cloneNode(optsArg, true));
|
|
849
|
+
return rewritten(args);
|
|
850
|
+
}
|
|
754
851
|
case "commit": return rewritten([]);
|
|
755
852
|
default: throw new Error(`Unsupported workflow chain method .${method.name}() in ${workflowName} (${filePath})`);
|
|
756
853
|
}
|
|
@@ -765,12 +862,14 @@ function getExportedName(node) {
|
|
|
765
862
|
* we emit a deterministic exported function whose name matches Temporal's runtime
|
|
766
863
|
* lookup and whose body delegates into the injected helper runtime.
|
|
767
864
|
*/
|
|
768
|
-
function createTemporalWorkflowStatements(exportName, workflowId, methods, filePath, includeCommit, stepBindings, workflowBindings, runtimeOptions) {
|
|
865
|
+
function createTemporalWorkflowStatements(exportName, workflowId, workflowIdValue, methods, filePath, includeCommit, stepBindings, workflowBindings, runtimeOptions) {
|
|
769
866
|
const createWorkflowArgs = [_babel_types.cloneNode(workflowId, true)];
|
|
770
867
|
if (runtimeOptions) createWorkflowArgs.push(_babel_types.cloneNode(runtimeOptions, true));
|
|
771
868
|
let expression = _babel_types.callExpression(_babel_types.identifier("createWorkflow"), createWorkflowArgs);
|
|
869
|
+
let mappingOrdinal = 0;
|
|
772
870
|
for (const method of methods) {
|
|
773
|
-
const rewrittenMethod = rewriteChainMethod(method, filePath, exportName, stepBindings, workflowBindings);
|
|
871
|
+
const rewrittenMethod = rewriteChainMethod(method, filePath, exportName, workflowIdValue, mappingOrdinal, stepBindings, workflowBindings);
|
|
872
|
+
if (method.name === "map") mappingOrdinal += 1;
|
|
774
873
|
expression = _babel_types.callExpression(_babel_types.memberExpression(expression, _babel_types.identifier(rewrittenMethod.name)), rewrittenMethod.args);
|
|
775
874
|
}
|
|
776
875
|
if (includeCommit && !methods.some((m) => m.name === "commit")) expression = _babel_types.callExpression(_babel_types.memberExpression(expression, _babel_types.identifier("commit")), []);
|
|
@@ -891,12 +990,12 @@ function rewriteWorkflowVariableDeclaration(statement, filePath, state) {
|
|
|
891
990
|
}
|
|
892
991
|
const [workflowConfig] = workflowChain.createWorkflowCall.arguments;
|
|
893
992
|
if (!workflowConfig || !_babel_types.isObjectExpression(workflowConfig)) throw new Error(`Unable to determine workflow config for ${declaration.id.name} in ${filePath}`);
|
|
894
|
-
const { expression: workflowId } = getWorkflowIdMetadata(workflowConfig, declaration.id.name, filePath);
|
|
993
|
+
const { expression: workflowId, workflowId: workflowIdValue } = getWorkflowIdMetadata(workflowConfig, declaration.id.name, filePath);
|
|
895
994
|
const workflowExport = getTemporalWorkflowExportFromDeclaration(declaration, filePath);
|
|
896
995
|
if (!workflowExport) throw new Error(`Unable to determine workflow export for ${declaration.id.name} in ${filePath}`);
|
|
897
996
|
const { exportName } = workflowExport;
|
|
898
997
|
state.workflowExports.push(workflowExport);
|
|
899
|
-
state.statements.push(...createTemporalWorkflowStatements(exportName, workflowId, workflowChain.methods, filePath, state.committedWorkflowNames.has(declaration.id.name), state.stepBindings, state.workflowBindings, state.runtimeOptions));
|
|
998
|
+
state.statements.push(...createTemporalWorkflowStatements(exportName, workflowId, workflowIdValue, workflowChain.methods, filePath, state.committedWorkflowNames.has(declaration.id.name), state.stepBindings, state.workflowBindings, state.runtimeOptions));
|
|
900
999
|
}
|
|
901
1000
|
if (declarations.length > 0) {
|
|
902
1001
|
const cloned = declarations.map((declaration) => _babel_types.cloneNode(declaration, true));
|