@lark-apaas/nestjs-trigger 0.0.2 → 0.0.4-alpha.20261025064823

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -157,7 +157,7 @@ export class NotificationAutomation {
157
157
  **接口详情:**
158
158
 
159
159
  ```http
160
- POST /innerapi/automation/invoke
160
+ POST /__innerapi__/automation/invoke
161
161
  ```
162
162
 
163
163
  **请求体:**
@@ -175,26 +175,37 @@ export interface TriggerExecutionDto {
175
175
 
176
176
  **响应:**
177
177
 
178
+ 接口会等待任务方法的 Promise 结束后再响应。成功示例:
179
+
178
180
  ```json
179
181
  {
180
182
  "code": 200,
181
- "message": ""
183
+ "message": "success"
182
184
  }
183
185
  ```
184
186
 
187
+ 失败响应保留同样可关联的 `code` 和 `message`,并将 HTTP 状态设为对应的 4xx/5xx,而不是在 HTTP 200 的 body 中表示失败。
188
+
185
189
  **状态码说明:**
186
190
 
187
- - `200`: 接收成功,异步执行
188
- - `400`: 缺少必填字段
189
- - `404`: triggerID 未注册
190
- - `500`: 内部错误
191
+ - `200`: 任务方法已成功完成
192
+ - `400`: 缺少必填字段或参数无效
193
+ - `404`: trigger 未注册
194
+ - `500`: 任务方法执行失败或内部错误
195
+ - `504`: 既有 `TIMEOUT` 错误结果的映射
196
+
197
+ ### 请求完成边界
198
+
199
+ Action 会在任务方法结束后上报一次真实终态,Trigger 随后以上述同一状态和输出上报一次,HTTP 请求最后结束。该合同只保证能在当前调用方 **15 秒预算内**结束的同步或短 async handler。
200
+
201
+ 等待 Promise 不表示支持分钟级任务,也不提供 SDK 内置超时、断连取消、重试或耐久执行。预计超过调用预算、需要跨实例存活或可靠重试的工作必须交给经核实的外部耐久执行机制,不能依赖此请求继续运行。
191
202
 
192
203
  ## 与 trigger-server 集成
193
204
 
194
205
  ### 集成架构
195
206
 
196
207
  ```
197
- Trigger Server → HTTP POST /innerapi/automation/invoke
208
+ Trigger Server → HTTP POST /__innerapi__/automation/invoke
198
209
  ↓
199
210
  AutomationController
200
211
  ↓
@@ -67,7 +67,8 @@ var convertActionContextToReportData = /* @__PURE__ */ __name((actionCtx) => {
67
67
  status: attributes?.status,
68
68
  phase: attributes?.phase,
69
69
  start_at: attributes?.startAt,
70
- end_at: attributes?.endAt
70
+ end_at: attributes?.endAt,
71
+ duration_ms: attributes?.duration_ms
71
72
  }
72
73
  ];
73
74
  }, "convertActionContextToReportData");
@@ -119,7 +120,7 @@ var TriggerClient = class {
119
120
  * @param context - 执行上下文
120
121
  * @returns 执行报告数据
121
122
  */
122
- executeAction(trigger, instanceID, context) {
123
+ async executeAction(trigger, instanceID, context) {
123
124
  let input;
124
125
  try {
125
126
  const parsed = JSON.parse(context.content || "{}");
@@ -133,29 +134,32 @@ var TriggerClient = class {
133
134
  message: `\u53C2\u6570\u89E3\u6790\u5931\u8D25(trigger: ${trigger}, instanceID: ${instanceID})`
134
135
  }
135
136
  });
136
- const actionCtx = {
137
+ const actionCtx2 = {
137
138
  ...context,
138
139
  attributes: {
139
140
  ...context.attributes,
140
141
  phase: ENUM_PHASE.Trigger,
141
142
  status: ENUM_STATUS.FAILED,
142
- endAt: Date.now()
143
+ endAt: Date.now(),
144
+ duration_ms: this._computeDuration(context.attributes.startAt)
143
145
  },
144
146
  content
145
147
  };
146
- this.report(...convertActionContextToReportData(actionCtx));
147
- return actionCtx;
148
+ this.report(...convertActionContextToReportData(actionCtx2));
149
+ return actionCtx2;
148
150
  }
151
+ let actionCtx;
149
152
  try {
150
153
  const action = this.getAction(trigger);
151
154
  if (!action) {
152
- const actionCtx2 = {
155
+ actionCtx = {
153
156
  ...context,
154
157
  attributes: {
155
158
  ...context.attributes,
156
159
  phase: ENUM_PHASE.Trigger,
157
160
  status: ENUM_STATUS.FAILED,
158
- endAt: Date.now()
161
+ endAt: Date.now(),
162
+ duration_ms: this._computeDuration(context.attributes.startAt)
159
163
  },
160
164
  content: JSON.stringify({
161
165
  input,
@@ -165,34 +169,31 @@ var TriggerClient = class {
165
169
  }
166
170
  })
167
171
  };
168
- this.report(...convertActionContextToReportData(actionCtx2));
169
- return actionCtx2;
172
+ } else {
173
+ const actionResult = await action.handler(context);
174
+ actionCtx = {
175
+ ...context,
176
+ attributes: {
177
+ ...context.attributes,
178
+ phase: ENUM_PHASE.Trigger,
179
+ status: actionResult.attributes.status,
180
+ endAt: Date.now(),
181
+ duration_ms: this._computeDuration(context.attributes.startAt)
182
+ },
183
+ // Trigger 必须复用 Action 的终态输出,避免失败被改写为成功。
184
+ content: actionResult.content
185
+ };
170
186
  }
171
- action.handler(context);
172
- const actionCtx = {
173
- ...context,
174
- attributes: {
175
- ...context.attributes,
176
- phase: ENUM_PHASE.Trigger,
177
- status: ENUM_STATUS.SUCCEEDED,
178
- endAt: Date.now()
179
- },
180
- content: JSON.stringify({
181
- input,
182
- output: null
183
- })
184
- };
185
- this.report(...convertActionContextToReportData(actionCtx));
186
- return actionCtx;
187
187
  } catch (error) {
188
188
  const errorMessage = error instanceof Error ? error.message : String(error);
189
- const actionCtx = {
189
+ actionCtx = {
190
190
  ...context,
191
191
  attributes: {
192
192
  ...context.attributes,
193
193
  phase: ENUM_PHASE.Trigger,
194
194
  status: ENUM_STATUS.FAILED,
195
- endAt: Date.now()
195
+ endAt: Date.now(),
196
+ duration_ms: this._computeDuration(context.attributes.startAt)
196
197
  },
197
198
  content: JSON.stringify({
198
199
  input,
@@ -202,9 +203,9 @@ var TriggerClient = class {
202
203
  }
203
204
  })
204
205
  };
205
- this.report(...convertActionContextToReportData(actionCtx));
206
- return actionCtx;
207
206
  }
207
+ this.report(...convertActionContextToReportData(actionCtx));
208
+ return actionCtx;
208
209
  }
209
210
  /**
210
211
  * 根据 trigger 获取对应的动作
@@ -340,16 +341,20 @@ var TriggerClient = class {
340
341
  * @param handler - 原始处理器
341
342
  * @returns 包装后的处理器
342
343
  */
344
+ _computeDuration(startAt) {
345
+ return startAt ? Date.now() - startAt : void 0;
346
+ }
343
347
  _wrapHandler(handler) {
344
348
  return async (context) => {
345
349
  let input;
350
+ const actionStartAt = Date.now();
346
351
  try {
347
352
  input = JSON.parse(context.content || "{}").input;
348
353
  } catch (error) {
349
354
  input = void 0;
350
355
  }
356
+ let actionCtx;
351
357
  try {
352
- const actionStartAt = Date.now();
353
358
  const output = await Promise.resolve(handler({
354
359
  attributes: {
355
360
  ...context.attributes,
@@ -359,31 +364,32 @@ var TriggerClient = class {
359
364
  input
360
365
  }
361
366
  }));
362
- const actionCtx = {
367
+ actionCtx = {
363
368
  ...context,
364
369
  attributes: {
365
370
  ...context.attributes,
366
371
  startAt: actionStartAt,
367
372
  phase: ENUM_PHASE.Action,
368
373
  status: ENUM_STATUS.SUCCEEDED,
369
- endAt: Date.now()
374
+ endAt: Date.now(),
375
+ duration_ms: this._computeDuration(actionStartAt)
370
376
  },
371
377
  content: JSON.stringify({
372
378
  input,
373
379
  output
374
380
  })
375
381
  };
376
- this.report(...convertActionContextToReportData(actionCtx));
377
- return actionCtx;
378
382
  } catch (error) {
379
383
  const errorMessage = error instanceof Error ? error.message : String(error);
380
- const actionCtx = {
384
+ actionCtx = {
381
385
  ...context,
382
386
  attributes: {
383
387
  ...context.attributes,
388
+ startAt: actionStartAt,
384
389
  phase: ENUM_PHASE.Action,
385
390
  status: ENUM_STATUS.FAILED,
386
- endAt: Date.now()
391
+ endAt: Date.now(),
392
+ duration_ms: this._computeDuration(actionStartAt)
387
393
  },
388
394
  content: JSON.stringify({
389
395
  input,
@@ -393,9 +399,9 @@ var TriggerClient = class {
393
399
  }
394
400
  })
395
401
  };
396
- this.report(...convertActionContextToReportData(actionCtx));
397
- return actionCtx;
398
402
  }
403
+ this.report(...convertActionContextToReportData(actionCtx));
404
+ return actionCtx;
399
405
  };
400
406
  }
401
407
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/client/index.ts","../../src/client/types.ts","../../src/client/utils.ts","../../src/client/trigger-client.ts"],"sourcesContent":["export * from './types';\nexport * from './trigger-client';\nexport * from './utils';\n","/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/**\n * Action handler function type\n */\nexport interface ActionHandler {\n (...args: any[]): any | Promise<any>;\n}\n\n/**\n * Action definition\n */\nexport interface Action extends ActionMetadata {\n handler: ActionHandler;\n}\n\nexport enum ENUM_STATUS {\n SUCCEEDED = 'succeed',\n FAILED = 'failed',\n}\n\nexport enum ENUM_PHASE {\n Trigger = 'trigger',\n Action = 'action',\n}\n\nexport enum ENUM_ENV {\n DEV = 'development',\n PROD = 'production',\n}\n\nexport interface ActionContext {\n attributes: {\n trigger: string;\n triggerID?: string;\n triggerType?: string;\n instanceID: string;\n status?: ENUM_STATUS;\n phase?: ENUM_PHASE;\n startAt?: number;\n endAt?: number;\n };\n content?: string; // '{ input: {}, output: {} }'\n}\n\n\nexport type TLogContent = string; // stringified { input, output }\nexport interface ILogAttributes {\n trigger?: string;\n trigger_id?: string;\n trigger_type?: string;\n instance_id?: string;\n status?: ENUM_STATUS;\n phase?: ENUM_PHASE;\n start_at?: number;\n end_at?: number;\n}\n\n/**\n * Action metadata (without handler)\n */\nexport interface ActionMetadata {\n name?: string;\n path?: string;\n desc?: string;\n}\n\n/**\n * Logger interface for client SDK\n */\nexport interface Logger {\n debug(message: string, extra?: any): void;\n info(message: string, extra?: any): void;\n warn(message: string, extra?: any): void;\n error(message: string, extra?: any): void;\n}\n\n/**\n * TriggerClient configuration options\n */\nexport interface TriggerClientOptions {\n /**\n * Timeout for action execution (ms)\n */\n timeout?: number;\n imports?: any[];\n}\n\nexport enum ENUM_ERROR {\n NOT_EXIST = 'NOT_EXIST',\n TIMEOUT = 'TIMEOUT',\n PARAM_INVALID = 'PARAM_INVALID',\n TRY_CATCH = 'TRY_CATCH',\n}\n\nexport interface ILogContentParsed {\n /** 触发器名称 (例如 'cron-daily') */\n trigger?: string;\n /** 触发器定义 ID */\n trigger_id?: string;\n /** 触发器类型 (例如 定时任务、记录变更) */\n trigger_type?: string;\n /** 执行实例 ID */\n instance_id?: string;\n /** 阶段:触发阶段或动作执行阶段 */\n phase?: ENUM_PHASE;\n /** 状态:成功或失败 */\n status?: ENUM_STATUS;\n /** 执行耗时 (毫秒)。计算逻辑:(endAt - startAt) 或内部计时器 */\n duration_ms?: number;\n /** 核心内容 */\n content?: {\n /** 动作入参 */\n input?: any;\n /** 动作出参 */\n output?: any;\n };\n /** 错误信息,仅在 status 为 failed 时填充,否则为空字符串 */\n error_message?: string;\n}\n","import { ActionContext, ILogAttributes, TLogContent } from './types';\n\nexport const convertActionContextToReportData = (actionCtx: ActionContext): [TLogContent, ILogAttributes] => {\n const { attributes, content } = actionCtx;\n return [\n content || '',\n {\n trigger: attributes?.trigger,\n trigger_id: attributes?.triggerID,\n trigger_type: attributes?.triggerType,\n instance_id: attributes?.instanceID,\n status: attributes?.status,\n phase: attributes?.phase,\n start_at: attributes?.startAt,\n end_at: attributes?.endAt,\n },\n ];\n};","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { Logger } from '@nestjs/common';\nimport {\n ENUM_STATUS,\n ENUM_PHASE,\n type Action,\n type ActionHandler,\n type ActionMetadata,\n ENUM_ERROR,\n ActionContext,\n TLogContent,\n ILogAttributes,\n ILogContentParsed,\n} from './types';\nimport { convertActionContextToReportData } from './utils';\n\nconst INTERNAL = 'AUTOMATION_INTERNAL';\n\n/**\n * TriggerClient\n *\n * 自动化触发器管理客户端核心类\n *\n * 负责管理触发器注册、执行和生命周期事件\n * 提供中间件支持和与 trigger-server 的回调集成\n */\nexport class TriggerClient {\n private _triggerActionMap: Map<string, Action> = new Map();\n private _logger: Logger;\n\n /**\n * 创建 TriggerClient 实例\n *\n * @param logger - 日志记录器\n */\n public constructor(logger: Logger) {\n this._logger = logger;\n }\n\n /**\n * 为指定的 trigger 注册动作\n *\n * @param trigger - 触发器标识\n * @param action - 动作配置\n */\n public registerAction(trigger: string, action: Action): void {\n this._logger.debug(\n `[${INTERNAL}] Registering action for trigger: ${trigger}`,\n {\n actionName: action.name,\n path: action.path,\n desc: action.desc,\n }\n );\n\n if (this._triggerActionMap.has(trigger)) {\n this._logger.debug(\n `[${INTERNAL}] Trigger ${trigger} already registered, overwriting`\n );\n }\n\n const wrappedHandler = this._wrapHandler(action.handler);\n const wrappedAction: Action = {\n ...action,\n handler: wrappedHandler,\n };\n\n this._triggerActionMap.set(trigger, wrappedAction);\n this._logger.debug(\n `[${INTERNAL}] Action registered successfully for trigger: ${trigger}`\n );\n }\n\n /**\n * 执行指定的 trigger 动作\n *\n * @param trigger - 触发器标识\n * @param instanceID - 实例ID\n * @param context - 执行上下文\n * @returns 执行报告数据\n */\n public executeAction(\n trigger: string,\n instanceID: string,\n context: ActionContext,\n ): ActionContext {\n let input;\n\n // 解析输入参数\n try {\n const parsed = JSON.parse(context.content || '{}');\n input = parsed?.input ?? null;\n } catch (error) {\n input = undefined;\n const content = JSON.stringify({\n input,\n output: {\n error: ENUM_ERROR.PARAM_INVALID,\n message: `参数解析失败(trigger: ${trigger}, instanceID: ${instanceID})`,\n },\n });\n const actionCtx: ActionContext = {\n ...context,\n attributes: {\n ...context.attributes,\n phase: ENUM_PHASE.Trigger,\n status: ENUM_STATUS.FAILED,\n endAt: Date.now()\n },\n content,\n };\n this.report(...convertActionContextToReportData(actionCtx));\n return actionCtx;\n }\n\n try {\n // 获取动作处理器\n const action = this.getAction(trigger);\n\n // 如果动作不存在,返回错误\n if (!action) {\n const actionCtx: ActionContext = {\n ...context,\n attributes: {\n ...context.attributes,\n phase: ENUM_PHASE.Trigger,\n status: ENUM_STATUS.FAILED,\n endAt: Date.now()\n },\n content: JSON.stringify({\n input,\n output: {\n error: ENUM_ERROR.NOT_EXIST,\n message: `执行动作不存在: ${trigger}`,\n },\n })\n };\n // 上报 trigger 结果{成功/失败}\n this.report(...convertActionContextToReportData(actionCtx));\n return actionCtx;\n }\n\n // 直接执行 _wrapHandler(handler),不会等待执行结束\n action.handler(context);\n\n const actionCtx: ActionContext = {\n ...context,\n attributes: {\n ...context.attributes,\n phase: ENUM_PHASE.Trigger,\n status: ENUM_STATUS.SUCCEEDED,\n endAt: Date.now(),\n },\n content: JSON.stringify({ input, output: null }),\n };\n // 上报 trigger 结果{成功/失败}\n this.report(...convertActionContextToReportData(actionCtx));\n\n return actionCtx;\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n\n const actionCtx: ActionContext = {\n ...context,\n attributes: {\n ...context.attributes,\n phase: ENUM_PHASE.Trigger,\n status: ENUM_STATUS.FAILED,\n endAt: Date.now(),\n },\n content: JSON.stringify({\n input,\n output: { error: ENUM_ERROR.TRY_CATCH, message: errorMessage },\n }),\n };\n // 上报 trigger 结果{成功/失败}\n this.report(...convertActionContextToReportData(actionCtx));\n\n return actionCtx;\n }\n }\n\n /**\n * 根据 trigger 获取对应的动作\n *\n * @param trigger - 触发器标识\n * @returns 动作实例,如果不存在返回 undefined\n */\n public getAction(trigger: string): Action | undefined {\n const action = this._triggerActionMap.get(trigger);\n\n if (!action) {\n this._logger.debug(`No action found for trigger: ${trigger}`);\n return undefined;\n }\n\n this._logger.debug(`Retrieved action for trigger: ${trigger}`, {\n actionName: action.name,\n path: action.path,\n });\n\n return action;\n }\n\n /**\n * 获取所有已注册的动作\n *\n * @returns 动作映射表\n */\n public getAllActions(): Map<string, Action> {\n return this._triggerActionMap;\n }\n\n /**\n * 根据 trigger 获取动作的元数据\n *\n * @param trigger - 触发器标识\n * @returns 动作元数据,如果不存在返回 undefined\n */\n public getActionMetadata(trigger: string): ActionMetadata | undefined {\n const action = this.getAction(trigger);\n\n if (!action) {\n return undefined;\n }\n\n return {\n name: action.name,\n path: action.path,\n desc: action.desc,\n };\n }\n\n /**\n * 获取所有已注册的 trigger 标识\n *\n * @returns trigger 标识数组\n */\n public getAllTriggers(): string[] {\n const triggers = Array.from(this._triggerActionMap.keys());\n this._logger.debug(`Retrieved all triggers`, {\n count: triggers.length,\n });\n return triggers;\n }\n\n /**\n * 根据 trigger 移除对应的动作\n *\n * @param trigger - 触发器标识\n * @returns 如果成功移除返回 true,如果不存在返回 false\n */\n public removeAction(trigger: string): boolean {\n const existed = this._triggerActionMap.has(trigger);\n\n if (existed) {\n this._triggerActionMap.delete(trigger);\n this._logger.debug(`Removed action for trigger: ${trigger}`);\n } else {\n this._logger.debug(\n `Attempted to remove non-existent trigger: ${trigger}`\n );\n }\n\n return existed;\n }\n\n /**\n * 清空所有已注册的动作\n */\n public clearAllActions(): void {\n const count = this._triggerActionMap.size;\n this._triggerActionMap.clear();\n this._logger.debug(`Cleared all actions`, { count });\n }\n\n /**\n * 上报执行数据,用于日志记录和调试\n */\n public report(msg: TLogContent, extra: ILogAttributes): void {\n const { status, phase, start_at, end_at, trigger, trigger_id, instance_id, trigger_type } =\n extra;\n\n let contentObj: { input: any; output: any } = { input: null, output: null };\n try {\n contentObj = JSON.parse(msg);\n } catch (error) {\n this._logger.debug(`Failed to parse log content as JSON: ${msg}`);\n }\n\n const duration_ms = end_at && start_at ? end_at - start_at : 0;\n\n let error_message;\n if (status === ENUM_STATUS.FAILED && contentObj?.output?.message) {\n error_message = contentObj.output.message;\n }\n\n const logContent: ILogContentParsed = {\n trigger,\n trigger_id,\n trigger_type,\n instance_id,\n phase,\n status,\n duration_ms,\n content: contentObj,\n error_message,\n };\n\n // for 观测\n const signature = { sourceType: 'platform', paas_attributes_module: 'trigger' };\n const newMsg = JSON.stringify(logContent);\n\n // msg\n if (status === ENUM_STATUS.FAILED) {\n this._logger.error(newMsg, { ...extra, ...signature });\n } else {\n this._logger.log(newMsg, { ...extra, ...signature });\n }\n }\n\n /**\n * 包装处理器,添加日志记录和计时功能\n *\n * @param handler - 原始处理器\n * @returns 包装后的处理器\n */\n private _wrapHandler(handler: Action['handler']): ActionHandler {\n return async (context: ActionContext): Promise<ActionContext> => {\n let input;\n\n // 解析输入参数\n try {\n input = JSON.parse(context.content || '{}').input;\n } catch (error) {\n input = undefined;\n }\n\n try {\n const actionStartAt = Date.now();\n const output = await Promise.resolve(\n handler({\n attributes: {\n ...context.attributes,\n startAt: actionStartAt\n },\n content: {\n input,\n },\n })\n );\n\n const actionCtx: ActionContext = {\n ...context,\n attributes: {\n ...context.attributes,\n startAt: actionStartAt,\n phase: ENUM_PHASE.Action,\n status: ENUM_STATUS.SUCCEEDED,\n endAt: Date.now(),\n },\n content: JSON.stringify({\n input,\n output,\n }),\n };\n this.report(...convertActionContextToReportData(actionCtx));\n\n return actionCtx;\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n\n const actionCtx: ActionContext = {\n ...context,\n attributes: {\n ...context.attributes,\n phase: ENUM_PHASE.Action,\n status: ENUM_STATUS.FAILED,\n endAt: Date.now(),\n },\n content: JSON.stringify({\n input,\n output: { error: ENUM_ERROR.TRY_CATCH, message: errorMessage },\n }),\n };\n this.report(...convertActionContextToReportData(actionCtx));\n return actionCtx;\n }\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;ACgBO,IAAKA,cAAAA,0BAAAA,cAAAA;;;SAAAA;;AAKL,IAAKC,aAAAA,0BAAAA,aAAAA;;;SAAAA;;AAKL,IAAKC,WAAAA,0BAAAA,WAAAA;;;SAAAA;;AA8DL,IAAKC,aAAAA,0BAAAA,aAAAA;;;;;SAAAA;;;;ACtFL,IAAMC,mCAAmC,wBAACC,cAAAA;AAC/C,QAAM,EAAEC,YAAYC,QAAO,IAAKF;AAChC,SAAO;IACLE,WAAW;IACX;MACEC,SAASF,YAAYE;MACrBC,YAAYH,YAAYI;MACxBC,cAAcL,YAAYM;MAC1BC,aAAaP,YAAYQ;MACzBC,QAAQT,YAAYS;MACpBC,OAAOV,YAAYU;MACnBC,UAAUX,YAAYY;MACtBC,QAAQb,YAAYc;IACtB;;AAEJ,GAfgD;;;ACchD,IAAMC,WAAW;AAUV,IAAMC,gBAAN,MAAMA;EA1Bb,OA0BaA;;;EACHC,oBAAyC,oBAAIC,IAAAA;EAC7CC;;;;;;EAOR,YAAmBC,QAAgB;AACjC,SAAKD,UAAUC;EACjB;;;;;;;EAQOC,e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AiBwB,QAAQxB,MAAMM,UAAUmB,OAAOzB,KAAAA;AAElD,cAAMO,YAA2B;UAC/B,GAAGb;UACHc,YAAY;YACV,GAAGd,QAAQc;YACXC,OAAOC,WAAWqD;YAClBnD,QAAQC,YAAYC;YACpBC,OAAOC,KAAKC,IAAG;UACjB;UACAlB,SAASF,KAAKK,UAAU;YACtBP;YACAQ,QAAQ;cAAEH,OAAOI,WAAWsB;cAAWpB,SAASiB;YAAa;UAC/D,CAAA;QACF;AACA,aAAKL,OAAM,GAAIC,iCAAiCZ,SAAAA,CAAAA;AAChD,eAAOA;MACT;IACF;EACF;AACF;","names":["ENUM_STATUS","ENUM_PHASE","ENUM_ENV","ENUM_ERROR","convertActionContextToReportData","actionCtx","attributes","content","trigger","trigger_id","triggerID","trigger_type","triggerType","instance_id","instanceID","status","phase","start_at","startAt","end_at","endAt","INTERNAL","TriggerClient","_triggerActionMap","Map","_logger","logger","registerAction","trigger","action","debug","actionName","name","path","desc","has","wrappedHandler","_wrapHandler","handler","wrappedAction","set","executeAction","instanceID","context","input","parsed","JSON","parse","content","error","undefined","stringify","output","ENUM_ERROR","PARAM_INVALID","message","actionCtx","attributes","phase","ENUM_PHASE","Trigger","status","ENUM_STATUS","FAILED","endAt","Date","now","report","convertActionContextToReportData","getAction","NOT_EXIST","SUCCEEDED","errorMessage","Error","String","TRY_CATCH","get","getAllActions","getActionMetadata","getAllTriggers","triggers","Array","from","keys","count","length","removeAction","existed","delete","clearAllActions","size","clear","msg","extra","start_at","end_at","trigger_id","instance_id","trigger_type","contentObj","duration_ms","error_message","logContent","signature","sourceType","paas_attributes_module","newMsg","log","actionStartAt","Promise","resolve","startAt","Action"]}
1
+ {"version":3,"sources":["../../src/client/index.ts","../../src/client/types.ts","../../src/client/utils.ts","../../src/client/trigger-client.ts"],"sourcesContent":["export * from './types';\nexport * from './trigger-client';\nexport * from './utils';\n","/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/**\n * Action handler function type\n */\nexport interface ActionHandler {\n (...args: any[]): any | Promise<any>;\n}\n\n/**\n * Action definition\n */\nexport interface Action extends ActionMetadata {\n handler: ActionHandler;\n}\n\nexport enum ENUM_STATUS {\n SUCCEEDED = 'succeed',\n FAILED = 'failed',\n}\n\nexport enum ENUM_PHASE {\n Trigger = 'trigger',\n Action = 'action',\n}\n\nexport enum ENUM_ENV {\n DEV = 'development',\n PROD = 'production',\n}\n\nexport interface ActionContext {\n attributes: {\n trigger: string;\n triggerID?: string;\n triggerType?: string;\n instanceID: string;\n status?: ENUM_STATUS;\n phase?: ENUM_PHASE;\n startAt?: number;\n endAt?: number;\n duration_ms?: number;\n };\n content?: string; // '{ input: {}, output: {} }'\n}\n\n\nexport type TLogContent = string; // stringified { input, output }\nexport interface ILogAttributes {\n trigger?: string;\n trigger_id?: string;\n trigger_type?: string;\n instance_id?: string;\n status?: ENUM_STATUS;\n phase?: ENUM_PHASE;\n start_at?: number;\n end_at?: number;\n duration_ms?: number;\n}\n\n/**\n * Action metadata (without handler)\n */\nexport interface ActionMetadata {\n name?: string;\n path?: string;\n desc?: string;\n}\n\n/**\n * Logger interface for client SDK\n */\nexport interface Logger {\n debug(message: string, extra?: any): void;\n info(message: string, extra?: any): void;\n warn(message: string, extra?: any): void;\n error(message: string, extra?: any): void;\n}\n\n/**\n * TriggerClient configuration options\n */\nexport interface TriggerClientOptions {\n /**\n * Timeout for action execution (ms)\n */\n timeout?: number;\n imports?: any[];\n}\n\nexport enum ENUM_ERROR {\n NOT_EXIST = 'NOT_EXIST',\n TIMEOUT = 'TIMEOUT',\n PARAM_INVALID = 'PARAM_INVALID',\n TRY_CATCH = 'TRY_CATCH',\n}\n\nexport interface ILogContentParsed {\n /** 触发器名称 (例如 'cron-daily') */\n trigger?: string;\n /** 触发器定义 ID */\n trigger_id?: string;\n /** 触发器类型 (例如 定时任务、记录变更) */\n trigger_type?: string;\n /** 执行实例 ID */\n instance_id?: string;\n /** 阶段:触发阶段或动作执行阶段 */\n phase?: ENUM_PHASE;\n /** 状态:成功或失败 */\n status?: ENUM_STATUS;\n /** 执行耗时 (毫秒)。计算逻辑:(endAt - startAt) 或内部计时器 */\n duration_ms?: number;\n /** 核心内容 */\n content?: {\n /** 动作入参 */\n input?: any;\n /** 动作出参 */\n output?: any;\n };\n /** 错误信息,仅在 status 为 failed 时填充,否则为空字符串 */\n error_message?: string;\n}\n","import { ActionContext, ILogAttributes, TLogContent } from './types';\n\nexport const convertActionContextToReportData = (actionCtx: ActionContext): [TLogContent, ILogAttributes] => {\n const { attributes, content } = actionCtx;\n return [\n content || '',\n {\n trigger: attributes?.trigger,\n trigger_id: attributes?.triggerID,\n trigger_type: attributes?.triggerType,\n instance_id: attributes?.instanceID,\n status: attributes?.status,\n phase: attributes?.phase,\n start_at: attributes?.startAt,\n end_at: attributes?.endAt,\n duration_ms: attributes?.duration_ms,\n },\n ];\n};","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { Logger } from '@nestjs/common';\nimport {\n ENUM_STATUS,\n ENUM_PHASE,\n type Action,\n type ActionHandler,\n type ActionMetadata,\n ENUM_ERROR,\n ActionContext,\n TLogContent,\n ILogAttributes,\n ILogContentParsed,\n} from './types';\nimport { convertActionContextToReportData } from './utils';\n\nconst INTERNAL = 'AUTOMATION_INTERNAL';\n\n/**\n * TriggerClient\n *\n * 自动化触发器管理客户端核心类\n *\n * 负责管理触发器注册、执行和生命周期事件\n * 提供中间件支持和与 trigger-server 的回调集成\n */\nexport class TriggerClient {\n private _triggerActionMap: Map<string, Action> = new Map();\n private _logger: Logger;\n\n /**\n * 创建 TriggerClient 实例\n *\n * @param logger - 日志记录器\n */\n public constructor(logger: Logger) {\n this._logger = logger;\n }\n\n /**\n * 为指定的 trigger 注册动作\n *\n * @param trigger - 触发器标识\n * @param action - 动作配置\n */\n public registerAction(trigger: string, action: Action): void {\n this._logger.debug(\n `[${INTERNAL}] Registering action for trigger: ${trigger}`,\n {\n actionName: action.name,\n path: action.path,\n desc: action.desc,\n }\n );\n\n if (this._triggerActionMap.has(trigger)) {\n this._logger.debug(\n `[${INTERNAL}] Trigger ${trigger} already registered, overwriting`\n );\n }\n\n const wrappedHandler = this._wrapHandler(action.handler);\n const wrappedAction: Action = {\n ...action,\n handler: wrappedHandler,\n };\n\n this._triggerActionMap.set(trigger, wrappedAction);\n this._logger.debug(\n `[${INTERNAL}] Action registered successfully for trigger: ${trigger}`\n );\n }\n\n /**\n * 执行指定的 trigger 动作\n *\n * @param trigger - 触发器标识\n * @param instanceID - 实例ID\n * @param context - 执行上下文\n * @returns 执行报告数据\n */\n public async executeAction(\n trigger: string,\n instanceID: string,\n context: ActionContext\n ): Promise<ActionContext> {\n let input;\n\n // 解析输入参数\n try {\n const parsed = JSON.parse(context.content || '{}');\n input = parsed?.input ?? null;\n } catch (error) {\n input = undefined;\n const content = JSON.stringify({\n input,\n output: {\n error: ENUM_ERROR.PARAM_INVALID,\n message: `参数解析失败(trigger: ${trigger}, instanceID: ${instanceID})`,\n },\n });\n const actionCtx: ActionContext = {\n ...context,\n attributes: {\n ...context.attributes,\n phase: ENUM_PHASE.Trigger,\n status: ENUM_STATUS.FAILED,\n endAt: Date.now(),\n duration_ms: this._computeDuration(context.attributes.startAt),\n },\n content,\n };\n this.report(...convertActionContextToReportData(actionCtx));\n return actionCtx;\n }\n\n let actionCtx: ActionContext;\n try {\n // 获取动作处理器\n const action = this.getAction(trigger);\n\n if (!action) {\n actionCtx = {\n ...context,\n attributes: {\n ...context.attributes,\n phase: ENUM_PHASE.Trigger,\n status: ENUM_STATUS.FAILED,\n endAt: Date.now(),\n duration_ms: this._computeDuration(context.attributes.startAt),\n },\n content: JSON.stringify({\n input,\n output: {\n error: ENUM_ERROR.NOT_EXIST,\n message: `执行动作不存在: ${trigger}`,\n },\n }),\n };\n } else {\n // 等待包装后的 handler 完成。包装层负责产生唯一的 Action 终态。\n const actionResult = await action.handler(context);\n actionCtx = {\n ...context,\n attributes: {\n ...context.attributes,\n phase: ENUM_PHASE.Trigger,\n status: actionResult.attributes.status,\n endAt: Date.now(),\n duration_ms: this._computeDuration(context.attributes.startAt),\n },\n // Trigger 必须复用 Action 的终态输出,避免失败被改写为成功。\n content: actionResult.content,\n };\n }\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n actionCtx = {\n ...context,\n attributes: {\n ...context.attributes,\n phase: ENUM_PHASE.Trigger,\n status: ENUM_STATUS.FAILED,\n endAt: Date.now(),\n duration_ms: this._computeDuration(context.attributes.startAt),\n },\n content: JSON.stringify({\n input,\n output: { error: ENUM_ERROR.TRY_CATCH, message: errorMessage },\n }),\n };\n }\n\n // 每次 executeAction 只上报一次 Trigger 终态。\n this.report(...convertActionContextToReportData(actionCtx));\n return actionCtx;\n }\n\n /**\n * 根据 trigger 获取对应的动作\n *\n * @param trigger - 触发器标识\n * @returns 动作实例,如果不存在返回 undefined\n */\n public getAction(trigger: string): Action | undefined {\n const action = this._triggerActionMap.get(trigger);\n\n if (!action) {\n this._logger.debug(`No action found for trigger: ${trigger}`);\n return undefined;\n }\n\n this._logger.debug(`Retrieved action for trigger: ${trigger}`, {\n actionName: action.name,\n path: action.path,\n });\n\n return action;\n }\n\n /**\n * 获取所有已注册的动作\n *\n * @returns 动作映射表\n */\n public getAllActions(): Map<string, Action> {\n return this._triggerActionMap;\n }\n\n /**\n * 根据 trigger 获取动作的元数据\n *\n * @param trigger - 触发器标识\n * @returns 动作元数据,如果不存在返回 undefined\n */\n public getActionMetadata(trigger: string): ActionMetadata | undefined {\n const action = this.getAction(trigger);\n\n if (!action) {\n return undefined;\n }\n\n return {\n name: action.name,\n path: action.path,\n desc: action.desc,\n };\n }\n\n /**\n * 获取所有已注册的 trigger 标识\n *\n * @returns trigger 标识数组\n */\n public getAllTriggers(): string[] {\n const triggers = Array.from(this._triggerActionMap.keys());\n this._logger.debug(`Retrieved all triggers`, {\n count: triggers.length,\n });\n return triggers;\n }\n\n /**\n * 根据 trigger 移除对应的动作\n *\n * @param trigger - 触发器标识\n * @returns 如果成功移除返回 true,如果不存在返回 false\n */\n public removeAction(trigger: string): boolean {\n const existed = this._triggerActionMap.has(trigger);\n\n if (existed) {\n this._triggerActionMap.delete(trigger);\n this._logger.debug(`Removed action for trigger: ${trigger}`);\n } else {\n this._logger.debug(\n `Attempted to remove non-existent trigger: ${trigger}`\n );\n }\n\n return existed;\n }\n\n /**\n * 清空所有已注册的动作\n */\n public clearAllActions(): void {\n const count = this._triggerActionMap.size;\n this._triggerActionMap.clear();\n this._logger.debug(`Cleared all actions`, { count });\n }\n\n /**\n * 上报执行数据,用于日志记录和调试\n */\n public report(msg: TLogContent, extra: ILogAttributes): void {\n const {\n status,\n phase,\n start_at,\n end_at,\n trigger,\n trigger_id,\n instance_id,\n trigger_type,\n } = extra;\n\n let contentObj: { input: any; output: any } = { input: null, output: null };\n try {\n contentObj = JSON.parse(msg);\n } catch (error) {\n this._logger.debug(`Failed to parse log content as JSON: ${msg}`);\n }\n\n const duration_ms = end_at && start_at ? end_at - start_at : 0;\n\n let error_message;\n if (status === ENUM_STATUS.FAILED && contentObj?.output?.message) {\n error_message = contentObj.output.message;\n }\n\n const logContent: ILogContentParsed = {\n trigger,\n trigger_id,\n trigger_type,\n instance_id,\n phase,\n status,\n duration_ms,\n content: contentObj,\n error_message,\n };\n\n // for 观测\n const signature = {\n sourceType: 'platform',\n paas_attributes_module: 'trigger',\n };\n const newMsg = JSON.stringify(logContent);\n\n // msg\n if (status === ENUM_STATUS.FAILED) {\n this._logger.error(newMsg, { ...extra, ...signature });\n } else {\n this._logger.log(newMsg, { ...extra, ...signature });\n }\n }\n\n /**\n * 包装处理器,添加日志记录和计时功能\n *\n * @param handler - 原始处理器\n * @returns 包装后的处理器\n */\n private _computeDuration(startAt?: number): number | undefined {\n return startAt ? Date.now() - startAt : undefined;\n }\n\n private _wrapHandler(handler: Action['handler']): ActionHandler {\n return async (context: ActionContext): Promise<ActionContext> => {\n let input;\n const actionStartAt = Date.now();\n\n // 解析输入参数\n try {\n input = JSON.parse(context.content || '{}').input;\n } catch (error) {\n input = undefined;\n }\n\n let actionCtx: ActionContext;\n try {\n const output = await Promise.resolve(\n handler({\n attributes: {\n ...context.attributes,\n startAt: actionStartAt,\n },\n content: {\n input,\n },\n })\n );\n\n actionCtx = {\n ...context,\n attributes: {\n ...context.attributes,\n startAt: actionStartAt,\n phase: ENUM_PHASE.Action,\n status: ENUM_STATUS.SUCCEEDED,\n endAt: Date.now(),\n duration_ms: this._computeDuration(actionStartAt),\n },\n content: JSON.stringify({\n input,\n output,\n }),\n };\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n actionCtx = {\n ...context,\n attributes: {\n ...context.attributes,\n startAt: actionStartAt,\n phase: ENUM_PHASE.Action,\n status: ENUM_STATUS.FAILED,\n endAt: Date.now(),\n duration_ms: this._computeDuration(actionStartAt),\n },\n content: JSON.stringify({\n input,\n output: { error: ENUM_ERROR.TRY_CATCH, message: errorMessage },\n }),\n };\n }\n\n // 包装层是 Action 报告的唯一生产者。\n this.report(...convertActionContextToReportData(actionCtx));\n return actionCtx;\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;ACgBO,IAAKA,cAAAA,0BAAAA,cAAAA;;;SAAAA;;AAKL,IAAKC,aAAAA,0BAAAA,aAAAA;;;SAAAA;;AAKL,IAAKC,WAAAA,0BAAAA,WAAAA;;;SAAAA;;AAgEL,IAAKC,aAAAA,0BAAAA,aAAAA;;;;;SAAAA;;;;ACxFL,IAAMC,mCAAmC,wBAACC,cAAAA;AAC/C,QAAM,EAAEC,YAAYC,QAAO,IAAKF;AAChC,SAAO;IACLE,WAAW;IACX;MACEC,SAASF,YAAYE;MACrBC,YAAYH,YAAYI;MACxBC,cAAcL,YAAYM;MAC1BC,aAAaP,YAAYQ;MACzBC,QAAQT,YAAYS;MACpBC,OAAOV,YAAYU;MACnBC,UAAUX,YAAYY;MACtBC,QAAQb,YAAYc;MACpBC,aAAaf,YAAYe;IAC3B;;AAEJ,GAhBgD;;;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QACF,CAAA,CAAA;AAGFY,oBAAY;UACV,GAAGb;UACHc,YAAY;YACV,GAAGd,QAAQc;YACXY,SAASyC;YACTpD,OAAOC,WAAWsD;YAClBpD,QAAQC,YAAYoD;YACpBlD,OAAOC,KAAKC,IAAG;YACfC,aAAa,KAAKC,iBAAiB0C,aAAAA;UACrC;UACA9D,SAASF,KAAKK,UAAU;YACtBP;YACAQ;UACF,CAAA;QACF;MACF,SAASH,OAAO;AACd,cAAM0B,eACJ1B,iBAAiB2B,QAAQ3B,MAAMM,UAAUsB,OAAO5B,KAAAA;AAClDO,oBAAY;UACV,GAAGb;UACHc,YAAY;YACV,GAAGd,QAAQc;YACXY,SAASyC;YACTpD,OAAOC,WAAWsD;YAClBpD,QAAQC,YAAYC;YACpBC,OAAOC,KAAKC,IAAG;YACfC,aAAa,KAAKC,iBAAiB0C,aAAAA;UACrC;UACA9D,SAASF,KAAKK,UAAU;YACtBP;YACAQ,QAAQ;cAAEH,OAAOI,WAAWyB;cAAWvB,SAASoB;YAAa;UAC/D,CAAA;QACF;MACF;AAGA,WAAKL,OAAM,GAAIC,iCAAiCf,SAAAA,CAAAA;AAChD,aAAOA;IACT;EACF;AACF;","names":["ENUM_STATUS","ENUM_PHASE","ENUM_ENV","ENUM_ERROR","convertActionContextToReportData","actionCtx","attributes","content","trigger","trigger_id","triggerID","trigger_type","triggerType","instance_id","instanceID","status","phase","start_at","startAt","end_at","endAt","duration_ms","INTERNAL","TriggerClient","_triggerActionMap","Map","_logger","logger","registerAction","trigger","action","debug","actionName","name","path","desc","has","wrappedHandler","_wrapHandler","handler","wrappedAction","set","executeAction","instanceID","context","input","parsed","JSON","parse","content","error","undefined","stringify","output","ENUM_ERROR","PARAM_INVALID","message","actionCtx","attributes","phase","ENUM_PHASE","Trigger","status","ENUM_STATUS","FAILED","endAt","Date","now","duration_ms","_computeDuration","startAt","report","convertActionContextToReportData","getAction","NOT_EXIST","actionResult","errorMessage","Error","String","TRY_CATCH","get","getAllActions","getActionMetadata","getAllTriggers","triggers","Array","from","keys","count","length","removeAction","existed","delete","clearAllActions","size","clear","msg","extra","start_at","end_at","trigger_id","instance_id","trigger_type","contentObj","error_message","logContent","signature","sourceType","paas_attributes_module","newMsg","log","actionStartAt","Promise","resolve","Action","SUCCEEDED"]}
@@ -34,6 +34,7 @@ interface ActionContext {
34
34
  phase?: ENUM_PHASE;
35
35
  startAt?: number;
36
36
  endAt?: number;
37
+ duration_ms?: number;
37
38
  };
38
39
  content?: string;
39
40
  }
@@ -47,6 +48,7 @@ interface ILogAttributes {
47
48
  phase?: ENUM_PHASE;
48
49
  start_at?: number;
49
50
  end_at?: number;
51
+ duration_ms?: number;
50
52
  }
51
53
  /**
52
54
  * Action metadata (without handler)
@@ -139,7 +141,7 @@ declare class TriggerClient {
139
141
  * @param context - 执行上下文
140
142
  * @returns 执行报告数据
141
143
  */
142
- executeAction(trigger: string, instanceID: string, context: ActionContext): ActionContext;
144
+ executeAction(trigger: string, instanceID: string, context: ActionContext): Promise<ActionContext>;
143
145
  /**
144
146
  * 根据 trigger 获取对应的动作
145
147
  *
@@ -187,6 +189,7 @@ declare class TriggerClient {
187
189
  * @param handler - 原始处理器
188
190
  * @returns 包装后的处理器
189
191
  */
192
+ private _computeDuration;
190
193
  private _wrapHandler;
191
194
  }
192
195
 
@@ -34,6 +34,7 @@ interface ActionContext {
34
34
  phase?: ENUM_PHASE;
35
35
  startAt?: number;
36
36
  endAt?: number;
37
+ duration_ms?: number;
37
38
  };
38
39
  content?: string;
39
40
  }
@@ -47,6 +48,7 @@ interface ILogAttributes {
47
48
  phase?: ENUM_PHASE;
48
49
  start_at?: number;
49
50
  end_at?: number;
51
+ duration_ms?: number;
50
52
  }
51
53
  /**
52
54
  * Action metadata (without handler)
@@ -139,7 +141,7 @@ declare class TriggerClient {
139
141
  * @param context - 执行上下文
140
142
  * @returns 执行报告数据
141
143
  */
142
- executeAction(trigger: string, instanceID: string, context: ActionContext): ActionContext;
144
+ executeAction(trigger: string, instanceID: string, context: ActionContext): Promise<ActionContext>;
143
145
  /**
144
146
  * 根据 trigger 获取对应的动作
145
147
  *
@@ -187,6 +189,7 @@ declare class TriggerClient {
187
189
  * @param handler - 原始处理器
188
190
  * @returns 包装后的处理器
189
191
  */
192
+ private _computeDuration;
190
193
  private _wrapHandler;
191
194
  }
192
195
 
@@ -38,7 +38,8 @@ var convertActionContextToReportData = /* @__PURE__ */ __name((actionCtx) => {
38
38
  status: attributes?.status,
39
39
  phase: attributes?.phase,
40
40
  start_at: attributes?.startAt,
41
- end_at: attributes?.endAt
41
+ end_at: attributes?.endAt,
42
+ duration_ms: attributes?.duration_ms
42
43
  }
43
44
  ];
44
45
  }, "convertActionContextToReportData");
@@ -90,7 +91,7 @@ var TriggerClient = class {
90
91
  * @param context - 执行上下文
91
92
  * @returns 执行报告数据
92
93
  */
93
- executeAction(trigger, instanceID, context) {
94
+ async executeAction(trigger, instanceID, context) {
94
95
  let input;
95
96
  try {
96
97
  const parsed = JSON.parse(context.content || "{}");
@@ -104,29 +105,32 @@ var TriggerClient = class {
104
105
  message: `\u53C2\u6570\u89E3\u6790\u5931\u8D25(trigger: ${trigger}, instanceID: ${instanceID})`
105
106
  }
106
107
  });
107
- const actionCtx = {
108
+ const actionCtx2 = {
108
109
  ...context,
109
110
  attributes: {
110
111
  ...context.attributes,
111
112
  phase: ENUM_PHASE.Trigger,
112
113
  status: ENUM_STATUS.FAILED,
113
- endAt: Date.now()
114
+ endAt: Date.now(),
115
+ duration_ms: this._computeDuration(context.attributes.startAt)
114
116
  },
115
117
  content
116
118
  };
117
- this.report(...convertActionContextToReportData(actionCtx));
118
- return actionCtx;
119
+ this.report(...convertActionContextToReportData(actionCtx2));
120
+ return actionCtx2;
119
121
  }
122
+ let actionCtx;
120
123
  try {
121
124
  const action = this.getAction(trigger);
122
125
  if (!action) {
123
- const actionCtx2 = {
126
+ actionCtx = {
124
127
  ...context,
125
128
  attributes: {
126
129
  ...context.attributes,
127
130
  phase: ENUM_PHASE.Trigger,
128
131
  status: ENUM_STATUS.FAILED,
129
- endAt: Date.now()
132
+ endAt: Date.now(),
133
+ duration_ms: this._computeDuration(context.attributes.startAt)
130
134
  },
131
135
  content: JSON.stringify({
132
136
  input,
@@ -136,34 +140,31 @@ var TriggerClient = class {
136
140
  }
137
141
  })
138
142
  };
139
- this.report(...convertActionContextToReportData(actionCtx2));
140
- return actionCtx2;
143
+ } else {
144
+ const actionResult = await action.handler(context);
145
+ actionCtx = {
146
+ ...context,
147
+ attributes: {
148
+ ...context.attributes,
149
+ phase: ENUM_PHASE.Trigger,
150
+ status: actionResult.attributes.status,
151
+ endAt: Date.now(),
152
+ duration_ms: this._computeDuration(context.attributes.startAt)
153
+ },
154
+ // Trigger 必须复用 Action 的终态输出,避免失败被改写为成功。
155
+ content: actionResult.content
156
+ };
141
157
  }
142
- action.handler(context);
143
- const actionCtx = {
144
- ...context,
145
- attributes: {
146
- ...context.attributes,
147
- phase: ENUM_PHASE.Trigger,
148
- status: ENUM_STATUS.SUCCEEDED,
149
- endAt: Date.now()
150
- },
151
- content: JSON.stringify({
152
- input,
153
- output: null
154
- })
155
- };
156
- this.report(...convertActionContextToReportData(actionCtx));
157
- return actionCtx;
158
158
  } catch (error) {
159
159
  const errorMessage = error instanceof Error ? error.message : String(error);
160
- const actionCtx = {
160
+ actionCtx = {
161
161
  ...context,
162
162
  attributes: {
163
163
  ...context.attributes,
164
164
  phase: ENUM_PHASE.Trigger,
165
165
  status: ENUM_STATUS.FAILED,
166
- endAt: Date.now()
166
+ endAt: Date.now(),
167
+ duration_ms: this._computeDuration(context.attributes.startAt)
167
168
  },
168
169
  content: JSON.stringify({
169
170
  input,
@@ -173,9 +174,9 @@ var TriggerClient = class {
173
174
  }
174
175
  })
175
176
  };
176
- this.report(...convertActionContextToReportData(actionCtx));
177
- return actionCtx;
178
177
  }
178
+ this.report(...convertActionContextToReportData(actionCtx));
179
+ return actionCtx;
179
180
  }
180
181
  /**
181
182
  * 根据 trigger 获取对应的动作
@@ -311,16 +312,20 @@ var TriggerClient = class {
311
312
  * @param handler - 原始处理器
312
313
  * @returns 包装后的处理器
313
314
  */
315
+ _computeDuration(startAt) {
316
+ return startAt ? Date.now() - startAt : void 0;
317
+ }
314
318
  _wrapHandler(handler) {
315
319
  return async (context) => {
316
320
  let input;
321
+ const actionStartAt = Date.now();
317
322
  try {
318
323
  input = JSON.parse(context.content || "{}").input;
319
324
  } catch (error) {
320
325
  input = void 0;
321
326
  }
327
+ let actionCtx;
322
328
  try {
323
- const actionStartAt = Date.now();
324
329
  const output = await Promise.resolve(handler({
325
330
  attributes: {
326
331
  ...context.attributes,
@@ -330,31 +335,32 @@ var TriggerClient = class {
330
335
  input
331
336
  }
332
337
  }));
333
- const actionCtx = {
338
+ actionCtx = {
334
339
  ...context,
335
340
  attributes: {
336
341
  ...context.attributes,
337
342
  startAt: actionStartAt,
338
343
  phase: ENUM_PHASE.Action,
339
344
  status: ENUM_STATUS.SUCCEEDED,
340
- endAt: Date.now()
345
+ endAt: Date.now(),
346
+ duration_ms: this._computeDuration(actionStartAt)
341
347
  },
342
348
  content: JSON.stringify({
343
349
  input,
344
350
  output
345
351
  })
346
352
  };
347
- this.report(...convertActionContextToReportData(actionCtx));
348
- return actionCtx;
349
353
  } catch (error) {
350
354
  const errorMessage = error instanceof Error ? error.message : String(error);
351
- const actionCtx = {
355
+ actionCtx = {
352
356
  ...context,
353
357
  attributes: {
354
358
  ...context.attributes,
359
+ startAt: actionStartAt,
355
360
  phase: ENUM_PHASE.Action,
356
361
  status: ENUM_STATUS.FAILED,
357
- endAt: Date.now()
362
+ endAt: Date.now(),
363
+ duration_ms: this._computeDuration(actionStartAt)
358
364
  },
359
365
  content: JSON.stringify({
360
366
  input,
@@ -364,9 +370,9 @@ var TriggerClient = class {
364
370
  }
365
371
  })
366
372
  };
367
- this.report(...convertActionContextToReportData(actionCtx));
368
- return actionCtx;
369
373
  }
374
+ this.report(...convertActionContextToReportData(actionCtx));
375
+ return actionCtx;
370
376
  };
371
377
  }
372
378
  };