@zintrust/workers 0.4.0 → 0.4.4

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
@@ -36,6 +36,15 @@ npm install brain.js ml.js simple-statistics
36
36
  npm install @tensorflow/tfjs-node
37
37
  ```
38
38
 
39
+ For queue integrations that are lazy-loaded by the workers package:
40
+
41
+ ```bash
42
+ npm install @zintrust/queue-redis
43
+ npm install @zintrust/queue-monitor
44
+ ```
45
+
46
+ These integrations are not auto-installed. `@zintrust/workers` will run without them and enable the related features only when they are present.
47
+
39
48
  ## Quick Start
40
49
 
41
50
  ### Basic Worker Creation
@@ -4,8 +4,8 @@
4
4
  * Sealed namespace for immutability
5
5
  */
6
6
  import { ErrorFactory, Logger, generateUuid } from '@zintrust/core';
7
- import { ResourceMonitor } from './ResourceMonitor';
8
- import { WorkerMetrics } from './WorkerMetrics';
7
+ import { ResourceMonitor } from './ResourceMonitor.js';
8
+ import { WorkerMetrics } from './WorkerMetrics.js';
9
9
  const configs = new Map();
10
10
  const models = new Map();
11
11
  const updateStats = (stats, value) => {
@@ -5,7 +5,7 @@
5
5
  * Use with Queue.dequeue() in a background process or cron job.
6
6
  */
7
7
  import { Broadcast } from '@zintrust/core';
8
- import { createQueueWorker } from './createQueueWorker';
8
+ import { createQueueWorker } from './createQueueWorker.js';
9
9
  export const BroadcastWorker = Object.freeze({
10
10
  ...createQueueWorker({
11
11
  kindLabel: 'broadcast',
@@ -4,7 +4,7 @@
4
4
  * Sealed namespace for immutability
5
5
  */
6
6
  import { ErrorFactory, Logger } from '@zintrust/core';
7
- import { CircuitBreaker } from './CircuitBreaker';
7
+ import { CircuitBreaker } from './CircuitBreaker.js';
8
8
  // Internal state
9
9
  const canaryDeployments = new Map();
10
10
  const canaryTimers = new Map();
@@ -4,10 +4,10 @@
4
4
  * Sealed namespace for immutability
5
5
  */
6
6
  import { ErrorFactory, Logger, generateUuid } from '@zintrust/core';
7
- import { CircuitBreaker } from './CircuitBreaker';
8
- import { Observability } from './Observability';
9
- import { ResourceMonitor } from './ResourceMonitor';
10
- import { WorkerRegistry } from './WorkerRegistry';
7
+ import { CircuitBreaker } from './CircuitBreaker.js';
8
+ import { Observability } from './Observability.js';
9
+ import { ResourceMonitor } from './ResourceMonitor.js';
10
+ import { WorkerRegistry } from './WorkerRegistry.js';
11
11
  const experiments = new Map();
12
12
  const EXPERIMENT_RETENTION_MS = 24 * 60 * 60 * 1000;
13
13
  const cleanupExpiredExperiments = () => {
@@ -4,7 +4,7 @@
4
4
  * Sealed namespace for immutability
5
5
  */
6
6
  import { ErrorFactory, Logger } from '@zintrust/core';
7
- import { ClusterLock } from './ClusterLock';
7
+ import { ClusterLock } from './ClusterLock.js';
8
8
  // Internal state
9
9
  const regions = new Map();
10
10
  const workerPlacements = new Map();
@@ -4,7 +4,7 @@
4
4
  * Sealed namespace for immutability
5
5
  */
6
6
  import { ErrorFactory, Logger, createRedisConnection } from '@zintrust/core';
7
- import { keyPrefix } from './config/workerConfig';
7
+ import { keyPrefix } from './config/workerConfig.js';
8
8
  // Redis key prefixes - using workers package prefix system
9
9
  const getDLQPrefix = () => {
10
10
  return keyPrefix() + ':dlq:';
@@ -1,5 +1,5 @@
1
1
  import { ErrorFactory, Logger } from '@zintrust/core';
2
- import { WorkerCreationStatus, WorkerFactory } from './WorkerFactory';
2
+ import { WorkerCreationStatus, WorkerFactory } from './WorkerFactory.js';
3
3
  const DEFAULT_CONFIG = {
4
4
  enabled: true,
5
5
  tickIntervalMs: 1000,
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import { ErrorFactory, Logger } from '@zintrust/core';
7
7
  import { Worker } from 'bullmq';
8
- import { PriorityQueue } from './PriorityQueue';
8
+ import { PriorityQueue } from './PriorityQueue.js';
9
9
  // Internal state
10
10
  const multiQueueWorkers = new Map();
11
11
  /**
@@ -5,7 +5,7 @@
5
5
  * Use with Queue.dequeue() in a background process or cron job.
6
6
  */
7
7
  import { Notification } from '@zintrust/core';
8
- import { createQueueWorker } from './createQueueWorker';
8
+ import { createQueueWorker } from './createQueueWorker.js';
9
9
  export const NotificationWorker = Object.freeze({
10
10
  ...createQueueWorker({
11
11
  kindLabel: 'notification',
@@ -4,8 +4,8 @@
4
4
  * Sealed namespace for immutability
5
5
  */
6
6
  import { ErrorFactory, Logger, generateUuid } from '@zintrust/core';
7
- import { HealthMonitor } from './HealthMonitor';
8
- import { WorkerMetrics } from './WorkerMetrics';
7
+ import { HealthMonitor } from './HealthMonitor.js';
8
+ import { WorkerMetrics } from './WorkerMetrics.js';
9
9
  const slaConfigs = new Map();
10
10
  const violationHistory = new Map();
11
11
  const lastAlertAt = new Map();
@@ -5,24 +5,24 @@
5
5
  */
6
6
  import { Cloudflare, createRedisConnection, databaseConfig, Env, ErrorFactory, generateUuid, getBullMQSafeQueueName, JobStateTracker, Logger, NodeSingletons, queueConfig, registerDatabasesFromRuntimeConfig, useEnsureDbConnected, workersConfig, ZintrustLang, } from '@zintrust/core';
7
7
  import { Worker } from 'bullmq';
8
- import { AutoScaler } from './AutoScaler';
9
- import { CanaryController } from './CanaryController';
10
- import { CircuitBreaker } from './CircuitBreaker';
11
- import { ClusterLock } from './ClusterLock';
12
- import { ComplianceManager } from './ComplianceManager';
13
- import { DatacenterOrchestrator } from './DatacenterOrchestrator';
14
- import { DeadLetterQueue } from './DeadLetterQueue';
15
- import { HealthMonitor } from './HealthMonitor';
16
- import { MultiQueueWorker } from './MultiQueueWorker';
17
- import { Observability } from './Observability';
18
- import { PluginManager } from './PluginManager';
19
- import { PriorityQueue } from './PriorityQueue';
20
- import { ResourceMonitor } from './ResourceMonitor';
21
- import { WorkerMetrics } from './WorkerMetrics';
22
- import { WorkerRegistry } from './WorkerRegistry';
23
- import { WorkerVersioning } from './WorkerVersioning';
24
- import { keyPrefix } from './config/workerConfig';
25
- import { DbWorkerStore, InMemoryWorkerStore, RedisWorkerStore, } from './storage/WorkerStore';
8
+ import { AutoScaler } from './AutoScaler.js';
9
+ import { CanaryController } from './CanaryController.js';
10
+ import { CircuitBreaker } from './CircuitBreaker.js';
11
+ import { ClusterLock } from './ClusterLock.js';
12
+ import { ComplianceManager } from './ComplianceManager.js';
13
+ import { DatacenterOrchestrator } from './DatacenterOrchestrator.js';
14
+ import { DeadLetterQueue } from './DeadLetterQueue.js';
15
+ import { HealthMonitor } from './HealthMonitor.js';
16
+ import { MultiQueueWorker } from './MultiQueueWorker.js';
17
+ import { Observability } from './Observability.js';
18
+ import { PluginManager } from './PluginManager.js';
19
+ import { PriorityQueue } from './PriorityQueue.js';
20
+ import { ResourceMonitor } from './ResourceMonitor.js';
21
+ import { WorkerMetrics } from './WorkerMetrics.js';
22
+ import { WorkerRegistry } from './WorkerRegistry.js';
23
+ import { WorkerVersioning } from './WorkerVersioning.js';
24
+ import { keyPrefix } from './config/workerConfig.js';
25
+ import { DbWorkerStore, InMemoryWorkerStore, RedisWorkerStore, } from './storage/WorkerStore.js';
26
26
  const path = NodeSingletons.path;
27
27
  const isNodeRuntime = () => typeof process !== 'undefined' && Boolean(process.versions?.node);
28
28
  const resolveProjectRoot = () => {
@@ -8,10 +8,10 @@
8
8
  * - Ensures graceful startup and shutdown
9
9
  */
10
10
  import { Env, Logger } from '@zintrust/core';
11
- import { ResourceMonitor } from './ResourceMonitor';
12
- import { WorkerFactory } from './WorkerFactory';
13
- import { WorkerShutdown } from './WorkerShutdown';
14
- import { keyPrefix } from './config/workerConfig';
11
+ import { ResourceMonitor } from './ResourceMonitor.js';
12
+ import { WorkerFactory } from './WorkerFactory.js';
13
+ import { WorkerShutdown } from './WorkerShutdown.js';
14
+ import { keyPrefix } from './config/workerConfig.js';
15
15
  // ============================================================================
16
16
  // State
17
17
  // ============================================================================
@@ -4,7 +4,7 @@
4
4
  * Sealed namespace for immutability
5
5
  */
6
6
  import { ErrorFactory, Logger } from '@zintrust/core';
7
- import { AnomalyDetection } from './AnomalyDetection';
7
+ import { AnomalyDetection } from './AnomalyDetection.js';
8
8
  // Internal storage
9
9
  const workers = new Map();
10
10
  const registrations = new Map();
@@ -5,7 +5,7 @@
5
5
  * Coordinates orderly shutdown of all worker modules and the WorkerFactory.
6
6
  */
7
7
  import { Logger } from '@zintrust/core';
8
- import { WorkerFactory } from './WorkerFactory';
8
+ import { WorkerFactory } from './WorkerFactory.js';
9
9
  // ============================================================================
10
10
  // Implementation
11
11
  // ============================================================================
@@ -1,6 +1,6 @@
1
1
  import { Env, ErrorFactory, Logger } from '@zintrust/core';
2
- import { WorkerFactory } from '../WorkerFactory';
3
- import { WorkerMetrics as WorkerMetricsManager } from '../WorkerMetrics';
2
+ import { WorkerFactory } from '../WorkerFactory.js';
3
+ import { WorkerMetrics as WorkerMetricsManager } from '../WorkerMetrics.js';
4
4
  const DEFAULT_PAGE_SIZE = 100;
5
5
  const MAX_PAGE_SIZE = 200;
6
6
  // Helper for timeout handling
@@ -3,9 +3,9 @@
3
3
  * HTTP handlers for worker management API
4
4
  */
5
5
  import { Logger } from '@zintrust/core';
6
- import { getWorkerDetails, getWorkers } from '../dashboard/workers-api';
7
- import { getParam } from '../helper';
8
- import { WorkerFactory } from '../WorkerFactory';
6
+ import { getWorkerDetails, getWorkers } from '../dashboard/workers-api.js';
7
+ import { getParam } from '../helper/index.js';
8
+ import { WorkerFactory } from '../WorkerFactory.js';
9
9
  /**
10
10
  * Helper to safely get a single string value from query params
11
11
  */
@@ -4,16 +4,16 @@
4
4
  * HTTP handlers for worker management API
5
5
  */
6
6
  import { Cloudflare, Env, Logger, getValidatedBody, } from '@zintrust/core';
7
- import { CanaryController } from '../CanaryController';
8
- import { HealthMonitor } from '../HealthMonitor';
9
- import { getParam } from '../helper';
10
- import { SLAMonitor } from '../index';
11
- import { ResourceMonitor } from '../ResourceMonitor';
12
- import { WorkerFactory } from '../WorkerFactory';
13
- import { WorkerRegistry } from '../WorkerRegistry';
14
- import { WorkerShutdown } from '../WorkerShutdown';
15
- import { WorkerVersioning } from '../WorkerVersioning';
16
- import { WorkerMonitoringService } from './WorkerMonitoringService';
7
+ import { CanaryController } from '../CanaryController.js';
8
+ import { HealthMonitor } from '../HealthMonitor.js';
9
+ import { getParam } from '../helper/index.js';
10
+ import { SLAMonitor } from '../index.js';
11
+ import { ResourceMonitor } from '../ResourceMonitor.js';
12
+ import { WorkerFactory } from '../WorkerFactory.js';
13
+ import { WorkerRegistry } from '../WorkerRegistry.js';
14
+ import { WorkerShutdown } from '../WorkerShutdown.js';
15
+ import { WorkerVersioning } from '../WorkerVersioning.js';
16
+ import { WorkerMonitoringService } from './WorkerMonitoringService.js';
17
17
  /**
18
18
  * Helper to get request body
19
19
  */
@@ -1,6 +1,6 @@
1
1
  import { Logger, NodeSingletons, workersConfig } from '@zintrust/core';
2
- import { HealthMonitor } from '../HealthMonitor';
3
- import { getWorkers } from '../dashboard/workers-api';
2
+ import { HealthMonitor } from '../HealthMonitor.js';
3
+ import { getWorkers } from '../dashboard/workers-api.js';
4
4
  const createFallbackEmitter = () => {
5
5
  const listeners = new Map();
6
6
  return {
@@ -1,13 +1,13 @@
1
1
  import { Logger } from '@zintrust/core';
2
2
  // Import individual validators
3
- import { withDatacenterValidation } from './DatacenterValidator';
4
- import { withFeaturesValidation } from './FeaturesValidator';
5
- import { withInfrastructureValidation } from './InfrastructureValidator';
6
- import { withStrictPayloadKeys } from './PayloadSanitizer';
7
- import { withProcessorPathValidation } from './ProcessorPathSanitizer';
8
- import { withQueueNameValidation } from './QueueNameSanitizer';
9
- import { withVersionValidation } from './VersionSanitizer';
10
- import { withWorkerNameValidation } from './WorkerNameSanitizer';
3
+ import { withDatacenterValidation } from './DatacenterValidator.js';
4
+ import { withFeaturesValidation } from './FeaturesValidator.js';
5
+ import { withInfrastructureValidation } from './InfrastructureValidator.js';
6
+ import { withStrictPayloadKeys } from './PayloadSanitizer.js';
7
+ import { withProcessorPathValidation } from './ProcessorPathSanitizer.js';
8
+ import { withQueueNameValidation } from './QueueNameSanitizer.js';
9
+ import { withVersionValidation } from './VersionSanitizer.js';
10
+ import { withWorkerNameValidation } from './WorkerNameSanitizer.js';
11
11
  /**
12
12
  * Composite middleware for worker edit validation
13
13
  * Maps processorSpec to processor for validation and validates all editable fields
@@ -1,14 +1,14 @@
1
1
  import { Logger } from '@zintrust/core';
2
2
  // Import individual validators
3
- import { withDatacenterValidation } from './DatacenterValidator';
4
- import { withFeaturesValidation } from './FeaturesValidator';
5
- import { withInfrastructureValidation } from './InfrastructureValidator';
6
- import { withOptionsValidation } from './OptionsValidator';
7
- import { withStrictPayloadKeys } from './PayloadSanitizer';
8
- import { withProcessorPathValidation } from './ProcessorPathSanitizer';
9
- import { withQueueNameValidation } from './QueueNameSanitizer';
10
- import { withVersionValidation } from './VersionSanitizer';
11
- import { withWorkerNameValidation } from './WorkerNameSanitizer';
3
+ import { withDatacenterValidation } from './DatacenterValidator.js';
4
+ import { withFeaturesValidation } from './FeaturesValidator.js';
5
+ import { withInfrastructureValidation } from './InfrastructureValidator.js';
6
+ import { withOptionsValidation } from './OptionsValidator.js';
7
+ import { withStrictPayloadKeys } from './PayloadSanitizer.js';
8
+ import { withProcessorPathValidation } from './ProcessorPathSanitizer.js';
9
+ import { withQueueNameValidation } from './QueueNameSanitizer.js';
10
+ import { withVersionValidation } from './VersionSanitizer.js';
11
+ import { withWorkerNameValidation } from './WorkerNameSanitizer.js';
12
12
  /**
13
13
  * Composite middleware for worker creation validation
14
14
  * Validates all required fields for creating a new worker
package/dist/index.js CHANGED
@@ -4,42 +4,42 @@
4
4
  * Central export file for all worker management modules.
5
5
  */
6
6
  // Core Infrastructure
7
- export { ClusterLock } from './ClusterLock';
8
- export { PriorityQueue } from './PriorityQueue';
9
- export { WorkerMetrics } from './WorkerMetrics';
10
- export { WorkerRegistry } from './WorkerRegistry';
7
+ export { ClusterLock } from './ClusterLock.js';
8
+ export { PriorityQueue } from './PriorityQueue.js';
9
+ export { WorkerMetrics } from './WorkerMetrics.js';
10
+ export { WorkerRegistry } from './WorkerRegistry.js';
11
11
  // Resilience & Recovery
12
- export { AutoScaler } from './AutoScaler';
13
- export { CircuitBreaker } from './CircuitBreaker';
14
- export { DeadLetterQueue } from './DeadLetterQueue';
12
+ export { AutoScaler } from './AutoScaler.js';
13
+ export { CircuitBreaker } from './CircuitBreaker.js';
14
+ export { DeadLetterQueue } from './DeadLetterQueue.js';
15
15
  // Monitoring & Resources
16
- export { HealthMonitor } from './HealthMonitor';
17
- export { ResourceMonitor } from './ResourceMonitor';
18
- export { SLAMonitor } from './SLAMonitor';
16
+ export { HealthMonitor } from './HealthMonitor.js';
17
+ export { ResourceMonitor } from './ResourceMonitor.js';
18
+ export { SLAMonitor } from './SLAMonitor.js';
19
19
  // Compliance & Security
20
- export { ComplianceManager } from './ComplianceManager';
20
+ export { ComplianceManager } from './ComplianceManager.js';
21
21
  // Observability
22
- export { Observability } from './Observability';
22
+ export { Observability } from './Observability.js';
23
23
  // Plugin System
24
- export { PluginManager } from './PluginManager';
24
+ export { PluginManager } from './PluginManager.js';
25
25
  // Advanced Features
26
- export { AnomalyDetection } from './AnomalyDetection';
27
- export { CanaryController } from './CanaryController';
28
- export { ChaosEngineering } from './ChaosEngineering';
29
- export { DatacenterOrchestrator } from './DatacenterOrchestrator';
30
- export { MultiQueueWorker } from './MultiQueueWorker';
31
- export { WorkerVersioning } from './WorkerVersioning';
26
+ export { AnomalyDetection } from './AnomalyDetection.js';
27
+ export { CanaryController } from './CanaryController.js';
28
+ export { ChaosEngineering } from './ChaosEngineering.js';
29
+ export { DatacenterOrchestrator } from './DatacenterOrchestrator.js';
30
+ export { MultiQueueWorker } from './MultiQueueWorker.js';
31
+ export { WorkerVersioning } from './WorkerVersioning.js';
32
32
  // Factory & Lifecycle
33
- export { WorkerFactory } from './WorkerFactory';
34
- export { WorkerInit } from './WorkerInit';
35
- export { WorkerShutdown } from './WorkerShutdown';
33
+ export { WorkerFactory } from './WorkerFactory.js';
34
+ export { WorkerInit } from './WorkerInit.js';
35
+ export { WorkerShutdown } from './WorkerShutdown.js';
36
36
  // HTTP Controllers & Routes
37
- export { WorkerController } from './http/WorkerController';
38
- export { registerWorkerRoutes } from './routes/workers';
37
+ export { WorkerController } from './http/WorkerController.js';
38
+ export { registerWorkerRoutes } from './routes/workers.js';
39
39
  // Queue Workers
40
- export { BroadcastWorker } from './BroadcastWorker';
41
- export { createQueueWorker } from './createQueueWorker';
42
- export { NotificationWorker } from './NotificationWorker';
40
+ export { BroadcastWorker } from './BroadcastWorker.js';
41
+ export { createQueueWorker } from './createQueueWorker.js';
42
+ export { NotificationWorker } from './NotificationWorker.js';
43
43
  /**
44
44
  * Package version and build metadata
45
45
  * Available at runtime for debugging and health checks
@@ -0,0 +1,9 @@
1
+ type CliCommandProvider = {
2
+ getCommand: () => unknown;
3
+ name?: string;
4
+ };
5
+ type Registry = {
6
+ register: (id: string, provider: CliCommandProvider) => void;
7
+ };
8
+ export declare function registerWorkerCliCommands(registry: Registry): void;
9
+ export {};
@@ -0,0 +1,37 @@
1
+ const commandModule = (await (async () => {
2
+ return (await import('@zintrust/core/cli'));
3
+ })());
4
+ const getWorkerProviders = () => {
5
+ const { WorkerCommands } = commandModule;
6
+ return [
7
+ ['worker:list', WorkerCommands.createWorkerListCommand()],
8
+ ['worker:status', WorkerCommands.createWorkerStatusCommand()],
9
+ ['worker:start', WorkerCommands.createWorkerStartCommand()],
10
+ ['worker:start-all', WorkerCommands.createWorkerStartAllCommand()],
11
+ ['worker:stop', WorkerCommands.createWorkerStopCommand()],
12
+ ['worker:restart', WorkerCommands.createWorkerRestartCommand()],
13
+ ['worker:summary', WorkerCommands.createWorkerSummaryCommand()],
14
+ ];
15
+ };
16
+ export function registerWorkerCliCommands(registry) {
17
+ for (const [id, provider] of getWorkerProviders()) {
18
+ registry.register(id, provider);
19
+ }
20
+ }
21
+ const globalWithRegistry = globalThis;
22
+ const globalRegistry = globalWithRegistry.__zintrust_cli_command_registry__ ??
23
+ (globalWithRegistry.__zintrust_cli_command_registry__ = new Map());
24
+ registerWorkerCliCommands({
25
+ register: (id, provider) => {
26
+ globalRegistry.set(id, provider);
27
+ },
28
+ });
29
+ try {
30
+ const core = (await import('@zintrust/core/cli'));
31
+ if (core.OptionalCliCommandRegistry !== undefined) {
32
+ registerWorkerCliCommands(core.OptionalCliCommandRegistry);
33
+ }
34
+ }
35
+ catch {
36
+ // no-op
37
+ }
@@ -3,17 +3,17 @@
3
3
  * HTTP API for managing workers with dashboard functionality
4
4
  */
5
5
  import { Cloudflare, Env, Logger, Router } from '@zintrust/core';
6
- import { HealthMonitor } from '../HealthMonitor';
7
- import { ValidationSchemas, withCustomValidation } from '../http/middleware/CustomValidation';
8
- import { withEditWorkerValidation } from '../http/middleware/EditWorkerValidation';
9
- import { withDriverValidation } from '../http/middleware/ValidateDriver';
10
- import { withCreateWorkerValidation, withWorkerOperationValidation, } from '../http/middleware/WorkerValidationChain';
11
- import { WorkerApiController } from '../http/WorkerApiController';
12
- import { WorkerController } from '../http/WorkerController';
13
- import { ResourceMonitor } from '../ResourceMonitor';
14
- import { TelemetryDashboard } from '../telemetry';
15
- import { registerStaticAssets } from '../ui/router/ui';
16
- import { WorkerFactory } from '../WorkerFactory';
6
+ import { HealthMonitor } from '../HealthMonitor.js';
7
+ import { ValidationSchemas, withCustomValidation } from '../http/middleware/CustomValidation.js';
8
+ import { withEditWorkerValidation } from '../http/middleware/EditWorkerValidation.js';
9
+ import { withDriverValidation } from '../http/middleware/ValidateDriver.js';
10
+ import { withCreateWorkerValidation, withWorkerOperationValidation, } from '../http/middleware/WorkerValidationChain.js';
11
+ import { WorkerApiController } from '../http/WorkerApiController.js';
12
+ import { WorkerController } from '../http/WorkerController.js';
13
+ import { ResourceMonitor } from '../ResourceMonitor.js';
14
+ import { TelemetryDashboard } from '../telemetry/index.js';
15
+ import { registerStaticAssets } from '../ui/router/ui.js';
16
+ import { WorkerFactory } from '../WorkerFactory.js';
17
17
  const controller = WorkerController.create();
18
18
  const apiController = WorkerApiController.create();
19
19
  function registerCoreWorkerRoutes(r) {
@@ -1,7 +1,7 @@
1
1
  import { Logger } from '@zintrust/core';
2
- import { getWorkers } from '../../dashboard/workers-api';
3
- import { HealthMonitor } from '../../HealthMonitor';
4
- import { ResourceMonitor } from '../../ResourceMonitor';
2
+ import { getWorkers } from '../../dashboard/workers-api.js';
3
+ import { HealthMonitor } from '../../HealthMonitor.js';
4
+ import { ResourceMonitor } from '../../ResourceMonitor.js';
5
5
  const isOkWithUsage = (value) => value.ok === true && 'usage' in value;
6
6
  const isOkWithSummary = (value) => value.ok === true && 'summary' in value;
7
7
  // Helper function to create stopped worker alert
@@ -1,7 +1,7 @@
1
1
  import { Router } from '@zintrust/core';
2
- import { createSnapshotBuilder } from './api/TelemetryAPI';
3
- import { teleStream } from './api/TelemetryMonitoringService';
4
- import { getDashboardHtml } from './routes/dashboard';
2
+ import { createSnapshotBuilder } from './api/TelemetryAPI.js';
3
+ import { teleStream } from './api/TelemetryMonitoringService.js';
4
+ import { getDashboardHtml } from './routes/dashboard.js';
5
5
  const DEFAULTS = {
6
6
  enabled: true,
7
7
  basePath: '/telemetry',
@@ -1,7 +1,7 @@
1
- import { renderAlertPanel } from '../components/AlertPanel';
2
- import { renderCostTracking } from '../components/CostTracking';
3
- import { renderResourceUsageChart } from '../components/ResourceUsageChart';
4
- import { renderWorkerHealthChart } from '../components/WorkerHealthChart';
1
+ import { renderAlertPanel } from '../components/AlertPanel.js';
2
+ import { renderCostTracking } from '../components/CostTracking.js';
3
+ import { renderResourceUsageChart } from '../components/ResourceUsageChart.js';
4
+ import { renderWorkerHealthChart } from '../components/WorkerHealthChart.js';
5
5
  const getDashboardColorStyles = () => `
6
6
  :root {
7
7
  --bg: #0b1220;
@@ -1,5 +1,5 @@
1
1
  import { Cloudflare, Logger, MIME_TYPES, NodeSingletons, Router } from '@zintrust/core';
2
- import { INDEX_HTML, MAIN_JS, STYLES_CSS, ZINTRUST_SVG } from './EmbeddedAssets';
2
+ import { INDEX_HTML, MAIN_JS, STYLES_CSS, ZINTRUST_SVG } from './EmbeddedAssets.js';
3
3
  const isCloudflare = (() => {
4
4
  try {
5
5
  return Cloudflare.getWorkersEnv() !== null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zintrust/workers",
3
- "version": "0.4.0",
3
+ "version": "0.4.4",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -14,6 +14,10 @@
14
14
  "types": "./dist/index.d.ts",
15
15
  "default": "./dist/index.js"
16
16
  },
17
+ "./register": {
18
+ "types": "./dist/register.d.ts",
19
+ "default": "./dist/register.js"
20
+ },
17
21
  "./HealthMonitor": {
18
22
  "types": "./dist/HealthMonitor.d.ts",
19
23
  "default": "./dist/HealthMonitor.js"
@@ -35,25 +39,31 @@
35
39
  "node": ">=20.0.0"
36
40
  },
37
41
  "peerDependencies": {
38
- "@zintrust/core": "^0.4.0"
42
+ "@zintrust/core": "^0.4.4",
43
+ "@zintrust/queue-monitor": "*",
44
+ "@zintrust/queue-redis": "*"
45
+ },
46
+ "peerDependenciesMeta": {
47
+ "@zintrust/queue-monitor": {
48
+ "optional": true
49
+ },
50
+ "@zintrust/queue-redis": {
51
+ "optional": true
52
+ }
39
53
  },
40
54
  "publishConfig": {
41
55
  "access": "public"
42
56
  },
43
57
  "scripts": {
44
- "build": "node scripts/generate-embedded-assets.mjs && tsc -p tsconfig.json",
58
+ "build": "node scripts/generate-embedded-assets.mjs && tsc -p tsconfig.json && node ../../scripts/fix-dist-esm-imports.mjs dist",
45
59
  "prepublishOnly": "npm run build"
46
60
  },
47
61
  "dependencies": {
48
62
  "@opentelemetry/api": "^1.9.0",
49
- "hot-shots": "^14.1.1",
63
+ "hot-shots": "^14.2.0",
50
64
  "ioredis": "^5.10.0",
51
65
  "ml.js": "^0.0.1",
52
66
  "prom-client": "^15.1.3",
53
- "simple-statistics": "^7.8.8"
54
- },
55
- "optionalDependencies": {
56
- "@zintrust/queue-monitor": "^0.1.51",
57
- "@zintrust/queue-redis": "^0.1.54"
67
+ "simple-statistics": "^7.8.9"
58
68
  }
59
69
  }
@@ -0,0 +1,71 @@
1
+ type CliCommandProvider = {
2
+ getCommand: () => unknown;
3
+ name?: string;
4
+ };
5
+
6
+ type Registry = {
7
+ register: (id: string, provider: CliCommandProvider) => void;
8
+ };
9
+
10
+ type WorkerCommandsModule = {
11
+ WorkerCommands: {
12
+ createWorkerListCommand: () => CliCommandProvider;
13
+ createWorkerStatusCommand: () => CliCommandProvider;
14
+ createWorkerStartCommand: () => CliCommandProvider;
15
+ createWorkerStartAllCommand: () => CliCommandProvider;
16
+ createWorkerStopCommand: () => CliCommandProvider;
17
+ createWorkerRestartCommand: () => CliCommandProvider;
18
+ createWorkerSummaryCommand: () => CliCommandProvider;
19
+ };
20
+ };
21
+
22
+ const commandModule = (await (async (): Promise<WorkerCommandsModule> => {
23
+ return (await import('@zintrust/core/cli')) as unknown as WorkerCommandsModule;
24
+ })()) satisfies WorkerCommandsModule;
25
+
26
+ const getWorkerProviders = (): Array<[string, CliCommandProvider]> => {
27
+ const { WorkerCommands } = commandModule;
28
+
29
+ return [
30
+ ['worker:list', WorkerCommands.createWorkerListCommand()],
31
+ ['worker:status', WorkerCommands.createWorkerStatusCommand()],
32
+ ['worker:start', WorkerCommands.createWorkerStartCommand()],
33
+ ['worker:start-all', WorkerCommands.createWorkerStartAllCommand()],
34
+ ['worker:stop', WorkerCommands.createWorkerStopCommand()],
35
+ ['worker:restart', WorkerCommands.createWorkerRestartCommand()],
36
+ ['worker:summary', WorkerCommands.createWorkerSummaryCommand()],
37
+ ];
38
+ };
39
+
40
+ export function registerWorkerCliCommands(registry: Registry): void {
41
+ for (const [id, provider] of getWorkerProviders()) {
42
+ registry.register(id, provider);
43
+ }
44
+ }
45
+
46
+ type GlobalWithRegistry = {
47
+ __zintrust_cli_command_registry__?: Map<string, CliCommandProvider>;
48
+ };
49
+
50
+ const globalWithRegistry = globalThis as unknown as GlobalWithRegistry;
51
+ const globalRegistry =
52
+ globalWithRegistry.__zintrust_cli_command_registry__ ??
53
+ (globalWithRegistry.__zintrust_cli_command_registry__ = new Map<string, CliCommandProvider>());
54
+
55
+ registerWorkerCliCommands({
56
+ register: (id, provider) => {
57
+ globalRegistry.set(id, provider);
58
+ },
59
+ });
60
+
61
+ try {
62
+ const core = (await import('@zintrust/core/cli')) as unknown as {
63
+ OptionalCliCommandRegistry?: Registry;
64
+ };
65
+
66
+ if (core.OptionalCliCommandRegistry !== undefined) {
67
+ registerWorkerCliCommands(core.OptionalCliCommandRegistry);
68
+ }
69
+ } catch {
70
+ // no-op
71
+ }