@pmate/chat-sdk 0.13.0-profile.8 → 0.14.0-seq.0
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 +57 -0
- package/lib/profile.d.ts +1 -1
- package/lib/profile.js +1 -1
- package/lib/runtime/profileChat.d.ts +7 -0
- package/lib/runtime/profileChat.js +105 -20
- package/lib/runtime/profileCommitQueue.js +3 -3
- package/lib/runtime/profileCoordinator.d.ts +25 -20
- package/lib/runtime/profileCoordinator.js +146 -128
- package/lib/runtime/profileDatabase.d.ts +6 -9
- package/lib/runtime/profileDatabase.js +10 -39
- package/lib/runtime/profileGenerationBuilder.d.ts +2 -3
- package/lib/runtime/profileGenerationBuilder.js +23 -23
- package/lib/runtime/profileInboxFeed.js +3 -2
- package/lib/runtime/profileLegacyInbox.js +2 -1
- package/lib/runtime/profileMemoryStore.d.ts +9 -3
- package/lib/runtime/profileMemoryStore.js +50 -10
- package/lib/runtime/profileOutboxDispatcher.js +4 -1
- package/lib/runtime/profileOwner.d.ts +2 -7
- package/lib/runtime/profileOwner.js +18 -46
- package/lib/runtime/profileProjection.d.ts +19 -1
- package/lib/runtime/profileProjection.js +139 -18
- package/lib/runtime/profileStoreTypes.d.ts +4 -11
- package/lib/runtime/profileWindows.d.ts +2 -0
- package/lib/runtime/profileWindows.js +13 -3
- package/lib/runtime/{profileReplica.d.ts → profileWorkerClient.d.ts} +9 -26
- package/lib/runtime/{profileReplica.js → profileWorkerClient.js} +46 -97
- package/lib/runtime/profileWorkerHost.d.ts +3 -6
- package/lib/runtime/profileWorkerHost.js +23 -30
- package/lib/runtime/readSync.d.ts +1 -1
- package/lib/runtime/readSync.js +10 -6
- package/lib/runtime/sourceCursor.d.ts +6 -0
- package/lib/runtime/sourceCursor.js +7 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -373,3 +373,60 @@ Empty ten-second checks and duplicate notifications do not open a projection
|
|
|
373
373
|
write transaction. Received receipt batches insert only new keys in one bulk
|
|
374
374
|
write. Own viewport read observations are coalesced over 100ms before their
|
|
375
375
|
pending intents become durable; callers resolve after commit.
|
|
376
|
+
|
|
377
|
+
## Profile Worker runtime (0.13 preview)
|
|
378
|
+
|
|
379
|
+
### Background
|
|
380
|
+
|
|
381
|
+
The Profile runtime prepares the full retained Inbox range once and exposes message windows from memory. Merry runs one application document: creating a distributed writer, lease and replica for every page is unnecessary and can block a healthy UI after a backgrounded WebView stops responding.
|
|
382
|
+
|
|
383
|
+
`ProfileCoordinator` now creates one Dedicated Worker for the active Profile and receives committed deltas over that Worker's ordered message port. `start()` is shared, `memory` retains its identity across Worker restarts, and `submit`, `synchronize`, `waitForCommand` and `voiceAttachment` delegate to the direct connection. Consumers must remove calls to the former `replica.repair()`; normal synchronization publishes its committed changes before its reply. `ProfileWorkerClient` replaces the former distributed `ProfileReplica` export.
|
|
384
|
+
|
|
385
|
+
There is no BroadcastChannel, delta journal, status poll, TTL lease, renewal or writer takeover in this runtime. A lifetime Web Lock excludes another document using the same Profile; the second gets `PROFILE_ALREADY_OPEN` and should ask the user to return to the original tab. This lock uses the previous writer lock name so an older lock-based client cannot race the upgrade. Supported browsers must provide Web Locks. Native page navigation stays inside the original document.
|
|
386
|
+
|
|
387
|
+
The per-Profile database upgrades to schema 2 by deleting only the obsolete `lease` record. Existing messages, windows, reading facts, generation progress, cursor and outbox remain. The serial commit queue still atomically persists changed records and the Inbox cursor before publication. Failed disk transactions retry after the existing ten-second interval. A revision conflict requires restarting from committed state rather than endlessly retrying a stale projection.
|
|
388
|
+
|
|
389
|
+
On a Worker error or command timeout, the coordinator terminates the old Worker before replacement. The replacement restores committed data into the same UI memory store. An interrupted command is replayed with its original IDs; a message committed before a lost reply remains one message. Waiting for remote delivery does not itself time out or repeatedly restart an offline Worker. Completed generation switches publish one prepared snapshot; routine updates send only their delta.
|
|
390
|
+
|
|
391
|
+
Tests cover v1 upgrade preservation, atomic writes, idle zero transactions, one Worker on concurrent startup, serial restart, crash after commit/before reply, immediate startup cancellation, generation switching, and memory-only reads/subscriptions. Native frame rate, real-account upgrade and server synchronization still require application acceptance.
|
|
392
|
+
|
|
393
|
+
### Projection v2 repair (0.13.0-profile.10)
|
|
394
|
+
|
|
395
|
+
An existing v1 projection remains committed while a new generation rebuilds from the retained Inbox range. It is marked `restoring`, so the application cannot treat an incomplete or obsolete projection as an empty ready conversation. The rebuild resumes its saved progress after interruption, validates complete message/window references and atomically switches the active generation. Incompatible unfinished generations are eligible for bounded cleanup; the active generation and current-version builds remain protected.
|
|
396
|
+
|
|
397
|
+
Thread assignment carries group controls and metadata, child discussions, reading sources, pending controls/receipts and local reading intents into the destination Team. Later source events still resolve into that canonical Thread. Organization retains its assigned agent; reply counts remain independent of agent ownership. Confirmed and pending reading sources and per-message played/preserved facts survive generation reconciliation, as do durable pending sends.
|
|
398
|
+
|
|
399
|
+
The upgrade regression starts with an obsolete cached projection containing inaccessible discussion children, a locally played voice and a failed outgoing message. It interrupts the rebuild with HTTP 503, reopens the owner, resumes the same generation and verifies group/discussion metadata, reading and the exact durable outgoing message without clearing any store. Full SDK suite: 766 passed, one production-only test skipped.
|
|
400
|
+
|
|
401
|
+
Duplicate Inbox events, registrations and already-read observations are rejected as no-op batches before opening an IndexedDB write transaction; queue and store tests verify zero transactions as well as unchanged revisions.
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
### Profile disposal (0.13.0-profile.11)
|
|
405
|
+
|
|
406
|
+
Final `ProfileCoordinator.close()` releases its UI memory entities, page caches,
|
|
407
|
+
reading indexes and subscriptions after pending startup/recovery settles. It also
|
|
408
|
+
terminates the Worker. Previously, retaining a closed coordinator retained its
|
|
409
|
+
full UI projection. Already published message/page objects remain unchanged.
|
|
410
|
+
Worker recovery keeps the same prepared UI store until its replacement snapshot
|
|
411
|
+
is validated; it must not call the final disposal path. Direct memory-store users
|
|
412
|
+
may call `dispose()` when permanently discarding that Profile. This release does
|
|
413
|
+
not claim that process RSS immediately falls or resolve all recovery peak memory.
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
### Sparse Window paging (0.13.0-profile.12)
|
|
417
|
+
|
|
418
|
+
Organizing messages may leave many empty sealed Windows. Their identities and
|
|
419
|
+
historical routing boundaries remain durable, while the in-memory page directory
|
|
420
|
+
now indexes only nonempty blocks. Reading a small page no longer walks intervening
|
|
421
|
+
empty block contents. A 10,002-Window regression with only two populated blocks
|
|
422
|
+
checks older/newer anchors, retained block identities and forked directories.
|
|
423
|
+
No storage schema or Window merge behavior changes.
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
### Empty Window display directory (0.13.0-profile.13)
|
|
427
|
+
|
|
428
|
+
Prepared `getWindowIds()` now returns only nonempty display blocks. Durable empty
|
|
429
|
+
sealed Windows still retain their identities and remain directly readable for
|
|
430
|
+
historical routing; they no longer consume load-older steps. Empty/refilled
|
|
431
|
+
transitions notify Window-list subscribers. Message-only changes retain the same
|
|
432
|
+
published ID array, and previously published arrays stay unchanged.
|
package/lib/profile.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { ProfileDatabase, profileDatabaseName } from "./runtime/profileDatabase.js";
|
|
2
2
|
export { ProfileOwner } from "./runtime/profileOwner.js";
|
|
3
3
|
export { ProfileMemoryStore, PROFILE_PROTOCOL_VERSION, PROFILE_PROJECTION_VERSION } from "./runtime/profileMemoryStore.js";
|
|
4
|
-
export {
|
|
4
|
+
export { ProfileWorkerClient, serveProfileWorker } from "./runtime/profileWorkerClient.js";
|
|
5
5
|
export { connectProfileWorker, installProfileWorker, profileChannelName } from "./runtime/profileWorkerHost.js";
|
|
6
6
|
export { profileDiscussionId } from "./runtime/profileProjection.js";
|
|
7
7
|
export { ProfileCoordinator } from "./runtime/profileCoordinator.js";
|
package/lib/profile.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { ProfileDatabase, profileDatabaseName } from "./runtime/profileDatabase.js";
|
|
2
2
|
export { ProfileOwner } from "./runtime/profileOwner.js";
|
|
3
3
|
export { ProfileMemoryStore, PROFILE_PROTOCOL_VERSION, PROFILE_PROJECTION_VERSION } from "./runtime/profileMemoryStore.js";
|
|
4
|
-
export {
|
|
4
|
+
export { ProfileWorkerClient, serveProfileWorker } from "./runtime/profileWorkerClient.js";
|
|
5
5
|
export { connectProfileWorker, installProfileWorker, profileChannelName } from "./runtime/profileWorkerHost.js";
|
|
6
6
|
export { profileDiscussionId } from "./runtime/profileProjection.js";
|
|
7
7
|
export { ProfileCoordinator } from "./runtime/profileCoordinator.js";
|
|
@@ -5,6 +5,7 @@ import { type ProfileOperation } from "./profileProjection.js";
|
|
|
5
5
|
import type { ProfileIdentity } from "./profileStoreTypes.js";
|
|
6
6
|
import { type ChatRuntimeMessage } from "./protocol.js";
|
|
7
7
|
import type { OnlineReachEvent } from "./reach.js";
|
|
8
|
+
import { type SocialGroup } from "./socialReadClient.js";
|
|
8
9
|
export type ProfileChatHost = {
|
|
9
10
|
identity: ProfileIdentity;
|
|
10
11
|
memory: ProfileMemoryStore;
|
|
@@ -13,6 +14,7 @@ export type ProfileChatHost = {
|
|
|
13
14
|
synchronize(): Promise<void>;
|
|
14
15
|
waitForCommand(id: string): Promise<void>;
|
|
15
16
|
voiceAttachment(id: string): Promise<Blob | null>;
|
|
17
|
+
readGroup(groupId: string, teamId: string): Promise<SocialGroup>;
|
|
16
18
|
};
|
|
17
19
|
export declare function getProfileChatRuntime(chat: Chat): ProfileChat;
|
|
18
20
|
export declare function createProfileChat(host: ProfileChatHost, teamId: string): Chat;
|
|
@@ -24,6 +26,8 @@ export declare class ProfileChat implements Chat {
|
|
|
24
26
|
readonly host: ProfileChatHost;
|
|
25
27
|
readonly teamId: string;
|
|
26
28
|
private discussion?;
|
|
29
|
+
private groupRequests;
|
|
30
|
+
private groupChecks;
|
|
27
31
|
private views;
|
|
28
32
|
private preparedInputs;
|
|
29
33
|
private limits;
|
|
@@ -78,6 +82,7 @@ export declare class ProfileChat implements Chat {
|
|
|
78
82
|
}[];
|
|
79
83
|
}>;
|
|
80
84
|
sendPrepared(threadId: string, wire: ChatRuntimeMessage, options?: SendOptions, voiceBlob?: Blob): Promise<ChatRuntimeMessage>;
|
|
85
|
+
private persistPrepared;
|
|
81
86
|
sendMessage(id: string, content: OutgoingContent, options?: SendOptions): Promise<SentMessage>;
|
|
82
87
|
retryMessage(messageId: string): Promise<{
|
|
83
88
|
id: string;
|
|
@@ -101,6 +106,8 @@ export declare class ProfileChat implements Chat {
|
|
|
101
106
|
release: () => void;
|
|
102
107
|
}>;
|
|
103
108
|
getGroup(id: string, options?: ReadOptions): Promise<ChatGroup>;
|
|
109
|
+
private loadGroup;
|
|
110
|
+
private refreshChangedGroups;
|
|
104
111
|
refreshGroup(id: string, options?: ReadOptions): Promise<ChatGroup>;
|
|
105
112
|
private waitGroup;
|
|
106
113
|
createGroup(input: {
|
|
@@ -2,10 +2,11 @@ import { ChatError } from "../chatError.js";
|
|
|
2
2
|
import { registerChatStore } from "../framework.js";
|
|
3
3
|
import { profileDiscussionId } from "./profileProjection.js";
|
|
4
4
|
import { createRuntimeMsg } from "./protocol.js";
|
|
5
|
-
import { outgoingContent } from "./outgoingContent.js";
|
|
5
|
+
import { outgoingContent, validMessageIdentifier } from "./outgoingContent.js";
|
|
6
6
|
import { dmThreadId, groupThreadId } from "./thread.js";
|
|
7
7
|
import { createUniqueGroup } from "./groupIdentity.js";
|
|
8
8
|
import { messageThreadRoot } from "./messageThread.js";
|
|
9
|
+
import { SocialReadError } from "./socialReadClient.js";
|
|
9
10
|
import { scopedGroupDenial } from "./groupDenial.js";
|
|
10
11
|
const sessions = new WeakMap();
|
|
11
12
|
export function getProfileChatRuntime(chat) {
|
|
@@ -34,6 +35,8 @@ export class ProfileChat {
|
|
|
34
35
|
host;
|
|
35
36
|
teamId;
|
|
36
37
|
discussion;
|
|
38
|
+
groupRequests = new Map();
|
|
39
|
+
groupChecks = new Map();
|
|
37
40
|
views = new Map();
|
|
38
41
|
preparedInputs = new Map();
|
|
39
42
|
limits = new Map();
|
|
@@ -53,7 +56,7 @@ export class ProfileChat {
|
|
|
53
56
|
? this.subscribeThread(target, () => listener()) : this.subscribeChat(() => target()));
|
|
54
57
|
registerChatStore(this, { getSnapshot: ((id) => id === undefined ? this.summary : this.snapshot(id)),
|
|
55
58
|
subscribeThread: (id, listener) => this.subscribeThread(id, () => listener()), subscribeChanges });
|
|
56
|
-
this.offList = host.memory.subscribeThreadList(() => this.prepareSummary());
|
|
59
|
+
this.offList = host.memory.subscribeThreadList(() => { this.prepareSummary(); this.refreshChangedGroups(); });
|
|
57
60
|
this.prepareSummary();
|
|
58
61
|
}
|
|
59
62
|
assertOpen() { if (this.closed)
|
|
@@ -76,7 +79,7 @@ export class ProfileChat {
|
|
|
76
79
|
assertAccessible(id) { this.assertOpen(); const error = this.accessError(id); if (error)
|
|
77
80
|
throw error; }
|
|
78
81
|
group(thread) {
|
|
79
|
-
const group = thread?.group;
|
|
82
|
+
const group = thread?.internal?.groupSource === "api" ? thread.group : undefined;
|
|
80
83
|
if (!group)
|
|
81
84
|
return;
|
|
82
85
|
const base = { groupId: group.groupId, teamId: group.teamId ?? this.teamId, ownerId: group.ownerId, revision: group.revision };
|
|
@@ -240,6 +243,16 @@ export class ProfileChat {
|
|
|
240
243
|
}) };
|
|
241
244
|
}
|
|
242
245
|
async sendPrepared(threadId, wire, options = {}, voiceBlob) {
|
|
246
|
+
const parent = this.parent(threadId);
|
|
247
|
+
if (parent?.kind === "group" && wire.body.kind !== "group") {
|
|
248
|
+
const group = await this.getGroup(threadId);
|
|
249
|
+
if (group.status !== "active")
|
|
250
|
+
throw new ChatError("access-denied", "Group dissolved");
|
|
251
|
+
wire = { ...wire, recipients: [...group.memberIds] };
|
|
252
|
+
}
|
|
253
|
+
return this.persistPrepared(threadId, wire, options, voiceBlob);
|
|
254
|
+
}
|
|
255
|
+
async persistPrepared(threadId, wire, options = {}, voiceBlob) {
|
|
243
256
|
this.assertAccessible(threadId);
|
|
244
257
|
if (!this.discussion && this.thread(threadId)?.kind === "discussion")
|
|
245
258
|
throw new ChatError("invalid-input", "Use a discussion session to send replies");
|
|
@@ -260,10 +273,13 @@ export class ProfileChat {
|
|
|
260
273
|
throw new ChatError("unavailable", "Conversation is not prepared");
|
|
261
274
|
const kind = parent.kind === "dm" ? "dm" : "group", identity = this.host.identity;
|
|
262
275
|
const expectedId = kind === "group" ? groupThreadId(identity.appId, parent.internal.targetId, this.teamId) : dmThreadId(identity.appId, identity.profileId, parent.internal.targetId, this.teamId);
|
|
263
|
-
const
|
|
276
|
+
const group = kind === "group" ? await this.getGroup(id) : undefined;
|
|
277
|
+
if (group?.status === "dissolved")
|
|
278
|
+
throw new ChatError("access-denied", "Group dissolved");
|
|
279
|
+
const input = outgoingContent({ ...identity, teamId: this.teamId }, { id: expectedId, kind, targetId: parent.internal.targetId, teamId: this.teamId, memberIds: group?.status === "active" ? group.memberIds : undefined }, { ...content, ...(this.discussion ? { threadRootId: this.discussion.rootId } : {}) });
|
|
264
280
|
const wire = createRuntimeMsg(identity.profileId, input.to, 1, input.body);
|
|
265
281
|
wire.recipients = input.recipients;
|
|
266
|
-
await this.
|
|
282
|
+
await this.persistPrepared(id, wire, options, input.voiceBlob);
|
|
267
283
|
return { id: wire.hash, timestamp: wire.t };
|
|
268
284
|
}
|
|
269
285
|
async retryMessage(messageId) {
|
|
@@ -315,22 +331,91 @@ export class ProfileChat {
|
|
|
315
331
|
const objectUrl = URL.createObjectURL(blob);
|
|
316
332
|
return { url: objectUrl, release: () => URL.revokeObjectURL(objectUrl) };
|
|
317
333
|
}
|
|
318
|
-
async getGroup(id, options = {}) {
|
|
319
|
-
|
|
320
|
-
|
|
334
|
+
async getGroup(id, options = {}) {
|
|
335
|
+
this.assertOpen();
|
|
336
|
+
options.signal?.throwIfAborted();
|
|
337
|
+
const parent = this.parent(id), access = this.accessError(id);
|
|
338
|
+
// A previous group projection/denial can be repaired by a fresh authorized read.
|
|
339
|
+
// Team revocation and foreign scopes still fail before the request.
|
|
340
|
+
if (!this.host.memory.isTeamAvailable(this.teamId) || parent?.teamId !== this.teamId || parent?.kind !== "group" || !parent.internal?.targetId) {
|
|
341
|
+
if (access)
|
|
342
|
+
throw access;
|
|
343
|
+
throw new ChatError("unavailable", "Conversation is not prepared");
|
|
344
|
+
}
|
|
345
|
+
const key = parent.threadId;
|
|
346
|
+
let pending = this.groupRequests.get(key);
|
|
347
|
+
if (!pending) {
|
|
348
|
+
this.groupChecks.set(key, parent.internal.groupControlRevision ?? 0);
|
|
349
|
+
pending = this.loadGroup(key, parent.internal.targetId);
|
|
350
|
+
this.groupRequests.set(key, pending);
|
|
351
|
+
void pending.finally(() => { this.groupRequests.delete(key); if (!this.closed)
|
|
352
|
+
this.refreshChangedGroups(); }).catch(() => { });
|
|
353
|
+
}
|
|
354
|
+
const group = await pending;
|
|
355
|
+
options.signal?.throwIfAborted();
|
|
356
|
+
this.assertOpen();
|
|
357
|
+
return group;
|
|
358
|
+
}
|
|
359
|
+
async loadGroup(id, groupId, attempt = 0) {
|
|
360
|
+
const expectedAccessRevision = this.host.memory.getAccessRevision();
|
|
361
|
+
const expectedControlRevision = this.host.memory.getThread(id)?.internal?.groupControlRevision ?? 0;
|
|
362
|
+
this.groupChecks.set(id, expectedControlRevision);
|
|
363
|
+
let value;
|
|
364
|
+
try {
|
|
365
|
+
value = await this.host.readGroup(groupId, this.teamId);
|
|
366
|
+
}
|
|
367
|
+
catch (error) {
|
|
368
|
+
if (error instanceof SocialReadError && error.status === 403) {
|
|
369
|
+
this.assertOpen();
|
|
370
|
+
await this.host.submit({ type: "groupDenied", threadId: id, expectedAccessRevision }, true);
|
|
371
|
+
throw scopedGroupDenial(new ChatError("access-denied", "Group access denied", { threadId: id, status: 403 }));
|
|
372
|
+
}
|
|
373
|
+
throw error;
|
|
374
|
+
}
|
|
375
|
+
this.assertOpen();
|
|
376
|
+
if (!value || value.appId !== this.host.identity.appId || value.teamId !== this.teamId || value.groupId !== groupId ||
|
|
377
|
+
!validMessageIdentifier(value.ownerId) || !validMessageIdentifier(value.revision) || !Number.isSafeInteger(value.versionNumber) || value.versionNumber < 1 ||
|
|
378
|
+
!["active", "dissolved"].includes(value.status ?? ""))
|
|
379
|
+
throw Error("INVALID_GROUP_METADATA");
|
|
380
|
+
if (value.status === "active" && (!Array.isArray(value.members) || !value.members.length || value.members.length > 256 ||
|
|
381
|
+
!value.members.every(validMessageIdentifier) || !value.members.includes(value.ownerId) || !value.members.includes(this.host.identity.profileId) ||
|
|
382
|
+
typeof value.title !== "string" || value.avatar != null && typeof value.avatar !== "string"))
|
|
383
|
+
throw Error("INVALID_GROUP_METADATA");
|
|
384
|
+
try {
|
|
385
|
+
await this.host.submit({ type: "groupSnapshot", threadId: id, group: value, expectedAccessRevision, expectedControlRevision }, true);
|
|
386
|
+
}
|
|
387
|
+
catch (error) {
|
|
388
|
+
if (error?.message === "GROUP_METADATA_STALE" && attempt < 2)
|
|
389
|
+
return this.loadGroup(id, groupId, attempt + 1);
|
|
390
|
+
throw error;
|
|
391
|
+
}
|
|
392
|
+
this.assertOpen();
|
|
393
|
+
const group = this.group(this.host.memory.getThread(id));
|
|
394
|
+
if (!group)
|
|
395
|
+
throw new ChatError("unavailable", "Group is not prepared");
|
|
396
|
+
// Directory callers may read the prepared store without a subscription.
|
|
397
|
+
this.prepare(id);
|
|
398
|
+
return group;
|
|
399
|
+
}
|
|
400
|
+
refreshChangedGroups() {
|
|
401
|
+
for (const [id, revision] of this.groupChecks) {
|
|
402
|
+
const thread = this.host.memory.getThread(id);
|
|
403
|
+
if (thread && (thread.internal?.groupControlRevision ?? 0) !== revision && !this.groupRequests.has(id))
|
|
404
|
+
void this.getGroup(id).catch(() => { });
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
async refreshGroup(id, options = {}) {
|
|
408
|
+
const pending = this.groupRequests.get(this.parent(id)?.threadId ?? id);
|
|
409
|
+
if (pending)
|
|
410
|
+
await pending.catch(() => { });
|
|
411
|
+
return this.getGroup(id, options);
|
|
412
|
+
}
|
|
321
413
|
async waitGroup(id, previous) {
|
|
322
|
-
|
|
323
|
-
const
|
|
324
|
-
if (
|
|
325
|
-
|
|
326
|
-
return
|
|
327
|
-
const timer = setTimeout(() => { off(); reject(new ChatError("unavailable", "Waiting for group confirmation")); }, 30000);
|
|
328
|
-
const off = this.host.memory.subscribeThread(id, () => { const group = get(); if (group) {
|
|
329
|
-
clearTimeout(timer);
|
|
330
|
-
off();
|
|
331
|
-
resolve(group);
|
|
332
|
-
} });
|
|
333
|
-
});
|
|
414
|
+
// Delivered commands have an accepted index cursor; the API is the authority.
|
|
415
|
+
const group = await this.refreshGroup(id);
|
|
416
|
+
if (previous !== undefined && group.revision === previous)
|
|
417
|
+
throw new ChatError("unavailable", "Waiting for group confirmation");
|
|
418
|
+
return group;
|
|
334
419
|
}
|
|
335
420
|
async createGroup(input) {
|
|
336
421
|
return createUniqueGroup(input.groupId, async (groupId) => {
|
|
@@ -84,9 +84,9 @@ export class ProfileCommitQueue {
|
|
|
84
84
|
entry.resolve(); });
|
|
85
85
|
}
|
|
86
86
|
catch (error) {
|
|
87
|
-
if (error?.message
|
|
88
|
-
//
|
|
89
|
-
//
|
|
87
|
+
if (["PROFILE_REVISION_CONFLICT", "PROFILE_GENERATION_MISMATCH"].includes(error?.message)) {
|
|
88
|
+
// A stale projection cannot become valid by retrying the same batch.
|
|
89
|
+
// Restart the Worker from its last committed database state.
|
|
90
90
|
this.closed = true;
|
|
91
91
|
clearTimeout(this.timer);
|
|
92
92
|
const pending = this.entries.splice(0);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ProfileMemoryStore } from "./profileMemoryStore.js";
|
|
2
|
+
import { ProfileWorkerClient, type ProfileMessagePort } from "./profileWorkerClient.js";
|
|
2
3
|
import { type ProfileWorkerConfiguration } from "./profileWorkerHost.js";
|
|
4
|
+
import { type SocialGroup } from "./socialReadClient.js";
|
|
3
5
|
import type { ProfileOperation } from "./profileProjection.js";
|
|
4
6
|
type WorkerHandle = ProfileMessagePort & {
|
|
5
7
|
terminate(): void;
|
|
@@ -7,40 +9,43 @@ type WorkerHandle = ProfileMessagePort & {
|
|
|
7
9
|
export type ProfileCoordinatorOptions = {
|
|
8
10
|
configuration: ProfileWorkerConfiguration;
|
|
9
11
|
createWorker: () => WorkerHandle;
|
|
10
|
-
channel?: (name: string) => ProfileMessagePort & {
|
|
11
|
-
close(): void;
|
|
12
|
-
};
|
|
13
12
|
onError?: (error: unknown) => void;
|
|
14
13
|
onProgress?: (progress: unknown) => void;
|
|
14
|
+
fetch?: typeof fetch;
|
|
15
15
|
requestTimeoutMs?: number;
|
|
16
|
-
retryMs?: number;
|
|
17
16
|
};
|
|
18
|
-
/**
|
|
19
|
-
*
|
|
17
|
+
/** One application document, one dedicated Worker and one stable UI memory store.
|
|
18
|
+
* A failed Worker is terminated before its replacement is created. */
|
|
20
19
|
export declare class ProfileCoordinator {
|
|
21
20
|
private options;
|
|
22
|
-
readonly
|
|
23
|
-
private channel;
|
|
21
|
+
readonly memory: ProfileMemoryStore;
|
|
24
22
|
private worker?;
|
|
23
|
+
private connection?;
|
|
25
24
|
private host?;
|
|
26
|
-
private acquiring?;
|
|
27
|
-
private timer?;
|
|
28
|
-
private closed;
|
|
29
|
-
private needsOwner;
|
|
30
25
|
private starting?;
|
|
31
|
-
private
|
|
26
|
+
private restarting?;
|
|
27
|
+
private openingAbort?;
|
|
28
|
+
private closed;
|
|
29
|
+
private groupRequests;
|
|
30
|
+
private groupAbort;
|
|
32
31
|
get identity(): import("./inboxStore.js").InboxScope;
|
|
33
|
-
get
|
|
34
|
-
submit(operation: ProfileOperation, immediate?: boolean): Promise<void>;
|
|
35
|
-
synchronize(): Promise<void>;
|
|
36
|
-
waitForCommand(id: string): Promise<void>;
|
|
37
|
-
voiceAttachment(id: string): Promise<Blob | null>;
|
|
32
|
+
get client(): ProfileWorkerClient;
|
|
38
33
|
constructor(options: ProfileCoordinatorOptions);
|
|
39
34
|
private report;
|
|
40
35
|
private workerMessage;
|
|
36
|
+
private workerFailed;
|
|
37
|
+
private listenFailure;
|
|
41
38
|
start(): Promise<void>;
|
|
42
39
|
private initialize;
|
|
43
|
-
private
|
|
40
|
+
private disposeWorker;
|
|
41
|
+
restart(): Promise<void>;
|
|
42
|
+
private invoke;
|
|
43
|
+
submit(operation: ProfileOperation, immediate?: boolean): Promise<void>;
|
|
44
|
+
synchronize(): Promise<void>;
|
|
45
|
+
waitForCommand(id: string): Promise<void>;
|
|
46
|
+
voiceAttachment(id: string): Promise<Blob | null>;
|
|
47
|
+
/** Current group authority comes from Hub, independently of Inbox history. */
|
|
48
|
+
readGroup(groupId: string, teamId: string): Promise<SocialGroup>;
|
|
44
49
|
updateToken(token: string): Promise<void>;
|
|
45
50
|
close(): Promise<void>;
|
|
46
51
|
}
|