@io-orkes/conductor-javascript 3.0.0 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -39160,7 +39160,7 @@ var defaultRunnerOptions = {
39160
39160
  concurrency: DEFAULT_CONCURRENCY,
39161
39161
  batchPollingTimeout: DEFAULT_BATCH_POLLING_TIMEOUT
39162
39162
  };
39163
- var TaskRunner = class {
39163
+ var TaskRunner = class _TaskRunner {
39164
39164
  _client;
39165
39165
  worker;
39166
39166
  logger;
@@ -39285,21 +39285,94 @@ var TaskRunner = class {
39285
39285
  throw error;
39286
39286
  }
39287
39287
  };
39288
+ /**
39289
+ * Probed once per process. null = unknown, true = v2 endpoint available,
39290
+ * false = legacy server (no /api/tasks/update-v2 endpoint).
39291
+ */
39292
+ static updateV2Available = null;
39288
39293
  updateTaskWithRetry = async (task, taskResult) => {
39289
39294
  const { workerID } = this.options;
39290
39295
  let retryCount = 0;
39291
39296
  let lastError = null;
39292
39297
  while (retryCount < this.maxRetries) {
39293
39298
  try {
39299
+ if (process.env.CI) {
39300
+ console.log(
39301
+ `[TaskRunner] Submitting task result taskId=${taskResult.taskId} workflowId=${taskResult.workflowInstanceId} taskType=${this.worker.taskDefName} attempt=${retryCount + 1}/${this.maxRetries}`
39302
+ );
39303
+ }
39294
39304
  const updateStart = Date.now();
39295
- const { data: nextTask } = await TaskResource.updateTaskV2({
39296
- client: this._client,
39297
- body: {
39298
- ...taskResult,
39299
- workerId: workerID
39305
+ if (_TaskRunner.updateV2Available === false) {
39306
+ await TaskResource.updateTask({
39307
+ client: this._client,
39308
+ body: { ...taskResult, workerId: workerID },
39309
+ throwOnError: true
39310
+ });
39311
+ const updateDurationMs2 = Date.now() - updateStart;
39312
+ if (process.env.CI) {
39313
+ console.log(
39314
+ `[TaskRunner] Task result accepted (legacy) taskId=${taskResult.taskId} durationMs=${updateDurationMs2}`
39315
+ );
39300
39316
  }
39317
+ await this.eventDispatcher.publishTaskUpdateCompleted({
39318
+ taskType: this.worker.taskDefName,
39319
+ taskId: taskResult.taskId ?? "",
39320
+ workerId: workerID,
39321
+ workflowInstanceId: taskResult.workflowInstanceId,
39322
+ durationMs: updateDurationMs2,
39323
+ timestamp: /* @__PURE__ */ new Date()
39324
+ });
39325
+ return void 0;
39326
+ }
39327
+ const {
39328
+ data: nextTask,
39329
+ error,
39330
+ response
39331
+ } = await TaskResource.updateTaskV2({
39332
+ client: this._client,
39333
+ body: { ...taskResult, workerId: workerID },
39334
+ throwOnError: false
39301
39335
  });
39336
+ if (response.status === 404 || response.status === 405) {
39337
+ if (_TaskRunner.updateV2Available === null) {
39338
+ console.log(
39339
+ `[TaskRunner] /api/tasks/update-v2 not available (HTTP ${response.status}), falling back to legacy /api/tasks endpoint`
39340
+ );
39341
+ _TaskRunner.updateV2Available = false;
39342
+ }
39343
+ await TaskResource.updateTask({
39344
+ client: this._client,
39345
+ body: { ...taskResult, workerId: workerID },
39346
+ throwOnError: true
39347
+ });
39348
+ const updateDurationMs2 = Date.now() - updateStart;
39349
+ if (process.env.CI) {
39350
+ console.log(
39351
+ `[TaskRunner] Task result accepted (legacy) taskId=${taskResult.taskId} durationMs=${updateDurationMs2}`
39352
+ );
39353
+ }
39354
+ await this.eventDispatcher.publishTaskUpdateCompleted({
39355
+ taskType: this.worker.taskDefName,
39356
+ taskId: taskResult.taskId ?? "",
39357
+ workerId: workerID,
39358
+ workflowInstanceId: taskResult.workflowInstanceId,
39359
+ durationMs: updateDurationMs2,
39360
+ timestamp: /* @__PURE__ */ new Date()
39361
+ });
39362
+ return void 0;
39363
+ }
39364
+ if (!response.ok) {
39365
+ throw error ?? new Error(`Task update failed with HTTP ${response.status}`);
39366
+ }
39367
+ if (_TaskRunner.updateV2Available === null) {
39368
+ _TaskRunner.updateV2Available = true;
39369
+ }
39302
39370
  const updateDurationMs = Date.now() - updateStart;
39371
+ if (process.env.CI) {
39372
+ console.log(
39373
+ `[TaskRunner] Task result accepted taskId=${taskResult.taskId} durationMs=${updateDurationMs}`
39374
+ );
39375
+ }
39303
39376
  await this.eventDispatcher.publishTaskUpdateCompleted({
39304
39377
  taskType: this.worker.taskDefName,
39305
39378
  taskId: taskResult.taskId ?? "",
@@ -39316,6 +39389,9 @@ var TaskRunner = class {
39316
39389
  `Error updating task ${taskResult.taskId} on retry ${retryCount + 1}/${this.maxRetries}`,
39317
39390
  error
39318
39391
  );
39392
+ console.log(
39393
+ `[TaskRunner] Task update failed taskId=${taskResult.taskId} attempt=${retryCount + 1}/${this.maxRetries} error=${lastError?.message ?? String(error)}`
39394
+ );
39319
39395
  retryCount++;
39320
39396
  if (retryCount < this.maxRetries) {
39321
39397
  const delayMs = retryCount * 10 * 1e3;
@@ -41328,20 +41404,51 @@ var TaskHandler = class _TaskHandler {
41328
41404
 
41329
41405
  // src/sdk/worker/schema/decorators.ts
41330
41406
  var SCHEMA_METADATA_KEY = Symbol("conductor:schemaField");
41407
+ function isNewDecoratorContext(arg) {
41408
+ return typeof arg === "object" && arg !== null && "kind" in arg && typeof arg.kind === "string";
41409
+ }
41410
+ var schemaFieldProcessed = /* @__PURE__ */ new WeakMap();
41411
+ function storeSchemaFieldMetadata(cls, propertyKey, options, designType) {
41412
+ const existing = Reflect.getOwnMetadata(SCHEMA_METADATA_KEY, cls) ?? [];
41413
+ existing.push({
41414
+ ...options,
41415
+ propertyKey,
41416
+ designType
41417
+ });
41418
+ Reflect.defineMetadata(SCHEMA_METADATA_KEY, existing, cls);
41419
+ }
41331
41420
  function schemaField(options = {}) {
41332
- return function(target, propertyKey) {
41333
- const existing = Reflect.getOwnMetadata(SCHEMA_METADATA_KEY, target.constructor) ?? [];
41421
+ return function(targetOrValue, propertyKeyOrContext) {
41422
+ if (isNewDecoratorContext(propertyKeyOrContext)) {
41423
+ const propertyKey2 = String(propertyKeyOrContext.name);
41424
+ return function(initialValue) {
41425
+ const cls = this.constructor;
41426
+ const processed = schemaFieldProcessed.get(cls) ?? /* @__PURE__ */ new Set();
41427
+ if (!processed.has(propertyKey2)) {
41428
+ processed.add(propertyKey2);
41429
+ schemaFieldProcessed.set(cls, processed);
41430
+ let designType2;
41431
+ try {
41432
+ designType2 = Reflect.getMetadata(
41433
+ "design:type",
41434
+ this,
41435
+ propertyKey2
41436
+ );
41437
+ } catch {
41438
+ }
41439
+ storeSchemaFieldMetadata(cls, propertyKey2, options, designType2);
41440
+ }
41441
+ return initialValue;
41442
+ };
41443
+ }
41444
+ const target = targetOrValue;
41445
+ const propertyKey = propertyKeyOrContext;
41334
41446
  let designType;
41335
41447
  try {
41336
41448
  designType = Reflect.getMetadata("design:type", target, propertyKey);
41337
41449
  } catch {
41338
41450
  }
41339
- existing.push({
41340
- ...options,
41341
- propertyKey,
41342
- designType
41343
- });
41344
- Reflect.defineMetadata(SCHEMA_METADATA_KEY, existing, target.constructor);
41451
+ storeSchemaFieldMetadata(target.constructor, propertyKey, options, designType);
41345
41452
  };
41346
41453
  }
41347
41454
  function inferType(designType) {
@@ -41402,9 +41509,20 @@ function generateSchemaFromClass(cls) {
41402
41509
  }
41403
41510
 
41404
41511
  // src/sdk/worker/decorators/worker.ts
41512
+ function isNewDecoratorContext2(arg) {
41513
+ return typeof arg === "object" && arg !== null && "kind" in arg && typeof arg.kind === "string";
41514
+ }
41405
41515
  function worker(options) {
41406
- return function(target, propertyKey, descriptor) {
41407
- const executeFunction = descriptor?.value || target;
41516
+ function decorator(target, propertyKeyOrContext, descriptor) {
41517
+ let executeFunction;
41518
+ let isNewApi = false;
41519
+ if (isNewDecoratorContext2(propertyKeyOrContext)) {
41520
+ executeFunction = target;
41521
+ isNewApi = true;
41522
+ } else {
41523
+ const fn = descriptor?.value ?? target;
41524
+ executeFunction = fn;
41525
+ }
41408
41526
  if (typeof executeFunction !== "function") {
41409
41527
  throw new Error(
41410
41528
  `@worker decorator can only be applied to functions. Received: ${typeof executeFunction}`
@@ -41418,10 +41536,14 @@ function worker(options) {
41418
41536
  let resolvedInputSchema = options.inputSchema;
41419
41537
  let resolvedOutputSchema = options.outputSchema;
41420
41538
  if (options.inputType) {
41421
- resolvedInputSchema = generateSchemaFromClass(options.inputType);
41539
+ resolvedInputSchema = generateSchemaFromClass(
41540
+ options.inputType
41541
+ );
41422
41542
  }
41423
41543
  if (options.outputType) {
41424
- resolvedOutputSchema = generateSchemaFromClass(options.outputType);
41544
+ resolvedOutputSchema = generateSchemaFromClass(
41545
+ options.outputType
41546
+ );
41425
41547
  }
41426
41548
  const registeredWorker = {
41427
41549
  taskDefName: options.taskDefName,
@@ -41448,18 +41570,25 @@ function worker(options) {
41448
41570
  builderArgs.inputParameters ?? {}
41449
41571
  );
41450
41572
  }
41451
- return executeFunction.apply(this, args);
41573
+ return executeFunction.apply(
41574
+ this,
41575
+ args
41576
+ );
41452
41577
  };
41453
41578
  Object.defineProperty(dualModeFunction, "name", {
41454
41579
  value: executeFunction.name,
41455
41580
  configurable: true
41456
41581
  });
41582
+ if (isNewApi) {
41583
+ return dualModeFunction;
41584
+ }
41457
41585
  if (descriptor) {
41458
41586
  descriptor.value = dualModeFunction;
41459
41587
  return descriptor;
41460
41588
  }
41461
41589
  return dualModeFunction;
41462
- };
41590
+ }
41591
+ return decorator;
41463
41592
  }
41464
41593
 
41465
41594
  // src/sdk/worker/metrics/MetricsCollector.ts