@tasker-systems/tasker 0.1.5 → 0.1.7

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.js CHANGED
@@ -2458,6 +2458,10 @@ var StepHandler = class {
2458
2458
  /**
2459
2459
  * Version string for the handler.
2460
2460
  * Default: "1.0.0"
2461
+ *
2462
+ * Currently a no-op — not yet wired through FFI bridges to
2463
+ * StepExecutionMetadata. Reserved for future observability
2464
+ * and compatibility tracking.
2461
2465
  */
2462
2466
  static handlerVersion = "1.0.0";
2463
2467
  /**
@@ -2902,6 +2906,34 @@ var APIMixin = class {
2902
2906
  };
2903
2907
  function applyAPI(target) {
2904
2908
  const mixin = new APIMixin();
2909
+ Object.defineProperty(mixin, "baseUrl", {
2910
+ get: () => {
2911
+ const ctor = target.constructor;
2912
+ return ctor.baseUrl || "";
2913
+ }
2914
+ });
2915
+ Object.defineProperty(mixin, "timeout", {
2916
+ get: () => {
2917
+ const ctor = target.constructor;
2918
+ return ctor.defaultTimeout || 3e4;
2919
+ }
2920
+ });
2921
+ Object.defineProperty(mixin, "defaultHeaders", {
2922
+ get: () => {
2923
+ const ctor = target.constructor;
2924
+ return ctor.defaultHeaders || {};
2925
+ }
2926
+ });
2927
+ target.get = mixin.get.bind(mixin);
2928
+ target.post = mixin.post.bind(mixin);
2929
+ target.put = mixin.put.bind(mixin);
2930
+ target.patch = mixin.patch.bind(mixin);
2931
+ target.delete = mixin.delete.bind(mixin);
2932
+ target.request = mixin.request.bind(mixin);
2933
+ target.apiSuccess = mixin.apiSuccess.bind(mixin);
2934
+ target.apiFailure = mixin.apiFailure.bind(mixin);
2935
+ target.connectionError = mixin.connectionError.bind(mixin);
2936
+ target.timeoutError = mixin.timeoutError.bind(mixin);
2905
2937
  Object.defineProperty(target, "baseUrl", {
2906
2938
  get: () => {
2907
2939
  const ctor = target.constructor;
@@ -2920,16 +2952,6 @@ function applyAPI(target) {
2920
2952
  return ctor.defaultHeaders || {};
2921
2953
  }
2922
2954
  });
2923
- target.get = mixin.get.bind(target);
2924
- target.post = mixin.post.bind(target);
2925
- target.put = mixin.put.bind(target);
2926
- target.patch = mixin.patch.bind(target);
2927
- target.delete = mixin.delete.bind(target);
2928
- target.request = mixin.request.bind(target);
2929
- target.apiSuccess = mixin.apiSuccess.bind(target);
2930
- target.apiFailure = mixin.apiFailure.bind(target);
2931
- target.connectionError = mixin.connectionError.bind(target);
2932
- target.timeoutError = mixin.timeoutError.bind(target);
2933
2955
  return target;
2934
2956
  }
2935
2957
 
@@ -4713,6 +4735,245 @@ function createFfiPollAdapter(module) {
4713
4735
  };
4714
4736
  }
4715
4737
 
4738
+ // src/handler/functional.ts
4739
+ var PermanentError = class extends Error {
4740
+ retryable = false;
4741
+ metadata;
4742
+ constructor(message, metadata) {
4743
+ super(message);
4744
+ this.name = "PermanentError";
4745
+ this.metadata = metadata ?? {};
4746
+ }
4747
+ };
4748
+ var RetryableError = class extends Error {
4749
+ retryable = true;
4750
+ metadata;
4751
+ constructor(message, metadata) {
4752
+ super(message);
4753
+ this.name = "RetryableError";
4754
+ this.metadata = metadata ?? {};
4755
+ }
4756
+ };
4757
+ var Decision = class _Decision {
4758
+ constructor(type, steps, reason, routingContext = {}) {
4759
+ this.type = type;
4760
+ this.steps = steps;
4761
+ this.reason = reason;
4762
+ this.routingContext = routingContext;
4763
+ }
4764
+ /**
4765
+ * Route to the specified steps.
4766
+ */
4767
+ static route(steps, routingContext) {
4768
+ return new _Decision("create_steps", steps, void 0, routingContext ?? {});
4769
+ }
4770
+ /**
4771
+ * Skip all branches.
4772
+ */
4773
+ static skip(reason, routingContext) {
4774
+ return new _Decision("no_branches", [], reason, routingContext ?? {});
4775
+ }
4776
+ };
4777
+ function wrapResult(result) {
4778
+ if (result instanceof StepHandlerResult) {
4779
+ return result;
4780
+ }
4781
+ if (result != null && typeof result === "object" && !Array.isArray(result)) {
4782
+ return StepHandlerResult.success(result);
4783
+ }
4784
+ if (result == null) {
4785
+ return StepHandlerResult.success({});
4786
+ }
4787
+ return StepHandlerResult.success({ result });
4788
+ }
4789
+ function wrapError(error) {
4790
+ if (error instanceof PermanentError) {
4791
+ return StepHandlerResult.failure(
4792
+ error.message,
4793
+ "permanent_error" /* PERMANENT_ERROR */,
4794
+ false,
4795
+ error.metadata
4796
+ );
4797
+ }
4798
+ if (error instanceof RetryableError) {
4799
+ return StepHandlerResult.failure(
4800
+ error.message,
4801
+ "retryable_error" /* RETRYABLE_ERROR */,
4802
+ true,
4803
+ error.metadata
4804
+ );
4805
+ }
4806
+ const message = error instanceof Error ? error.message : String(error);
4807
+ return StepHandlerResult.failure(message, "handler_error" /* HANDLER_ERROR */, true, {
4808
+ errorType: error instanceof Error ? error.constructor.name : typeof error
4809
+ });
4810
+ }
4811
+ function injectArgs(context, depends, inputs) {
4812
+ const args = { context };
4813
+ for (const [paramName, stepName] of Object.entries(depends)) {
4814
+ args[paramName] = context.getDependencyResult(stepName);
4815
+ }
4816
+ for (const [paramName, inputKey] of Object.entries(inputs)) {
4817
+ args[paramName] = context.getInput(inputKey);
4818
+ }
4819
+ return args;
4820
+ }
4821
+ function defineHandler(name, options, fn) {
4822
+ const depends = options.depends ?? {};
4823
+ const inputs = options.inputs ?? {};
4824
+ const version = options.version ?? "1.0.0";
4825
+ const HandlerClass = class extends StepHandler {
4826
+ static handlerName = name;
4827
+ static handlerVersion = version;
4828
+ async call(context) {
4829
+ try {
4830
+ const args = injectArgs(context, depends, inputs);
4831
+ const rawResult = await fn(args);
4832
+ return wrapResult(rawResult);
4833
+ } catch (error) {
4834
+ return wrapError(error);
4835
+ }
4836
+ }
4837
+ };
4838
+ Object.defineProperty(HandlerClass, "name", { value: name });
4839
+ return HandlerClass;
4840
+ }
4841
+ function defineDecisionHandler(name, options, fn) {
4842
+ const depends = options.depends ?? {};
4843
+ const inputs = options.inputs ?? {};
4844
+ const version = options.version ?? "1.0.0";
4845
+ const HandlerClass = class extends StepHandler {
4846
+ static handlerName = name;
4847
+ static handlerVersion = version;
4848
+ get capabilities() {
4849
+ return ["process", "decision", "routing"];
4850
+ }
4851
+ async call(context) {
4852
+ try {
4853
+ const args = injectArgs(context, depends, inputs);
4854
+ const rawResult = await fn(args);
4855
+ if (rawResult instanceof StepHandlerResult) {
4856
+ return rawResult;
4857
+ }
4858
+ if (rawResult instanceof Decision) {
4859
+ const mixin = new DecisionMixin();
4860
+ Object.defineProperty(mixin, "name", { get: () => name });
4861
+ Object.defineProperty(mixin, "version", { get: () => version });
4862
+ if (rawResult.type === "create_steps") {
4863
+ return mixin.decisionSuccess(rawResult.steps, rawResult.routingContext);
4864
+ }
4865
+ return mixin.skipBranches(rawResult.reason ?? "", rawResult.routingContext);
4866
+ }
4867
+ return wrapResult(rawResult);
4868
+ } catch (error) {
4869
+ return wrapError(error);
4870
+ }
4871
+ }
4872
+ };
4873
+ Object.defineProperty(HandlerClass, "name", { value: name });
4874
+ return HandlerClass;
4875
+ }
4876
+ function defineBatchAnalyzer(name, options, fn) {
4877
+ const depends = options.depends ?? {};
4878
+ const inputs = options.inputs ?? {};
4879
+ const version = options.version ?? "1.0.0";
4880
+ const workerTemplate = options.workerTemplate;
4881
+ const HandlerClass = class extends StepHandler {
4882
+ static handlerName = name;
4883
+ static handlerVersion = version;
4884
+ async call(context) {
4885
+ try {
4886
+ const args = injectArgs(context, depends, inputs);
4887
+ const rawResult = await fn(args);
4888
+ if (rawResult instanceof StepHandlerResult) {
4889
+ return rawResult;
4890
+ }
4891
+ const config = rawResult;
4892
+ const { totalItems, batchSize } = config;
4893
+ const batchMixin = new BatchableMixin();
4894
+ const cursorRanges = batchMixin.createCursorRanges(totalItems, batchSize);
4895
+ const rustConfigs = cursorRanges.map((c, idx) => ({
4896
+ batch_id: `batch_${String(idx).padStart(3, "0")}`,
4897
+ start_cursor: c.startCursor,
4898
+ end_cursor: c.endCursor,
4899
+ batch_size: c.endCursor - c.startCursor
4900
+ }));
4901
+ const batchProcessingOutcome = createBatches(
4902
+ workerTemplate,
4903
+ rustConfigs.length,
4904
+ rustConfigs,
4905
+ totalItems
4906
+ );
4907
+ return StepHandlerResult.success(
4908
+ { batch_processing_outcome: batchProcessingOutcome },
4909
+ {
4910
+ batch_count: rustConfigs.length,
4911
+ total_items: totalItems,
4912
+ ...config.metadata ?? {}
4913
+ }
4914
+ );
4915
+ } catch (error) {
4916
+ return wrapError(error);
4917
+ }
4918
+ }
4919
+ };
4920
+ Object.defineProperty(HandlerClass, "name", { value: name });
4921
+ return HandlerClass;
4922
+ }
4923
+ function defineBatchWorker(name, options, fn) {
4924
+ const depends = options.depends ?? {};
4925
+ const inputs = options.inputs ?? {};
4926
+ const version = options.version ?? "1.0.0";
4927
+ const HandlerClass = class extends StepHandler {
4928
+ static handlerName = name;
4929
+ static handlerVersion = version;
4930
+ async call(context) {
4931
+ try {
4932
+ const args = injectArgs(context, depends, inputs);
4933
+ const batchMixin = new BatchableMixin();
4934
+ args.batchContext = batchMixin.getBatchContext(context);
4935
+ const rawResult = await fn(args);
4936
+ return wrapResult(rawResult);
4937
+ } catch (error) {
4938
+ return wrapError(error);
4939
+ }
4940
+ }
4941
+ };
4942
+ Object.defineProperty(HandlerClass, "name", { value: name });
4943
+ return HandlerClass;
4944
+ }
4945
+ function defineApiHandler(name, options, fn) {
4946
+ const depends = options.depends ?? {};
4947
+ const inputs = options.inputs ?? {};
4948
+ const version = options.version ?? "1.0.0";
4949
+ const apiBaseUrl = options.baseUrl;
4950
+ const apiTimeout = options.defaultTimeout ?? 3e4;
4951
+ const apiHeaders = options.defaultHeaders ?? {};
4952
+ const HandlerClass = class extends StepHandler {
4953
+ static handlerName = name;
4954
+ static handlerVersion = version;
4955
+ static baseUrl = apiBaseUrl;
4956
+ static defaultTimeout = apiTimeout;
4957
+ static defaultHeaders = apiHeaders;
4958
+ constructor() {
4959
+ super();
4960
+ applyAPI(this);
4961
+ }
4962
+ async call(context) {
4963
+ try {
4964
+ const args = injectArgs(context, depends, inputs);
4965
+ args.api = this;
4966
+ const rawResult = await fn(args);
4967
+ return wrapResult(rawResult);
4968
+ } catch (error) {
4969
+ return wrapError(error);
4970
+ }
4971
+ }
4972
+ };
4973
+ Object.defineProperty(HandlerClass, "name", { value: name });
4974
+ return HandlerClass;
4975
+ }
4976
+
4716
4977
  // src/registry/errors.ts
4717
4978
  var ResolutionError = class extends Error {
4718
4979
  constructor(message) {
@@ -5419,9 +5680,17 @@ var HandlerSystem = class {
5419
5680
  }
5420
5681
  log5.info(`Loading handlers from: ${path}`, { operation: "load_from_path" });
5421
5682
  try {
5683
+ let totalCount = 0;
5422
5684
  const indexResult = await this.tryImportIndexFile(path);
5423
5685
  if (indexResult.module) {
5424
- return this.registerHandlersFromModule(indexResult.module, indexResult.path);
5686
+ totalCount += this.registerHandlersFromModule(indexResult.module, indexResult.path);
5687
+ }
5688
+ const dslResult = await this.tryImportDslExamplesIndex(path);
5689
+ if (dslResult.module) {
5690
+ totalCount += this.registerHandlersFromModule(dslResult.module, dslResult.path);
5691
+ }
5692
+ if (totalCount > 0) {
5693
+ return totalCount;
5425
5694
  }
5426
5695
  log5.debug("No index file found, scanning for handler files...", {
5427
5696
  operation: "load_from_path"
@@ -5609,20 +5878,45 @@ var HandlerSystem = class {
5609
5878
  }
5610
5879
  return { module: null, path: null };
5611
5880
  }
5881
+ /**
5882
+ * TAS-294: Try to import the dsl_examples index file.
5883
+ * This is separate from tryImportIndexFile because dsl_examples/ is a sibling
5884
+ * directory to examples/, and both need to be loaded.
5885
+ */
5886
+ async tryImportDslExamplesIndex(handlerPath) {
5887
+ const dslPaths = [
5888
+ join(handlerPath, "dsl_examples", "index.js"),
5889
+ join(handlerPath, "dsl_examples", "index.ts")
5890
+ ];
5891
+ for (const indexPath of dslPaths) {
5892
+ if (existsSync(indexPath)) {
5893
+ const module = await import(`file://${indexPath}`);
5894
+ return { module, path: indexPath };
5895
+ }
5896
+ }
5897
+ return { module: null, path: null };
5898
+ }
5612
5899
  /**
5613
5900
  * Register handlers from a module's exports.
5614
5901
  */
5615
5902
  registerHandlersFromModule(module, importPath) {
5616
5903
  log5.info(`Loaded handler module from: ${importPath}`, { operation: "import_handlers" });
5904
+ let count = 0;
5617
5905
  if (Array.isArray(module.ALL_EXAMPLE_HANDLERS)) {
5618
- return this.registerFromHandlerArray(module.ALL_EXAMPLE_HANDLERS);
5906
+ count += this.registerFromHandlerArray(module.ALL_EXAMPLE_HANDLERS, "ALL_EXAMPLE_HANDLERS");
5907
+ }
5908
+ if (Array.isArray(module.ALL_DSL_HANDLERS)) {
5909
+ count += this.registerFromHandlerArray(module.ALL_DSL_HANDLERS, "ALL_DSL_HANDLERS");
5910
+ }
5911
+ if (count > 0) {
5912
+ return count;
5619
5913
  }
5620
5914
  return this.registerFromModuleExports(module);
5621
5915
  }
5622
5916
  /**
5623
- * Register handlers from ALL_EXAMPLE_HANDLERS array.
5917
+ * Register handlers from a named handler array.
5624
5918
  */
5625
- registerFromHandlerArray(handlers) {
5919
+ registerFromHandlerArray(handlers, arrayName = "ALL_EXAMPLE_HANDLERS") {
5626
5920
  let count = 0;
5627
5921
  for (const handlerClass of handlers) {
5628
5922
  if (this.isValidHandlerClass(handlerClass)) {
@@ -5630,7 +5924,7 @@ var HandlerSystem = class {
5630
5924
  count++;
5631
5925
  }
5632
5926
  }
5633
- log5.info(`Registered ${count} handlers from ALL_EXAMPLE_HANDLERS`, {
5927
+ log5.info(`Registered ${count} handlers from ${arrayName}`, {
5634
5928
  operation: "import_handlers"
5635
5929
  });
5636
5930
  return count;
@@ -6164,6 +6458,6 @@ var WorkerServer = class {
6164
6458
  }
6165
6459
  };
6166
6460
 
6167
- export { APIMixin, ApiHandler, ApiResponse, BasePublisher, BaseSubscriber, BatchableMixin, ClassLookupResolver, DecisionHandler, DecisionMixin, DecisionType, DefaultPublisher, DuplicatePublisherError, ErrorType, EventNames, EventPoller, EventSystem, ExplicitMappingResolver, FfiLayer, HandlerRegistry, HandlerSystem, InProcessDomainEventPoller, MethodDispatchError, MethodDispatchWrapper, MetricsEventNames, NoResolverMatchError, PollerEventNames, PublisherNotFoundError, PublisherRegistry, PublisherValidationError, RegistryFrozenError, RegistryResolver, ResolutionError, ResolverChain, ResolverNotFoundError, ShutdownController, StepContext, StepEventNames, StepExecutionSubscriber, StepHandler, StepHandlerResult, SubscriberRegistry, TaskerClient, TaskerClientError, TaskerEventEmitter, WorkerEventNames, WorkerServer, aggregateBatchResults, applyAPI, applyBatchable, applyDecision, bootstrapWorker, createBatchWorkerContext, createBatches, createDomainEvent, createEventPoller, createFfiPollAdapter, createLogger, createStepEventContext, effectiveMethod, ffiEventToDomainEvent, fromCallable, fromDto, getRustVersion, getVersion, getWorkerStatus, hasResolverHint, healthCheck, isCreateBatches, isNoBatches, isStandardErrorType, isTypicallyRetryable, isWorkerRunning, logDebug, logError, logInfo, logTrace, logWarn, noBatches, normalizeToDefinition, stopWorker, transitionToGracefulShutdown, usesMethodDispatch };
6461
+ export { APIMixin, ApiHandler, ApiResponse, BasePublisher, BaseSubscriber, BatchableMixin, ClassLookupResolver, Decision, DecisionHandler, DecisionMixin, DecisionType, DefaultPublisher, DuplicatePublisherError, ErrorType, EventNames, EventPoller, EventSystem, ExplicitMappingResolver, FfiLayer, HandlerRegistry, HandlerSystem, InProcessDomainEventPoller, MethodDispatchError, MethodDispatchWrapper, MetricsEventNames, NoResolverMatchError, PermanentError, PollerEventNames, PublisherNotFoundError, PublisherRegistry, PublisherValidationError, RegistryFrozenError, RegistryResolver, ResolutionError, ResolverChain, ResolverNotFoundError, RetryableError, ShutdownController, StepContext, StepEventNames, StepExecutionSubscriber, StepHandler, StepHandlerResult, SubscriberRegistry, TaskerClient, TaskerClientError, TaskerEventEmitter, WorkerEventNames, WorkerServer, aggregateBatchResults, applyAPI, applyBatchable, applyDecision, bootstrapWorker, createBatchWorkerContext, createBatches, createDomainEvent, createEventPoller, createFfiPollAdapter, createLogger, createStepEventContext, defineApiHandler, defineBatchAnalyzer, defineBatchWorker, defineDecisionHandler, defineHandler, effectiveMethod, ffiEventToDomainEvent, fromCallable, fromDto, getRustVersion, getVersion, getWorkerStatus, hasResolverHint, healthCheck, isCreateBatches, isNoBatches, isStandardErrorType, isTypicallyRetryable, isWorkerRunning, logDebug, logError, logInfo, logTrace, logWarn, noBatches, normalizeToDefinition, stopWorker, transitionToGracefulShutdown, usesMethodDispatch };
6168
6462
  //# sourceMappingURL=index.js.map
6169
6463
  //# sourceMappingURL=index.js.map