@acorex/platform 21.0.0-next.5 → 21.0.0-next.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.
@@ -629,99 +629,11 @@ interface AXPWorkflowDefinitionLoader {
629
629
  */
630
630
  getAllNames?(): Promise<string[]>;
631
631
  }
632
- /**
633
- * Workflow definition preloader interface.
634
- * Implement this to provide a list of workflow definitions that should be preloaded.
635
- */
636
- interface AXPWorkflowDefinitionPreloader {
637
- /**
638
- * Get list of workflow definition IDs to preload.
639
- * @returns Array of definition IDs
640
- */
641
- preload(): string[];
642
- }
643
632
  /**
644
633
  * Injection token for workflow definition loaders.
645
634
  * Multiple loaders can be provided (multi: true).
646
635
  */
647
636
  declare const AXP_WORKFLOW_DEFINITION_LOADER: InjectionToken<AXPWorkflowDefinitionLoader>;
648
- /**
649
- * Resolver service for workflow definitions.
650
- * Aggregates all registered loaders and resolves workflow definitions.
651
- */
652
- declare class AXPWorkflowDefinitionResolver {
653
- private loaders;
654
- /**
655
- * Get workflow definition by name (unique key).
656
- * Tries all registered loaders until one returns a definition.
657
- * @param name - The workflow name (unique key)
658
- * @returns Workflow definition or null if not found
659
- */
660
- get(name: string): Promise<AXPWorkflowDefinition | null>;
661
- /**
662
- * Get all available workflow names from all loaders.
663
- * @returns Array of unique workflow names
664
- */
665
- getAllNames(): Promise<string[]>;
666
- static ɵfac: i0.ɵɵFactoryDeclaration<AXPWorkflowDefinitionResolver, never>;
667
- static ɵprov: i0.ɵɵInjectableDeclaration<AXPWorkflowDefinitionResolver>;
668
- }
669
-
670
- /**
671
- * Registry service for workflow definitions.
672
- * Caches loaded definitions and provides change notifications.
673
- */
674
- declare class AXPWorkflowDefinitionRegistryService {
675
- private resolver;
676
- private cache;
677
- private onChanged;
678
- /**
679
- * Observable for workflow definition changes.
680
- */
681
- get onChanged$(): rxjs.Observable<{
682
- name: string;
683
- action: "registered" | "updated" | "removed";
684
- }>;
685
- /**
686
- * Get workflow definition by name (unique key).
687
- * Uses cache if available, otherwise loads from resolver.
688
- * @param name - The workflow name (unique key)
689
- * @returns Workflow definition or null if not found
690
- */
691
- get(name: string): Promise<AXPWorkflowDefinition | null>;
692
- /**
693
- * Register a workflow definition in the cache.
694
- * @param definition - The workflow definition to register
695
- */
696
- register(definition: AXPWorkflowDefinition): void;
697
- /**
698
- * Update a workflow definition in the cache.
699
- * @param definition - The updated workflow definition
700
- */
701
- update(definition: AXPWorkflowDefinition): void;
702
- /**
703
- * Remove a workflow definition from the cache.
704
- * @param name - The workflow name to remove
705
- */
706
- remove(name: string): void;
707
- /**
708
- * Clear all cached workflow definitions.
709
- */
710
- clear(): void;
711
- /**
712
- * Check if a workflow definition is cached.
713
- * @param definitionId - The workflow definition ID
714
- * @returns True if cached, false otherwise
715
- */
716
- has(definitionId: string): boolean;
717
- /**
718
- * Get all cached workflow definition IDs.
719
- * @returns Array of definition IDs (only those that have been loaded)
720
- */
721
- getAllIds(): string[];
722
- static ɵfac: i0.ɵɵFactoryDeclaration<AXPWorkflowDefinitionRegistryService, never>;
723
- static ɵprov: i0.ɵɵInjectableDeclaration<AXPWorkflowDefinitionRegistryService>;
724
- }
725
637
 
726
638
  /**
727
639
  * Workflow status.
@@ -1379,10 +1291,6 @@ declare class AXPActivityDefinitionService {
1379
1291
  static ɵprov: i0.ɵɵInjectableDeclaration<AXPActivityDefinitionService>;
1380
1292
  }
1381
1293
 
1382
- /**
1383
- * Types and interfaces for Workflow Execution Service.
1384
- */
1385
-
1386
1294
  /**
1387
1295
  * Represents a workflow task that needs to be executed.
1388
1296
  * Inspired by Temporal's Activity Tasks and Camunda's External Tasks.
@@ -1421,9 +1329,9 @@ interface AXPWorkflowTask {
1421
1329
  config?: Record<string, any>;
1422
1330
  }
1423
1331
  /**
1424
- * Request to start a workflow execution.
1332
+ * Request to start a workflow instance.
1425
1333
  */
1426
- interface AXPStartWorkflowExecutionRequest {
1334
+ interface AXPStartWorkflowRequest {
1427
1335
  /**
1428
1336
  * Workflow ID to execute.
1429
1337
  */
@@ -1434,17 +1342,17 @@ interface AXPStartWorkflowExecutionRequest {
1434
1342
  input: Record<string, any>;
1435
1343
  }
1436
1344
  /**
1437
- * Response after starting workflow execution.
1345
+ * Response after starting workflow instance.
1438
1346
  */
1439
- interface AXPStartWorkflowExecutionResponse {
1347
+ interface AXPStartWorkflowResponse {
1440
1348
  /**
1441
- * Unique execution ID for this workflow run.
1349
+ * Unique instance ID for this workflow run.
1442
1350
  */
1443
- executionId: string;
1351
+ instanceId: string;
1444
1352
  /**
1445
1353
  * Current workflow state.
1446
1354
  */
1447
- state: AXPWorkflowExecutionState;
1355
+ state: AXPWorkflowInstanceState;
1448
1356
  /**
1449
1357
  * First task to execute (determined by backend).
1450
1358
  * Client should execute this task based on executionMode.
@@ -1454,11 +1362,11 @@ interface AXPStartWorkflowExecutionResponse {
1454
1362
  /**
1455
1363
  * Request to resume a suspended workflow.
1456
1364
  */
1457
- interface AXPResumeWorkflowExecutionRequest {
1365
+ interface AXPResumeWorkflowRequest {
1458
1366
  /**
1459
- * Execution ID.
1367
+ * Instance ID.
1460
1368
  */
1461
- executionId: string;
1369
+ instanceId: string;
1462
1370
  /**
1463
1371
  * Step ID that was waiting for user input.
1464
1372
  */
@@ -1480,7 +1388,7 @@ interface AXPResumeWorkflowExecutionRequest {
1480
1388
  /**
1481
1389
  * Response after resuming workflow.
1482
1390
  */
1483
- interface AXPResumeWorkflowExecutionResponse {
1391
+ interface AXPResumeWorkflowResponse {
1484
1392
  /**
1485
1393
  * Activity execution output.
1486
1394
  */
@@ -1496,49 +1404,31 @@ interface AXPResumeWorkflowExecutionResponse {
1496
1404
  /**
1497
1405
  * Updated workflow state.
1498
1406
  */
1499
- state: AXPWorkflowExecutionState;
1407
+ state: AXPWorkflowInstanceState;
1500
1408
  }
1501
1409
  /**
1502
- * Request to get workflow execution state.
1410
+ * Request to get workflow instance state.
1503
1411
  */
1504
- interface AXPGetWorkflowExecutionStateRequest {
1412
+ interface AXPGetWorkflowStateRequest {
1505
1413
  /**
1506
- * Execution ID.
1414
+ * Instance ID.
1507
1415
  */
1508
- executionId: string;
1416
+ instanceId: string;
1509
1417
  }
1510
1418
  /**
1511
- * Request to get workflow definition.
1419
+ * Workflow instance state (managed by backend, cached in client).
1512
1420
  */
1513
- interface AXPGetWorkflowDefinitionRequest {
1421
+ interface AXPWorkflowInstanceState {
1514
1422
  /**
1515
- * Workflow ID or definition ID.
1516
- */
1517
- workflowId: string;
1518
- }
1519
- /**
1520
- * Response with workflow definition.
1521
- */
1522
- interface AXPGetWorkflowDefinitionResponse {
1523
- /**
1524
- * Workflow definition.
1525
- */
1526
- workflow: AXPWorkflowDefinition;
1527
- }
1528
- /**
1529
- * Workflow execution state (managed by backend, cached in client).
1530
- */
1531
- interface AXPWorkflowExecutionState {
1532
- /**
1533
- * Unique execution ID.
1423
+ * Unique instance ID.
1534
1424
  */
1535
- executionId: string;
1425
+ instanceId: string;
1536
1426
  /**
1537
1427
  * Workflow ID.
1538
1428
  */
1539
1429
  workflowId: string;
1540
1430
  /**
1541
- * Current execution status.
1431
+ * Current instance status.
1542
1432
  */
1543
1433
  status: 'running' | 'completed' | 'suspended' | 'error';
1544
1434
  /**
@@ -1564,245 +1454,566 @@ interface AXPWorkflowExecutionState {
1564
1454
  }
1565
1455
 
1566
1456
  /**
1567
- * Workflow execution result.
1457
+ * Interface for workflow engine operations.
1458
+ */
1459
+ interface AXPWorkflowEngine {
1460
+ /**
1461
+ * Start a new workflow instance.
1462
+ *
1463
+ * Creates a new workflow instance in backend and returns instance ID.
1464
+ *
1465
+ * @param request - Start workflow request
1466
+ * @returns Response with instanceId and initial state
1467
+ *
1468
+ */
1469
+ start(request: AXPStartWorkflowRequest): Promise<AXPStartWorkflowResponse>;
1470
+ /**
1471
+ * Resume a suspended workflow instance.
1472
+ *
1473
+ * Resumes workflow instance after user interaction (e.g., after show-dialog).
1474
+ *
1475
+ * @param request - Resume workflow request
1476
+ * @returns Resume response with next step and updated state
1477
+ *
1478
+ */
1479
+ resume(request: AXPResumeWorkflowRequest): Promise<AXPResumeWorkflowResponse>;
1480
+ /**
1481
+ * Get current workflow instance state.
1482
+ *
1483
+ * Retrieves current state of a workflow instance from backend.
1484
+ *
1485
+ * @param request - Get state request
1486
+ * @returns Current workflow instance state
1487
+ *
1488
+ */
1489
+ getState(request: AXPGetWorkflowStateRequest): Promise<AXPWorkflowInstanceState>;
1490
+ }
1491
+ /**
1492
+ * Injection token for workflow engine.
1493
+ * Default implementation is AXPWorkflowLocalEngine.
1494
+ */
1495
+ declare const AXP_WORKFLOW_ENGINE: InjectionToken<AXPWorkflowEngine>;
1496
+
1497
+ /**
1498
+ * Result of executing a frontend task.
1499
+ */
1500
+ interface FrontendTaskExecutionResult {
1501
+ /**
1502
+ * Task execution output.
1503
+ */
1504
+ output: any;
1505
+ /**
1506
+ * Task execution outcome (e.g., 'Done', 'Confirmed', 'Cancelled', 'Failed').
1507
+ */
1508
+ outcome: string;
1509
+ }
1510
+ /**
1511
+ * Service responsible for executing frontend workflow tasks.
1512
+ *
1513
+ * This service handles the execution of frontend or hybrid tasks using
1514
+ * the command infrastructure. It translates command results into
1515
+ * workflow-compatible output and outcome format.
1516
+ *
1517
+ * This service is replaceable per platform and contains all execution logic.
1518
+ */
1519
+ declare class FrontendTaskExecutor {
1520
+ private readonly commandService;
1521
+ /**
1522
+ * Execute a frontend workflow task.
1523
+ *
1524
+ * Only executes tasks with executionMode 'frontend' or 'both'.
1525
+ * Backend tasks should not be passed to this executor.
1526
+ *
1527
+ * @param task - Task to execute
1528
+ * @returns Execution result with output and outcome
1529
+ *
1530
+ * @throws Error if task is not a frontend task
1531
+ */
1532
+ execute(task: AXPWorkflowTask): Promise<FrontendTaskExecutionResult>;
1533
+ static ɵfac: i0.ɵɵFactoryDeclaration<FrontendTaskExecutor, never>;
1534
+ static ɵprov: i0.ɵɵInjectableDeclaration<FrontendTaskExecutor>;
1535
+ }
1536
+
1537
+ /**
1538
+ * Result of starting a workflow.
1568
1539
  */
1569
- interface WorkflowExecutionResult {
1540
+ interface WorkflowStartResult {
1541
+ /**
1542
+ * Whether the operation succeeded.
1543
+ */
1544
+ success: boolean;
1545
+ /**
1546
+ * Workflow instance ID.
1547
+ */
1548
+ instanceId?: string;
1549
+ /**
1550
+ * Initial workflow state.
1551
+ */
1552
+ state?: AXPWorkflowInstanceState;
1553
+ /**
1554
+ * First task to execute (if any).
1555
+ */
1556
+ nextTask?: AXPWorkflowTask | null;
1557
+ /**
1558
+ * Workflow output (if completed immediately).
1559
+ */
1560
+ output?: any;
1561
+ /**
1562
+ * Error message (if failed).
1563
+ */
1564
+ error?: string;
1565
+ }
1566
+ /**
1567
+ * Result of completing a task.
1568
+ */
1569
+ interface WorkflowCompleteResult {
1570
+ /**
1571
+ * Whether the operation succeeded.
1572
+ */
1570
1573
  success: boolean;
1574
+ /**
1575
+ * Workflow instance ID.
1576
+ */
1577
+ instanceId: string;
1578
+ /**
1579
+ * Updated workflow state.
1580
+ */
1581
+ state?: AXPWorkflowInstanceState;
1582
+ /**
1583
+ * Next task to execute (if any).
1584
+ */
1585
+ nextTask?: AXPWorkflowTask | null;
1586
+ /**
1587
+ * Workflow output (if completed).
1588
+ */
1571
1589
  output?: any;
1590
+ /**
1591
+ * Error message (if failed).
1592
+ */
1572
1593
  error?: string;
1594
+ }
1595
+ /**
1596
+ * Result of resuming a workflow.
1597
+ */
1598
+ interface WorkflowResumeResult {
1599
+ /**
1600
+ * Whether the operation succeeded.
1601
+ */
1602
+ success: boolean;
1603
+ /**
1604
+ * Workflow instance ID.
1605
+ */
1606
+ instanceId: string;
1607
+ /**
1608
+ * Updated workflow state.
1609
+ */
1610
+ state?: AXPWorkflowInstanceState;
1611
+ /**
1612
+ * Next task to execute (if any).
1613
+ */
1573
1614
  nextTask?: AXPWorkflowTask | null;
1574
- executionId?: string;
1575
- state?: AXPWorkflowExecutionState;
1615
+ /**
1616
+ * Workflow output (if completed).
1617
+ */
1618
+ output?: any;
1619
+ /**
1620
+ * Error message (if failed).
1621
+ */
1622
+ error?: string;
1576
1623
  }
1577
1624
  /**
1578
- * Production Workflow Coordinator.
1625
+ * Workflow Manager - Facade for workflow lifecycle orchestration.
1626
+ *
1627
+ * This service is the ONLY interface the frontend uses to interact with workflows.
1628
+ * It follows Clean Architecture principles and does NOT contain execution or business logic.
1579
1629
  *
1580
- * Separates frontend/backend execution:
1581
- * - Frontend activities: Execute with AXPCommand in browser
1582
- * - Backend activities: Execute via API calls to backend
1583
- * - State caching: Caches workflow state in client for performance
1630
+ * Responsibilities:
1631
+ * - Orchestrate workflow lifecycle (start, execute, complete, resume)
1632
+ * - Delegate execution to FrontendTaskExecutor
1633
+ * - Cache workflow state in memory
1634
+ * - Expose a stable API for UI
1584
1635
  *
1636
+ * Rules:
1637
+ * - No HTTP calls (delegates to AXPWorkflowEngine)
1638
+ * - No CommandBus / Command execution (delegates to FrontendTaskExecutor)
1639
+ * - No workflow branching logic (backend decides)
1640
+ * - No business validation (backend validates)
1641
+ * - No backend assumptions (uses abstract runtime service)
1585
1642
  */
1586
- declare class WorkflowCoordinator {
1587
- private readonly workflowExecutionService;
1588
- private readonly commandService;
1643
+ declare class AXPWorkflowManager {
1644
+ private readonly workflowEngine;
1645
+ private readonly frontendTaskExecutor;
1589
1646
  /**
1590
1647
  * Cache workflow states in memory for quick access.
1591
- * Key: executionId
1592
- * Value: AXPWorkflowExecutionState
1648
+ * Key: instanceId
1649
+ * Value: AXPWorkflowInstanceState
1593
1650
  */
1594
1651
  private stateCache;
1595
1652
  /**
1596
- * Start workflow execution in backend.
1653
+ * Cache TTL in milliseconds (5 minutes).
1654
+ */
1655
+ private readonly CACHE_TTL;
1656
+ /**
1657
+ * Start a new workflow instance.
1597
1658
  *
1659
+ * Creates a new workflow instance in backend and returns instance ID.
1598
1660
  * Backend decides what to do: returns pendingTask or indicates completion.
1599
- * Frontend only calls API - no business logic here.
1600
1661
  *
1601
- * @param workflowId - Workflow ID
1602
- * @param input - Initial input data
1603
- * @returns Execution result with pendingTask (if any)
1662
+ * @param workflowId - Workflow ID to start
1663
+ * @param input - Initial input data (optional)
1664
+ * @returns Start result with instanceId, state, and nextTask
1604
1665
  *
1605
1666
  * @example
1606
1667
  * ```typescript
1607
- * const result = await coordinator.startWorkflow('my-workflow', { userId: '123' });
1668
+ * const result = await workflowManager.start('my-workflow', { userId: '123' });
1608
1669
  *
1609
- * if (result.pendingTask) {
1610
- * // Execute task if frontend, or wait for backend to complete
1611
- * if (result.pendingTask.executionMode === 'frontend') {
1612
- * await coordinator.executeTask(result.pendingTask);
1613
- * await coordinator.completeTask(result.executionId, result.pendingTask, outcome, output);
1670
+ * if (result.success && result.nextTask) {
1671
+ * // Execute task if frontend
1672
+ * if (result.nextTask.executionMode === 'frontend') {
1673
+ * const execResult = await workflowManager.execute(result.nextTask);
1674
+ * await workflowManager.complete(result.instanceId!, result.nextTask, execResult.outcome, execResult.output);
1614
1675
  * }
1615
1676
  * }
1616
1677
  * ```
1617
1678
  */
1618
- startWorkflow(workflowId: string, input?: Record<string, any>): Promise<WorkflowExecutionResult>;
1679
+ start(workflowId: string, input?: Record<string, any>): Promise<WorkflowStartResult>;
1619
1680
  /**
1620
- * Execute a frontend task using AXPCommand.
1681
+ * Execute a frontend task.
1621
1682
  *
1622
- * Only executes if task.executionMode is 'frontend' or 'both'.
1623
- * Backend tasks are handled automatically by backend.
1683
+ * Delegates to FrontendTaskExecutor for actual execution.
1684
+ * Only executes tasks with executionMode 'frontend' or 'both'.
1624
1685
  *
1625
1686
  * @param task - Task to execute
1626
1687
  * @returns Execution result with output and outcome
1688
+ *
1689
+ * @throws Error if task is not a frontend task
1627
1690
  */
1628
- executeTask(task: AXPWorkflowTask): Promise<{
1629
- output: any;
1630
- outcome: string;
1631
- }>;
1691
+ execute(task: AXPWorkflowTask): Promise<FrontendTaskExecutionResult>;
1632
1692
  /**
1633
1693
  * Complete a task and get next task from backend.
1634
1694
  *
1635
1695
  * Sends task result to backend API.
1636
1696
  * Backend decides: next task, fail, or complete workflow.
1637
1697
  *
1638
- * @param executionId - Execution ID
1698
+ * @param instanceId - Workflow instance ID
1639
1699
  * @param task - Completed task
1640
1700
  * @param outcome - Task outcome (e.g., 'Done', 'Confirmed', 'Cancelled')
1641
- * @param output - Task output/result
1642
- * @returns Next task from backend (if any)
1643
- */
1644
- completeTask(executionId: string, task: AXPWorkflowTask, outcome: string, output?: any): Promise<WorkflowExecutionResult>;
1645
- /**
1646
- * Execute workflow by ID (backward compatibility).
1647
- *
1648
- * @deprecated Use startWorkflow + executeTask + completeTask pattern instead.
1649
- * This method is kept for backward compatibility but will be removed.
1701
+ * @param output - Task output/result (optional)
1702
+ * @returns Complete result with next task (if any)
1650
1703
  */
1651
- executeWorkflowById(workflowId: string, input?: Record<string, any>): Promise<WorkflowExecutionResult>;
1704
+ complete(instanceId: string, task: AXPWorkflowTask, outcome: string, output?: any): Promise<WorkflowCompleteResult>;
1652
1705
  /**
1653
1706
  * Resume a suspended workflow (e.g., after user interaction).
1654
1707
  *
1655
1708
  * Backend determines nextStep based on outcome and outcomeConnections.
1656
- * Client only provides executionId, stepId, outcome, and optional userInput.
1709
+ * Client only provides instanceId, stepId, outcome, and optional userInput.
1657
1710
  *
1658
- * @param executionId - Workflow execution ID
1711
+ * @param instanceId - Workflow instance ID
1659
1712
  * @param stepId - Step ID that was waiting for user input
1660
1713
  * @param outcome - User action outcome (e.g., 'Confirmed', 'Cancelled', 'Submitted')
1661
1714
  * @param userInput - Optional user input data
1715
+ * @param taskToken - Secure task token (required for secure resumption)
1716
+ * @returns Resume result with next task (if any)
1662
1717
  */
1663
- resumeWorkflow(executionId: string, stepId: string, outcome: string, userInput?: any, taskToken?: string): Promise<WorkflowExecutionResult>;
1664
- /**
1665
- * Get workflow execution state (from cache or backend).
1666
- */
1667
- getWorkflowState(executionId: string): Promise<AXPWorkflowExecutionState | null>;
1718
+ resume(instanceId: string, stepId: string, outcome: string, userInput?: any, taskToken?: string): Promise<WorkflowResumeResult>;
1668
1719
  /**
1669
- * Execute a frontend activity using CommandBus.
1720
+ * Get workflow instance state.
1670
1721
  *
1671
- * Frontend activities are executed in the browser using AXPCommandService.
1672
- * Activities can also be executed in both frontend and backend (hybrid mode).
1722
+ * Retrieves state from cache (if valid) or from backend.
1673
1723
  *
1674
- * @param task - Frontend task to execute
1675
- * @returns Execution result with output and outcome
1676
- */
1677
- private executeFrontendActivity;
1678
- /**
1679
- * Start workflow execution in backend.
1680
- * Backend returns executionId, initial state, and first task to execute.
1724
+ * @param instanceId - Workflow instance ID
1725
+ * @returns Workflow instance state or null if not found
1681
1726
  */
1682
- private startWorkflowExecution;
1683
- static ɵfac: i0.ɵɵFactoryDeclaration<WorkflowCoordinator, never>;
1684
- static ɵprov: i0.ɵɵInjectableDeclaration<WorkflowCoordinator>;
1727
+ getState(instanceId: string): Promise<AXPWorkflowInstanceState | null>;
1728
+ static ɵfac: i0.ɵɵFactoryDeclaration<AXPWorkflowManager, never>;
1729
+ static ɵprov: i0.ɵɵInjectableDeclaration<AXPWorkflowManager>;
1685
1730
  }
1686
1731
 
1687
1732
  /**
1688
- * Abstract service for workflow execution operations.
1733
+ * Local engine implementation that manages workflow progression and state.
1689
1734
  *
1690
- * This service handles communication with backend for workflow execution.
1735
+ * This engine:
1736
+ * - Returns frontend/both activities as pendingTask (does NOT execute them)
1737
+ * - Skips backend activities (does not error, continues execution)
1738
+ * - Maintains workflow state in memory
1739
+ * - Does not require backend API calls
1691
1740
  *
1692
- * Implementation should be provided in connectivity layer:
1693
- * - Mock implementation: @acorex/connectivity/mock
1694
- * - API implementation: @acorex/connectivity/api
1741
+ * Execution of frontend tasks is handled by AXPWorkflowManager via FrontendTaskExecutor.
1742
+ * This engine only manages workflow progression and state storage.
1695
1743
  *
1696
- * @example
1697
- * ```typescript
1698
- * // In connectivity/mock
1699
- * @Injectable()
1700
- * export class AXCWorkflowExecutionService implements AXPWorkflowExecutionService {
1701
- * async startExecution(request: AXPStartWorkflowExecutionRequest): Promise<AXPStartWorkflowExecutionResponse> {
1702
- * // Mock implementation
1703
- * }
1704
- * }
1705
- *
1706
- * // In connectivity/api
1707
- * @Injectable()
1708
- * export class AXCWorkflowExecutionService implements AXPWorkflowExecutionService {
1709
- * constructor(private http: HttpClient) {}
1710
- *
1711
- * async startExecution(request: AXPStartWorkflowExecutionRequest): Promise<AXPStartWorkflowExecutionResponse> {
1712
- * return firstValueFrom(
1713
- * this.http.post<AXPStartWorkflowExecutionResponse>(
1714
- * `${this.config.baseUrl}/api/workflows/${request.workflowId}/start`,
1715
- * { input: request.input }
1716
- * )
1717
- * );
1718
- * }
1719
- * }
1720
- * ```
1744
+ * This is the DEFAULT engine provider. Applications can override it with
1745
+ * an API-based engine implementation.
1721
1746
  */
1722
- declare abstract class AXPWorkflowExecutionService {
1747
+ declare class AXPWorkflowLocalEngine implements AXPWorkflowEngine {
1748
+ private readonly definitionLoaders;
1749
+ constructor(definitionLoaders?: AXPWorkflowDefinitionLoader[] | null);
1723
1750
  /**
1724
- * Start a new workflow execution.
1751
+ * In-memory storage for workflow instances.
1752
+ * Key: instanceId
1753
+ * Value: LocalWorkflowState
1754
+ */
1755
+ private instances;
1756
+ /**
1757
+ * Task token storage for secure resume operations.
1758
+ * Key: taskToken
1759
+ * Value: { instanceId, activityId }
1760
+ */
1761
+ private taskTokens;
1762
+ /**
1763
+ * Start a new workflow instance.
1725
1764
  *
1726
- * Creates a new workflow execution instance in backend and returns execution ID.
1765
+ * Creates an in-memory workflow instance and progresses it.
1766
+ * Frontend/both activities are returned as pendingTask for external execution.
1767
+ * Backend activities are skipped.
1768
+ */
1769
+ start(request: AXPStartWorkflowRequest): Promise<AXPStartWorkflowResponse>;
1770
+ /**
1771
+ * Resume a suspended workflow instance.
1727
1772
  *
1728
- * @param request - Start execution request
1729
- * @returns Execution response with executionId and initial state
1773
+ * Validates task token, applies externally executed result,
1774
+ * and continues progressing workflow steps.
1775
+ */
1776
+ resume(request: AXPResumeWorkflowRequest): Promise<AXPResumeWorkflowResponse>;
1777
+ /**
1778
+ * Get current workflow instance state.
1779
+ */
1780
+ getState(request: AXPGetWorkflowStateRequest): Promise<AXPWorkflowInstanceState>;
1781
+ /**
1782
+ * Get workflow definition from available loaders.
1783
+ */
1784
+ private getDefinition;
1785
+ /**
1786
+ * Progress workflow steps starting from the current position.
1730
1787
  *
1731
- * @example
1732
- * ```typescript
1733
- * const response = await workflowExecutionService.startExecution({
1734
- * workflowId: 'my-workflow',
1735
- * input: { userId: '123', action: 'create' }
1736
- * });
1788
+ * For frontend/both activities: returns task immediately (suspends workflow).
1789
+ * For backend activities: skips and continues.
1737
1790
  *
1738
- * console.log('Execution ID:', response.executionId);
1739
- * console.log('Initial State:', response.state);
1740
- * ```
1791
+ * Returns the next pending task (if frontend activity found) or null (if completed).
1792
+ */
1793
+ private executeWorkflowSteps;
1794
+ /**
1795
+ * Get next activity ID based on connections and outcomes.
1796
+ */
1797
+ private getNextActivityId;
1798
+ static ɵfac: i0.ɵɵFactoryDeclaration<AXPWorkflowLocalEngine, [{ optional: true; }]>;
1799
+ static ɵprov: i0.ɵɵInjectableDeclaration<AXPWorkflowLocalEngine>;
1800
+ }
1801
+
1802
+ /**
1803
+ * Workflow Category - Extends AXPCategoryEntity for consistency and performance
1804
+ *
1805
+ * Inherited properties from AXPCategoryEntity:
1806
+ * - id: string - Unique identifier
1807
+ * - title: string - Display name
1808
+ * - description?: string - Category description
1809
+ * - parentId?: string - Parent category ID
1810
+ * - childrenCount: number - Direct child categories count (enables lazy loading)
1811
+ * - itemsCount?: number - Direct workflows count
1812
+ * - totalChildren?: number - Total nested categories (optional, for analytics)
1813
+ * - totalItems?: number - Total workflows in tree (optional, for analytics)
1814
+ */
1815
+ interface AXPWorkflowCategory extends AXPCategoryEntity {
1816
+ }
1817
+ /**
1818
+ * Workflow Definition - Metadata for UI and tooling.
1819
+ * Contains all metadata needed for displaying workflows in toolbox and designer.
1820
+ * The `name` property is used as the workflow identifier.
1821
+ */
1822
+ interface AXPWorkflowDefinitionMetadata {
1823
+ /**
1824
+ * Workflow name - used as unique identifier.
1825
+ * This is the unique identifier for the workflow.
1826
+ */
1827
+ name: string;
1828
+ /**
1829
+ * Display name for UI.
1830
+ */
1831
+ title?: string;
1832
+ /**
1833
+ * Description of what the workflow does.
1834
+ */
1835
+ description?: string;
1836
+ /**
1837
+ * Category for grouping in toolbox.
1838
+ */
1839
+ category?: string;
1840
+ /**
1841
+ * Icon name or class.
1842
+ */
1843
+ icon?: string;
1844
+ /**
1845
+ * Whether this workflow is browsable in the toolbox.
1846
+ * Default: true
1741
1847
  */
1742
- abstract startExecution(request: AXPStartWorkflowExecutionRequest): Promise<AXPStartWorkflowExecutionResponse>;
1848
+ isBrowsable?: boolean;
1849
+ /**
1850
+ * Version number.
1851
+ */
1852
+ version?: number;
1853
+ /**
1854
+ * Whether this workflow is published.
1855
+ */
1856
+ isPublished?: boolean;
1857
+ }
1858
+ type AXPWorkflowProviderToken = AXPWorkflowProvider | Promise<AXPWorkflowProvider>;
1859
+ declare const AXP_WORKFLOW_PROVIDER: InjectionToken<AXPWorkflowProviderToken[]>;
1860
+ interface AXPWorkflowProvider {
1861
+ /**
1862
+ * Get list of workflow definitions for a category.
1863
+ * @param categoryId - Category ID to filter workflows
1864
+ * @returns Promise of workflow definition metadata array
1865
+ */
1866
+ getList(categoryId: string): Promise<AXPWorkflowDefinitionMetadata[]>;
1867
+ /**
1868
+ * Get workflow definition metadata by name (unique identifier).
1869
+ * @param name - Workflow name (unique identifier)
1870
+ * @returns Promise of workflow definition metadata or undefined if not found
1871
+ */
1872
+ getById(name: string): Promise<AXPWorkflowDefinitionMetadata | undefined>;
1873
+ }
1874
+ type AXPWorkflowCategoryProviderToken = AXPWorkflowCategoryProvider | Promise<AXPWorkflowCategoryProvider>;
1875
+ declare const AXP_WORKFLOW_CATEGORY_PROVIDER: InjectionToken<AXPWorkflowCategoryProviderToken[]>;
1876
+ interface AXPWorkflowCategoryProvider {
1877
+ getList(parentId?: string): Promise<AXPWorkflowCategory[]>;
1878
+ getById(id: string): Promise<AXPWorkflowCategory | undefined>;
1879
+ }
1880
+
1881
+ /**
1882
+ * Optimized Workflow Definition Service
1883
+ *
1884
+ * Manages workflow definitions (metadata) for UI and tooling.
1885
+ * Similar to AXPActivityDefinitionService - only handles metadata, not execution.
1886
+ *
1887
+ * Performance optimizations:
1888
+ * 1. Uses childrenCount to determine if category has children (no query needed)
1889
+ * 2. Uses itemsCount to determine if category has workflows (no query needed)
1890
+ * 3. Aggressive caching prevents duplicate API calls
1891
+ * 4. Single pending request per resource prevents race conditions
1892
+ * 5. Lazy loading - only loads data when needed
1893
+ */
1894
+ declare class AXPWorkflowDefinitionService {
1895
+ private readonly categoryProviders;
1896
+ private readonly workflowProviders;
1897
+ /** Cache for categories by id - O(1) lookup */
1898
+ private categoriesById;
1899
+ /** Cache for categories by parentId - O(1) lookup */
1900
+ private categoriesByParentId;
1901
+ /** Cache for workflow definitions by categoryId - O(1) lookup */
1902
+ private workflowsByCategory;
1903
+ /** Cache for individual workflow definitions by name - O(1) lookup */
1904
+ private workflowsByName;
1905
+ /** Track which provider index owns each category (by category ID) */
1906
+ private categoryOwnership;
1907
+ /** Pending API requests to prevent duplicate calls */
1908
+ private pendingCategoriesRequests;
1909
+ private pendingWorkflowsRequests;
1910
+ private pendingWorkflowRequests;
1743
1911
  /**
1744
- * Resume a suspended workflow execution.
1912
+ * Get categories by parentId with aggressive caching
1745
1913
  *
1746
- * Resumes workflow execution after user interaction (e.g., after show-dialog).
1914
+ * Optimization: Returns cached result immediately if available,
1915
+ * preventing unnecessary API calls during navigation
1747
1916
  *
1748
- * @param request - Resume execution request
1749
- * @returns Resume response with next step and updated state
1917
+ * @param parentId - Parent category ID (undefined = root categories)
1918
+ * @returns Array of categories with count metadata (childrenCount, itemsCount)
1919
+ */
1920
+ getCategories(parentId?: string): Promise<AXPWorkflowCategory[]>;
1921
+ /**
1922
+ * Get single category by ID with O(1) lookup
1750
1923
  *
1751
- * @example
1752
- * ```typescript
1753
- * const response = await workflowExecutionService.resumeExecution({
1754
- * executionId: 'exec-123',
1755
- * stepId: 'step-dialog-1',
1756
- * taskToken: 'sec-task-token',
1757
- * outcome: 'Confirmed',
1758
- * userInput: { confirmed: true }
1759
- * });
1924
+ * Optimization: Uses Map for instant retrieval, falls back to
1925
+ * searching cache, then providers if not found
1926
+ */
1927
+ getCategoryById(categoryId: string): Promise<AXPWorkflowCategory | undefined>;
1928
+ /**
1929
+ * Get category path from root to specified category
1760
1930
  *
1761
- * console.log('Next Step:', response.nextStep);
1762
- * console.log('Updated State:', response.state);
1763
- * ```
1931
+ * Optimization: Builds path using cached categories only
1764
1932
  */
1765
- abstract resumeExecution(request: AXPResumeWorkflowExecutionRequest): Promise<AXPResumeWorkflowExecutionResponse>;
1933
+ getCategoriesPathById(categoryId: string): Promise<AXPWorkflowCategory[]>;
1766
1934
  /**
1767
- * Get current workflow execution state.
1935
+ * Get workflow definitions for a category with smart caching
1768
1936
  *
1769
- * Retrieves current state of a workflow execution from backend.
1937
+ * Optimization: Checks itemsCount before querying
1938
+ * - If itemsCount = 0, returns empty array (no API call)
1939
+ * - If itemsCount > 0, loads and caches workflow definitions
1940
+ * - Returns cached result on subsequent calls
1770
1941
  *
1771
- * @param request - Get state request
1772
- * @returns Current workflow execution state
1942
+ * @param categoryId - Category ID to get workflow definitions from
1943
+ * @returns Array of workflow definition metadata
1944
+ */
1945
+ getWorkflowsByCategoryId(categoryId: string): Promise<AXPWorkflowDefinitionMetadata[]>;
1946
+ /**
1947
+ * Get single workflow definition metadata by name with O(1) lookup
1773
1948
  *
1774
- * @example
1775
- * ```typescript
1776
- * const state = await workflowExecutionService.getExecutionState({
1777
- * executionId: 'exec-123'
1778
- * });
1949
+ * Optimization: Uses Map for instant retrieval
1779
1950
  *
1780
- * console.log('Status:', state.status);
1781
- * console.log('Variables:', state.variables);
1782
- * ```
1951
+ * @param name - Workflow name (unique identifier)
1952
+ * @returns Workflow definition metadata or undefined if not found
1783
1953
  */
1784
- abstract getExecutionState(request: AXPGetWorkflowExecutionStateRequest): Promise<AXPWorkflowExecutionState>;
1954
+ getWorkflowByName(name: string): Promise<AXPWorkflowDefinitionMetadata | undefined>;
1785
1955
  /**
1786
- * Get workflow definition by ID.
1956
+ * Get category ID containing a specific workflow definition
1787
1957
  *
1788
- * Retrieves workflow definition from backend.
1958
+ * Optimization: Searches cache first, loads on-demand if needed
1959
+ */
1960
+ getCategoryIdByWorkflowName(workflowName: string): Promise<string | undefined>;
1961
+ /**
1962
+ * Get category path for a workflow
1963
+ */
1964
+ getCategoriesPathByWorkflowName(workflowName: string): Promise<AXPWorkflowCategory[]>;
1965
+ /**
1966
+ * Load categories from providers and cache results
1789
1967
  *
1790
- * @param request - Get workflow definition request
1791
- * @returns Workflow definition in executable format
1968
+ * Optimization: Tracks provider ownership to avoid unnecessary API calls
1969
+ * - For root (parentId = undefined): Query ALL providers
1970
+ * - For children: Only query the provider that owns the parent
1971
+ */
1972
+ private loadCategoriesFromProviders;
1973
+ /**
1974
+ * Get the provider index that owns a specific category
1792
1975
  *
1793
- * @example
1794
- * ```typescript
1795
- * const response = await workflowExecutionService.getWorkflowDefinition({
1796
- * workflowId: 'my-workflow'
1797
- * });
1976
+ * @returns Array with provider index, or null if ownership unknown (query all)
1977
+ */
1978
+ private getProviderIndexForCategory;
1979
+ /**
1980
+ * Load workflow definitions from providers and cache results
1798
1981
  *
1799
- * console.log('Workflow:', response.workflow);
1800
- * ```
1982
+ * Optimization: Only queries the provider that owns the category
1983
+ * Uses provider INDEX to match category provider with workflow provider
1984
+ */
1985
+ private loadWorkflowsFromProviders;
1986
+ /**
1987
+ * Load single workflow definition from providers and cache result
1988
+ */
1989
+ private loadWorkflowFromProviders;
1990
+ /**
1991
+ * Breadth-first search through category hierarchy
1992
+ */
1993
+ private searchCategoryInHierarchy;
1994
+ /**
1995
+ * Check if category has children (uses cached count)
1996
+ */
1997
+ categoryHasChildren(categoryId: string): boolean;
1998
+ /**
1999
+ * Check if category has workflows (uses cached count)
2000
+ */
2001
+ categoryHasWorkflows(categoryId: string): boolean;
2002
+ /**
2003
+ * Clear all caches
2004
+ */
2005
+ clearAllCache(): void;
2006
+ /**
2007
+ * Clear categories cache only
2008
+ */
2009
+ clearCategoriesCache(): void;
2010
+ /**
2011
+ * Clear workflows cache only
1801
2012
  */
1802
- abstract getWorkflowDefinition(request: AXPGetWorkflowDefinitionRequest): Promise<AXPGetWorkflowDefinitionResponse>;
1803
- static ɵfac: i0.ɵɵFactoryDeclaration<AXPWorkflowExecutionService, never>;
1804
- static ɵprov: i0.ɵɵInjectableDeclaration<AXPWorkflowExecutionService>;
2013
+ clearWorkflowsCache(): void;
2014
+ static ɵfac: i0.ɵɵFactoryDeclaration<AXPWorkflowDefinitionService, never>;
2015
+ static ɵprov: i0.ɵɵInjectableDeclaration<AXPWorkflowDefinitionService>;
1805
2016
  }
1806
2017
 
1807
- export { AXPActivityDefinitionService, AXPWorkflowAction, AXPWorkflowContext, AXPWorkflowDefinitionRegistryService, AXPWorkflowDefinitionResolver, AXPWorkflowError, AXPWorkflowEventService, AXPWorkflowExecutionService, AXPWorkflowFunction, AXPWorkflowModule, AXPWorkflowRegistryService, AXPWorkflowService, AXP_ACTIVITY_CATEGORY_PROVIDER, AXP_ACTIVITY_PROVIDER, AXP_WORKFLOW_DEFINITION_LOADER, WorkflowCoordinator, createWorkFlowEvent, ofType };
1808
- export type { AXPActivity, AXPActivityCategory, AXPActivityCategoryProvider, AXPActivityCategoryProviderToken, AXPActivityDefinition, AXPActivityExecutionContextState, AXPActivityIncident, AXPActivityProvider, AXPActivityProviderToken, AXPActivityStatus, AXPActivityVariable, AXPBookmark, AXPCompletionCallbackState, AXPConnection, AXPCustomProperties, AXPEndpoint, AXPExceptionState, AXPExpression, AXPFlowchart, AXPGetWorkflowDefinitionRequest, AXPGetWorkflowDefinitionResponse, AXPGetWorkflowExecutionStateRequest, AXPInputValue, AXPMetadata, AXPOutputValue, AXPPosition, AXPResumeWorkflowExecutionRequest, AXPResumeWorkflowExecutionResponse, AXPStartWorkflowExecutionRequest, AXPStartWorkflowExecutionResponse, AXPStoredWorkflowDefinition, AXPVariableDefinition, AXPVariableModel, AXPVersionedEntity, AXPWorkflow, AXPWorkflowActionInput, AXPActivity$1 as AXPWorkflowActivity, AXPWorkflowCondition, AXPWorkflowConditionType, AXPWorkflowDefinition, AXPWorkflowDefinitionJson, AXPWorkflowDefinitionLoader, AXPWorkflowDefinitionPreloader, AXPWorkflowEvent, AXPWorkflowExecutionState, AXPWorkflowFaultState, AXPWorkflowInputDefinition, AXPWorkflowInstance, AXPWorkflowModuleConfigs, AXPWorkflowNextStep, AXPWorkflowOptions, AXPWorkflowOutputDefinition, AXPWorkflowState, AXPWorkflowStatus, AXPWorkflowStep, AXPWorkflowSubStatus, AXPWorkflowTask, ActivityPropertyWidget, InputDescriptor, OutputDescriptor, WorkflowExecutionResult };
2018
+ export { AXPActivityDefinitionService, AXPWorkflowAction, AXPWorkflowContext, AXPWorkflowDefinitionService, AXPWorkflowError, AXPWorkflowEventService, AXPWorkflowFunction, AXPWorkflowLocalEngine, AXPWorkflowManager, AXPWorkflowModule, AXPWorkflowRegistryService, AXPWorkflowService, AXP_ACTIVITY_CATEGORY_PROVIDER, AXP_ACTIVITY_PROVIDER, AXP_WORKFLOW_CATEGORY_PROVIDER, AXP_WORKFLOW_DEFINITION_LOADER, AXP_WORKFLOW_ENGINE, AXP_WORKFLOW_PROVIDER, FrontendTaskExecutor, createWorkFlowEvent, ofType };
2019
+ export type { AXPActivity, AXPActivityCategory, AXPActivityCategoryProvider, AXPActivityCategoryProviderToken, AXPActivityDefinition, AXPActivityExecutionContextState, AXPActivityIncident, AXPActivityProvider, AXPActivityProviderToken, AXPActivityStatus, AXPActivityVariable, AXPBookmark, AXPCompletionCallbackState, AXPConnection, AXPCustomProperties, AXPEndpoint, AXPExceptionState, AXPExpression, AXPFlowchart, AXPGetWorkflowStateRequest, AXPInputValue, AXPMetadata, AXPOutputValue, AXPPosition, AXPResumeWorkflowRequest, AXPResumeWorkflowResponse, AXPStartWorkflowRequest, AXPStartWorkflowResponse, AXPStoredWorkflowDefinition, AXPVariableDefinition, AXPVariableModel, AXPVersionedEntity, AXPWorkflow, AXPWorkflowActionInput, AXPActivity$1 as AXPWorkflowActivity, AXPWorkflowCategory, AXPWorkflowCategoryProvider, AXPWorkflowCategoryProviderToken, AXPWorkflowCondition, AXPWorkflowConditionType, AXPWorkflowDefinition, AXPWorkflowDefinitionJson, AXPWorkflowDefinitionLoader, AXPWorkflowDefinitionMetadata, AXPWorkflowEngine, AXPWorkflowEvent, AXPWorkflowFaultState, AXPWorkflowInputDefinition, AXPWorkflowInstance, AXPWorkflowInstanceState, AXPWorkflowModuleConfigs, AXPWorkflowNextStep, AXPWorkflowOptions, AXPWorkflowOutputDefinition, AXPWorkflowProvider, AXPWorkflowProviderToken, AXPWorkflowState, AXPWorkflowStatus, AXPWorkflowStep, AXPWorkflowSubStatus, AXPWorkflowTask, ActivityPropertyWidget, FrontendTaskExecutionResult, InputDescriptor, OutputDescriptor, WorkflowCompleteResult, WorkflowResumeResult, WorkflowStartResult };