vantuz 3.4.2 → 3.5.1

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.
Files changed (92) hide show
  1. package/.env.example +21 -0
  2. package/.openclaw/completions/openclaw.bash +227 -0
  3. package/.openclaw/completions/openclaw.fish +1552 -0
  4. package/.openclaw/completions/openclaw.ps1 +1966 -0
  5. package/.openclaw/completions/openclaw.zsh +3571 -0
  6. package/.openclaw/gateway.cmd +10 -0
  7. package/.openclaw/identity/device.json +7 -0
  8. package/.openclaw/openclaw.json +40 -0
  9. package/.windsurf/workflows/vantuz-dev.md +31 -0
  10. package/DOCS_TR.md +80 -0
  11. package/LICENSE +45 -45
  12. package/README.md +52 -21
  13. package/cli.js +685 -585
  14. package/config.js +733 -733
  15. package/core/agent-loop.js +190 -190
  16. package/core/ai-provider.js +298 -261
  17. package/core/automation.js +523 -523
  18. package/core/brand-analyst.js +101 -0
  19. package/core/channels.js +167 -167
  20. package/core/dashboard.js +230 -230
  21. package/core/database.js +135 -37
  22. package/core/eia-monitor.js +3 -1
  23. package/core/engine.js +648 -636
  24. package/core/gateway.js +447 -447
  25. package/core/learning.js +214 -214
  26. package/core/license.js +113 -0
  27. package/core/marketplace-adapter.js +168 -168
  28. package/core/memory.js +190 -190
  29. package/core/migrations/001-initial-schema.sql +1 -1
  30. package/core/queue.js +120 -120
  31. package/core/self-healer.js +314 -314
  32. package/core/unified-product.js +214 -214
  33. package/core/vision-service.js +113 -113
  34. package/index.js +217 -174
  35. package/modules/crm/sentiment-crm.js +231 -231
  36. package/modules/healer/listing-healer.js +201 -201
  37. package/modules/oracle/predictor.js +214 -214
  38. package/modules/researcher/agent.js +169 -169
  39. package/modules/team/agents/base.js +92 -92
  40. package/modules/team/agents/dev.js +33 -33
  41. package/modules/team/agents/josh.js +40 -40
  42. package/modules/team/agents/marketing.js +33 -33
  43. package/modules/team/agents/milo.js +36 -36
  44. package/modules/team/index.js +78 -78
  45. package/modules/team/shared-memory.js +87 -87
  46. package/modules/war-room/competitor-tracker.js +250 -250
  47. package/modules/war-room/pricing-engine.js +308 -308
  48. package/n11docs.md +1680 -0
  49. package/nodes/warehouse.js +238 -238
  50. package/onboard.js +1 -1
  51. package/openclawdocs.md +3 -0
  52. package/package.json +7 -5
  53. package/platforms/pttavm.js +14 -14
  54. package/plugins/vantuz/index.js +528 -528
  55. package/plugins/vantuz/memory/hippocampus.js +465 -465
  56. package/plugins/vantuz/package.json +20 -20
  57. package/plugins/vantuz/platforms/_template.js +118 -118
  58. package/plugins/vantuz/platforms/amazon.js +236 -236
  59. package/plugins/vantuz/platforms/ciceksepeti.js +166 -166
  60. package/plugins/vantuz/platforms/hepsiburada.js +180 -180
  61. package/plugins/vantuz/platforms/index.js +165 -165
  62. package/plugins/vantuz/platforms/n11.js +229 -229
  63. package/plugins/vantuz/platforms/pazarama.js +154 -154
  64. package/plugins/vantuz/platforms/pttavm.js +127 -127
  65. package/plugins/vantuz/platforms/trendyol.js +326 -326
  66. package/plugins/vantuz/services/alerts.js +253 -253
  67. package/plugins/vantuz/services/license.js +34 -34
  68. package/plugins/vantuz/services/scheduler.js +232 -232
  69. package/plugins/vantuz/tools/analytics.js +152 -152
  70. package/plugins/vantuz/tools/crossborder.js +187 -187
  71. package/plugins/vantuz/tools/nl-parser.js +211 -211
  72. package/plugins/vantuz/tools/product.js +110 -110
  73. package/plugins/vantuz/tools/quick-report.js +175 -175
  74. package/plugins/vantuz/tools/repricer.js +314 -314
  75. package/plugins/vantuz/tools/sentiment.js +115 -115
  76. package/plugins/vantuz/tools/vision.js +257 -257
  77. package/public.pem +9 -0
  78. package/server/app.js +260 -260
  79. package/server/public/index.html +514 -514
  80. package/start.bat +33 -33
  81. package/vantuz.sqlite +0 -0
  82. package/workspace/AGENTS.md +73 -0
  83. package/workspace/BRAND.md +29 -0
  84. package/workspace/SOUL.md +72 -0
  85. package/workspace/team/DECISIONS.md +3 -0
  86. package/workspace/team/GOALS.md +3 -0
  87. package/workspace/team/PROJECT_STATUS.md +3 -0
  88. package/workspace/team/agents/dev/SOUL.md +12 -0
  89. package/workspace/team/agents/josh/SOUL.md +12 -0
  90. package/workspace/team/agents/marketing/SOUL.md +12 -0
  91. package/workspace/team/agents/milo/SOUL.md +12 -0
  92. package/vantuz-3.3.4.tgz +0 -0
package/core/memory.js CHANGED
@@ -1,190 +1,190 @@
1
- // core/memory.js
2
- // Persistent Memory Module for Vantuz AI
3
- // Provides long-term fact storage and recall via JSON files.
4
-
5
- import fs from 'fs';
6
- import path from 'path';
7
- import os from 'os';
8
- import { log } from './ai-provider.js';
9
-
10
- const MEMORY_DIR = path.join(os.homedir(), '.vantuz', 'memory');
11
- const FACTS_FILE = path.join(MEMORY_DIR, 'facts.json');
12
- const STRATEGY_FILE = path.join(MEMORY_DIR, 'strategy.json');
13
- const MAX_FACTS = 500;
14
-
15
- /**
16
- * Ensures the memory directory exists.
17
- */
18
- function ensureDir() {
19
- if (!fs.existsSync(MEMORY_DIR)) {
20
- fs.mkdirSync(MEMORY_DIR, { recursive: true });
21
- log('INFO', 'Memory directory created', { path: MEMORY_DIR });
22
- }
23
- }
24
-
25
- /**
26
- * Loads a JSON file safely.
27
- */
28
- function loadJson(filePath) {
29
- try {
30
- if (fs.existsSync(filePath)) {
31
- return JSON.parse(fs.readFileSync(filePath, 'utf-8'));
32
- }
33
- } catch (e) {
34
- log('WARN', `Memory file corrupt or unreadable: ${filePath}`, { error: e.message });
35
- }
36
- return [];
37
- }
38
-
39
- /**
40
- * Saves data to a JSON file atomically.
41
- */
42
- function saveJson(filePath, data) {
43
- ensureDir();
44
- const tmp = filePath + '.tmp';
45
- fs.writeFileSync(tmp, JSON.stringify(data, null, 2), 'utf-8');
46
- fs.renameSync(tmp, filePath);
47
- }
48
-
49
- // ═══════════════════════════════════════════════════════════════════════════
50
- // MEMORY CLASS
51
- // ═══════════════════════════════════════════════════════════════════════════
52
-
53
- class Memory {
54
- constructor() {
55
- ensureDir();
56
- this.facts = loadJson(FACTS_FILE);
57
- this.strategies = loadJson(STRATEGY_FILE);
58
- log('INFO', 'Memory loaded', {
59
- facts: this.facts.length,
60
- strategies: this.strategies.length
61
- });
62
- }
63
-
64
- /**
65
- * Remember a fact. Facts are timestamped entries.
66
- * @param {string} fact - The fact to remember.
67
- * @param {string} category - Category: 'general', 'customer', 'product', 'strategy'
68
- */
69
- remember(fact, category = 'general') {
70
- const entry = {
71
- id: Date.now().toString(36) + Math.random().toString(36).slice(2, 6),
72
- fact,
73
- category,
74
- createdAt: new Date().toISOString()
75
- };
76
-
77
- this.facts.push(entry);
78
-
79
- // Evict oldest if over limit
80
- if (this.facts.length > MAX_FACTS) {
81
- this.facts = this.facts.slice(-MAX_FACTS);
82
- }
83
-
84
- saveJson(FACTS_FILE, this.facts);
85
- log('INFO', 'Fact remembered', { id: entry.id, category });
86
- return entry;
87
- }
88
-
89
- /**
90
- * Recall facts matching a keyword query.
91
- * Simple substring search (can be upgraded to vector later).
92
- * @param {string} query - Search query.
93
- * @param {number} limit - Max results.
94
- * @returns {Array} Matching facts.
95
- */
96
- recall(query, limit = 10) {
97
- const q = query.toLowerCase();
98
- const matches = this.facts.filter(f =>
99
- f.fact.toLowerCase().includes(q) ||
100
- f.category.toLowerCase().includes(q)
101
- );
102
- return matches.slice(-limit);
103
- }
104
-
105
- /**
106
- * Save a strategic decision or rule.
107
- * @param {string} rule - The strategy rule.
108
- * @param {string} context - Why this decision was made.
109
- */
110
- addStrategy(rule, context = '') {
111
- const entry = {
112
- id: Date.now().toString(36),
113
- rule,
114
- context,
115
- createdAt: new Date().toISOString()
116
- };
117
-
118
- this.strategies.push(entry);
119
- saveJson(STRATEGY_FILE, this.strategies);
120
- log('INFO', 'Strategy recorded', { id: entry.id });
121
- return entry;
122
- }
123
-
124
- /**
125
- * Get all strategies.
126
- */
127
- getStrategies() {
128
- return this.strategies;
129
- }
130
-
131
- /**
132
- * Get recent facts for context injection.
133
- * @param {number} count - How many recent facts.
134
- */
135
- getRecentFacts(count = 20) {
136
- return this.facts.slice(-count);
137
- }
138
-
139
- /**
140
- * Get a summary string for AI injection.
141
- */
142
- getContextSummary() {
143
- const recentFacts = this.getRecentFacts(10);
144
- const strategies = this.getStrategies();
145
-
146
- let summary = '';
147
-
148
- if (strategies.length > 0) {
149
- summary += '\n--- STRATEJİK KURALLAR ---\n';
150
- strategies.forEach(s => {
151
- summary += `- ${s.rule}\n`;
152
- });
153
- }
154
-
155
- if (recentFacts.length > 0) {
156
- summary += '\n--- SON HATIRALAR ---\n';
157
- recentFacts.forEach(f => {
158
- summary += `- [${f.category}] ${f.fact}\n`;
159
- });
160
- }
161
-
162
- return summary;
163
- }
164
-
165
- /**
166
- * Full reset (dangerous).
167
- */
168
- clear() {
169
- this.facts = [];
170
- this.strategies = [];
171
- saveJson(FACTS_FILE, this.facts);
172
- saveJson(STRATEGY_FILE, this.strategies);
173
- log('WARN', 'Memory cleared');
174
- }
175
- }
176
-
177
- // ═══════════════════════════════════════════════════════════════════════════
178
- // SINGLETON
179
- // ═══════════════════════════════════════════════════════════════════════════
180
-
181
- let memoryInstance = null;
182
-
183
- export function getMemory() {
184
- if (!memoryInstance) {
185
- memoryInstance = new Memory();
186
- }
187
- return memoryInstance;
188
- }
189
-
190
- export default Memory;
1
+ // core/memory.js
2
+ // Persistent Memory Module for Vantuz AI
3
+ // Provides long-term fact storage and recall via JSON files.
4
+
5
+ import fs from 'fs';
6
+ import path from 'path';
7
+ import os from 'os';
8
+ import { log } from './ai-provider.js';
9
+
10
+ const MEMORY_DIR = path.join(os.homedir(), '.vantuz', 'memory');
11
+ const FACTS_FILE = path.join(MEMORY_DIR, 'facts.json');
12
+ const STRATEGY_FILE = path.join(MEMORY_DIR, 'strategy.json');
13
+ const MAX_FACTS = 500;
14
+
15
+ /**
16
+ * Ensures the memory directory exists.
17
+ */
18
+ function ensureDir() {
19
+ if (!fs.existsSync(MEMORY_DIR)) {
20
+ fs.mkdirSync(MEMORY_DIR, { recursive: true });
21
+ log('INFO', 'Memory directory created', { path: MEMORY_DIR });
22
+ }
23
+ }
24
+
25
+ /**
26
+ * Loads a JSON file safely.
27
+ */
28
+ function loadJson(filePath) {
29
+ try {
30
+ if (fs.existsSync(filePath)) {
31
+ return JSON.parse(fs.readFileSync(filePath, 'utf-8'));
32
+ }
33
+ } catch (e) {
34
+ log('WARN', `Memory file corrupt or unreadable: ${filePath}`, { error: e.message });
35
+ }
36
+ return [];
37
+ }
38
+
39
+ /**
40
+ * Saves data to a JSON file atomically.
41
+ */
42
+ function saveJson(filePath, data) {
43
+ ensureDir();
44
+ const tmp = filePath + '.tmp';
45
+ fs.writeFileSync(tmp, JSON.stringify(data, null, 2), 'utf-8');
46
+ fs.renameSync(tmp, filePath);
47
+ }
48
+
49
+ // ═══════════════════════════════════════════════════════════════════════════
50
+ // MEMORY CLASS
51
+ // ═══════════════════════════════════════════════════════════════════════════
52
+
53
+ class Memory {
54
+ constructor() {
55
+ ensureDir();
56
+ this.facts = loadJson(FACTS_FILE);
57
+ this.strategies = loadJson(STRATEGY_FILE);
58
+ log('INFO', 'Memory loaded', {
59
+ facts: this.facts.length,
60
+ strategies: this.strategies.length
61
+ });
62
+ }
63
+
64
+ /**
65
+ * Remember a fact. Facts are timestamped entries.
66
+ * @param {string} fact - The fact to remember.
67
+ * @param {string} category - Category: 'general', 'customer', 'product', 'strategy'
68
+ */
69
+ remember(fact, category = 'general') {
70
+ const entry = {
71
+ id: Date.now().toString(36) + Math.random().toString(36).slice(2, 6),
72
+ fact,
73
+ category,
74
+ createdAt: new Date().toISOString()
75
+ };
76
+
77
+ this.facts.push(entry);
78
+
79
+ // Evict oldest if over limit
80
+ if (this.facts.length > MAX_FACTS) {
81
+ this.facts = this.facts.slice(-MAX_FACTS);
82
+ }
83
+
84
+ saveJson(FACTS_FILE, this.facts);
85
+ log('INFO', 'Fact remembered', { id: entry.id, category });
86
+ return entry;
87
+ }
88
+
89
+ /**
90
+ * Recall facts matching a keyword query.
91
+ * Simple substring search (can be upgraded to vector later).
92
+ * @param {string} query - Search query.
93
+ * @param {number} limit - Max results.
94
+ * @returns {Array} Matching facts.
95
+ */
96
+ recall(query, limit = 10) {
97
+ const q = query.toLowerCase();
98
+ const matches = this.facts.filter(f =>
99
+ f.fact.toLowerCase().includes(q) ||
100
+ f.category.toLowerCase().includes(q)
101
+ );
102
+ return matches.slice(-limit);
103
+ }
104
+
105
+ /**
106
+ * Save a strategic decision or rule.
107
+ * @param {string} rule - The strategy rule.
108
+ * @param {string} context - Why this decision was made.
109
+ */
110
+ addStrategy(rule, context = '') {
111
+ const entry = {
112
+ id: Date.now().toString(36),
113
+ rule,
114
+ context,
115
+ createdAt: new Date().toISOString()
116
+ };
117
+
118
+ this.strategies.push(entry);
119
+ saveJson(STRATEGY_FILE, this.strategies);
120
+ log('INFO', 'Strategy recorded', { id: entry.id });
121
+ return entry;
122
+ }
123
+
124
+ /**
125
+ * Get all strategies.
126
+ */
127
+ getStrategies() {
128
+ return this.strategies;
129
+ }
130
+
131
+ /**
132
+ * Get recent facts for context injection.
133
+ * @param {number} count - How many recent facts.
134
+ */
135
+ getRecentFacts(count = 20) {
136
+ return this.facts.slice(-count);
137
+ }
138
+
139
+ /**
140
+ * Get a summary string for AI injection.
141
+ */
142
+ getContextSummary() {
143
+ const recentFacts = this.getRecentFacts(10);
144
+ const strategies = this.getStrategies();
145
+
146
+ let summary = '';
147
+
148
+ if (strategies.length > 0) {
149
+ summary += '\n--- STRATEJİK KURALLAR ---\n';
150
+ strategies.forEach(s => {
151
+ summary += `- ${s.rule}\n`;
152
+ });
153
+ }
154
+
155
+ if (recentFacts.length > 0) {
156
+ summary += '\n--- SON HATIRALAR ---\n';
157
+ recentFacts.forEach(f => {
158
+ summary += `- [${f.category}] ${f.fact}\n`;
159
+ });
160
+ }
161
+
162
+ return summary;
163
+ }
164
+
165
+ /**
166
+ * Full reset (dangerous).
167
+ */
168
+ clear() {
169
+ this.facts = [];
170
+ this.strategies = [];
171
+ saveJson(FACTS_FILE, this.facts);
172
+ saveJson(STRATEGY_FILE, this.strategies);
173
+ log('WARN', 'Memory cleared');
174
+ }
175
+ }
176
+
177
+ // ═══════════════════════════════════════════════════════════════════════════
178
+ // SINGLETON
179
+ // ═══════════════════════════════════════════════════════════════════════════
180
+
181
+ let memoryInstance = null;
182
+
183
+ export function getMemory() {
184
+ if (!memoryInstance) {
185
+ memoryInstance = new Memory();
186
+ }
187
+ return memoryInstance;
188
+ }
189
+
190
+ export default Memory;
@@ -17,4 +17,4 @@ CREATE TABLE historical_prices (
17
17
 
18
18
  -- down
19
19
  DROP TABLE IF EXISTS historical_prices;
20
- DROP TABLE IF EXISTS products;
20
+ DROP TABLE IF EXISTS products;
package/core/queue.js CHANGED
@@ -1,120 +1,120 @@
1
- // core/queue.js
2
- // Critical Operation Queue (Lane Queue) for Vantuz AI
3
- // Ensures write operations (price/stock updates) execute serially, never in parallel.
4
-
5
- import { log } from './ai-provider.js';
6
-
7
- class CriticalQueue {
8
- constructor() {
9
- this._queue = [];
10
- this._running = false;
11
- this._stats = { processed: 0, errors: 0, lastRun: null };
12
- log('INFO', 'CriticalQueue (Lane Queue) initialized');
13
- }
14
-
15
- /**
16
- * Enqueue a critical operation.
17
- * @param {string} label - Human readable label (e.g. "Fiyat güncelle: SKU-123")
18
- * @param {function} fn - Async function to execute.
19
- * @param {object} options - { priority: 'high'|'normal', dryRun: false }
20
- * @returns {Promise} Resolves when the operation completes.
21
- */
22
- enqueue(label, fn, options = {}) {
23
- const { priority = 'normal', dryRun = false } = options;
24
-
25
- return new Promise((resolve, reject) => {
26
- const task = { label, fn, resolve, reject, priority, dryRun, enqueuedAt: Date.now() };
27
-
28
- if (priority === 'high') {
29
- // Insert at the front (after any currently running task)
30
- this._queue.unshift(task);
31
- } else {
32
- this._queue.push(task);
33
- }
34
-
35
- log('INFO', `Operation queued: "${label}"`, {
36
- position: this._queue.length,
37
- dryRun,
38
- priority
39
- });
40
-
41
- this._processNext();
42
- });
43
- }
44
-
45
- /**
46
- * Process the next item in the queue.
47
- */
48
- async _processNext() {
49
- if (this._running || this._queue.length === 0) return;
50
-
51
- this._running = true;
52
- const task = this._queue.shift();
53
-
54
- log('INFO', `▶ Executing: "${task.label}"`, {
55
- waitedMs: Date.now() - task.enqueuedAt,
56
- remaining: this._queue.length
57
- });
58
-
59
- try {
60
- if (task.dryRun) {
61
- log('INFO', `[DRY RUN] Would execute: "${task.label}"`);
62
- task.resolve({ dryRun: true, label: task.label, status: 'skipped' });
63
- } else {
64
- const result = await task.fn();
65
- this._stats.processed++;
66
- this._stats.lastRun = new Date().toISOString();
67
- task.resolve(result);
68
- }
69
- } catch (error) {
70
- this._stats.errors++;
71
- log('ERROR', `✘ Failed: "${task.label}"`, { error: error.message });
72
- task.reject(error);
73
- } finally {
74
- this._running = false;
75
- // Process next in queue
76
- if (this._queue.length > 0) {
77
- // Small delay to prevent tight loops
78
- setTimeout(() => this._processNext(), 50);
79
- }
80
- }
81
- }
82
-
83
- /**
84
- * Get queue status.
85
- */
86
- getStatus() {
87
- return {
88
- queueLength: this._queue.length,
89
- isRunning: this._running,
90
- pendingLabels: this._queue.map(t => t.label),
91
- stats: { ...this._stats }
92
- };
93
- }
94
-
95
- /**
96
- * Drain the queue (cancel all pending, don't cancel running).
97
- */
98
- drain() {
99
- const cancelled = this._queue.length;
100
- this._queue.forEach(t => t.reject(new Error('Queue drained')));
101
- this._queue = [];
102
- log('WARN', `Queue drained, ${cancelled} operations cancelled`);
103
- return cancelled;
104
- }
105
- }
106
-
107
- // ═══════════════════════════════════════════════════════════════════════════
108
- // SINGLETON
109
- // ═══════════════════════════════════════════════════════════════════════════
110
-
111
- let queueInstance = null;
112
-
113
- export function getCriticalQueue() {
114
- if (!queueInstance) {
115
- queueInstance = new CriticalQueue();
116
- }
117
- return queueInstance;
118
- }
119
-
120
- export default CriticalQueue;
1
+ // core/queue.js
2
+ // Critical Operation Queue (Lane Queue) for Vantuz AI
3
+ // Ensures write operations (price/stock updates) execute serially, never in parallel.
4
+
5
+ import { log } from './ai-provider.js';
6
+
7
+ class CriticalQueue {
8
+ constructor() {
9
+ this._queue = [];
10
+ this._running = false;
11
+ this._stats = { processed: 0, errors: 0, lastRun: null };
12
+ log('INFO', 'CriticalQueue (Lane Queue) initialized');
13
+ }
14
+
15
+ /**
16
+ * Enqueue a critical operation.
17
+ * @param {string} label - Human readable label (e.g. "Fiyat güncelle: SKU-123")
18
+ * @param {function} fn - Async function to execute.
19
+ * @param {object} options - { priority: 'high'|'normal', dryRun: false }
20
+ * @returns {Promise} Resolves when the operation completes.
21
+ */
22
+ enqueue(label, fn, options = {}) {
23
+ const { priority = 'normal', dryRun = false } = options;
24
+
25
+ return new Promise((resolve, reject) => {
26
+ const task = { label, fn, resolve, reject, priority, dryRun, enqueuedAt: Date.now() };
27
+
28
+ if (priority === 'high') {
29
+ // Insert at the front (after any currently running task)
30
+ this._queue.unshift(task);
31
+ } else {
32
+ this._queue.push(task);
33
+ }
34
+
35
+ log('INFO', `Operation queued: "${label}"`, {
36
+ position: this._queue.length,
37
+ dryRun,
38
+ priority
39
+ });
40
+
41
+ this._processNext();
42
+ });
43
+ }
44
+
45
+ /**
46
+ * Process the next item in the queue.
47
+ */
48
+ async _processNext() {
49
+ if (this._running || this._queue.length === 0) return;
50
+
51
+ this._running = true;
52
+ const task = this._queue.shift();
53
+
54
+ log('INFO', `▶ Executing: "${task.label}"`, {
55
+ waitedMs: Date.now() - task.enqueuedAt,
56
+ remaining: this._queue.length
57
+ });
58
+
59
+ try {
60
+ if (task.dryRun) {
61
+ log('INFO', `[DRY RUN] Would execute: "${task.label}"`);
62
+ task.resolve({ dryRun: true, label: task.label, status: 'skipped' });
63
+ } else {
64
+ const result = await task.fn();
65
+ this._stats.processed++;
66
+ this._stats.lastRun = new Date().toISOString();
67
+ task.resolve(result);
68
+ }
69
+ } catch (error) {
70
+ this._stats.errors++;
71
+ log('ERROR', `✘ Failed: "${task.label}"`, { error: error.message });
72
+ task.reject(error);
73
+ } finally {
74
+ this._running = false;
75
+ // Process next in queue
76
+ if (this._queue.length > 0) {
77
+ // Small delay to prevent tight loops
78
+ setTimeout(() => this._processNext(), 50);
79
+ }
80
+ }
81
+ }
82
+
83
+ /**
84
+ * Get queue status.
85
+ */
86
+ getStatus() {
87
+ return {
88
+ queueLength: this._queue.length,
89
+ isRunning: this._running,
90
+ pendingLabels: this._queue.map(t => t.label),
91
+ stats: { ...this._stats }
92
+ };
93
+ }
94
+
95
+ /**
96
+ * Drain the queue (cancel all pending, don't cancel running).
97
+ */
98
+ drain() {
99
+ const cancelled = this._queue.length;
100
+ this._queue.forEach(t => t.reject(new Error('Queue drained')));
101
+ this._queue = [];
102
+ log('WARN', `Queue drained, ${cancelled} operations cancelled`);
103
+ return cancelled;
104
+ }
105
+ }
106
+
107
+ // ═══════════════════════════════════════════════════════════════════════════
108
+ // SINGLETON
109
+ // ═══════════════════════════════════════════════════════════════════════════
110
+
111
+ let queueInstance = null;
112
+
113
+ export function getCriticalQueue() {
114
+ if (!queueInstance) {
115
+ queueInstance = new CriticalQueue();
116
+ }
117
+ return queueInstance;
118
+ }
119
+
120
+ export default CriticalQueue;