@peopl-health/nexus 3.13.0 → 3.13.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.
- package/lib/core/BatchingManager.js +14 -0
- package/lib/index.d.ts +5 -0
- package/package.json +1 -1
|
@@ -15,6 +15,7 @@ class BatchingManager {
|
|
|
15
15
|
this.activeRequests = new Map();
|
|
16
16
|
this.abandonedRuns = new Set();
|
|
17
17
|
this.typingIntervals = new Map();
|
|
18
|
+
this.chatQueues = new Map();
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
setProvider(provider) {
|
|
@@ -38,6 +39,7 @@ class BatchingManager {
|
|
|
38
39
|
|
|
39
40
|
if (this.config.immediateRestart) {
|
|
40
41
|
this._clearProcessingState(chatId);
|
|
42
|
+
this.processingLocks.set(chatId, true);
|
|
41
43
|
await this._runWithLock(chatId, processingFn, sendResponseFn);
|
|
42
44
|
}
|
|
43
45
|
}
|
|
@@ -48,7 +50,17 @@ class BatchingManager {
|
|
|
48
50
|
await this._runWithLock(chatId, processingFn, sendResponseFn);
|
|
49
51
|
}
|
|
50
52
|
|
|
53
|
+
async enqueueProcessing(chatId, processingFn, sendResponseFn) {
|
|
54
|
+
await this._runWithLock(chatId, processingFn, sendResponseFn);
|
|
55
|
+
}
|
|
56
|
+
|
|
51
57
|
async _runWithLock(chatId, processingFn, sendResponseFn) {
|
|
58
|
+
const prev = this.chatQueues.get(chatId) || Promise.resolve();
|
|
59
|
+
let resolveGate;
|
|
60
|
+
const gate = new Promise(r => { resolveGate = r; });
|
|
61
|
+
this.chatQueues.set(chatId, gate);
|
|
62
|
+
await prev;
|
|
63
|
+
|
|
52
64
|
this.processingLocks.set(chatId, true);
|
|
53
65
|
const runId = `run_${Date.now()}_${Math.random().toString(36).slice(2, 9)}`;
|
|
54
66
|
this.activeRequests.set(chatId, runId);
|
|
@@ -67,6 +79,8 @@ class BatchingManager {
|
|
|
67
79
|
if (this.activeRequests.get(chatId) === runId) {
|
|
68
80
|
this._clearProcessingState(chatId);
|
|
69
81
|
}
|
|
82
|
+
resolveGate();
|
|
83
|
+
if (this.chatQueues.get(chatId) === gate) this.chatQueues.delete(chatId);
|
|
70
84
|
if (this.abandonedRuns.size > 100) {
|
|
71
85
|
const toKeep = [...this.abandonedRuns].slice(-20);
|
|
72
86
|
this.abandonedRuns.clear();
|
package/lib/index.d.ts
CHANGED
|
@@ -518,6 +518,11 @@ declare module '@peopl-health/nexus' {
|
|
|
518
518
|
processingFn: (runId: string) => Promise<any>,
|
|
519
519
|
sendResponseFn: (result: any) => Promise<void>
|
|
520
520
|
): Promise<void>;
|
|
521
|
+
enqueueProcessing(
|
|
522
|
+
chatId: string,
|
|
523
|
+
processingFn: (runId: string) => Promise<any>,
|
|
524
|
+
sendResponseFn: (result: any) => Promise<void>
|
|
525
|
+
): Promise<void>;
|
|
521
526
|
}
|
|
522
527
|
|
|
523
528
|
// ProcessingPipeline — hook lifecycle for all LLM operations
|