@tasker-systems/tasker 0.1.7 → 0.1.8

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.
@@ -1244,9 +1244,25 @@ declare class StepExecutionSubscriber {
1244
1244
  /**
1245
1245
  * Send a completion result to Rust via FFI and handle the response.
1246
1246
  *
1247
+ * If the primary FFI call fails (e.g. serialization error, unexpected
1248
+ * type mismatch), we construct a guaranteed-safe failure result so the
1249
+ * step is marked as permanently failed rather than silently lost.
1250
+ *
1247
1251
  * @returns true if the completion was accepted by Rust, false otherwise
1248
1252
  */
1249
1253
  private sendCompletionViaFfi;
1254
+ /**
1255
+ * Submit a minimal safe-failure result after the primary FFI call fails.
1256
+ *
1257
+ * Builds a primitive-only result guaranteed to serialize, then attempts
1258
+ * to submit it. Throws if the fallback is also rejected or fails,
1259
+ * since the step would otherwise be silently lost.
1260
+ */
1261
+ private submitFallbackFailure;
1262
+ /**
1263
+ * Throw an error indicating a step has been orphaned (both primary and fallback failed).
1264
+ */
1265
+ private throwOrphanedError;
1250
1266
  /**
1251
1267
  * Handle successful FFI completion submission.
1252
1268
  */
@@ -1259,6 +1275,14 @@ declare class StepExecutionSubscriber {
1259
1275
  * Handle FFI completion error.
1260
1276
  */
1261
1277
  private handleFfiError;
1278
+ /**
1279
+ * Build a minimal NapiStepExecutionResult guaranteed to serialize through napi-rs.
1280
+ *
1281
+ * Uses only primitive values so there is zero chance of a secondary
1282
+ * serialization failure. The step will be marked as permanently failed
1283
+ * rather than silently lost.
1284
+ */
1285
+ private buildFfiSafeFailure;
1262
1286
  }
1263
1287
 
1264
1288
  /**
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { NapiModule, FfiLayer, FfiDomainEvent, FfiLayerConfig } from './ffi/index.js';
2
2
  export { BootstrapConfig as FfiBootstrapConfig, BootstrapResult as FfiBootstrapResult, FfiDispatchMetrics, LogFields as FfiLogFields, FfiStepEvent, StopResult as FfiStopResult, WorkerStatus as FfiWorkerStatus, NapiBackoffHint, NapiCheckpointYieldData, NapiClientResult, NapiDependencyResult, NapiDispatchMetrics, NapiDomainEvent, NapiDomainEventMetadata, NapiListTasksParams, NapiOrchestrationMetadata, NapiStepDefinition, NapiStepEvent, NapiStepExecutionError, NapiStepExecutionMetadata, NapiStepExecutionResult, NapiTaskInfo, NapiTaskRequest, NapiWorkflowStep, StepExecutionResult } from './ffi/index.js';
3
- import { S as StepHandlerResult, a as StepHandler, B as BatchWorkerConfig, b as StepContext, c as StepHandlerClass, E as ExecutableHandler, T as TaskerEventEmitter, d as EventPoller, e as StepExecutionSubscriber, f as EventSystem } from './index-CRCYa9Xk.js';
4
- export { y as ErrorCallback, I as ErrorType, n as EventName, o as EventNames, z as EventPollerConfig, F as EventSystemConfig, G as EventSystemStats, A as MetricsCallback, p as MetricsEventName, q as MetricsEventNames, M as MetricsPayload, P as PollerCyclePayload, r as PollerEventName, s as PollerEventNames, C as PollerState, g as StepCompletionSentPayload, L as StepContextParams, D as StepEventCallback, t as StepEventName, u as StepEventNames, h as StepExecutionCompletedPayload, i as StepExecutionFailedPayload, j as StepExecutionReceivedPayload, k as StepExecutionStartedPayload, H as StepExecutionSubscriberConfig, N as StepHandlerResultParams, l as TaskerEventMap, W as WorkerErrorPayload, v as WorkerEventName, w as WorkerEventNames, m as WorkerEventPayload, x as createEventPoller, J as isStandardErrorType, K as isTypicallyRetryable } from './index-CRCYa9Xk.js';
3
+ import { S as StepHandlerResult, a as StepHandler, B as BatchWorkerConfig, b as StepContext, c as StepHandlerClass, E as ExecutableHandler, T as TaskerEventEmitter, d as EventPoller, e as StepExecutionSubscriber, f as EventSystem } from './index-CVhy3k3k.js';
4
+ export { y as ErrorCallback, I as ErrorType, n as EventName, o as EventNames, z as EventPollerConfig, F as EventSystemConfig, G as EventSystemStats, A as MetricsCallback, p as MetricsEventName, q as MetricsEventNames, M as MetricsPayload, P as PollerCyclePayload, r as PollerEventName, s as PollerEventNames, C as PollerState, g as StepCompletionSentPayload, L as StepContextParams, D as StepEventCallback, t as StepEventName, u as StepEventNames, h as StepExecutionCompletedPayload, i as StepExecutionFailedPayload, j as StepExecutionReceivedPayload, k as StepExecutionStartedPayload, H as StepExecutionSubscriberConfig, N as StepHandlerResultParams, l as TaskerEventMap, W as WorkerErrorPayload, v as WorkerEventName, w as WorkerEventNames, m as WorkerEventPayload, x as createEventPoller, J as isStandardErrorType, K as isTypicallyRetryable } from './index-CVhy3k3k.js';
5
5
  import { Logger } from 'pino';
6
6
  import 'eventemitter3';
7
7
 
@@ -220,6 +220,155 @@ declare function getRustVersion(module?: NapiModule): string;
220
220
  */
221
221
  declare function healthCheck(module?: NapiModule): boolean;
222
222
 
223
+ /**
224
+ * Client response types matching tasker-shared API response structs.
225
+ *
226
+ * These interfaces mirror the Rust types in `tasker_shared::types::api::orchestration`
227
+ * that are serialized to JSON via `serde_json::to_value()` in the FfiClientBridge.
228
+ * Field names use snake_case because serde's default serialization preserves the
229
+ * Rust field names.
230
+ *
231
+ * Source of truth: tasker-shared/src/types/api/orchestration.rs
232
+ */
233
+ /**
234
+ * Step readiness analysis from the orchestration database function.
235
+ *
236
+ * Mirrors: tasker_shared::database::sql_functions::StepReadinessStatus
237
+ */
238
+ interface StepReadinessStatus {
239
+ workflow_step_uuid: string;
240
+ task_uuid: string;
241
+ named_step_uuid: string;
242
+ name: string;
243
+ current_state: string;
244
+ dependencies_satisfied: boolean;
245
+ retry_eligible: boolean;
246
+ ready_for_execution: boolean;
247
+ last_failure_at: string | null;
248
+ next_retry_at: string | null;
249
+ total_parents: number;
250
+ completed_parents: number;
251
+ attempts: number;
252
+ max_attempts: number;
253
+ backoff_request_seconds: number | null;
254
+ last_attempted_at: string | null;
255
+ }
256
+ /**
257
+ * Task details response with execution context and step readiness.
258
+ *
259
+ * Mirrors: tasker_shared::types::api::orchestration::TaskResponse
260
+ */
261
+ interface TaskResponse {
262
+ task_uuid: string;
263
+ name: string;
264
+ namespace: string;
265
+ version: string;
266
+ status: string;
267
+ created_at: string;
268
+ updated_at: string;
269
+ completed_at: string | null;
270
+ context: Record<string, unknown>;
271
+ initiator: string;
272
+ source_system: string;
273
+ reason: string;
274
+ priority: number | null;
275
+ tags: string[] | null;
276
+ correlation_id: string;
277
+ parent_correlation_id: string | null;
278
+ total_steps: number;
279
+ pending_steps: number;
280
+ in_progress_steps: number;
281
+ completed_steps: number;
282
+ failed_steps: number;
283
+ ready_steps: number;
284
+ execution_status: string;
285
+ recommended_action: string;
286
+ completion_percentage: number;
287
+ health_status: string;
288
+ steps: StepReadinessStatus[];
289
+ }
290
+ /**
291
+ * Pagination metadata for list responses.
292
+ *
293
+ * Mirrors: tasker_shared::models::core::task::PaginationInfo
294
+ */
295
+ interface PaginationInfo {
296
+ total: number;
297
+ limit: number;
298
+ offset: number;
299
+ has_more: boolean;
300
+ }
301
+ /**
302
+ * Task list response with pagination.
303
+ *
304
+ * Mirrors: tasker_shared::types::api::orchestration::TaskListResponse
305
+ */
306
+ interface TaskListResponse {
307
+ tasks: TaskResponse[];
308
+ pagination: PaginationInfo;
309
+ }
310
+ /**
311
+ * Cancel task response.
312
+ *
313
+ * Constructed directly in FfiClientBridge::cancel_task as `{ "cancelled": true }`.
314
+ */
315
+ interface CancelTaskResponse {
316
+ cancelled: boolean;
317
+ }
318
+ /**
319
+ * Step details response with readiness information.
320
+ *
321
+ * Mirrors: tasker_shared::types::api::orchestration::StepResponse
322
+ */
323
+ interface StepResponse {
324
+ step_uuid: string;
325
+ task_uuid: string;
326
+ name: string;
327
+ created_at: string;
328
+ updated_at: string;
329
+ completed_at: string | null;
330
+ results: Record<string, unknown> | null;
331
+ current_state: string;
332
+ dependencies_satisfied: boolean;
333
+ retry_eligible: boolean;
334
+ ready_for_execution: boolean;
335
+ total_parents: number;
336
+ completed_parents: number;
337
+ attempts: number;
338
+ max_attempts: number;
339
+ last_failure_at: string | null;
340
+ next_retry_at: string | null;
341
+ last_attempted_at: string | null;
342
+ }
343
+ /**
344
+ * Step audit record for SOC2-compliant audit trails.
345
+ *
346
+ * Mirrors: tasker_shared::types::api::orchestration::StepAuditResponse
347
+ */
348
+ interface StepAuditResponse {
349
+ audit_uuid: string;
350
+ workflow_step_uuid: string;
351
+ transition_uuid: string;
352
+ task_uuid: string;
353
+ recorded_at: string;
354
+ worker_uuid?: string;
355
+ correlation_id?: string;
356
+ success: boolean;
357
+ execution_time_ms?: number;
358
+ result?: Record<string, unknown>;
359
+ step_name: string;
360
+ from_state?: string;
361
+ to_state: string;
362
+ }
363
+ /**
364
+ * Health check response.
365
+ *
366
+ * Constructed directly in FfiClientBridge::health_check as `{ "healthy": true }`.
367
+ */
368
+ interface HealthCheckResponse {
369
+ healthy: boolean;
370
+ }
371
+
223
372
  /**
224
373
  * High-level client wrapper for orchestration API operations.
225
374
  *
@@ -229,14 +378,11 @@ declare function healthCheck(module?: NapiModule): boolean;
229
378
  *
230
379
  * @example
231
380
  * ```typescript
232
- * import { FfiLayer, TaskerClient } from '@tasker-systems/tasker';
233
- *
234
- * const ffiLayer = new FfiLayer();
235
- * await ffiLayer.load();
236
- * const client = new TaskerClient(ffiLayer);
381
+ * import { getTaskerClient } from '@tasker-systems/tasker';
237
382
  *
383
+ * const client = await getTaskerClient();
238
384
  * const task = client.createTask({ name: 'process_order', namespace: 'ecommerce' });
239
- * console.log(task.taskUuid);
385
+ * console.log(task.task_uuid);
240
386
  * ```
241
387
  *
242
388
  * @packageDocumentation
@@ -307,26 +453,26 @@ declare class TaskerClient {
307
453
  * Create a task via the orchestration API.
308
454
  *
309
455
  * @param options - Task creation options (only `name` is required)
310
- * @returns Typed task response data
456
+ * @returns Task response with execution context and step readiness
311
457
  * @throws TaskerClientError if the operation fails
312
458
  */
313
- createTask(options: CreateTaskOptions): unknown;
459
+ createTask(options: CreateTaskOptions): TaskResponse;
314
460
  /**
315
461
  * Get a task by UUID.
316
462
  *
317
463
  * @param taskUuid - The task UUID
318
- * @returns Typed task response data
464
+ * @returns Task response with execution context and step readiness
319
465
  * @throws TaskerClientError if the operation fails
320
466
  */
321
- getTask(taskUuid: string): unknown;
467
+ getTask(taskUuid: string): TaskResponse;
322
468
  /**
323
469
  * List tasks with optional filtering and pagination.
324
470
  *
325
471
  * @param options - Filtering and pagination options
326
- * @returns Typed task list response data
472
+ * @returns Task list with pagination metadata
327
473
  * @throws TaskerClientError if the operation fails
328
474
  */
329
- listTasks(options?: ListTasksOptions): unknown;
475
+ listTasks(options?: ListTasksOptions): TaskListResponse;
330
476
  /**
331
477
  * Cancel a task by UUID.
332
478
  *
@@ -338,37 +484,42 @@ declare class TaskerClient {
338
484
  * List workflow steps for a task.
339
485
  *
340
486
  * @param taskUuid - The task UUID
341
- * @returns Array of step data
487
+ * @returns Array of step responses with readiness information
342
488
  * @throws TaskerClientError if the operation fails
343
489
  */
344
- listTaskSteps(taskUuid: string): unknown;
490
+ listTaskSteps(taskUuid: string): StepResponse[];
345
491
  /**
346
492
  * Get a specific workflow step.
347
493
  *
348
494
  * @param taskUuid - The task UUID
349
495
  * @param stepUuid - The step UUID
350
- * @returns Typed step response data
496
+ * @returns Step response with readiness information
351
497
  * @throws TaskerClientError if the operation fails
352
498
  */
353
- getStep(taskUuid: string, stepUuid: string): unknown;
499
+ getStep(taskUuid: string, stepUuid: string): StepResponse;
354
500
  /**
355
501
  * Get audit history for a workflow step.
356
502
  *
357
503
  * @param taskUuid - The task UUID
358
504
  * @param stepUuid - The step UUID
359
- * @returns Array of audit history entries
505
+ * @returns Array of audit history entries with attribution context
360
506
  * @throws TaskerClientError if the operation fails
361
507
  */
362
- getStepAuditHistory(taskUuid: string, stepUuid: string): unknown;
508
+ getStepAuditHistory(taskUuid: string, stepUuid: string): StepAuditResponse[];
363
509
  /**
364
510
  * Check orchestration API health.
365
511
  *
366
- * @returns Typed health response data
512
+ * @returns Health status from the orchestration API
367
513
  * @throws TaskerClientError if the operation fails
368
514
  */
369
- healthCheck(): unknown;
515
+ healthCheck(): HealthCheckResponse;
370
516
  /**
371
517
  * Unwrap a NapiClientResult envelope, throwing on error.
518
+ *
519
+ * The type parameter allows callers to assert the expected response shape.
520
+ * The actual data comes from Rust via serde_json serialization, so the
521
+ * runtime shape is guaranteed by the Rust type system — the cast here
522
+ * is safe at the FFI boundary.
372
523
  */
373
524
  private unwrap;
374
525
  /**
@@ -376,6 +527,37 @@ declare class TaskerClient {
376
527
  */
377
528
  private getModule;
378
529
  }
530
+ /**
531
+ * Returns a loaded FfiLayer singleton, initializing it on first call.
532
+ *
533
+ * The native library is loaded once and reused for all subsequent calls.
534
+ * Safe to call concurrently — concurrent callers await the same load promise.
535
+ *
536
+ * @example
537
+ * ```typescript
538
+ * import { getFfiLayer } from '@tasker-systems/tasker';
539
+ *
540
+ * const ffiLayer = await getFfiLayer();
541
+ * // Use for custom TaskerClient construction or direct FFI access
542
+ * ```
543
+ */
544
+ declare function getFfiLayer(): Promise<FfiLayer>;
545
+ /**
546
+ * Returns a TaskerClient backed by the shared FfiLayer singleton.
547
+ *
548
+ * This is the recommended entry point for most consumers. The FfiLayer
549
+ * is loaded lazily on first call and reused thereafter.
550
+ *
551
+ * @example
552
+ * ```typescript
553
+ * import { getTaskerClient } from '@tasker-systems/tasker';
554
+ *
555
+ * const client = await getTaskerClient();
556
+ * const task = client.createTask({ name: 'process_order', namespace: 'ecommerce' });
557
+ * console.log(task.task_uuid);
558
+ * ```
559
+ */
560
+ declare function getTaskerClient(): Promise<TaskerClient>;
379
561
 
380
562
  /**
381
563
  * API mixin for HTTP functionality.
@@ -4361,4 +4543,4 @@ declare class WorkerServer {
4361
4543
  private cleanupOnError;
4362
4544
  }
4363
4545
 
4364
- export { type APICapable, APIMixin, ApiHandler, type ApiHandlerArgs, type ApiHandlerOptions, ApiResponse, BasePublisher, type BaseResolver, BaseSubscriber, type BatchAggregationResult, type BatchAnalyzerOutcome, type BatchConfig, type BatchMetadata, type BatchProcessingOutcome, type BatchWorkerContext, type BatchWorkerOutcome, type Batchable, BatchableMixin, type BootstrapConfig, type BootstrapResult, ClassLookupResolver, type CreateBatchesOutcome, type CreateTaskOptions, type CursorConfig, Decision, type DecisionCapable, DecisionHandler, DecisionMixin, type DecisionPointOutcome, DecisionType, DefaultPublisher, type DomainEvent, type DomainEventCallback, type DomainEventErrorCallback, type DomainEventMetadata, type DomainEventPollerConfig, DuplicatePublisherError, type EventDeclaration, EventPoller, EventSystem, ExecutableHandler, ExplicitMappingResolver, type FailureStrategy, FfiDomainEvent, FfiLayer, FfiLayerConfig, type HandlerArgs, type HandlerDefinition, type HandlerEntry, type HandlerFactory, type HandlerFn, type HandlerOptions, HandlerRegistry, type HandlerSpec, HandlerSystem, InProcessDomainEventPoller, type ListTasksOptions, type LogFields, MethodDispatchError, MethodDispatchWrapper, NapiModule, type NoBatchesOutcome, NoResolverMatchError, PermanentError, type PollerStats, type PublishContext, PublisherNotFoundError, PublisherRegistry, PublisherValidationError, RegistryFrozenError, RegistryResolver, type RegistryResolverStatic, ResolutionError, ResolverChain, type ResolverConfig, ResolverNotFoundError, RetryableError, type RustBatchWorkerInputs, type RustCursorConfig, type ServerComponents, type HealthCheckResult as ServerHealthCheckResult, type ServerState, type ServerStatus, ShutdownController, type ShutdownHandler, StepContext, type StepEventContext, StepExecutionSubscriber, StepHandler, StepHandlerClass, StepHandlerResult, type StepResult, type StopResult, type SubscriberClass, SubscriberRegistry, type SubscriberStats, TaskerClient, TaskerClientError, TaskerEventEmitter, WorkerServer, type WorkerServerConfig, type WorkerStatus, aggregateBatchResults, applyAPI, applyBatchable, applyDecision, bootstrapWorker, createBatchWorkerContext, createBatches, createDomainEvent, createFfiPollAdapter, createLogger, createStepEventContext, defineApiHandler, defineBatchAnalyzer, defineBatchWorker, defineDecisionHandler, defineHandler, effectiveMethod, ffiEventToDomainEvent, fromCallable, fromDto, getRustVersion, getVersion, getWorkerStatus, hasResolverHint, healthCheck, isCreateBatches, isNoBatches, isWorkerRunning, logDebug, logError, logInfo, logTrace, logWarn, noBatches, normalizeToDefinition, stopWorker, transitionToGracefulShutdown, usesMethodDispatch };
4546
+ export { type APICapable, APIMixin, ApiHandler, type ApiHandlerArgs, type ApiHandlerOptions, ApiResponse, BasePublisher, type BaseResolver, BaseSubscriber, type BatchAggregationResult, type BatchAnalyzerOutcome, type BatchConfig, type BatchMetadata, type BatchProcessingOutcome, type BatchWorkerContext, type BatchWorkerOutcome, type Batchable, BatchableMixin, type BootstrapConfig, type BootstrapResult, type CancelTaskResponse, ClassLookupResolver, type CreateBatchesOutcome, type CreateTaskOptions, type CursorConfig, Decision, type DecisionCapable, DecisionHandler, DecisionMixin, type DecisionPointOutcome, DecisionType, DefaultPublisher, type DomainEvent, type DomainEventCallback, type DomainEventErrorCallback, type DomainEventMetadata, type DomainEventPollerConfig, DuplicatePublisherError, type EventDeclaration, EventPoller, EventSystem, ExecutableHandler, ExplicitMappingResolver, type FailureStrategy, FfiDomainEvent, FfiLayer, FfiLayerConfig, type HandlerArgs, type HandlerDefinition, type HandlerEntry, type HandlerFactory, type HandlerFn, type HandlerOptions, HandlerRegistry, type HandlerSpec, HandlerSystem, type HealthCheckResponse, InProcessDomainEventPoller, type ListTasksOptions, type LogFields, MethodDispatchError, MethodDispatchWrapper, NapiModule, type NoBatchesOutcome, NoResolverMatchError, type PaginationInfo, PermanentError, type PollerStats, type PublishContext, PublisherNotFoundError, PublisherRegistry, PublisherValidationError, RegistryFrozenError, RegistryResolver, type RegistryResolverStatic, ResolutionError, ResolverChain, type ResolverConfig, ResolverNotFoundError, RetryableError, type RustBatchWorkerInputs, type RustCursorConfig, type ServerComponents, type HealthCheckResult as ServerHealthCheckResult, type ServerState, type ServerStatus, ShutdownController, type ShutdownHandler, type StepAuditResponse, StepContext, type StepEventContext, StepExecutionSubscriber, StepHandler, StepHandlerClass, StepHandlerResult, type StepReadinessStatus, type StepResponse, type StepResult, type StopResult, type SubscriberClass, SubscriberRegistry, type SubscriberStats, type TaskListResponse, type TaskResponse, TaskerClient, TaskerClientError, TaskerEventEmitter, WorkerServer, type WorkerServerConfig, type WorkerStatus, aggregateBatchResults, applyAPI, applyBatchable, applyDecision, bootstrapWorker, createBatchWorkerContext, createBatches, createDomainEvent, createFfiPollAdapter, createLogger, createStepEventContext, defineApiHandler, defineBatchAnalyzer, defineBatchWorker, defineDecisionHandler, defineHandler, effectiveMethod, ffiEventToDomainEvent, fromCallable, fromDto, getFfiLayer, getRustVersion, getTaskerClient, getVersion, getWorkerStatus, hasResolverHint, healthCheck, isCreateBatches, isNoBatches, isWorkerRunning, logDebug, logError, logInfo, logTrace, logWarn, noBatches, normalizeToDefinition, stopWorker, transitionToGracefulShutdown, usesMethodDispatch };