@pmate/chat-sdk 0.14.0-seq.10 → 0.14.0-seq.11
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.
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { PROFILE_PROJECTION_VERSION } from "./profileMemoryStore.js";
|
|
2
2
|
import { inboxSequence } from "./inboxStore.js";
|
|
3
|
+
const checkIntervalMs = 10_000;
|
|
4
|
+
const liveFreshnessMs = 35_000;
|
|
5
|
+
const reconciliationIntervalMs = 60_000;
|
|
3
6
|
/** The existing Inbox HTTP/live protocol, with no raw event cache. Each page is
|
|
4
7
|
* backpressured by durable owner commits; long requests never hold its queue. */
|
|
5
8
|
export class ProfileInboxFeed {
|
|
@@ -9,6 +12,8 @@ export class ProfileInboxFeed {
|
|
|
9
12
|
running;
|
|
10
13
|
liveTask;
|
|
11
14
|
timer;
|
|
15
|
+
lastLiveFrame = Number.NEGATIVE_INFINITY;
|
|
16
|
+
lastReconciliation = Number.NEGATIVE_INFINITY;
|
|
12
17
|
closed = false;
|
|
13
18
|
building;
|
|
14
19
|
constructor(options) {
|
|
@@ -43,7 +48,7 @@ export class ProfileInboxFeed {
|
|
|
43
48
|
}
|
|
44
49
|
async start() {
|
|
45
50
|
if (!this.timer)
|
|
46
|
-
this.timer = setInterval(() => { void this.tick().catch(error => this.report(error)); },
|
|
51
|
+
this.timer = setInterval(() => { void this.tick().catch(error => this.report(error)); }, checkIntervalMs);
|
|
47
52
|
await this.tick();
|
|
48
53
|
}
|
|
49
54
|
synchronize() {
|
|
@@ -53,7 +58,9 @@ export class ProfileInboxFeed {
|
|
|
53
58
|
return Promise.reject(Error("PROFILE_OWNER_UNAVAILABLE"));
|
|
54
59
|
if (this.running)
|
|
55
60
|
return this.running;
|
|
56
|
-
const task = this.catchUp().
|
|
61
|
+
const task = this.catchUp().then(() => {
|
|
62
|
+
this.lastReconciliation = performance.now();
|
|
63
|
+
}).catch(error => { this.progress("error"); throw error; });
|
|
57
64
|
this.running = task;
|
|
58
65
|
void task.finally(() => { if (this.running === task)
|
|
59
66
|
this.running = undefined; }).catch(() => { });
|
|
@@ -182,9 +189,14 @@ export class ProfileInboxFeed {
|
|
|
182
189
|
this.streamController?.abort();
|
|
183
190
|
return;
|
|
184
191
|
}
|
|
192
|
+
const now = performance.now();
|
|
193
|
+
if (this.liveTask && now - this.lastLiveFrame < liveFreshnessMs &&
|
|
194
|
+
now - this.lastReconciliation < reconciliationIntervalMs)
|
|
195
|
+
return;
|
|
185
196
|
await this.synchronize();
|
|
186
197
|
if (this.options.live === false || this.liveTask)
|
|
187
198
|
return;
|
|
199
|
+
this.lastLiveFrame = Number.NEGATIVE_INFINITY;
|
|
188
200
|
const task = this.listen().catch(error => { if (error?.name !== "AbortError")
|
|
189
201
|
this.report(error); });
|
|
190
202
|
this.liveTask = task;
|
|
@@ -230,6 +242,7 @@ export class ProfileInboxFeed {
|
|
|
230
242
|
}
|
|
231
243
|
this.validate(page, this.options.owner.current.epoch);
|
|
232
244
|
await this.commit(page.events);
|
|
245
|
+
this.lastLiveFrame = performance.now();
|
|
233
246
|
}
|
|
234
247
|
}
|
|
235
248
|
}
|
package/package.json
CHANGED